Merge branch 'master' into gh-1175

pull/1176/head
Rich Harris 8 years ago
commit e95a0b60a9

@ -1,5 +1,19 @@
# Svelte changelog
## 1.56.0
* Internal refactor ([#1122](https://github.com/sveltejs/svelte/issues/1122))
* Use correct context for component events ([#1184](https://github.com/sveltejs/svelte/issues/1184))
* Allow observing `$foo` in dev mode ([#1181](https://github.com/sveltejs/svelte/issues/1181))
* Handle dynamic data in default slot ([#1144](https://github.com/sveltejs/svelte/issues/1144))
## 1.55.1
* Fix cancellation of store `onchange` handlers ([#1177](https://github.com/sveltejs/svelte/issues/1177))
* Write `["default"]` instead of `.default` in legacy mode ([#1166](https://github.com/sveltejs/svelte/issues/1166))
* Upgrade Acorn ([#1182](https://github.com/sveltejs/svelte/pull/1182))
* Don't warn about capitalisation if `options.name` begins with non-alphabetical character ([#1179](https://github.com/sveltejs/svelte/pull/1179))
## 1.55.0
* Add `immutable` compiler option for Svelte and runtime option for `Store` ([#1146](https://github.com/sveltejs/svelte/issues/1146))

@ -21,6 +21,7 @@ This is the Svelte compiler, which is primarily intended for authors of tooling
* [svelte-hot-loader](https://github.com/ekhaled/svelte-hot-loader) Webpack loader addon to support HMR
* [meteor-svelte](https://github.com/klaussner/meteor-svelte) Meteor build plugin
* [sveltejs-brunch](https://github.com/StarpTech/sveltejs-brunch) Brunch build plugin
* [svelte-dev-store](https://github.com/GarethOates/svelte-dev-store) - Use Redux tools to visualise Svelte store
* More to come!

@ -1,6 +1,6 @@
{
"name": "svelte",
"version": "1.55.0",
"version": "1.56.0",
"description": "The magical disappearing UI framework",
"main": "compiler/svelte.js",
"files": [
@ -45,7 +45,7 @@
"devDependencies": {
"@types/mocha": "^2.2.41",
"@types/node": "^8.0.17",
"acorn": "^5.1.1",
"acorn": "^5.4.1",
"acorn-dynamic-import": "^2.0.2",
"chalk": "^2.0.1",
"codecov": "^2.2.0",

@ -7,28 +7,11 @@ import typescript from 'rollup-plugin-typescript';
import buble from 'rollup-plugin-buble';
import pkg from './package.json';
const src = path.resolve('src');
export default [
/* compiler/svelte.js */
{
input: 'src/index.ts',
plugins: [
{
resolveId(importee, importer) {
// bit of a hack — TypeScript only really works if it can resolve imports,
// but they misguidedly chose to reject imports with file extensions. This
// means we need to resolve them here
if (
importer &&
importer.startsWith(src) &&
importee[0] === '.' &&
path.extname(importee) === ''
) {
return path.resolve(path.dirname(importer), `${importee}.ts`);
}
}
},
replace({
__VERSION__: pkg.version
}),

@ -373,8 +373,8 @@ export default class Generator {
return alias;
}
getUniqueNameMaker(params: string[]) {
const localUsedNames = new Set(params);
getUniqueNameMaker() {
const localUsedNames = new Set();
function add(name: string) {
localUsedNames.add(name);

@ -17,7 +17,6 @@ export interface BlockOptions {
contextTypes?: Map<string, string>;
indexes?: Map<string, string>;
changeableIndexes?: Map<string, boolean>;
params?: string[];
indexNames?: Map<string, string>;
listNames?: Map<string, string>;
indexName?: string;
@ -41,7 +40,6 @@ export default class Block {
indexes: Map<string, string>;
changeableIndexes: Map<string, boolean>;
dependencies: Set<string>;
params: string[];
indexNames: Map<string, string>;
listNames: Map<string, string>;
indexName: string;
@ -90,10 +88,10 @@ export default class Block {
this.changeableIndexes = options.changeableIndexes;
this.dependencies = new Set();
this.params = options.params;
this.indexNames = options.indexNames;
this.listNames = options.listNames;
this.indexName = options.indexName;
this.listName = options.listName;
this.builders = {
@ -116,7 +114,7 @@ export default class Block {
this.aliases = new Map();
this.variables = new Map();
this.getUniqueName = this.generator.getUniqueNameMaker(options.params);
this.getUniqueName = this.generator.getUniqueNameMaker();
this.hasUpdateMethod = false; // determined later
}
@ -191,6 +189,29 @@ export default class Block {
this.builders.mount.addLine(`${this.autofocus}.focus();`);
}
// TODO `this.contexts` is possibly redundant post-#1122
const initializers = [];
const updaters = [];
this.contexts.forEach((alias, name) => {
// TODO only the ones that are actually used in this block...
const assignment = `${alias} = state.${name}`;
initializers.push(assignment);
updaters.push(`${assignment};`);
this.hasUpdateMethod = true;
});
this.indexNames.forEach((alias, name) => {
// TODO only the ones that are actually used in this block...
const assignment = `${alias} = state.${alias}`; // TODO this is wrong!!!
initializers.push(assignment);
updaters.push(`${assignment};`);
this.hasUpdateMethod = true;
});
// minor hack we need to ensure that any {{{triples}}} are detached first
this.builders.unmount.addBlockAtStart(this.builders.detachRaw.toString());
@ -250,11 +271,12 @@ export default class Block {
}
if (this.hasUpdateMethod) {
if (this.builders.update.isEmpty()) {
if (this.builders.update.isEmpty() && updaters.length === 0) {
properties.addBlock(`p: @noop,`);
} else {
properties.addBlock(deindent`
p: function update(changed, ${this.params.join(', ')}) {
p: function update(changed, state) {
${updaters}
${this.builders.update}
},
`);
@ -328,7 +350,9 @@ export default class Block {
return deindent`
${this.comment && `// ${escape(this.comment)}`}
function ${this.name}(${this.params.join(', ')}, #component${this.key ? `, ${localKey}` : ''}) {
function ${this.name}(#component${this.key ? `, ${localKey}` : ''}, state) {
${initializers.length > 0 &&
`var ${initializers.join(', ')};`}
${this.variables.size > 0 &&
`var ${Array.from(this.variables.keys())
.map(key => {

@ -49,8 +49,8 @@ export class DomGenerator extends Generator {
this.metaBindings = [];
}
getUniqueNameMaker(params: string[]) {
const localUsedNames = new Set(params);
getUniqueNameMaker() {
const localUsedNames = new Set();
function add(name: string) {
localUsedNames.add(name);
@ -257,7 +257,7 @@ export default function dom(
${generator.slots.size && `this.slots = {};`}
this._fragment = @create_main_fragment(this._state, this);
this._fragment = @create_main_fragment(this, this._state);
${(templateProperties.oncreate) && deindent`
this.root._oncreate.push(_oncreate);

@ -35,22 +35,19 @@ export default class AwaitBlock extends Node {
].forEach(([status, arg]) => {
const child = this[status];
const context = block.getUniqueName(arg || '_'); // TODO can we remove the extra param from pending blocks?
const contexts = new Map(block.contexts);
contexts.set(arg, context);
const contextTypes = new Map(block.contextTypes);
contextTypes.set(arg, status);
child.block = block.child({
comment: createDebuggingComment(child, this.generator),
name: this.generator.getUniqueName(`create_${status}_block`),
params: block.params.concat(context),
context,
contexts,
contextTypes
contexts: new Map(block.contexts),
contextTypes: new Map(block.contextTypes)
});
if (arg) {
child.block.context = arg;
child.block.contexts.set(arg, arg); // TODO should be using getUniqueName
child.block.contextTypes.set(arg, status);
}
child.initChildren(child.block, stripWhitespace, nextSibling);
this.generator.blocks.push(child.block);
@ -75,8 +72,6 @@ export default class AwaitBlock extends Node {
const anchor = this.getOrCreateAnchor(block, parentNode, parentNodes);
const updateMountNode = this.getUpdateMountNode(anchor);
const params = block.params.join(', ');
block.contextualise(this.expression);
const { snippet } = this.metadata;
@ -106,11 +101,11 @@ export default class AwaitBlock extends Node {
// but it's probably not worth it
block.builders.init.addBlock(deindent`
function ${replace_await_block}(${token}, type, ${value}, ${params}) {
function ${replace_await_block}(${token}, type, state) {
if (${token} !== ${await_token}) return;
var ${old_block} = ${await_block};
${await_block} = (${await_block_type} = type)(${params}, ${resolved} = ${value}, #component);
${await_block} = type && (${await_block_type} = type)(#component, state);
if (${old_block}) {
${old_block}.u();
@ -122,33 +117,43 @@ export default class AwaitBlock extends Node {
}
}
function ${handle_promise}(${promise}, ${params}) {
function ${handle_promise}(${promise}, state) {
var ${token} = ${await_token} = {};
if (@isPromise(${promise})) {
${promise}.then(function(${value}) {
${this.then.block.context ? deindent`
var state = #component.get();
${replace_await_block}(${token}, ${create_then_block}, ${value}, ${params});
${resolved} = { ${this.then.block.context}: ${value} };
${replace_await_block}(${token}, ${create_then_block}, @assign({}, state, ${resolved}));
` : deindent`
${replace_await_block}(${token}, null, null);
`}
}, function (${error}) {
${this.catch.block.context ? deindent`
var state = #component.get();
${replace_await_block}(${token}, ${create_catch_block}, ${error}, ${params});
${resolved} = { ${this.catch.block.context}: ${error} };
${replace_await_block}(${token}, ${create_catch_block}, @assign({}, state, ${resolved}));
` : deindent`
${replace_await_block}(${token}, null, null);
`}
});
// if we previously had a then/catch block, destroy it
if (${await_block_type} !== ${create_pending_block}) {
${replace_await_block}(${token}, ${create_pending_block}, null, ${params});
${replace_await_block}(${token}, ${create_pending_block}, state);
return true;
}
} else {
${resolved} = ${promise};
${resolved} = { ${this.then.block.context}: ${promise} };
if (${await_block_type} !== ${create_then_block}) {
${replace_await_block}(${token}, ${create_then_block}, ${resolved}, ${params});
${replace_await_block}(${token}, ${create_then_block}, @assign({}, state, ${resolved}));
return true;
}
}
}
${handle_promise}(${promise} = ${snippet}, ${params});
${handle_promise}(${promise} = ${snippet}, state);
`);
block.builders.create.addBlock(deindent`
@ -177,7 +182,7 @@ export default class AwaitBlock extends Node {
conditions.push(
`${promise} !== (${promise} = ${snippet})`,
`${handle_promise}(${promise}, ${params})`
`${handle_promise}(${promise}, state)`
);
if (this.pending.block.hasUpdateMethod) {
@ -185,7 +190,7 @@ export default class AwaitBlock extends Node {
if (${conditions.join(' && ')}) {
// nothing
} else {
${await_block}.p(changed, ${params}, ${resolved});
${await_block}.p(changed, @assign({}, state, ${resolved}));
}
`);
} else {

@ -5,10 +5,17 @@ import CodeBuilder from '../../utils/CodeBuilder';
import getTailSnippet from '../../utils/getTailSnippet';
import getObject from '../../utils/getObject';
import getExpressionPrecedence from '../../utils/getExpressionPrecedence';
import isValidIdentifier from '../../utils/isValidIdentifier';
import reservedNames from '../../utils/reservedNames';
import Node from './shared/Node';
import Block from '../dom/Block';
import Attribute from './Attribute';
function quoteIfNecessary(name, legacy) {
if (!isValidIdentifier || (legacy && reservedNames.has(name))) return `"${name}"`;
return name;
}
export default class Component extends Node {
type: 'Component';
name: string;
@ -71,17 +78,16 @@ export default class Component extends Node {
const componentInitProperties = [`root: #component.root`];
if (this.children.length > 0) {
const slots = Array.from(this._slots).map(name => `${name}: @createFragment()`);
const slots = Array.from(this._slots).map(name => `${quoteIfNecessary(name, generator.legacy)}: @createFragment()`);
componentInitProperties.push(`slots: { ${slots.join(', ')} }`);
this.children.forEach((child: Node) => {
child.build(block, `${this.var}._slotted.default`, 'nodes');
child.build(block, `${this.var}._slotted${generator.legacy ? `["default"]` : `.default`}`, 'nodes');
});
}
const allContexts = new Set();
const statements: string[] = [];
const name_context = block.getUniqueName(`${name}_context`);
let name_updating: string;
let name_initial_data: string;
@ -97,7 +103,7 @@ export default class Component extends Node {
const eventHandlers = this.attributes
.filter((a: Node) => a.type === 'EventHandler')
.map(a => mungeEventHandler(generator, this, a, block, name_context, allContexts));
.map(a => mungeEventHandler(generator, this, a, block, allContexts));
const ref = this.attributes.find((a: Node) => a.type === 'Ref');
if (ref) generator.usesRefs = true;
@ -156,8 +162,8 @@ export default class Component extends Node {
const tail = binding.value.type === 'MemberExpression' ? getTailSnippet(binding.value) : '';
setFromChild = deindent`
var list = ${name_context}.${block.listNames.get(key)};
var index = ${name_context}.${block.indexNames.get(key)};
var list = state.${block.listNames.get(key)};
var index = ${block.indexNames.get(key)};
list[index]${tail} = childState.${binding.name};
${binding.dependencies
@ -265,12 +271,10 @@ export default class Component extends Node {
const anchor = this.getOrCreateAnchor(block, parentNode, parentNodes);
const params = block.params.join(', ');
block.builders.init.addBlock(deindent`
var ${switch_vars.value} = ${snippet};
function ${switch_vars.props}(${params}) {
function ${switch_vars.props}(state) {
${statements.length > 0 && statements.join('\n')}
return {
${componentInitProperties.join(',\n')}
@ -278,7 +282,7 @@ export default class Component extends Node {
}
if (${switch_vars.value}) {
var ${name} = new ${expression}(${switch_vars.props}(${params}));
var ${name} = new ${expression}(${switch_vars.props}(state));
${beforecreate}
}
@ -313,7 +317,7 @@ export default class Component extends Node {
if (${name}) ${name}.destroy();
if (${switch_vars.value}) {
${name} = new ${switch_vars.value}(${switch_vars.props}(${params}));
${name} = new ${switch_vars.value}(${switch_vars.props}(state));
${name}._fragment.c();
${this.children.map(child => remount(generator, child, name))}
@ -393,41 +397,6 @@ export default class Component extends Node {
${ref && `if (#component.refs.${ref.name} === ${name}) #component.refs.${ref.name} = null;`}
`);
}
// maintain component context
if (allContexts.size) {
const contexts = Array.from(allContexts);
const initialProps = contexts
.map(contextName => {
if (contextName === 'state') return `state: state`;
const listName = block.listNames.get(contextName);
const indexName = block.indexNames.get(contextName);
return `${listName}: ${listName},\n${indexName}: ${indexName}`;
})
.join(',\n');
const updates = contexts
.map(contextName => {
if (contextName === 'state') return `${name_context}.state = state;`;
const listName = block.listNames.get(contextName);
const indexName = block.indexNames.get(contextName);
return `${name_context}.${listName} = ${listName};\n${name_context}.${indexName} = ${indexName};`;
})
.join('\n');
block.builders.init.addBlock(deindent`
var ${name_context} = {
${initialProps}
};
`);
block.builders.update.addBlock(updates);
}
}
}
@ -515,8 +484,8 @@ function mungeBinding(binding: Node, block: Block): Binding {
let prop;
if (contextual) {
obj = block.listNames.get(name);
prop = block.indexNames.get(name);
obj = `state.${block.listNames.get(name)}`;
prop = `${block.indexNames.get(name)}`;
} else if (binding.value.type === 'MemberExpression') {
prop = `[✂${binding.value.property.start}-${binding.value.property.end}✂]`;
if (!binding.value.computed) prop = `'${prop}'`;
@ -537,7 +506,7 @@ function mungeBinding(binding: Node, block: Block): Binding {
};
}
function mungeEventHandler(generator: DomGenerator, node: Node, handler: Node, block: Block, name_context: string, allContexts: Set<string>) {
function mungeEventHandler(generator: DomGenerator, node: Node, handler: Node, block: Block, allContexts: Set<string>) {
let body;
if (handler.expression) {
@ -547,30 +516,15 @@ function mungeEventHandler(generator: DomGenerator, node: Node, handler: Node, b
`${block.alias('component')}.`
);
const usedContexts: string[] = [];
handler.expression.arguments.forEach((arg: Node) => {
const { contexts } = block.contextualise(arg, null, true);
contexts.forEach(context => {
if (!~usedContexts.indexOf(context)) usedContexts.push(context);
allContexts.add(context);
});
});
// TODO hoist event handlers? can do `this.__component.method(...)`
const declarations = usedContexts.map(name => {
if (name === 'state') return `var state = ${name_context}.state;`;
const listName = block.listNames.get(name);
const indexName = block.indexNames.get(name);
return `var ${listName} = ${name_context}.${listName}, ${indexName} = ${name_context}.${indexName}, ${name} = ${listName}[${indexName}]`;
});
body = deindent`
${declarations}
[${handler.expression.start}-${handler.expression.end}];
`;
} else {
@ -599,7 +553,7 @@ function remount(generator: DomGenerator, node: Node, name: string) {
// TODO make this a method of the nodes
if (node.type === 'Component') {
return `${node.var}._mount(${name}._slotted.default, null);`;
return `${node.var}._mount(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
}
if (node.type === 'Element') {
@ -608,17 +562,17 @@ function remount(generator: DomGenerator, node: Node, name: string) {
return `@appendNode(${node.var}, ${name}._slotted.${node.getStaticAttributeValue('slot')});`;
}
return `@appendNode(${node.var}, ${name}._slotted.default);`;
return `@appendNode(${node.var}, ${name}._slotted${generator.legacy ? `["default"]` : `.default`});`;
}
if (node.type === 'Text' || node.type === 'MustacheTag' || node.type === 'RawMustacheTag') {
return `@appendNode(${node.var}, ${name}._slotted.default);`;
return `@appendNode(${node.var}, ${name}._slotted${generator.legacy ? `["default"]` : `.default`});`;
}
if (node.type === 'EachBlock') {
// TODO consider keyed blocks
return `for (var #i = 0; #i < ${node.iterations}.length; #i += 1) ${node.iterations}[#i].m(${name}._slotted.default, null);`;
return `for (var #i = 0; #i < ${node.iterations}.length; #i += 1) ${node.iterations}[#i].m(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
}
return `${node.var}.m(${name}._slotted.default, null);`;
return `${node.var}.m(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
}

@ -29,60 +29,61 @@ export default class EachBlock extends Node {
this.var = block.getUniqueName(`each`);
this.iterations = block.getUniqueName(`${this.var}_blocks`);
this.each_context = block.getUniqueName(`${this.var}_context`);
const { dependencies } = this.metadata;
block.addDependencies(dependencies);
const indexNames = new Map(block.indexNames);
const indexName =
this.index || block.getUniqueName(`${this.context}_index`);
indexNames.set(this.context, indexName);
this.block = block.child({
comment: createDebuggingComment(this, this.generator),
name: this.generator.getUniqueName('create_each_block'),
context: this.context,
key: this.key,
contexts: new Map(block.contexts),
contextTypes: new Map(block.contextTypes),
indexes: new Map(block.indexes),
changeableIndexes: new Map(block.changeableIndexes),
const listNames = new Map(block.listNames);
const listName = block.getUniqueName(
listName: (
(this.expression.type === 'MemberExpression' && !this.expression.computed) ? this.expression.property.name :
this.expression.type === 'Identifier' ? this.expression.name :
`each_value`
);
listNames.set(this.context, listName);
),
indexName: this.index || `${this.context}_index`,
const contextTypes = new Map(block.contextTypes);
contextTypes.set(this.context, 'each');
const context = block.getUniqueName(this.context);
const contexts = new Map(block.contexts);
contexts.set(this.context, context);
indexNames: new Map(block.indexNames),
listNames: new Map(block.listNames)
});
const indexes = new Map(block.indexes);
if (this.index) indexes.set(this.index, this.context);
this.block.contextTypes.set(this.context, 'each');
this.block.indexNames.set(this.context, this.block.indexName);
this.block.listNames.set(this.context, this.block.listName);
if (this.index) {
this.block.indexes.set(this.index, this.context);
this.block.changeableIndexes.set(this.index, this.key)
}
const changeableIndexes = new Map(block.changeableIndexes);
if (this.index) changeableIndexes.set(this.index, this.key);
const context = this.block.getUniqueName(this.context);
this.block.contexts.set(this.context, context); // TODO this is now redundant?
if (this.destructuredContexts) {
for (let i = 0; i < this.destructuredContexts.length; i += 1) {
contexts.set(this.destructuredContexts[i], `${context}[${i}]`);
const context = this.block.getUniqueName(this.destructuredContexts[i]);
this.block.contexts.set(this.destructuredContexts[i], context);
}
}
this.block = block.child({
comment: createDebuggingComment(this, this.generator),
name: this.generator.getUniqueName('create_each_block'),
context: this.context,
key: this.key,
contexts,
contextTypes,
indexes,
changeableIndexes,
listName,
indexName,
this.contextProps = [
`${this.context}: ${this.block.listName}[#i]`,
`${this.block.indexName}: #i`
];
indexNames,
listNames,
params: block.params.concat(listName, context, indexName),
});
if (this.destructuredContexts) {
for (let i = 0; i < this.destructuredContexts.length; i += 1) {
this.contextProps.push(`${this.destructuredContexts[i]}: ${this.block.listName}[#i][${i}]`);
}
}
this.generator.blocks.push(this.block);
this.initChildren(this.block, stripWhitespace, nextSibling);
@ -117,7 +118,6 @@ export default class EachBlock extends Node {
const create_each_block = this.block.name;
const each_block_value = this.block.listName;
const iterations = this.iterations;
const params = block.params.join(', ');
const needsAnchor = this.next ? !this.next.isDomNode() : !parentNode || !this.parent.isDomNode();
const anchor = needsAnchor
@ -138,7 +138,6 @@ export default class EachBlock extends Node {
each_block_value,
length,
iterations,
params,
anchor,
mountOrIntro,
};
@ -171,7 +170,7 @@ export default class EachBlock extends Node {
// TODO neaten this up... will end up with an empty line in the block
block.builders.init.addBlock(deindent`
if (!${each_block_value}.${length}) {
${each_block_else} = ${this.else.block.name}(${params}, #component);
${each_block_else} = ${this.else.block.name}(#component, state);
${each_block_else}.c();
}
`);
@ -187,9 +186,9 @@ export default class EachBlock extends Node {
if (this.else.block.hasUpdateMethod) {
block.builders.update.addBlock(deindent`
if (!${each_block_value}.${length} && ${each_block_else}) {
${each_block_else}.p( changed, ${params} );
${each_block_else}.p(changed, state);
} else if (!${each_block_value}.${length}) {
${each_block_else} = ${this.else.block.name}(${params}, #component);
${each_block_else} = ${this.else.block.name}(#component, state);
${each_block_else}.c();
${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor});
} else if (${each_block_else}) {
@ -207,7 +206,7 @@ export default class EachBlock extends Node {
${each_block_else} = null;
}
} else if (!${each_block_else}) {
${each_block_else} = ${this.else.block.name}(${params}, #component);
${each_block_else} = ${this.else.block.name}(#component, state);
${each_block_else}.c();
${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor});
}
@ -244,7 +243,6 @@ export default class EachBlock extends Node {
create_each_block,
each_block_value,
length,
params,
anchor,
mountOrIntro,
}
@ -275,7 +273,9 @@ export default class EachBlock extends Node {
block.builders.init.addBlock(deindent`
for (var #i = 0; #i < ${each_block_value}.${length}; #i += 1) {
var ${key} = ${each_block_value}[#i].${this.key};
var ${iteration} = ${lookup}[${key}] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component, ${key});
var ${iteration} = ${lookup}[${key}] = ${create_each_block}(#component, ${key}, @assign({}, state, {
${this.contextProps.join(',\n')}
}));
if (${last}) ${last}.next = ${iteration};
${iteration}.last = ${last};
@ -379,8 +379,12 @@ export default class EachBlock extends Node {
var ${key} = ${each_block_value}[#i].${this.key};
var ${iteration} = ${lookup}[${key}];
var ${this.each_context} = @assign({}, state, {
${this.contextProps.join(',\n')}
});
${dynamic &&
`if (${iteration}) ${iteration}.p(changed, ${params}, ${each_block_value}, ${each_block_value}[#i], #i);`}
`if (${iteration}) ${iteration}.p(changed, ${this.each_context});`}
if (${expected}) {
if (${key} === ${expected}.key) {
@ -401,7 +405,7 @@ export default class EachBlock extends Node {
if (!${expected}) ${iteration}.m(${updateMountNode}, ${anchor});
} else {
// key is being inserted
${iteration} = ${lookup}[${key}] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component, ${key});
${iteration} = ${lookup}[${key}] = ${create_each_block}(#component, ${key}, ${this.each_context});
${iteration}.c();
${iteration}.${mountOrIntro}(${updateMountNode}, ${expected}.first);
@ -416,7 +420,7 @@ export default class EachBlock extends Node {
${iteration}.next = null;
${iteration}.m(${updateMountNode}, ${anchor});
} else {
${iteration} = ${lookup}[${key}] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component, ${key});
${iteration} = ${lookup}[${key}] = ${create_each_block}(#component, ${key}, ${this.each_context});
${iteration}.c();
${iteration}.${mountOrIntro}(${updateMountNode}, ${anchor});
}
@ -464,7 +468,6 @@ export default class EachBlock extends Node {
each_block_value,
length,
iterations,
params,
anchor,
mountOrIntro,
}
@ -473,7 +476,9 @@ export default class EachBlock extends Node {
var ${iterations} = [];
for (var #i = 0; #i < ${each_block_value}.${length}; #i += 1) {
${iterations}[#i] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component);
${iterations}[#i] = ${create_each_block}(#component, @assign({}, state, {
${this.contextProps.join(',\n')}
}));
}
`);
@ -517,24 +522,24 @@ export default class EachBlock extends Node {
? this.block.hasIntroMethod
? deindent`
if (${iterations}[#i]) {
${iterations}[#i].p(changed, ${params}, ${each_block_value}, ${each_block_value}[#i], #i);
${iterations}[#i].p(changed, ${this.each_context});
} else {
${iterations}[#i] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component);
${iterations}[#i] = ${create_each_block}(#component, ${this.each_context});
${iterations}[#i].c();
}
${iterations}[#i].i(${updateMountNode}, ${anchor});
`
: deindent`
if (${iterations}[#i]) {
${iterations}[#i].p(changed, ${params}, ${each_block_value}, ${each_block_value}[#i], #i);
${iterations}[#i].p(changed, ${this.each_context});
} else {
${iterations}[#i] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component);
${iterations}[#i] = ${create_each_block}(#component, ${this.each_context});
${iterations}[#i].c();
${iterations}[#i].m(${updateMountNode}, ${anchor});
}
`
: deindent`
${iterations}[#i] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component);
${iterations}[#i] = ${create_each_block}(#component, ${this.each_context});
${iterations}[#i].c();
${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor});
`;
@ -569,6 +574,10 @@ export default class EachBlock extends Node {
if (${condition}) {
for (var #i = ${start}; #i < ${each_block_value}.${length}; #i += 1) {
var ${this.each_context} = @assign({}, state, {
${this.contextProps.join(',\n')}
});
${forLoopBody}
}

@ -386,10 +386,10 @@ export default class Element extends Node {
const indexName = block.indexNames.get(contextName);
initialProps.push(
`${listName}: ${listName},\n${indexName}: ${indexName}`
`${listName}: state.${listName},\n${indexName}: state.${indexName}`
);
updates.push(
`${name}._svelte.${listName} = ${listName};\n${name}._svelte.${indexName} = ${indexName};`
`${name}._svelte.${listName} = state.${listName};\n${name}._svelte.${indexName} = state.${indexName};`
);
});

@ -16,7 +16,6 @@ export default class Fragment extends Node {
indexes: new Map(),
changeableIndexes: new Map(),
params: ['state'],
indexNames: new Map(),
listNames: new Map(),

@ -100,7 +100,6 @@ export default class IfBlock extends Node {
const anchor = needsAnchor
? block.getUniqueName(`${name}_anchor`)
: (this.next && this.next.var) || 'null';
const params = block.params.join(', ');
const branches = getBranches(this.generator, block, parentNode, parentNodes, this);
@ -110,7 +109,7 @@ export default class IfBlock extends Node {
const dynamic = branches[0].hasUpdateMethod; // can use [0] as proxy for all, since they necessarily have the same value
const hasOutros = branches[0].hasOutroMethod;
const vars = { name, anchor, params, if_name, hasElse };
const vars = { name, anchor, if_name, hasElse };
if (this.else) {
if (hasOutros) {
@ -218,10 +217,10 @@ function simple(
node: Node,
branch,
dynamic,
{ name, anchor, params, if_name }
{ name, anchor, if_name }
) {
block.builders.init.addBlock(deindent`
var ${name} = (${branch.condition}) && ${branch.block}(${params}, #component);
var ${name} = (${branch.condition}) && ${branch.block}(#component, state);
`);
const mountOrIntro = branch.hasIntroMethod ? 'i' : 'm';
@ -238,9 +237,9 @@ function simple(
? branch.hasIntroMethod
? deindent`
if (${name}) {
${name}.p(changed, ${params});
${name}.p(changed, state);
} else {
${name} = ${branch.block}(${params}, #component);
${name} = ${branch.block}(#component, state);
if (${name}) ${name}.c();
}
@ -248,9 +247,9 @@ function simple(
`
: deindent`
if (${name}) {
${name}.p(changed, ${params});
${name}.p(changed, state);
} else {
${name} = ${branch.block}(${params}, #component);
${name} = ${branch.block}(#component, state);
${name}.c();
${name}.m(${updateMountNode}, ${anchor});
}
@ -258,14 +257,14 @@ function simple(
: branch.hasIntroMethod
? deindent`
if (!${name}) {
${name} = ${branch.block}(${params}, #component);
${name} = ${branch.block}(#component, state);
${name}.c();
}
${name}.i(${updateMountNode}, ${anchor});
`
: deindent`
if (!${name}) {
${name} = ${branch.block}(${params}, #component);
${name} = ${branch.block}(#component, state);
${name}.c();
${name}.m(${updateMountNode}, ${anchor});
}
@ -308,14 +307,14 @@ function compound(
node: Node,
branches,
dynamic,
{ name, anchor, params, hasElse, if_name }
{ name, anchor, hasElse, if_name }
) {
const select_block_type = generator.getUniqueName(`select_block_type`);
const current_block_type = block.getUniqueName(`current_block_type`);
const current_block_type_and = hasElse ? '' : `${current_block_type} && `;
generator.blocks.push(deindent`
function ${select_block_type}(${params}) {
function ${select_block_type}(state) {
${branches
.map(({ condition, block }) => `${condition ? `if (${condition}) ` : ''}return ${block};`)
.join('\n')}
@ -323,8 +322,8 @@ function compound(
`);
block.builders.init.addBlock(deindent`
var ${current_block_type} = ${select_block_type}(${params});
var ${name} = ${current_block_type_and}${current_block_type}(${params}, #component);
var ${current_block_type} = ${select_block_type}(state);
var ${name} = ${current_block_type_and}${current_block_type}(#component, state);
`);
const mountOrIntro = branches[0].hasIntroMethod ? 'i' : 'm';
@ -348,22 +347,22 @@ function compound(
${name}.u();
${name}.d();
}`}
${name} = ${current_block_type_and}${current_block_type}(${params}, #component);
${name} = ${current_block_type_and}${current_block_type}(#component, state);
${if_name}${name}.c();
${if_name}${name}.${mountOrIntro}(${updateMountNode}, ${anchor});
`;
if (dynamic) {
block.builders.update.addBlock(deindent`
if (${current_block_type} === (${current_block_type} = ${select_block_type}(${params})) && ${name}) {
${name}.p(changed, ${params});
if (${current_block_type} === (${current_block_type} = ${select_block_type}(state)) && ${name}) {
${name}.p(changed, state);
} else {
${changeBlock}
}
`);
} else {
block.builders.update.addBlock(deindent`
if (${current_block_type} !== (${current_block_type} = ${select_block_type}(${params}))) {
if (${current_block_type} !== (${current_block_type} = ${select_block_type}(state))) {
${changeBlock}
}
`);
@ -384,7 +383,7 @@ function compoundWithOutros(
node: Node,
branches,
dynamic,
{ name, anchor, params, hasElse }
{ name, anchor, hasElse }
) {
const select_block_type = block.getUniqueName(`select_block_type`);
const current_block_type_index = block.getUniqueName(`current_block_type_index`);
@ -406,7 +405,7 @@ function compoundWithOutros(
var ${if_blocks} = [];
function ${select_block_type}(${params}) {
function ${select_block_type}(state) {
${branches
.map(({ condition, block }, i) => `${condition ? `if (${condition}) ` : ''}return ${block ? i : -1};`)
.join('\n')}
@ -415,13 +414,13 @@ function compoundWithOutros(
if (hasElse) {
block.builders.init.addBlock(deindent`
${current_block_type_index} = ${select_block_type}(${params});
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](${params}, #component);
${current_block_type_index} = ${select_block_type}(state);
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, state);
`);
} else {
block.builders.init.addBlock(deindent`
if (~(${current_block_type_index} = ${select_block_type}(${params}))) {
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](${params}, #component);
if (~(${current_block_type_index} = ${select_block_type}(state))) {
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, state);
}
`);
}
@ -447,7 +446,7 @@ function compoundWithOutros(
const createNewBlock = deindent`
${name} = ${if_blocks}[${current_block_type_index}];
if (!${name}) {
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](${params}, #component);
${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](#component, state);
${name}.c();
}
${name}.${mountOrIntro}(${updateMountNode}, ${anchor});
@ -474,9 +473,9 @@ function compoundWithOutros(
if (dynamic) {
block.builders.update.addBlock(deindent`
var ${previous_block_index} = ${current_block_type_index};
${current_block_type_index} = ${select_block_type}(${params});
${current_block_type_index} = ${select_block_type}(state);
if (${current_block_type_index} === ${previous_block_index}) {
${if_current_block_type_index}${if_blocks}[${current_block_type_index}].p(changed, ${params});
${if_current_block_type_index}${if_blocks}[${current_block_type_index}].p(changed, state);
} else {
${changeBlock}
}
@ -484,7 +483,7 @@ function compoundWithOutros(
} else {
block.builders.update.addBlock(deindent`
var ${previous_block_index} = ${current_block_type_index};
${current_block_type_index} = ${select_block_type}(${params});
${current_block_type_index} = ${select_block_type}(state);
if (${current_block_type_index} !== ${previous_block_index}) {
${changeBlock}
}

@ -1,4 +1,6 @@
import deindent from '../../utils/deindent';
import isValidIdentifier from '../../utils/isValidIdentifier';
import reservedNames from '../../utils/reservedNames';
import Node from './shared/Node';
import Element from './Element';
import Attribute from './Attribute';
@ -35,7 +37,8 @@ export default class Slot extends Element {
generator.slots.add(slotName);
const content_name = block.getUniqueName(`slot_content_${slotName}`);
block.addVariable(content_name, `#component._slotted.${slotName}`);
const prop = !isValidIdentifier(slotName) || (generator.legacy && reservedNames.has(slotName)) ? `["${slotName}"]` : `.${slotName}`;
block.addVariable(content_name, `#component._slotted${prop}`);
const needsAnchorBefore = this.prev ? this.prev.type !== 'Element' : !parentNode;
const needsAnchorAfter = this.next ? this.next.type !== 'Element' : !parentNode;
@ -54,6 +57,7 @@ export default class Slot extends Element {
block.builders.create.pushCondition(`!${content_name}`);
block.builders.hydrate.pushCondition(`!${content_name}`);
block.builders.mount.pushCondition(`!${content_name}`);
block.builders.update.pushCondition(`!${content_name}`);
block.builders.unmount.pushCondition(`!${content_name}`);
block.builders.destroy.pushCondition(`!${content_name}`);
@ -64,6 +68,7 @@ export default class Slot extends Element {
block.builders.create.popCondition();
block.builders.hydrate.popCondition();
block.builders.mount.popCondition();
block.builders.update.popCondition();
block.builders.unmount.popCondition();
block.builders.destroy.popCondition();

@ -11,7 +11,7 @@ export default function visitEachBlock(
block.contextualise(node.expression);
const { dependencies, snippet } = node.metadata;
const open = `\${ ${node.else ? `${snippet}.length ? ` : ''}${snippet}.map(${node.index ? `(${node.context}, ${node.index})` : node.context} => \``;
const open = `\${ ${node.else ? `${snippet}.length ? ` : ''}${snippet}.map(${node.index ? `(${node.context}, ${node.index})` : `(${node.context})`} => \``;
generator.append(open);
// TODO should this be the generator's job? It's duplicated between

@ -31,7 +31,9 @@ function readExpression(parser: Parser, start: number, quoteMark: string|null) {
}
}
const expression = parseExpressionAt(repeat(' ', start) + str, start);
const expression = parseExpressionAt(repeat(' ', start) + str, start, {
ecmaVersion: 9,
});
parser.index = expression.end;
parser.allowWhitespace();
@ -102,7 +104,7 @@ export function readBindingDirective(
}
const source = repeat(' ', a) + parser.template.slice(a, b);
value = parseExpressionAt(source, a);
value = parseExpressionAt(source, a, { ecmaVersion: 9 });
if (value.type !== 'Identifier' && value.type !== 'MemberExpression') {
parser.error(`Cannot bind to rvalue`, value.start);

@ -32,6 +32,7 @@ export default function readExpression(parser: Parser) {
try {
const node = parseExpressionAt(parser.template, parser.index, {
ecmaVersion: 9,
preserveParens: true,
});
parser.index = node.end;

@ -22,7 +22,7 @@ export default function readScript(parser: Parser, start: number, attributes: No
try {
ast = acorn.parse(source, {
ecmaVersion: 8,
ecmaVersion: 9,
sourceType: 'module',
plugins: {
dynamicImport: true

@ -100,7 +100,7 @@ export function observe(key, callback, options) {
}
export function observeDev(key, callback, options) {
var c = (key = '' + key).search(/[^\w]/);
var c = (key = '' + key).search(/[.[]/);
if (c > -1) {
var message =
'The first argument to component.observe(...) must be the name of a top-level property';

@ -101,7 +101,7 @@ export default function validate(
throw error;
}
if (name && !/^[A-Z]/.test(name)) {
if (name && /^[a-z]/.test(name)) {
const message = `options.name should be capitalised`;
onwarn({
message,

@ -111,10 +111,13 @@ assign(Store.prototype, {
onchange: function(callback) {
this._changeHandlers.push(callback);
var store = this;
return {
cancel: function() {
var index = this._changeHandlers.indexOf(callback);
if (~index) this._changeHandlers.splice(index, 1);
var index = store._changeHandlers.indexOf(callback);
if (~index) store._changeHandlers.splice(index, 1);
}
};
},

@ -209,7 +209,7 @@ function add_css() {
appendNode(style, document.head);
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var p, text;
return {
@ -248,7 +248,7 @@ function SvelteComponent(options) {
if (!document.getElementById("svelte-2794052100-style")) add_css();
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -16,7 +16,7 @@ function add_css() {
appendNode(style, document.head);
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var p, text;
return {
@ -55,7 +55,7 @@ function SvelteComponent(options) {
if (!document.getElementById("svelte-2794052100-style")) add_css();
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -176,7 +176,7 @@ var proto = {
/* generated by Svelte vX.Y.Z */
var Nested = window.Nested;
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var nested = new Nested({
root: component.root,
@ -214,7 +214,7 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -3,7 +3,7 @@ import { _differsImmutable, assign, callAll, init, noop, proto } from "svelte/sh
var Nested = window.Nested;
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var nested = new Nested({
root: component.root,
@ -41,7 +41,7 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -176,7 +176,7 @@ var proto = {
/* generated by Svelte vX.Y.Z */
var Nested = window.Nested;
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var nested = new Nested({
root: component.root,
@ -214,7 +214,7 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -3,7 +3,7 @@ import { _differsImmutable, assign, callAll, init, noop, proto } from "svelte/sh
var Nested = window.Nested;
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var nested = new Nested({
root: component.root,
@ -41,7 +41,7 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -172,7 +172,7 @@ var proto = {
/* generated by Svelte vX.Y.Z */
var Nested = window.Nested;
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var nested = new Nested({
root: component.root,
@ -210,7 +210,7 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -3,7 +3,7 @@ import { assign, callAll, init, noop, proto } from "svelte/shared.js";
var Nested = window.Nested;
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var nested = new Nested({
root: component.root,
@ -41,7 +41,7 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -178,7 +178,7 @@ function b(x) {
return x * 3;
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
return {
c: noop,
@ -198,7 +198,7 @@ function SvelteComponent(options) {
this._state = assign({}, options.data);
this._recompute({ x: 1 }, this._state);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -9,7 +9,7 @@ function b(x) {
return x * 3;
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
return {
c: noop,
@ -29,7 +29,7 @@ function SvelteComponent(options) {
this._state = assign({}, options.data);
this._recompute({ x: 1 }, this._state);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -201,7 +201,7 @@ function add_css() {
appendNode(style, document.head);
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -234,7 +234,7 @@ function SvelteComponent(options) {
if (!document.getElementById("svelte-3905933315-style")) add_css();
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -12,7 +12,7 @@ function add_css() {
appendNode(style, document.head);
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -45,7 +45,7 @@ function SvelteComponent(options) {
if (!document.getElementById("svelte-3905933315-style")) add_css();
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -182,7 +182,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -215,7 +215,7 @@ class SvelteComponent extends HTMLElement {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `<style>div{animation:foo 1s}@keyframes foo{0%{opacity:0}100%{opacity:1}}</style>`;
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
this._fragment.c();
this._fragment.m(this.shadowRoot, null);

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -34,7 +34,7 @@ class SvelteComponent extends HTMLElement {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `<style>div{animation:foo 1s}@keyframes foo{0%{opacity:0}100%{opacity:1}}</style>`;
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
this._fragment.c();
this._fragment.m(this.shadowRoot, null);

@ -180,7 +180,7 @@ function oncreate() {
alert(JSON.stringify(data()));
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
return {
c: noop,
@ -205,7 +205,7 @@ function SvelteComponent(options) {
this._oncreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
this.root._oncreate.push(_oncreate);

@ -11,7 +11,7 @@ function oncreate() {
alert(JSON.stringify(data()));
};
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
return {
c: noop,
@ -36,7 +36,7 @@ function SvelteComponent(options) {
this._oncreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
this.root._oncreate.push(_oncreate);

@ -186,7 +186,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div, text, div_1;
return {
@ -228,7 +228,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div, text, div_1;
return {
@ -43,7 +43,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -190,7 +190,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div, text, div_1;
return {
@ -232,7 +232,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div, text, div_1;
return {
@ -43,7 +43,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -190,7 +190,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var svg, g, g_1;
return {
@ -230,7 +230,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createSvgElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var svg, g, g_1;
return {
@ -41,7 +41,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -202,7 +202,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var text, p, text_1;
var comments = state.comments;
@ -210,7 +210,10 @@ function create_main_fragment(state, component) {
var each_blocks = [];
for (var i = 0; i < comments.length; i += 1) {
each_blocks[i] = create_each_block(state, comments, comments[i], i, component);
each_blocks[i] = create_each_block(component, assign({}, state, {
comment: comments[i],
i: i
}));
}
return {
@ -239,10 +242,15 @@ function create_main_fragment(state, component) {
if (changed.comments || changed.elapsed || changed.time) {
for (var i = 0; i < comments.length; i += 1) {
var each_context = assign({}, state, {
comment: comments[i],
i: i
});
if (each_blocks[i]) {
each_blocks[i].p(changed, state, comments, comments[i], i);
each_blocks[i].p(changed, each_context);
} else {
each_blocks[i] = create_each_block(state, comments, comments[i], i, component);
each_blocks[i] = create_each_block(component, each_context);
each_blocks[i].c();
each_blocks[i].m(text.parentNode, text);
}
@ -276,7 +284,8 @@ function create_main_fragment(state, component) {
}
// (1:0) {{#each comments as comment, i}}
function create_each_block(state, comments, comment, i, component) {
function create_each_block(component, state) {
var comment = state.comment, i = state.i;
var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before;
return {
@ -315,7 +324,9 @@ function create_each_block(state, comments, comment, i, component) {
raw_before.insertAdjacentHTML("afterend", raw_value);
},
p: function update(changed, state, comments, comment, i) {
p: function update(changed, state) {
comment = state.comment;
i = state.i;
if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) {
text_2.data = text_2_value;
}
@ -344,7 +355,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var text, p, text_1;
var comments = state.comments;
@ -9,7 +9,10 @@ function create_main_fragment(state, component) {
var each_blocks = [];
for (var i = 0; i < comments.length; i += 1) {
each_blocks[i] = create_each_block(state, comments, comments[i], i, component);
each_blocks[i] = create_each_block(component, assign({}, state, {
comment: comments[i],
i: i
}));
}
return {
@ -38,10 +41,15 @@ function create_main_fragment(state, component) {
if (changed.comments || changed.elapsed || changed.time) {
for (var i = 0; i < comments.length; i += 1) {
var each_context = assign({}, state, {
comment: comments[i],
i: i
});
if (each_blocks[i]) {
each_blocks[i].p(changed, state, comments, comments[i], i);
each_blocks[i].p(changed, each_context);
} else {
each_blocks[i] = create_each_block(state, comments, comments[i], i, component);
each_blocks[i] = create_each_block(component, each_context);
each_blocks[i].c();
each_blocks[i].m(text.parentNode, text);
}
@ -75,7 +83,8 @@ function create_main_fragment(state, component) {
}
// (1:0) {{#each comments as comment, i}}
function create_each_block(state, comments, comment, i, component) {
function create_each_block(component, state) {
var comment = state.comment, i = state.i;
var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before;
return {
@ -114,7 +123,9 @@ function create_each_block(state, comments, comment, i, component) {
raw_before.insertAdjacentHTML("afterend", raw_value);
},
p: function update(changed, state, comments, comment, i) {
p: function update(changed, state) {
comment = state.comment;
i = state.i;
if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) {
text_2.data = text_2_value;
}
@ -143,7 +154,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -192,7 +192,7 @@ var methods = {
}
};
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var button, foo_handler;
return {
@ -229,7 +229,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -11,7 +11,7 @@ var methods = {
}
};
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var button, foo_handler;
return {
@ -48,7 +48,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -182,7 +182,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var meta, meta_1;
return {
@ -219,7 +219,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createElement, detachNode, init, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var meta, meta_1;
return {
@ -38,7 +38,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -186,11 +186,11 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var if_block_anchor;
var current_block_type = select_block_type(state);
var if_block = current_block_type(state, component);
var if_block = current_block_type(component, state);
return {
c: function create() {
@ -207,7 +207,7 @@ function create_main_fragment(state, component) {
if (current_block_type !== (current_block_type = select_block_type(state))) {
if_block.u();
if_block.d();
if_block = current_block_type(state, component);
if_block = current_block_type(component, state);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
@ -225,7 +225,7 @@ function create_main_fragment(state, component) {
}
// (1:0) {{#if foo}}
function create_if_block(state, component) {
function create_if_block(component, state) {
var p;
return {
@ -247,7 +247,7 @@ function create_if_block(state, component) {
}
// (3:0) {{else}}
function create_if_block_1(state, component) {
function create_if_block_1(component, state) {
var p;
return {
@ -277,7 +277,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,11 +1,11 @@
/* generated by Svelte vX.Y.Z */
import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var if_block_anchor;
var current_block_type = select_block_type(state);
var if_block = current_block_type(state, component);
var if_block = current_block_type(component, state);
return {
c: function create() {
@ -22,7 +22,7 @@ function create_main_fragment(state, component) {
if (current_block_type !== (current_block_type = select_block_type(state))) {
if_block.u();
if_block.d();
if_block = current_block_type(state, component);
if_block = current_block_type(component, state);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
@ -40,7 +40,7 @@ function create_main_fragment(state, component) {
}
// (1:0) {{#if foo}}
function create_if_block(state, component) {
function create_if_block(component, state) {
var p;
return {
@ -62,7 +62,7 @@ function create_if_block(state, component) {
}
// (3:0) {{else}}
function create_if_block_1(state, component) {
function create_if_block_1(component, state) {
var p;
return {
@ -92,7 +92,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -186,10 +186,10 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var if_block_anchor;
var if_block = (state.foo) && create_if_block(state, component);
var if_block = (state.foo) && create_if_block(component, state);
return {
c: function create() {
@ -205,7 +205,7 @@ function create_main_fragment(state, component) {
p: function update(changed, state) {
if (state.foo) {
if (!if_block) {
if_block = create_if_block(state, component);
if_block = create_if_block(component, state);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
@ -228,7 +228,7 @@ function create_main_fragment(state, component) {
}
// (1:0) {{#if foo}}
function create_if_block(state, component) {
function create_if_block(component, state) {
var p;
return {
@ -253,7 +253,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,10 +1,10 @@
/* generated by Svelte vX.Y.Z */
import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var if_block_anchor;
var if_block = (state.foo) && create_if_block(state, component);
var if_block = (state.foo) && create_if_block(component, state);
return {
c: function create() {
@ -20,7 +20,7 @@ function create_main_fragment(state, component) {
p: function update(changed, state) {
if (state.foo) {
if (!if_block) {
if_block = create_if_block(state, component);
if_block = create_if_block(component, state);
if_block.c();
if_block.m(if_block_anchor.parentNode, if_block_anchor);
}
@ -43,7 +43,7 @@ function create_main_fragment(state, component) {
}
// (1:0) {{#if foo}}
function create_if_block(state, component) {
function create_if_block(component, state) {
var p;
return {
@ -68,7 +68,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -186,7 +186,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -226,7 +226,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -41,7 +41,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -186,7 +186,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -221,7 +221,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -36,7 +36,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -186,7 +186,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -221,7 +221,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -36,7 +36,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -186,7 +186,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div, text, div_1, div_1_style_value;
return {
@ -232,7 +232,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div, text, div_1, div_1_style_value;
return {
@ -47,7 +47,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -190,7 +190,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var input;
function input_change_handler() {
@ -232,7 +232,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var input;
function input_change_handler() {
@ -43,7 +43,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -0,0 +1,5 @@
export default {
options: {
legacy: true
}
};

@ -0,0 +1,289 @@
function noop() {}
function assign(target) {
var k,
source,
i = 1,
len = arguments.length;
for (; i < len; i++) {
source = arguments[i];
for (k in source) target[k] = source[k];
}
return target;
}
function appendNode(node, target) {
target.appendChild(node);
}
function insertNode(node, target, anchor) {
target.insertBefore(node, anchor);
}
function detachNode(node) {
node.parentNode.removeChild(node);
}
function reinsertBetween(before, after, target) {
while (before.nextSibling && before.nextSibling !== after) {
target.appendChild(before.parentNode.removeChild(before.nextSibling));
}
}
function createFragment() {
return document.createDocumentFragment();
}
function createElement(name) {
return document.createElement(name);
}
function createText(data) {
return document.createTextNode(data);
}
function createComment() {
return document.createComment('');
}
function blankObject() {
return Object.create(null);
}
function destroy(detach) {
this.destroy = noop;
this.fire('destroy');
this.set = this.get = noop;
if (detach !== false) this._fragment.u();
this._fragment.d();
this._fragment = this._state = null;
}
function _differs(a, b) {
return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function');
}
function dispatchObservers(component, group, changed, newState, oldState) {
for (var key in group) {
if (!changed[key]) continue;
var newValue = newState[key];
var oldValue = oldState[key];
var callbacks = group[key];
if (!callbacks) continue;
for (var i = 0; i < callbacks.length; i += 1) {
var callback = callbacks[i];
if (callback.__calling) continue;
callback.__calling = true;
callback.call(component, newValue, oldValue);
callback.__calling = false;
}
}
}
function fire(eventName, data) {
var handlers =
eventName in this._handlers && this._handlers[eventName].slice();
if (!handlers) return;
for (var i = 0; i < handlers.length; i += 1) {
handlers[i].call(this, data);
}
}
function get(key) {
return key ? this._state[key] : this._state;
}
function init(component, options) {
component._observers = { pre: blankObject(), post: blankObject() };
component._handlers = blankObject();
component._bind = options._bind;
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
}
function observe(key, callback, options) {
var group = options && options.defer
? this._observers.post
: this._observers.pre;
(group[key] || (group[key] = [])).push(callback);
if (!options || options.init !== false) {
callback.__calling = true;
callback.call(this, this._state[key]);
callback.__calling = false;
}
return {
cancel: function() {
var index = group[key].indexOf(callback);
if (~index) group[key].splice(index, 1);
}
};
}
function on(eventName, handler) {
if (eventName === 'teardown') return this.on('destroy', handler);
var handlers = this._handlers[eventName] || (this._handlers[eventName] = []);
handlers.push(handler);
return {
cancel: function() {
var index = handlers.indexOf(handler);
if (~index) handlers.splice(index, 1);
}
};
}
function set(newState) {
this._set(assign({}, newState));
if (this.root._lock) return;
this.root._lock = true;
callAll(this.root._beforecreate);
callAll(this.root._oncreate);
callAll(this.root._aftercreate);
this.root._lock = false;
}
function _set(newState) {
var oldState = this._state,
changed = {},
dirty = false;
for (var key in newState) {
if (this._differs(newState[key], oldState[key])) changed[key] = dirty = true;
}
if (!dirty) return;
this._state = assign({}, oldState, newState);
this._recompute(changed, this._state);
if (this._bind) this._bind(changed, this._state);
if (this._fragment) {
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
this._fragment.p(changed, this._state);
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
}
}
function callAll(fns) {
while (fns && fns.length) fns.shift()();
}
function _mount(target, anchor) {
this._fragment.m(target, anchor);
}
function _unmount() {
if (this._fragment) this._fragment.u();
}
var proto = {
destroy: destroy,
get: get,
fire: fire,
observe: observe,
on: on,
set: set,
teardown: destroy,
_recompute: noop,
_set: _set,
_mount: _mount,
_unmount: _unmount,
_differs: _differs
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(component, state) {
var text, p, text_1, text_2, text_3, slot_content_default = component._slotted["default"], slot_content_default_before, slot_content_default_after;
var foo = new Foo({
root: component.root,
slots: { "default": createFragment() }
});
return {
c: function create() {
text = createText("\n\t");
p = createElement("p");
text_1 = createText("some default slotted content");
text_2 = createText("\n");
foo._fragment.c();
text_3 = createText("\n\n");
},
m: function mount(target, anchor) {
appendNode(text, foo._slotted["default"]);
appendNode(p, foo._slotted["default"]);
appendNode(text_1, p);
appendNode(text_2, foo._slotted["default"]);
foo._mount(target, anchor);
insertNode(text_3, target, anchor);
if (slot_content_default) {
insertNode(slot_content_default_before || (slot_content_default_before = createComment()), target, anchor);
insertNode(slot_content_default, target, anchor);
insertNode(slot_content_default_after || (slot_content_default_after = createComment()), target, anchor);
}
},
p: noop,
u: function unmount() {
foo._unmount();
detachNode(text_3);
if (slot_content_default) {
reinsertBetween(slot_content_default_before, slot_content_default_after, slot_content_default);
detachNode(slot_content_default_before);
detachNode(slot_content_default_after);
}
},
d: function destroy$$1() {
foo.destroy(false);
}
};
}
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._slotted = options.slots || {};
if (!options.root) {
this._oncreate = [];
this._beforecreate = [];
this._aftercreate = [];
}
this.slots = {};
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
this._fragment.m(options.target, options.anchor || null);
this._lock = true;
callAll(this._beforecreate);
callAll(this._oncreate);
callAll(this._aftercreate);
this._lock = false;
}
}
assign(SvelteComponent.prototype, proto);
export default SvelteComponent;

@ -0,0 +1,85 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, callAll, createComment, createElement, createFragment, createText, detachNode, init, insertNode, noop, proto, reinsertBetween } from "svelte/shared.js";
function create_main_fragment(component, state) {
var text, p, text_1, text_2, text_3, slot_content_default = component._slotted["default"], slot_content_default_before, slot_content_default_after;
var foo = new Foo({
root: component.root,
slots: { "default": createFragment() }
});
return {
c: function create() {
text = createText("\n\t");
p = createElement("p");
text_1 = createText("some default slotted content");
text_2 = createText("\n");
foo._fragment.c();
text_3 = createText("\n\n");
},
m: function mount(target, anchor) {
appendNode(text, foo._slotted["default"]);
appendNode(p, foo._slotted["default"]);
appendNode(text_1, p);
appendNode(text_2, foo._slotted["default"]);
foo._mount(target, anchor);
insertNode(text_3, target, anchor);
if (slot_content_default) {
insertNode(slot_content_default_before || (slot_content_default_before = createComment()), target, anchor);
insertNode(slot_content_default, target, anchor);
insertNode(slot_content_default_after || (slot_content_default_after = createComment()), target, anchor);
}
},
p: noop,
u: function unmount() {
foo._unmount();
detachNode(text_3);
if (slot_content_default) {
reinsertBetween(slot_content_default_before, slot_content_default_after, slot_content_default);
detachNode(slot_content_default_before);
detachNode(slot_content_default_after);
}
},
d: function destroy() {
foo.destroy(false);
}
};
}
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._slotted = options.slots || {};
if (!options.root) {
this._oncreate = [];
this._beforecreate = [];
this._aftercreate = [];
}
this.slots = {};
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();
this._fragment.m(options.target, options.anchor || null);
this._lock = true;
callAll(this._beforecreate);
callAll(this._oncreate);
callAll(this._aftercreate);
this._lock = false;
}
}
assign(SvelteComponent.prototype, proto);
export default SvelteComponent;

@ -0,0 +1,11 @@
<Foo>
<p>some default slotted content</p>
</Foo>
<slot></slot>
<script>
export default {
components: { Foo }
};
</script>

@ -188,7 +188,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var input;
return {
@ -219,7 +219,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var input;
return {
@ -32,7 +32,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -205,7 +205,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -244,7 +244,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
var nodes = children(options.target);

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div;
return {
@ -40,7 +40,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
var nodes = children(options.target);

@ -198,7 +198,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var audio, audio_is_paused = true, audio_updating = false, audio_animationframe;
function audio_timeupdate_handler() {
@ -290,7 +290,7 @@ function SvelteComponent(options) {
this._beforecreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { addListener, assign, callAll, createElement, detachNode, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var audio, audio_is_paused = true, audio_updating = false, audio_animationframe;
function audio_timeupdate_handler() {
@ -93,7 +93,7 @@ function SvelteComponent(options) {
this._beforecreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -184,7 +184,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var text;
var imported = new Imported({
@ -233,7 +233,7 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -4,7 +4,7 @@ import Imported from 'Imported.html';
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var text;
var imported = new Imported({
@ -53,7 +53,7 @@ function SvelteComponent(options) {
this._aftercreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -174,7 +174,7 @@ function oncreate() {}
function ondestroy() {}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
return {
c: noop,
@ -201,7 +201,7 @@ function SvelteComponent(options) {
this._oncreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
this.root._oncreate.push(_oncreate);

@ -5,7 +5,7 @@ function oncreate() {};
function ondestroy() {};
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
return {
c: noop,
@ -32,7 +32,7 @@ function SvelteComponent(options) {
this._oncreate = [];
}
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
this.root._oncreate.push(_oncreate);

@ -186,7 +186,7 @@ function setup(Component) {
Component.prototype.foo( 'baz' );
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
return {
c: noop,
@ -205,7 +205,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -17,7 +17,7 @@ function setup(Component) {
Component.prototype.foo( 'baz' );
}
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
return {
c: noop,
@ -36,7 +36,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -190,7 +190,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var svg, title, text;
return {
@ -220,7 +220,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createSvgElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var svg, title, text;
return {
@ -31,7 +31,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -170,7 +170,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var title_value;
document.title = title_value = "a " + state.custom + " title";
@ -196,7 +196,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { assign, init, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var title_value;
document.title = title_value = "a " + state.custom + " title";
@ -27,7 +27,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -194,18 +194,18 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor;
var if_block = (state.a) && create_if_block(state, component);
var if_block = (state.a) && create_if_block(component, state);
var if_block_1 = (state.b) && create_if_block_1(state, component);
var if_block_1 = (state.b) && create_if_block_1(component, state);
var if_block_2 = (state.c) && create_if_block_2(state, component);
var if_block_2 = (state.c) && create_if_block_2(component, state);
var if_block_3 = (state.d) && create_if_block_3(state, component);
var if_block_3 = (state.d) && create_if_block_3(component, state);
var if_block_4 = (state.e) && create_if_block_4(state, component);
var if_block_4 = (state.e) && create_if_block_4(component, state);
return {
c: function create() {
@ -249,7 +249,7 @@ function create_main_fragment(state, component) {
p: function update(changed, state) {
if (state.a) {
if (!if_block) {
if_block = create_if_block(state, component);
if_block = create_if_block(component, state);
if_block.c();
if_block.m(div, text);
}
@ -261,7 +261,7 @@ function create_main_fragment(state, component) {
if (state.b) {
if (!if_block_1) {
if_block_1 = create_if_block_1(state, component);
if_block_1 = create_if_block_1(component, state);
if_block_1.c();
if_block_1.m(div, text_3);
}
@ -273,7 +273,7 @@ function create_main_fragment(state, component) {
if (state.c) {
if (!if_block_2) {
if_block_2 = create_if_block_2(state, component);
if_block_2 = create_if_block_2(component, state);
if_block_2.c();
if_block_2.m(div, text_4);
}
@ -285,7 +285,7 @@ function create_main_fragment(state, component) {
if (state.d) {
if (!if_block_3) {
if_block_3 = create_if_block_3(state, component);
if_block_3 = create_if_block_3(component, state);
if_block_3.c();
if_block_3.m(div, null);
}
@ -297,7 +297,7 @@ function create_main_fragment(state, component) {
if (state.e) {
if (!if_block_4) {
if_block_4 = create_if_block_4(state, component);
if_block_4 = create_if_block_4(component, state);
if_block_4.c();
if_block_4.m(if_block_4_anchor.parentNode, if_block_4_anchor);
}
@ -330,7 +330,7 @@ function create_main_fragment(state, component) {
}
// (2:1) {{#if a}}
function create_if_block(state, component) {
function create_if_block(component, state) {
var p;
return {
@ -352,7 +352,7 @@ function create_if_block(state, component) {
}
// (8:1) {{#if b}}
function create_if_block_1(state, component) {
function create_if_block_1(component, state) {
var p;
return {
@ -374,7 +374,7 @@ function create_if_block_1(state, component) {
}
// (12:1) {{#if c}}
function create_if_block_2(state, component) {
function create_if_block_2(component, state) {
var p;
return {
@ -396,7 +396,7 @@ function create_if_block_2(state, component) {
}
// (18:1) {{#if d}}
function create_if_block_3(state, component) {
function create_if_block_3(component, state) {
var p;
return {
@ -418,7 +418,7 @@ function create_if_block_3(state, component) {
}
// (25:0) {{#if e}}
function create_if_block_4(state, component) {
function create_if_block_4(component, state) {
var p;
return {
@ -443,7 +443,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,18 +1,18 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor;
var if_block = (state.a) && create_if_block(state, component);
var if_block = (state.a) && create_if_block(component, state);
var if_block_1 = (state.b) && create_if_block_1(state, component);
var if_block_1 = (state.b) && create_if_block_1(component, state);
var if_block_2 = (state.c) && create_if_block_2(state, component);
var if_block_2 = (state.c) && create_if_block_2(component, state);
var if_block_3 = (state.d) && create_if_block_3(state, component);
var if_block_3 = (state.d) && create_if_block_3(component, state);
var if_block_4 = (state.e) && create_if_block_4(state, component);
var if_block_4 = (state.e) && create_if_block_4(component, state);
return {
c: function create() {
@ -56,7 +56,7 @@ function create_main_fragment(state, component) {
p: function update(changed, state) {
if (state.a) {
if (!if_block) {
if_block = create_if_block(state, component);
if_block = create_if_block(component, state);
if_block.c();
if_block.m(div, text);
}
@ -68,7 +68,7 @@ function create_main_fragment(state, component) {
if (state.b) {
if (!if_block_1) {
if_block_1 = create_if_block_1(state, component);
if_block_1 = create_if_block_1(component, state);
if_block_1.c();
if_block_1.m(div, text_3);
}
@ -80,7 +80,7 @@ function create_main_fragment(state, component) {
if (state.c) {
if (!if_block_2) {
if_block_2 = create_if_block_2(state, component);
if_block_2 = create_if_block_2(component, state);
if_block_2.c();
if_block_2.m(div, text_4);
}
@ -92,7 +92,7 @@ function create_main_fragment(state, component) {
if (state.d) {
if (!if_block_3) {
if_block_3 = create_if_block_3(state, component);
if_block_3 = create_if_block_3(component, state);
if_block_3.c();
if_block_3.m(div, null);
}
@ -104,7 +104,7 @@ function create_main_fragment(state, component) {
if (state.e) {
if (!if_block_4) {
if_block_4 = create_if_block_4(state, component);
if_block_4 = create_if_block_4(component, state);
if_block_4.c();
if_block_4.m(if_block_4_anchor.parentNode, if_block_4_anchor);
}
@ -137,7 +137,7 @@ function create_main_fragment(state, component) {
}
// (2:1) {{#if a}}
function create_if_block(state, component) {
function create_if_block(component, state) {
var p;
return {
@ -159,7 +159,7 @@ function create_if_block(state, component) {
}
// (8:1) {{#if b}}
function create_if_block_1(state, component) {
function create_if_block_1(component, state) {
var p;
return {
@ -181,7 +181,7 @@ function create_if_block_1(state, component) {
}
// (12:1) {{#if c}}
function create_if_block_2(state, component) {
function create_if_block_2(component, state) {
var p;
return {
@ -203,7 +203,7 @@ function create_if_block_2(state, component) {
}
// (18:1) {{#if d}}
function create_if_block_3(state, component) {
function create_if_block_3(component, state) {
var p;
return {
@ -225,7 +225,7 @@ function create_if_block_3(state, component) {
}
// (25:0) {{#if e}}
function create_if_block_4(state, component) {
function create_if_block_4(component, state) {
var p;
return {
@ -250,7 +250,7 @@ function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -190,7 +190,7 @@ var proto = {
};
/* generated by Svelte vX.Y.Z */
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1;
function onwindowscroll(event) {
@ -245,7 +245,7 @@ function SvelteComponent(options) {
this._state = assign({}, options.data);
this._state.y = window.pageYOffset;
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -1,7 +1,7 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createElement, createText, detachNode, init, insertNode, proto } from "svelte/shared.js";
function create_main_fragment(state, component) {
function create_main_fragment(component, state) {
var window_updating = false, clear_window_updating = function() { window_updating = false; }, window_updating_timeout, p, text, text_1;
function onwindowscroll(event) {
@ -56,7 +56,7 @@ function SvelteComponent(options) {
this._state = assign({}, options.data);
this._state.y = window.pageYOffset;
this._fragment = create_main_fragment(this._state, this);
this._fragment = create_main_fragment(this, this._state);
if (options.target) {
this._fragment.c();

@ -0,0 +1,13 @@
<slot>
<span>{{foo}}</span>
</slot>
<script>
export default {
data() {
return {
foo: 'a'
};
}
};
</script>

@ -0,0 +1,9 @@
export default {
html: `
<p>override default slot</p>
`,
test(assert, component) {
component.refs.nested.set({ foo: 'b' });
}
};

@ -0,0 +1,13 @@
<Nested ref:nested>
<p>override default slot</p>
</Nested>
<script>
import Nested from './Nested.html';
export default {
components: {
Nested
}
};
</script>

@ -0,0 +1,25 @@
import { Store } from '../../../../store.js';
const store = new Store({
name: 'world'
});
export default {
store,
html: `<h1>Hello world!</h1>`,
dev: true,
test(assert, component) {
const names = [];
component.observe('$name', name => {
names.push(name);
});
store.set({ name: 'everybody' });
assert.deepEqual(names, ['world', 'everybody']);
}
};

@ -113,6 +113,15 @@ describe('store', () => {
});
});
it('allows user to cancel state change callback', () => {
const store = new Store();
const handler = store.onchange(() => {});
assert.doesNotThrow(() => {
handler.cancel();
}, TypeError, 'this._changeHandlers is undefined');
});
describe('computed', () => {
it('computes a property based on data', () => {
const store = new Store({

@ -88,4 +88,19 @@ describe("validate", () => {
}
]);
});
it("does not warn if options.name begins with non-alphabetic character", () => {
const warnings = [];
svelte.compile("<div></div>", {
name: "_",
onwarn(warning) {
warnings.push({
message: warning.message,
pos: warning.pos,
loc: warning.loc
});
}
});
assert.deepEqual(warnings, []);
});
});

@ -58,10 +58,14 @@ acorn@^4.0.3:
version "4.0.13"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787"
acorn@^5.0.0, acorn@^5.1.1, acorn@^5.2.1, acorn@^5.3.0:
acorn@^5.0.0, acorn@^5.2.1, acorn@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.3.0.tgz#7446d39459c54fb49a80e6ee6478149b940ec822"
acorn@^5.4.1:
version "5.4.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.4.1.tgz#fdc58d9d17f4a4e98d102ded826a9b9759125102"
acorn@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.2.tgz#911cb53e036807cf0fa778dc5d370fbd864246d7"

Loading…
Cancel
Save