Skip to content

Commit 2f01115

Browse files
committed
merge master -> gh-1118
2 parents cbd1a11 + 0c3e44a commit 2f01115

File tree

101 files changed

+856
-709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+856
-709
lines changed

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Svelte changelog
22

3+
## 1.56.4
4+
5+
* Allow `component` and `state` to be context names ([#1213](https://github.com/sveltejs/svelte/issues/1213))
6+
* Don't remove `@supports` rules when `cascade: false` ([#1215](https://github.com/sveltejs/svelte/issues/1215))
7+
8+
## 1.56.3
9+
10+
* Top-level transitions work inside nested components ([#1188](https://github.com/sveltejs/svelte/issues/1188))
11+
* Always use internal `_mount` method ([#1201](https://github.com/sveltejs/svelte/issues/1201))
12+
13+
## 1.56.2
14+
15+
* Null out `key` for children of keyed each blocks ([#1202](https://github.com/sveltejs/svelte/issues/1202))
16+
17+
## 1.56.1
18+
19+
* Fix if-in-each bug ([#1195](https://github.com/sveltejs/svelte/issues/1195))
20+
* Cross-browser `scrollX`/`scrollY` support ([#1175](https://github.com/sveltejs/svelte/issues/1175))
21+
322
## 1.56.0
423

524
* Internal refactor ([#1122](https://github.com/sveltejs/svelte/issues/1122))

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This is the Svelte compiler, which is primarily intended for authors of tooling
2121
* [svelte-hot-loader](https://github.com/ekhaled/svelte-hot-loader) – Webpack loader addon to support HMR
2222
* [meteor-svelte](https://github.com/klaussner/meteor-svelte) – Meteor build plugin
2323
* [sveltejs-brunch](https://github.com/StarpTech/sveltejs-brunch) – Brunch build plugin
24+
* [svelte-dev-store](https://github.com/GarethOates/svelte-dev-store) - Use Redux tools to visualise Svelte store
2425
* More to come!
2526

2627

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "svelte",
3-
"version": "1.56.0",
3+
"version": "1.56.4",
44
"description": "The magical disappearing UI framework",
55
"main": "compiler/svelte.js",
66
"files": [
@@ -66,7 +66,7 @@
6666
"nyc": "^11.1.0",
6767
"prettier": "^1.7.0",
6868
"reify": "^0.12.3",
69-
"rollup": "^0.48.2",
69+
"rollup": "^0.56.4",
7070
"rollup-plugin-buble": "^0.15.0",
7171
"rollup-plugin-commonjs": "^8.0.2",
7272
"rollup-plugin-json": "^2.1.0",

src/css/Stylesheet.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ class Atrule {
163163
}
164164

165165
apply(node: Element, stack: Element[]) {
166-
if (this.node.name === 'media') {
166+
if (this.node.name === 'media' || this.node.name === 'supports') {
167167
this.children.forEach(child => {
168168
child.apply(node, stack);
169169
});
@@ -199,6 +199,14 @@ class Atrule {
199199
if (this.node.expression.start - c > 1) code.overwrite(c, this.node.expression.start, ' ');
200200
c = this.node.expression.end;
201201
if (this.node.block.start - c > 0) code.remove(c, this.node.block.start);
202+
} else if (this.node.name === 'supports') {
203+
let c = this.node.start + 9;
204+
if (this.node.expression.start - c > 1) code.overwrite(c, this.node.expression.start, ' ');
205+
this.node.expression.children.forEach((query: Node) => {
206+
// TODO minify queries
207+
c = query.end;
208+
});
209+
code.remove(c, this.node.block.start);
202210
}
203211

204212
// TODO other atrules

src/generators/Generator.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import MagicString, { Bundle } from 'magic-string';
2+
import isReference from 'is-reference';
23
import { walk, childKeys } from 'estree-walker';
34
import { getLocator } from 'locate-character';
45
import deindent from '../utils/deindent';
56
import CodeBuilder from '../utils/CodeBuilder';
67
import getCodeFrame from '../utils/getCodeFrame';
7-
import isReference from '../utils/isReference';
88
import flattenReference from '../utils/flattenReference';
99
import reservedNames from '../utils/reservedNames';
1010
import namespaces from '../utils/namespaces';
@@ -168,7 +168,7 @@ export default class Generator {
168168
if (options.customElement === true) {
169169
this.customElement = {
170170
tag: this.tag,
171-
props: this.props // TODO autofill this in
171+
props: this.props
172172
}
173173
} else {
174174
this.customElement = options.customElement;
@@ -752,12 +752,6 @@ export default class Generator {
752752
if (node.type === 'Element' && (node.name === ':Component' || node.name === ':Self' || generator.components.has(node.name))) {
753753
node.type = 'Component';
754754
Object.setPrototypeOf(node, nodes.Component.prototype);
755-
} else if (node.name === ':Window') { // TODO do this in parse?
756-
node.type = 'Window';
757-
Object.setPrototypeOf(node, nodes.Window.prototype);
758-
} else if (node.name === ':Head') { // TODO do this in parse?
759-
node.type = 'Head';
760-
Object.setPrototypeOf(node, nodes.Head.prototype);
761755
} else if (node.type === 'Element' && node.name === 'title' && parentIsHead(parent)) { // TODO do this in parse?
762756
node.type = 'Title';
763757
Object.setPrototypeOf(node, nodes.Title.prototype);

src/generators/dom/Block.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ export default class Block {
112112
this.hasOutroMethod = false;
113113
this.outros = 0;
114114

115-
this.aliases = new Map();
116-
this.variables = new Map();
117115
this.getUniqueName = this.generator.getUniqueNameMaker();
116+
this.variables = new Map();
117+
118+
this.aliases = new Map()
119+
.set('component', this.getUniqueName('component'))
120+
.set('state', this.getUniqueName('state'));
121+
if (this.key) this.aliases.set('key', this.getUniqueName('key'));
118122

119123
this.hasUpdateMethod = false; // determined later
120124
}
@@ -163,7 +167,7 @@ export default class Block {
163167
}
164168

165169
child(options: BlockOptions) {
166-
return new Block(Object.assign({}, this, options, { parent: this }));
170+
return new Block(Object.assign({}, this, { key: null }, options, { parent: this }));
167171
}
168172

169173
contextualise(expression: Node, context?: string, isEventHandler?: boolean) {
@@ -308,22 +312,19 @@ export default class Block {
308312
if (this.hasOutroMethod) {
309313
if (hasOutros) {
310314
properties.addBlock(deindent`
311-
o: function outro(${this.alias('outrocallback')}) {
315+
o: function outro(#outrocallback) {
312316
if (${outroing}) return;
313317
${outroing} = true;
314318
${hasIntros && `${introing} = false;`}
315319
316-
var ${this.alias('outros')} = ${this.outros};
320+
var #outros = ${this.outros};
317321
318322
${this.builders.outro}
319323
},
320324
`);
321325
} else {
322-
// TODO should this be a helper?
323326
properties.addBlock(deindent`
324-
o: function outro(outrocallback) {
325-
outrocallback();
326-
},
327+
o: @run,
327328
`);
328329
}
329330
}

src/generators/dom/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import MagicString from 'magic-string';
2+
import isReference from 'is-reference';
23
import { parseExpressionAt } from 'acorn';
34
import annotateWithScopes from '../../utils/annotateWithScopes';
4-
import isReference from '../../utils/isReference';
55
import { walk } from 'estree-walker';
66
import deindent from '../../utils/deindent';
77
import { stringify, escape } from '../../utils/stringify';
@@ -259,7 +259,7 @@ export default function dom(
259259
this._fragment.c();
260260
this._fragment.${block.hasIntroMethod ? 'i' : 'm'}(this.shadowRoot, null);
261261
262-
if (options.target) this._mount(options.target, options.anchor || null);
262+
if (options.target) this._mount(options.target, options.anchor);
263263
` : deindent`
264264
if (options.target) {
265265
${generator.hydratable
@@ -272,7 +272,7 @@ export default function dom(
272272
${options.dev && `if (options.hydrate) throw new Error("options.hydrate only works if the component was compiled with the \`hydratable: true\` option");`}
273273
this._fragment.c();
274274
`}
275-
this._fragment.${block.hasIntroMethod ? 'i' : 'm'}(options.target, options.anchor || null);
275+
this._mount(options.target, options.anchor);
276276
277277
${(generator.hasComponents || generator.hasComplexBindings || templateProperties.oncreate || generator.hasIntroTransitions) && deindent`
278278
${generator.hasComponents && `this._lock = true;`}

src/generators/nodes/Component.ts

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export default class Component extends Node {
320320
${name} = new ${switch_vars.value}(${switch_vars.props}(state));
321321
${name}._fragment.c();
322322
323-
${this.children.map(child => remount(generator, child, name))}
323+
${this.children.map(child => child.remount(name))}
324324
${name}._mount(${updateMountNode}, ${anchor});
325325
326326
${eventHandlers.map(handler => deindent`
@@ -398,6 +398,10 @@ export default class Component extends Node {
398398
`);
399399
}
400400
}
401+
402+
remount(name: string) {
403+
return `${this.var}._mount(${name}._slotted${this.generator.legacy ? `["default"]` : `.default`}, null);`;
404+
}
401405
}
402406

403407
function mungeAttribute(attribute: Node, block: Block): Attribute {
@@ -547,32 +551,4 @@ function isComputed(node: Node) {
547551
}
548552

549553
return false;
550-
}
551-
552-
function remount(generator: DomGenerator, node: Node, name: string) {
553-
// TODO make this a method of the nodes
554-
555-
if (node.type === 'Component') {
556-
return `${node.var}._mount(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
557-
}
558-
559-
if (node.type === 'Element') {
560-
const slot = node.attributes.find(attribute => attribute.name === 'slot');
561-
if (slot) {
562-
return `@appendNode(${node.var}, ${name}._slotted.${node.getStaticAttributeValue('slot')});`;
563-
}
564-
565-
return `@appendNode(${node.var}, ${name}._slotted${generator.legacy ? `["default"]` : `.default`});`;
566-
}
567-
568-
if (node.type === 'Text' || node.type === 'MustacheTag' || node.type === 'RawMustacheTag') {
569-
return `@appendNode(${node.var}, ${name}._slotted${generator.legacy ? `["default"]` : `.default`});`;
570-
}
571-
572-
if (node.type === 'EachBlock') {
573-
// TODO consider keyed blocks
574-
return `for (var #i = 0; #i < ${node.iterations}.length; #i += 1) ${node.iterations}[#i].m(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
575-
}
576-
577-
return `${node.var}.m(${name}._slotted${generator.legacy ? `["default"]` : `.default`}, null);`;
578554
}

src/generators/nodes/EachBlock.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,4 +594,9 @@ export default class EachBlock extends Node {
594594

595595
block.builders.destroy.addBlock(`@destroyEach(${iterations});`);
596596
}
597+
598+
remount(name: string) {
599+
// TODO consider keyed blocks
600+
return `for (var #i = 0; #i < ${this.iterations}.length; #i += 1) ${this.iterations}[#i].m(${name}._slotted${this.generator.legacy ? `["default"]` : `.default`}, null);`;
601+
}
597602
}

src/generators/nodes/Element.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,15 @@ export default class Element extends Node {
677677
isMediaNode() {
678678
return this.name === 'audio' || this.name === 'video';
679679
}
680+
681+
remount(name: string) {
682+
const slot = this.attributes.find(attribute => attribute.name === 'slot');
683+
if (slot) {
684+
return `@appendNode(${this.var}, ${name}._slotted.${this.getStaticAttributeValue('slot')});`;
685+
}
686+
687+
return `@appendNode(${this.var}, ${name}._slotted${this.generator.legacy ? `["default"]` : `.default`});`;
688+
}
680689
}
681690

682691
function getRenderStatement(

0 commit comments

Comments
 (0)