Merge remote-tracking branch 'upstream/master' into gh-1212

pull/1234/head
pk 7 years ago
commit 7661c2818c

@ -8,6 +8,9 @@ indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
[test/**/expected.css]
insert_final_newline = false
[{package.json,.travis.yml,.eslintrc.json}]
indent_style = space
indent_size = 2

@ -1,5 +1,43 @@
# Svelte changelog
## 2.8.1
* Fix prefixed animation name replacement ([#1556](https://github.com/sveltejs/svelte/pull/1556))
## 2.8.0
* Correctly set store on nested components (to parent store, not root store) ([#1538](https://github.com/sveltejs/svelte/issues/1538))
## 2.7.2
* Prevent unnecessary remounts ([#1527](https://github.com/sveltejs/svelte/issues/1527))
* Allow `refs.*` as callee ([#1526](https://github.com/sveltejs/svelte/pull/1526))
* Handle empty lists when outroing ([#1532](https://github.com/sveltejs/svelte/issues/1532))
## 2.7.1
* Fix spread props with multiple dependencies ([#1515](https://github.com/sveltejs/svelte/issues/1515))
## 2.7.0
* Add `__svelte_meta` object to elements in dev mode, containing source info ([#1499](https://github.com/sveltejs/svelte/issues/1499))
* Fix `bind:online` in dev mode ([#1502](https://github.com/sveltejs/svelte/issues/1502))
* Update v1 warnings/errors ([#1508](https://github.com/sveltejs/svelte/pull/1508))
* Transform prefixed keyframes ([#1504](https://github.com/sveltejs/svelte/issues/1504))
## 2.6.6
* Fix nested transition bug ([#1497](https://github.com/sveltejs/svelte/issues/1497))
## 2.6.5
* Handle cases where only some `if` block branches have outros ([#1492](https://github.com/sveltejs/svelte/issues/1492))
## 2.6.4
* Web worker support ([#1487](https://github.com/sveltejs/svelte/issues/1487))
* Update dynamic component bindings when component changes ([#1489](https://github.com/sveltejs/svelte/issues/1489))
## 2.6.3
* Nested transitions respect `skipIntroByDefault` ([#1460](https://github.com/sveltejs/svelte/issues/1460))

@ -1,6 +1,6 @@
{
"name": "svelte",
"version": "2.6.3",
"version": "2.8.1",
"description": "The magical disappearing UI framework",
"main": "compiler/svelte.js",
"bin": {
@ -82,6 +82,7 @@
"rollup-watch": "^4.3.1",
"sade": "^1.4.0",
"sander": "^0.6.0",
"shelljs": "^0.8.2",
"source-map": "0.6",
"source-map-support": "^0.5.4",
"tiny-glob": "^0.2.1",

@ -6,7 +6,7 @@ const now = (typeof process !== 'undefined' && process.hrtime)
const t = process.hrtime();
return t[0] * 1e3 + t[1] / 1e6;
}
: () => window.performance.now();
: () => self.performance.now();
type Timing = {
label: string;

@ -117,6 +117,8 @@ export default class Compiler {
expectedProperties: Set<string>;
usesRefs: boolean;
file: string;
fileVar: string;
locate: (c: number) => { line: number, column: number };
stylesheet: Stylesheet;
@ -159,6 +161,9 @@ export default class Compiler {
this.bindingGroups = [];
this.indirectDependencies = new Map();
this.file = options.filename && (
typeof process !== 'undefined' ? options.filename.replace(process.cwd(), '').replace(/^[\/\\]/, '') : options.filename
);
this.locate = getLocator(this.source);
// track which properties are needed, so we can provide useful info
@ -178,6 +183,8 @@ export default class Compiler {
this.aliases = new Map();
this.usedNames = new Set();
this.fileVar = options.dev && this.getUniqueName('file');
this.computations = [];
this.templateProperties = {};

@ -44,7 +44,9 @@ export default class Block {
maintainContext: boolean;
hasAnimation: boolean;
hasIntroMethod: boolean;
hasIntros: boolean;
hasOutros: boolean;
hasIntroMethod: boolean; // could have the method without the transition, due to siblings
hasOutroMethod: boolean;
outros: number;
@ -132,11 +134,11 @@ export default class Block {
}
addIntro() {
this.hasIntroMethod = this.compiler.target.hasIntroTransitions = true;
this.hasIntros = this.hasIntroMethod = this.compiler.target.hasIntroTransitions = true;
}
addOutro() {
this.hasOutroMethod = this.compiler.target.hasOutroTransitions = true;
this.hasOutros = this.hasOutroMethod = this.compiler.target.hasOutroTransitions = true;
this.outros += 1;
}
@ -145,6 +147,10 @@ export default class Block {
}
addVariable(name: string, init?: string) {
if (name[0] === '#') {
name = this.alias(name.slice(1));
}
if (this.variables.has(name) && this.variables.get(name) !== init) {
throw new Error(
`Variable '${name}' already initialised with a different value`
@ -169,18 +175,16 @@ export default class Block {
toString() {
const { dev } = this.compiler.options;
let introing;
const hasIntros = !this.builders.intro.isEmpty();
if (hasIntros) {
introing = this.getUniqueName('introing');
this.addVariable(introing);
if (this.hasIntroMethod || this.hasOutroMethod) {
this.addVariable('#current');
if (!this.builders.mount.isEmpty()) {
this.builders.mount.addLine(`#current = true;`);
}
let outroing;
const hasOutros = !this.builders.outro.isEmpty();
if (hasOutros) {
outroing = this.alias('outroing');
this.addVariable(outroing);
if (!this.builders.outro.isEmpty()) {
this.builders.outro.addLine(`#current = false;`);
}
}
if (this.autofocus) {
@ -278,46 +282,30 @@ export default class Block {
}
if (this.hasIntroMethod || this.hasOutroMethod) {
if (hasIntros) {
properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
if (${introing}) return;
${introing} = true;
${hasOutros && `${outroing} = false;`}
${this.builders.intro}
this.m(#target, anchor);
},
`);
} else {
if (this.builders.mount.isEmpty()) {
properties.addBlock(`i: @noop,`);
} else {
properties.addBlock(deindent`
${dev ? 'i: function intro' : 'i'}(#target, anchor) {
if (#current) return;
${this.builders.intro}
this.m(#target, anchor);
},
`);
}
}
if (hasOutros) {
if (this.builders.outro.isEmpty()) {
properties.addBlock(`o: @run,`);
} else {
properties.addBlock(deindent`
${dev ? 'o: function outro' : 'o'}(#outrocallback) {
if (${outroing}) return;
${outroing} = true;
${hasIntros && `${introing} = false;`}
if (!#current) return;
${this.outros > 1 && `#outrocallback = @callAfter(#outrocallback, ${this.outros});`}
${this.builders.outro}
},
`);
} else {
properties.addBlock(deindent`
o: @run,
`);
}
}

@ -100,6 +100,10 @@ export default function dom(
builder.addBlock(compiler.javascript);
}
if (compiler.options.dev) {
builder.addLine(`const ${compiler.fileVar} = ${JSON.stringify(compiler.file)};`);
}
const css = compiler.stylesheet.render(options.filename, !compiler.customElement);
const styles = compiler.stylesheet.hasStyles && stringify(options.dev ?
`${css.code}\n/*# sourceMappingURL=${css.map.toUrl()} */` :
@ -360,12 +364,8 @@ export default function dom(
let result = builder.toString();
const filename = options.filename && (
typeof process !== 'undefined' ? options.filename.replace(process.cwd(), '').replace(/^[\/\\]/, '') : options.filename
);
return compiler.generate(result, options, {
banner: `/* ${filename ? `${filename} ` : ``}generated by Svelte v${"__VERSION__"} */`,
banner: `/* ${compiler.file ? `${compiler.file} ` : ``}generated by Svelte v${"__VERSION__"} */`,
sharedPath,
name,
format,

@ -232,7 +232,7 @@ export default class Attribute extends Node {
if (this.dependencies.size || isSelectValueAttribute) {
const dependencies = Array.from(this.dependencies);
const changedCheck = (
( block.hasOutroMethod ? `#outroing || ` : '' ) +
(block.hasOutros ? `!#current || ` : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
);
@ -308,7 +308,7 @@ export default class Attribute extends Node {
if (propDependencies.size) {
const dependencies = Array.from(propDependencies);
const condition = (
(block.hasOutroMethod ? `#outroing || ` : '') +
(block.hasOutros ? `!#current || ` : '') +
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
);

@ -61,8 +61,8 @@ export default class AwaitBlock extends Node {
block.addDependencies(child.block.dependencies);
}
if (child.block.hasIntroMethod) hasIntros = true;
if (child.block.hasOutroMethod) hasOutros = true;
if (child.block.hasIntros) hasIntros = true;
if (child.block.hasOutros) hasOutros = true;
});
this.pending.block.hasUpdateMethod = isDynamic;
@ -172,12 +172,13 @@ export default class AwaitBlock extends Node {
}
if (this.pending.block.hasOutroMethod && this.compiler.options.nestedTransitions) {
const countdown = block.getUniqueName('countdown');
block.builders.outro.addBlock(deindent`
#outrocallback = @callAfter(#outrocallback, 3);
const ${countdown} = @callAfter(#outrocallback, 3);
for (let #i = 0; #i < 3; #i += 1) {
const block = ${info}.blocks[#i];
if (block) block.o(#outrocallback);
else #outrocallback();
if (block) block.o(${countdown});
else ${countdown}();
}
`);
}

@ -123,7 +123,7 @@ export default class Component extends Node {
const name = this.var;
const componentInitProperties = [`root: #component.root`];
const componentInitProperties = [`root: #component.root`, `store: #component.store`];
if (this.children.length > 0) {
const slots = Array.from(this._slots).map(name => `${quoteNameIfNecessary(name)}: @createFragment()`);
@ -176,7 +176,7 @@ export default class Component extends Node {
const { name, dependencies } = attr;
const condition = dependencies.size > 0 && (dependencies.size !== allDependencies.size)
? [...dependencies].map(d => `changed.${d}`).join(' || ')
? `(${[...dependencies].map(d => `changed.${d}`).join(' || ')})`
: null;
if (attr.isSpread) {
@ -290,7 +290,7 @@ export default class Component extends Node {
}
statements.push(deindent`
if (${binding.prop} in ${binding.obj}) {
if (${binding.value.snippet} !== void 0) {
${name_initial_data}.${binding.name} = ${binding.value.snippet};
${name_updating}.${binding.name} = true;
}`
@ -304,7 +304,7 @@ export default class Component extends Node {
updates.push(deindent`
if (!${name_updating}.${binding.name} && ${[...binding.value.dependencies].map((dependency: string) => `changed.${dependency}`).join(' || ')}) {
${name_changes}.${binding.name} = ${binding.value.snippet};
${name_updating}.${binding.name} = true;
${name_updating}.${binding.name} = ${binding.value.snippet} !== void 0;
}
`);
});
@ -318,7 +318,7 @@ export default class Component extends Node {
// TODO use component.on('state', ...) instead of _bind
componentInitProperties.push(deindent`
_bind: function(changed, childState) {
_bind(changed, childState) {
var ${initialisers};
${builder}
${hasStoreBindings && `#component.store.set(newStoreState);`}
@ -328,7 +328,7 @@ export default class Component extends Node {
`);
beforecreate = deindent`
#component.root._beforecreate.push(function() {
#component.root._beforecreate.push(() => {
${name}._bind({ ${this.bindings.map(b => `${b.name}: 1`).join(', ')} }, ${name}.get());
});
`;
@ -406,6 +406,14 @@ export default class Component extends Node {
if (${switch_value}) {
${name} = new ${switch_value}(${switch_props}(ctx));
${this.bindings.length > 0 && deindent`
#component.root._beforecreate.push(() => {
const changed = {};
${this.bindings.map(binding => deindent`
if (${binding.value.snippet} === void 0) changed.${binding.name} = 1;`)}
${name}._bind(changed, ${name}.get());
});`}
${name}._fragment.c();
${this.children.map(child => child.remount(name))}
@ -554,8 +562,8 @@ export default class Component extends Node {
const expression = (
this.name === 'svelte:self' ? this.compiler.name :
isDynamicComponent ? `((${this.expression.snippet}) || @missingComponent)` :
`%components-${this.name}`
(isDynamicComponent ? `((${this.expression.snippet}) || @missingComponent)` :
`%components-${this.name}`)
);
this.bindings.forEach(binding => {

@ -119,7 +119,7 @@ export default class EachBlock extends Node {
this.else.block.hasUpdateMethod = this.else.block.dependencies.size > 0;
}
if (this.block.hasOutroMethod || (this.else && this.else.block.hasOutroMethod)) {
if (this.block.hasOutros || (this.else && this.else.block.hasOutros)) {
block.addOutro();
}
}
@ -317,23 +317,24 @@ export default class EachBlock extends Node {
const rects = block.getUniqueName('rects');
const destroy = this.block.hasAnimation
? `@fixAndOutroAndDestroyBlock`
: this.block.hasOutroMethod
: this.block.hasOutros
? `@outroAndDestroyBlock`
: `@destroyBlock`;
block.builders.update.addBlock(deindent`
const ${this.each_block_value} = ${snippet};
${this.block.hasOutroMethod && `@transitionManager.groupOutros();`}
${this.block.hasOutros && `@transitionManager.groupOutros();`}
${this.block.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].r();`}
${blocks} = @updateKeyedEach(${blocks}, #component, changed, ${get_key}, ${dynamic ? '1' : '0'}, ctx, ${this.each_block_value}, ${lookup}, ${updateMountNode}, ${destroy}, ${create_each_block}, "${mountOrIntro}", ${anchor}, ${this.get_each_context});
${this.block.hasAnimation && `for (let #i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].a();`}
`);
if (this.compiler.options.nestedTransitions) {
const countdown = block.getUniqueName('countdown');
block.builders.outro.addBlock(deindent`
#outrocallback = @callAfter(#outrocallback, ${blocks}.length);
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].o(#outrocallback);
const ${countdown} = @callAfter(#outrocallback, ${blocks}.length);
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].o(${countdown});
`);
}
@ -393,14 +394,16 @@ export default class EachBlock extends Node {
allDependencies.add(dependency);
});
const outro = this.block.hasOutroMethod && block.getUniqueName('outro')
if (outro) {
const outroBlock = this.block.hasOutros && block.getUniqueName('outroBlock')
if (outroBlock) {
block.builders.init.addBlock(deindent`
function ${outro}(i, detach, fn) {
function ${outroBlock}(i, detach, fn) {
if (${iterations}[i]) {
${iterations}[i].o(() => {
if (detach) {
${iterations}[i].d(detach);
if (detach) ${iterations}[i] = null;
${iterations}[i] = null;
}
if (fn) fn();
});
}
@ -415,7 +418,7 @@ export default class EachBlock extends Node {
if (condition !== '') {
const forLoopBody = this.block.hasUpdateMethod
? (this.block.hasIntroMethod || this.block.hasOutroMethod)
? (this.block.hasIntros || this.block.hasOutros)
? deindent`
if (${iterations}[#i]) {
${iterations}[#i].p(changed, child_ctx);
@ -444,10 +447,10 @@ export default class EachBlock extends Node {
let destroy;
if (this.block.hasOutroMethod) {
if (this.block.hasOutros) {
destroy = deindent`
@transitionManager.groupOutros();
for (; #i < ${iterations}.length; #i += 1) ${outro}(#i, 1);
for (; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 1);
`;
} else {
destroy = deindent`
@ -473,10 +476,11 @@ export default class EachBlock extends Node {
`);
}
if (outro && this.compiler.options.nestedTransitions) {
if (outroBlock && this.compiler.options.nestedTransitions) {
const countdown = block.getUniqueName('countdown');
block.builders.outro.addBlock(deindent`
#outrocallback = @callAfter(#outrocallback, #i);
for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outro}(#i, 0, #outrocallback);`
const ${countdown} = @callAfter(#outrocallback, ${iterations}.length);
for (let #i = 0; #i < ${iterations}.length; #i += 1) ${outroBlock}(#i, 0, ${countdown});`
);
}

@ -143,7 +143,7 @@ export default class Element extends Node {
stripWhitespace: boolean,
nextSibling: Node
) {
if (this.name === 'slot' || this.name === 'option') {
if (this.name === 'slot' || this.name === 'option' || this.compiler.options.dev) {
this.cannotUseInnerHTML();
}
@ -300,13 +300,6 @@ export default class Element extends Node {
block.builders.destroy.addConditional('detach', `@detachNode(${name});`);
}
// TODO move this into a class as well?
if (this._cssRefAttribute) {
block.builders.hydrate.addLine(
`@setAttribute(${name}, "svelte-ref-${this._cssRefAttribute}", "");`
)
}
// insert static children with textContent or innerHTML
if (!this.namespace && this.canUseInnerHTML && this.children.length > 0) {
if (this.children.length === 1 && this.children[0].type === 'Text') {
@ -394,10 +387,6 @@ export default class Element extends Node {
let open = `<${node.name}`;
if (node._cssRefAttribute) {
open += ` svelte-ref-${node._cssRefAttribute}`;
}
node.attributes.forEach((attr: Node) => {
open += ` ${fixAttributeCasing(attr.name)}${stringifyAttributeValue(attr.chunks)}`
});
@ -406,6 +395,13 @@ export default class Element extends Node {
return `${open}>${node.children.map(toHTML).join('')}</${node.name}>`;
}
if (this.compiler.options.dev) {
const loc = this.compiler.locate(this.start);
block.builders.hydrate.addLine(
`@addLoc(${this.var}, ${this.compiler.fileVar}, ${loc.line}, ${loc.column}, ${this.start});`
);
}
}
addBindings(
@ -563,7 +559,7 @@ export default class Element extends Node {
.filter(attr => attr.type === 'Attribute' || attr.type === 'Spread')
.forEach(attr => {
const condition = attr.dependencies.size > 0
? [...attr.dependencies].map(d => `changed.${d}`).join(' || ')
? `(${[...attr.dependencies].map(d => `changed.${d}`).join(' || ')})`
: null;
if (attr.isSpread) {
@ -858,19 +854,17 @@ export default class Element extends Node {
return `@appendNode(${this.var}, ${name}._slotted.default);`;
}
addCssClass() {
addCssClass(className = this.compiler.stylesheet.id) {
const classAttribute = this.attributes.find(a => a.name === 'class');
if (classAttribute && !classAttribute.isTrue) {
if (classAttribute.chunks.length === 1 && classAttribute.chunks[0].type === 'Text') {
(<Text>classAttribute.chunks[0]).data += ` ${this.compiler.stylesheet.id}`;
(<Text>classAttribute.chunks[0]).data += ` ${className}`;
} else {
(<Node[]>classAttribute.chunks).push(
new Text(this.compiler, this, this.scope, {
type: 'Text',
data: ` ${this.compiler.stylesheet.id}`
data: ` ${className}`
})
// new Text({ type: 'Text', data: ` ${this.compiler.stylesheet.id}` })
);
}
} else {
@ -878,7 +872,7 @@ export default class Element extends Node {
new Attribute(this.compiler, this, this.scope, {
type: 'Attribute',
name: 'class',
value: [{ type: 'Text', data: `${this.compiler.stylesheet.id}` }]
value: [{ type: 'Text', data: className }]
})
);
}
@ -945,10 +939,6 @@ export default class Element extends Node {
});
}
if (this._cssRefAttribute) {
openingTag += ` svelte-ref-${this._cssRefAttribute}`;
}
openingTag += '>';
compiler.target.append(openingTag);

@ -68,8 +68,8 @@ export default class IfBlock extends Node {
block.addDependencies(node.block.dependencies);
}
if (node.block.hasIntroMethod) hasIntros = true;
if (node.block.hasOutroMethod) hasOutros = true;
if (node.block.hasIntros) hasIntros = true;
if (node.block.hasOutros) hasOutros = true;
if (isElseIf(node.else)) {
attachBlocks(node.else.children[0]);
@ -147,9 +147,10 @@ export default class IfBlock extends Node {
this.buildSimple(block, parentNode, parentNodes, branches[0], dynamic, vars);
if (hasOutros && this.compiler.options.nestedTransitions) {
block.builders.outro.addLine(
`if (${name}) ${name}.o(#outrocallback);`
);
block.builders.outro.addBlock(deindent`
if (${name}) ${name}.o(#outrocallback);
else #outrocallback();
`);
}
}
@ -355,9 +356,7 @@ export default class IfBlock extends Node {
}
block.builders.destroy.addLine(deindent`
${if_current_block_type_index}{
${if_blocks}[${current_block_type_index}].d(${parentNode ? '' : 'detach'});
}
${if_current_block_type_index}${if_blocks}[${current_block_type_index}].d(${parentNode ? '' : 'detach'});
`);
}

@ -35,7 +35,7 @@ export default class Title extends Node {
// TODO some of this code is repeated in Tag.ts — would be good to
// DRY it out if that's possible without introducing crazy indirection
if (this.children.length === 1) {
// single {{tag}} — may be a non-string
// single {tag} — may be a non-string
const { expression } = this.children[0];
const { dependencies, snippet } = this.children[0].expression;
@ -81,7 +81,7 @@ export default class Title extends Node {
if (allDependencies.size) {
const dependencies = Array.from(allDependencies);
const changedCheck = (
( block.hasOutroMethod ? `#outroing || ` : '' ) +
( block.hasOutros ? `!#current || ` : '' ) +
dependencies.map(dependency => `changed.${dependency}`).join(' || ')
);

@ -200,7 +200,9 @@ export default class Window extends Node {
const handlerName = block.getUniqueName(`onlinestatuschanged`);
block.builders.init.addBlock(deindent`
function ${handlerName}(event) {
${compiler.options.dev && `component._updatingReadonlyProperty = true;`}
#component.set({ ${bindings.online}: navigator.onLine });
${compiler.options.dev && `component._updatingReadonlyProperty = false;`}
}
window.addEventListener("online", ${handlerName});
window.addEventListener("offline", ${handlerName});

@ -35,7 +35,7 @@ export default class Tag extends Node {
if (dependencies.size) {
const changedCheck = (
(block.hasOutroMethod ? `#outroing || ` : '') +
(block.hasOutros ? `!#current || ` : '') +
[...dependencies].map((dependency: string) => `changed.${dependency}`).join(' || ')
);

@ -30,7 +30,7 @@ export default class Selector {
apply(node: Node, stack: Node[]) {
const toEncapsulate: Node[] = [];
applySelector(this.localBlocks.slice(), node, stack.slice(), toEncapsulate);
applySelector(this.stylesheet, this.localBlocks.slice(), node, stack.slice(), toEncapsulate);
if (toEncapsulate.length > 0) {
toEncapsulate.filter((_, i) => i === 0 || i === toEncapsulate.length - 1).forEach(({ node, block }) => {
@ -76,7 +76,7 @@ export default class Selector {
const selector = block.selectors[i];
if (selector.type === 'RefSelector') {
code.overwrite(selector.start, selector.end, `[svelte-ref-${selector.name}]`, {
code.overwrite(selector.start, selector.end, `.svelte-ref-${selector.name}`, {
contentOnly: true,
storeName: false
});
@ -136,7 +136,7 @@ function isDescendantSelector(selector: Node) {
return selector.type === 'WhiteSpace' || selector.type === 'Combinator';
}
function applySelector(blocks: Block[], node: Node, stack: Node[], toEncapsulate: any[]): boolean {
function applySelector(stylesheet: Stylesheet, blocks: Block[], node: Node, stack: Node[], toEncapsulate: any[]): boolean {
const block = blocks.pop();
if (!block) return false;
@ -179,7 +179,7 @@ function applySelector(blocks: Block[], node: Node, stack: Node[], toEncapsulate
else if (selector.type === 'RefSelector') {
if (node.ref === selector.name) {
node._cssRefAttribute = selector.name;
stylesheet.nodesWithRefCssClass.set(selector.name, node);
toEncapsulate.push({ node, block });
return true;
}
@ -196,7 +196,7 @@ function applySelector(blocks: Block[], node: Node, stack: Node[], toEncapsulate
if (block.combinator) {
if (block.combinator.type === 'WhiteSpace') {
while (stack.length) {
if (applySelector(blocks.slice(), stack.pop(), stack, toEncapsulate)) {
if (applySelector(stylesheet, blocks.slice(), stack.pop(), stack, toEncapsulate)) {
toEncapsulate.push({ node, block });
return true;
}
@ -204,7 +204,7 @@ function applySelector(blocks: Block[], node: Node, stack: Node[], toEncapsulate
return false;
} else if (block.combinator.name === '>') {
if (applySelector(blocks, stack.pop(), stack, toEncapsulate)) {
if (applySelector(stylesheet, blocks, stack.pop(), stack, toEncapsulate)) {
toEncapsulate.push({ node, block });
return true;
}

@ -4,10 +4,13 @@ import { getLocator } from 'locate-character';
import Selector from './Selector';
import getCodeFrame from '../utils/getCodeFrame';
import hash from '../utils/hash';
import removeCSSPrefix from '../utils/removeCSSPrefix';
import Element from '../compile/nodes/Element';
import { Validator } from '../validate/index';
import { Node, Ast, Warning } from '../interfaces';
const isKeyframesNode = (node: Node) => removeCSSPrefix(node.name) === 'keyframes'
class Rule {
selectors: Selector[];
declarations: Declaration[];
@ -26,7 +29,7 @@ class Rule {
}
isUsed(dev: boolean) {
if (this.parent && this.parent.node.type === 'Atrule' && this.parent.node.name === 'keyframes') return true;
if (this.parent && this.parent.node.type === 'Atrule' && isKeyframesNode(this.parent.node)) return true;
if (this.declarations.length === 0) return dev;
return this.selectors.some(s => s.used);
}
@ -67,7 +70,7 @@ class Rule {
}
transform(code: MagicString, id: string, keyframes: Map<string, string>) {
if (this.parent && this.parent.node.type === 'Atrule' && this.parent.node.name === 'keyframes') return true;
if (this.parent && this.parent.node.type === 'Atrule' && isKeyframesNode(this.parent.node)) return true;
const attr = `.${id}`;
@ -96,7 +99,7 @@ class Declaration {
}
transform(code: MagicString, keyframes: Map<string, string>) {
const property = this.node.property && this.node.property.toLowerCase();
const property = this.node.property && removeCSSPrefix(this.node.property.toLowerCase());
if (property === 'animation' || property === 'animation-name') {
this.node.value.children.forEach((block: Node) => {
if (block.type === 'Identifier') {
@ -142,7 +145,7 @@ class Atrule {
});
}
else if (this.node.name === 'keyframes') {
else if (isKeyframesNode(this.node)) {
this.children.forEach((rule: Rule) => {
rule.selectors.forEach(selector => {
selector.used = true;
@ -167,8 +170,8 @@ class Atrule {
});
code.remove(c, this.node.block.start);
} else if (this.node.name === 'keyframes') {
let c = this.node.start + 10;
} else if (isKeyframesNode(this.node)) {
let c = this.node.start + this.node.name.length + 1;
if (this.node.expression.start - c > 1) code.overwrite(c, this.node.expression.start, ' ');
c = this.node.expression.end;
if (this.node.block.start - c > 0) code.remove(c, this.node.block.start);
@ -200,7 +203,7 @@ class Atrule {
}
transform(code: MagicString, id: string, keyframes: Map<string, string>) {
if (this.node.name === 'keyframes') {
if (isKeyframesNode(this.node)) {
this.node.expression.children.forEach(({ type, name, start, end }: Node) => {
if (type === 'Identifier') {
if (name.startsWith('-global-')) {
@ -247,6 +250,7 @@ export default class Stylesheet {
keyframes: Map<string, string>;
nodesWithCssClass: Set<Node>;
nodesWithRefCssClass: Map<String, Node>;
constructor(source: string, ast: Ast, filename: string, dev: boolean) {
this.source = source;
@ -258,6 +262,7 @@ export default class Stylesheet {
this.keyframes = new Map();
this.nodesWithCssClass = new Set();
this.nodesWithRefCssClass = new Map();
if (ast.css && ast.css.children.length) {
this.id = `svelte-${hash(ast.css.content.styles)}`;
@ -285,7 +290,7 @@ export default class Stylesheet {
this.children.push(atrule);
}
if (node.name === 'keyframes') {
if (isKeyframesNode(node)) {
node.expression.children.forEach((expression: Node) => {
if (expression.type === 'Identifier' && !expression.name.startsWith('-global-')) {
this.keyframes.set(expression.name, `${this.id}-${expression.name}`);
@ -337,6 +342,9 @@ export default class Stylesheet {
this.nodesWithCssClass.forEach((node: Node) => {
node.addCssClass();
});
this.nodesWithRefCssClass.forEach((node: Node, name: String) => {
node.addCssClass(`svelte-ref-${name}`);
})
}
render(cssOutputFilename: string, shouldTransformSelectors: boolean) {

@ -37,7 +37,7 @@ export default function mustache(parser: Parser) {
parser.allowWhitespace();
// {{/if}} or {{/each}}
// {/if} or {/each}
if (parser.eat('/')) {
let block = parser.current();
let expected;
@ -92,7 +92,7 @@ export default function mustache(parser: Parser) {
if (block.type !== 'IfBlock')
parser.error({
code: `invalid-elseif-placement`,
message: 'Cannot have an {{elseif ...}} block outside an {{#if ...}} block'
message: 'Cannot have an {:elseif ...} block outside an {#if ...} block'
});
parser.requireWhitespace();
@ -124,7 +124,7 @@ export default function mustache(parser: Parser) {
if (block.type !== 'IfBlock' && block.type !== 'EachBlock') {
parser.error({
code: `invalid-else-placement`,
message: 'Cannot have an {{else}} block outside an {{#if ...}} or {{#each ...}} block'
message: 'Cannot have an {:else} block outside an {#if ...} or {#each ...} block'
});
}
@ -187,7 +187,7 @@ export default function mustache(parser: Parser) {
parser.stack.push(catchBlock);
}
} else if (parser.eat('#')) {
// {{#if foo}} or {{#each foo}}
// {#if foo}, {#each foo} or {#await foo}
let type;
if (parser.eat('if')) {
@ -244,7 +244,7 @@ export default function mustache(parser: Parser) {
parser.allowWhitespace();
// {{#each}} blocks must declare a context {{#each list as item}}
// {#each} blocks must declare a context {#each list as item}
if (type === 'EachBlock') {
parser.eat('as', true);
parser.requireWhitespace();
@ -299,7 +299,7 @@ export default function mustache(parser: Parser) {
parser.stack.push(childBlock);
}
} else if (parser.eat('@html')) {
// {{{raw}}} mustache
// {@html content} tag
const expression = readExpression(parser);
parser.allowWhitespace();

@ -65,7 +65,7 @@ export function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
export function on(eventName, handler) {

@ -15,7 +15,14 @@ export function isPromise(value) {
}
export function callAfter(fn, i) {
if (i === 0) fn();
return () => {
if (!--i) fn();
};
}
export function addLoc(element, file, line, column, char) {
element.__svelte_meta = {
loc: { file, line, column, char }
};
}

@ -0,0 +1,3 @@
export default function(name: string): string {
return name.replace(/^-((webkit)|(moz)|(o)|(ms))-/, '');
}

@ -69,7 +69,7 @@ export default function validateElement(
if (child.type !== 'Text' && child.type !== 'MustacheTag') {
validator.error(child, {
code: 'illegal-structure',
message: `<title> can only contain text and {{tags}}`
message: `<title> can only contain text and {tags}`
});
}
});

@ -43,7 +43,7 @@ export default function validateEventHandlerCallee(
return;
}
const validCallees = ['this.*', 'event.*', 'options.*', 'console.*'].concat(
const validCallees = ['this.*', 'refs.*', 'event.*', 'options.*', 'console.*'].concat(
Array.from(validBuiltins),
Array.from(validator.methods.keys())
);

@ -13,7 +13,7 @@ export default function validateHead(validator: Validator, node: Node, refs: Map
// TODO ensure only valid elements are included here
node.children.forEach(node => {
if (node.type !== 'Element' && node.type !== 'Title') return; // TODO handle {{#if}} and friends?
if (node.type !== 'Element' && node.type !== 'Title') return; // TODO handle {#if} and friends?
validateElement(validator, node, refs, refCallees, [], []);
});
}

@ -1,15 +1,18 @@
const fs = require('fs');
const path = require('path');
const child_process = require('child_process');
const assert = require('assert');
const glob = require('tiny-glob/sync.js');
const shell = require("shelljs");
const bin = path.resolve(`svelte`);
const cli = path.resolve(__dirname, "../../cli/index.ts.js");
function normalize(str) {
return str
.replace(/^\s+$/gm, '')
.replace(/generated by Svelte v[.\d]+/, `generated by Svelte vx.y.z`)
.replace(
/\/\*(.*?)generated by Svelte v[.\d]+/,
(_, path) => `/*${path.replace(/\\/g, '/')}generated by Svelte vx.y.z`
)
.trim();
}
@ -31,14 +34,14 @@ describe('cli', () => {
const command = fs.readFileSync('command.sh', 'utf-8');
child_process.exec(`
alias svelte=${bin}
mkdir -p actual
rm -rf actual/*
${command}
`, (err, stdout, stderr) => {
if (err) {
done(err);
shell.mkdir("-p", "actual");
shell.rm("-rf", "actual/*");
const { commandErr } = shell.exec(
command.replace(/^svelte /, `node ${cli} `)
);
if (commandErr) {
done(commandErr);
return;
}
@ -76,4 +79,3 @@ describe('cli', () => {
});
});
});
});

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
function create_main_fragment(component, ctx) {
var p;
@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
function create_main_fragment(component, ctx) {
var p;
@ -90,7 +90,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,16 +1,20 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
const file = "src/Main.html";
function create_main_fragment(component, ctx) {
var p;
var p, text;
return {
c: function create() {
p = createElement("p");
p.textContent = "Hello world!";
text = createText("Hello world!");
addLoc(p, file, 0, 0, 0);
},
m: function mount(target, anchor) {
insertNode(p, target, anchor);
appendNode(text, p);
},
p: noop,
@ -59,10 +63,24 @@ function createElement(name) {
return document.createElement(name);
}
function createText(data) {
return document.createTextNode(data);
}
function addLoc(element, file, line, column, char) {
element.__svelte_meta = {
loc: { file, line, column, char }
};
}
function insertNode(node, target, anchor) {
target.insertBefore(node, anchor);
}
function appendNode(node, target) {
target.appendChild(node);
}
function noop() {}
function detachNode(node) {
@ -75,7 +93,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte v2.7.2 */
import Widget from './Widget.html';
@ -6,7 +6,8 @@ import Widget from './Widget.html';
function create_main_fragment(component, ctx) {
var widget = new Widget({
root: component.root
root: component.root,
store: component.store
});
return {
@ -72,7 +73,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1 +1 @@
{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["<Widget/>\n\n<script>\n\timport Widget from './Widget.html';\n\n\texport default {\n\t\tcomponents: {\n\t\t\tWidget\n\t\t}\n\t};\n</script>"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
{"version":3,"file":"Main.js","sources":["../src/Main.html"],"sourcesContent":["<Widget/>\n\n<script>\n\timport Widget from './Widget.html';\n\n\texport default {\n\t\tcomponents: {\n\t\t\tWidget\n\t\t}\n\t};\n</script>"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}

@ -1,4 +1,4 @@
/* src/Widget.html generated by Svelte v2.5.1 */
/* src/Widget.html generated by Svelte v2.7.2 */
function create_main_fragment(component, ctx) {
var p;
@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
import Widget from './widget/Widget.html';
@ -6,7 +6,8 @@ import Widget from './widget/Widget.html';
function create_main_fragment(component, ctx) {
var widget = new Widget({
root: component.root
root: component.root,
store: component.store
});
return {
@ -72,7 +73,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/widget/Widget.html generated by Svelte v2.5.1 */
/* src/widget/Widget.html generated by Svelte vx.y.z */
function create_main_fragment(component, ctx) {
var p;
@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
import Widget from './Widget.html';
@ -6,7 +6,8 @@ import Widget from './Widget.html';
function create_main_fragment(component, ctx) {
var widget = new Widget({
root: component.root
root: component.root,
store: component.store
});
return {
@ -72,7 +73,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Widget.html generated by Svelte v2.5.1 */
/* src/Widget.html generated by Svelte vx.y.z */
function create_main_fragment(component, ctx) {
var p;
@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
var Main = (function(answer) { "use strict";
answer = (answer && answer.__esModule) ? answer["default"] : answer;
@ -90,7 +90,7 @@ var Main = (function(answer) { "use strict";
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
function create_main_fragment(component, ctx) {
var p;
@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
function create_main_fragment(component, ctx) {
var p;
@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,4 @@
/* src/Main.html generated by Svelte v2.5.1 */
/* src/Main.html generated by Svelte vx.y.z */
function create_main_fragment(component, ctx) {
var h1, text, text_1;
@ -85,7 +85,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function assign(tar, src) {

@ -1,4 +1,5 @@
const sander = require('sander');
const glob = require('tiny-glob/sync');
process.chdir(__dirname);
@ -6,5 +7,14 @@ sander.readdirSync('samples').forEach(dir => {
if (dir[0] === '.') return;
sander.rimrafSync(`samples/${dir}/expected`);
sander.copydirSync(`samples/${dir}/actual`).to(`samples/${dir}/expected`);
const files = glob(`**`, { cwd: `samples/${dir}/actual`, filesOnly: true });
files.forEach(file => {
const source = sander.readFileSync(`samples/${dir}/actual/${file}`, { encoding: 'utf-8' });
sander.writeFileSync(
`samples/${dir}/expected/${file}`,
source.replace(/generated by Svelte v(\d+\.\d+\.\d+)/, 'generated by Svelte vx.y.z')
);
});
});

@ -0,0 +1 @@
@keyframes svelte-xyz-why{0%{color:red}100%{color:blue}}@-webkit-keyframes svelte-xyz-why{0%{color:red}100%{color:blue}}@-moz-keyframes svelte-xyz-why{0%{color:red}100%{color:blue}}@-o-keyframes svelte-xyz-why{0%{color:red}100%{color:blue}}.animated.svelte-xyz{-webkit-animation:svelte-xyz-why 2s;animation:svelte-xyz-why 2s}.also-animated.svelte-xyz{-webkit-animation:not-defined-here 2s;animation:not-defined-here 2s}

@ -0,0 +1,34 @@
<div class='animated'>animated</div>
<div class='also-animated'>also animated</div>
<style>
@keyframes why {
0% { color: red; }
100% { color: blue; }
}
@-webkit-keyframes why {
0% { color: red; }
100% { color: blue; }
}
@-moz-keyframes why {
0% { color: red; }
100% { color: blue; }
}
@-o-keyframes why {
0% { color: red; }
100% { color: blue; }
}
.animated {
-webkit-animation: why 2s;
animation: why 2s;
}
.also-animated {
-webkit-animation: not-defined-here 2s;
animation: not-defined-here 2s;
}
</style>

@ -1 +1 @@
[svelte-ref-button].active.svelte-xyz{color:red}
.svelte-ref-button.active.svelte-xyz{color:red}

@ -1 +1 @@
<button svelte-ref-button="" class="active svelte-xyz">deactivate</button>
<button class="active svelte-xyz svelte-ref-button">deactivate</button>

@ -1 +1 @@
[svelte-ref-a].svelte-xyz{color:red}[svelte-ref-b].svelte-xyz{color:green}
.svelte-ref-a.svelte-xyz{color:red}.svelte-ref-b.svelte-xyz{color:green}

@ -1,3 +1,3 @@
<div class="svelte-xyz" svelte-ref-a=''></div>
<div class="svelte-xyz" svelte-ref-b=''></div>
<div class="svelte-xyz svelte-ref-a"></div>
<div class="svelte-xyz svelte-ref-b"></div>
<div></div>

@ -61,7 +61,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -93,7 +93,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -49,7 +49,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {
@ -124,6 +124,7 @@ function create_main_fragment(component, ctx) {
var nested_initial_data = { foo: [1, 2, 3] };
var nested = new Nested({
root: component.root,
store: component.store,
data: nested_initial_data
});

@ -8,6 +8,7 @@ function create_main_fragment(component, ctx) {
var nested_initial_data = { foo: [1, 2, 3] };
var nested = new Nested({
root: component.root,
store: component.store,
data: nested_initial_data
});

@ -53,7 +53,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {
@ -128,6 +128,7 @@ function create_main_fragment(component, ctx) {
var nested_initial_data = { foo: "bar" };
var nested = new Nested({
root: component.root,
store: component.store,
data: nested_initial_data
});

@ -8,6 +8,7 @@ function create_main_fragment(component, ctx) {
var nested_initial_data = { foo: "bar" };
var nested = new Nested({
root: component.root,
store: component.store,
data: nested_initial_data
});

@ -53,7 +53,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {
@ -128,6 +128,7 @@ function create_main_fragment(component, ctx) {
var nested_initial_data = { foo: "bar" };
var nested = new Nested({
root: component.root,
store: component.store,
data: nested_initial_data
});

@ -8,6 +8,7 @@ function create_main_fragment(component, ctx) {
var nested_initial_data = { foo: "bar" };
var nested = new Nested({
root: component.root,
store: component.store,
data: nested_initial_data
});

@ -49,7 +49,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {
@ -124,6 +124,7 @@ function create_main_fragment(component, ctx) {
var nested_initial_data = { foo: "bar" };
var nested = new Nested({
root: component.root,
store: component.store,
data: nested_initial_data
});

@ -8,6 +8,7 @@ function create_main_fragment(component, ctx) {
var nested_initial_data = { foo: "bar" };
var nested = new Nested({
root: component.root,
store: component.store,
data: nested_initial_data
});

@ -49,7 +49,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -65,7 +65,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -61,7 +61,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -79,7 +79,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -54,7 +54,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -5,6 +5,12 @@ function assign(tar, src) {
return tar;
}
function addLoc(element, file, line, column, char) {
element.__svelte_meta = {
loc: { file, line, column, char }
};
}
function appendNode(node, target) {
target.appendChild(node);
}
@ -76,7 +82,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {
@ -159,6 +165,8 @@ function bar({ foo }) {
return foo * 2;
}
const file = undefined;
function create_main_fragment(component, ctx) {
var p, text_value = ctx.Math.max(0, ctx.foo), text, text_1, text_2;
@ -168,6 +176,7 @@ function create_main_fragment(component, ctx) {
text = createText(text_value);
text_1 = createText("\n\t");
text_2 = createText(ctx.bar);
addLoc(p, file, 0, 0, 0);
},
m: function mount(target, anchor) {

@ -1,10 +1,12 @@
/* generated by Svelte vX.Y.Z */
import { appendNode, assign, createElement, createText, detachNode, init, insertNode, protoDev } from "svelte/shared.js";
import { addLoc, appendNode, assign, createElement, createText, detachNode, init, insertNode, protoDev } from "svelte/shared.js";
function bar({ foo }) {
return foo * 2;
}
const file = undefined;
function create_main_fragment(component, ctx) {
var p, text_value = ctx.Math.max(0, ctx.foo), text, text_1, text_2;
@ -14,6 +16,7 @@ function create_main_fragment(component, ctx) {
text = createText(text_value);
text_1 = createText("\n\t");
text_2 = createText(ctx.bar);
addLoc(p, file, 0, 0, 0);
},
m: function mount(target, anchor) {

@ -65,7 +65,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -81,7 +81,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -391,7 +391,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -164,7 +164,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -61,7 +61,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -61,7 +61,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -65,7 +65,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -65,7 +65,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -65,7 +65,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -65,7 +65,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -65,7 +65,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -65,7 +65,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -77,7 +77,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -73,7 +73,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -67,7 +67,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -77,7 +77,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -63,7 +63,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {
@ -137,11 +137,13 @@ function create_main_fragment(component, ctx) {
var text;
var imported = new Imported({
root: component.root
root: component.root,
store: component.store
});
var nonimported = new NonImported({
root: component.root
root: component.root,
store: component.store
});
return {

@ -8,11 +8,13 @@ function create_main_fragment(component, ctx) {
var text;
var imported = new Imported({
root: component.root
root: component.root,
store: component.store
});
var nonimported = new NonImported({
root: component.root
root: component.root,
store: component.store
});
return {

@ -49,7 +49,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -49,7 +49,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -73,7 +73,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -69,7 +69,7 @@ function init(component, options) {
component.options = options;
component.root = options.root || component;
component.store = component.root.store || options.store;
component.store = options.store || component.root.store;
}
function on(eventName, handler) {

@ -0,0 +1,11 @@
<p>green {foo}</p>
<script>
export default {
data() {
return {
foo: 'green'
};
}
};
</script>

@ -0,0 +1,11 @@
<p>red {foo}</p>
<script>
export default {
data() {
return {
foo: 'red'
};
}
};
</script>

@ -0,0 +1,36 @@
export default {
data: {
x: true
},
html: `
<p>parent green</p>
<p>green green</p>
`,
test(assert, component, target) {
// TODO replace this with component.set({ foo: undefined }) post-#1488
// component.set({ foo: undefined });
// delete component._state.foo;
component.set({
x: false,
foo: undefined
});
assert.htmlEqual(target.innerHTML, `
<p>parent red</p>
<p>red red</p>
`);
component.set({
x: true,
foo: undefined
});
assert.htmlEqual(target.innerHTML, `
<p>parent green</p>
<p>green green</p>
`);
}
};

@ -0,0 +1,16 @@
<p>parent {foo}</p>
<svelte:component this="{x ? Green : Red}" bind:foo />
<script>
import Green from './Green.html';
import Red from './Red.html';
export default {
data() {
return {
Green,
Red
};
}
};
</script>

@ -0,0 +1,20 @@
export default {
data: {
visible: true,
empty: []
},
html: `
<div>
<p>text</p>
</div>
`,
nestedTransitions: true,
test(assert, component, target) {
component.set({ visible: false });
assert.htmlEqual(target.innerHTML, ``);
}
};

@ -0,0 +1,17 @@
{#if visible}
<div>
{#each empty as thing}
<Thing {thing}/>
{/each}
<p>text</p>
</div>
{/if}
<script>
export default {
components: {
Thing: './Thing.html'
}
};
</script>

@ -0,0 +1,3 @@
<div>
<p>this is a paragraph</p>
</div>

@ -0,0 +1,24 @@
import path from 'path';
export default {
dev: true,
test(assert, component, target) {
const h1 = target.querySelector('h1');
const p = target.querySelector('p');
assert.deepEqual(h1.__svelte_meta.loc, {
file: path.relative(process.cwd(), path.resolve(__dirname, 'main.html')),
line: 0,
column: 0,
char: 0
});
assert.deepEqual(p.__svelte_meta.loc, {
file: path.relative(process.cwd(), path.resolve(__dirname, 'Foo.html')),
line: 1,
column: 1,
char: 7
});
}
};

@ -0,0 +1,10 @@
<h1>this is a header</h1>
<Foo/>
<script>
export default {
components: {
Foo: './Foo.html'
}
};
</script>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save