From 0a7e6183fd89477473cafdaab4af3afb55bdb9ab Mon Sep 17 00:00:00 2001 From: Conduitry Date: Thu, 21 Sep 2017 10:06:27 -0400 Subject: [PATCH 01/64] do not use self-closing tags in .innerHTML (#866) --- src/generators/dom/visitors/Element/Element.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/generators/dom/visitors/Element/Element.ts b/src/generators/dom/visitors/Element/Element.ts index 8b42d40a18..ccb6ec64ae 100644 --- a/src/generators/dom/visitors/Element/Element.ts +++ b/src/generators/dom/visitors/Element/Element.ts @@ -252,7 +252,6 @@ export default function visitElement( }); if (isVoidElementName(node.name)) return open + '>'; - if (node.children.length === 0) return open + '/>'; return `${open}>${node.children.map(toHTML).join('')}`; } From 707405af7a7532f683a2dfc766aaf12ed1ca77df Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 22 Sep 2017 10:31:59 -0400 Subject: [PATCH 02/64] fix sigil escaping in .textContent and .innerHTML (#868) --- src/generators/dom/visitors/Element/Element.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/generators/dom/visitors/Element/Element.ts b/src/generators/dom/visitors/Element/Element.ts index 8b42d40a18..fe874790d0 100644 --- a/src/generators/dom/visitors/Element/Element.ts +++ b/src/generators/dom/visitors/Element/Element.ts @@ -16,6 +16,7 @@ import Block from '../../Block'; import { Node } from '../../../../interfaces'; import { State } from '../../interfaces'; import reservedNames from '../../../../utils/reservedNames'; +import { stringify } from '../../../../utils/stringify'; const meta = { ':Window': visitWindow, @@ -205,11 +206,11 @@ export default function visitElement( if (!childState.namespace && node.canUseInnerHTML && node.children.length > 0) { if (node.children.length === 1 && node.children[0].type === 'Text') { block.builders.create.addLine( - `${name}.textContent = ${JSON.stringify(node.children[0].data)};` + `${name}.textContent = ${stringify(node.children[0].data)};` ); } else { block.builders.create.addLine( - `${name}.innerHTML = ${JSON.stringify(node.children.map(toHTML).join(''))};` + `${name}.innerHTML = ${stringify(node.children.map(toHTML).join(''))};` ); } } else { From 7b25b1202f5b18b9480363d27fbb61ff9a77a62b Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 22 Sep 2017 10:35:45 -0400 Subject: [PATCH 03/64] expand unit test --- test/runtime/samples/escaped-text/_config.js | 15 ++++++++++++++- test/runtime/samples/escaped-text/main.html | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/test/runtime/samples/escaped-text/_config.js b/test/runtime/samples/escaped-text/_config.js index 43644dde82..85235fe56d 100644 --- a/test/runtime/samples/escaped-text/_config.js +++ b/test/runtime/samples/escaped-text/_config.js @@ -3,5 +3,18 @@ export default { @@x %1 %%2 + +
+ @@x + %1 + %%2 +
+ +
+ @@x + %1 + %%2 + inner +
` -}; \ No newline at end of file +}; diff --git a/test/runtime/samples/escaped-text/main.html b/test/runtime/samples/escaped-text/main.html index 603b331ca6..0b3109d693 100644 --- a/test/runtime/samples/escaped-text/main.html +++ b/test/runtime/samples/escaped-text/main.html @@ -1,3 +1,16 @@ @@x %1 -%%2 \ No newline at end of file +%%2 + +
+ @@x + %1 + %%2 +
+ +
+ @@x + %1 + %%2 + inner +
From 9c7c5b9636b60841c433cb862b60da7a4cc4f55b Mon Sep 17 00:00:00 2001 From: Conduitry Date: Fri, 22 Sep 2017 11:24:05 -0400 Subject: [PATCH 04/64] more testing --- test/runtime/samples/escaped-text/_config.js | 9 +++++++++ test/runtime/samples/escaped-text/main.html | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/test/runtime/samples/escaped-text/_config.js b/test/runtime/samples/escaped-text/_config.js index 85235fe56d..206a1afb51 100644 --- a/test/runtime/samples/escaped-text/_config.js +++ b/test/runtime/samples/escaped-text/_config.js @@ -1,17 +1,26 @@ export default { html: ` + @x @@x + #foo + ##foo %1 %%2
+ @x @@x + #foo + ##foo %1 %%2
+ @x @@x + #foo + ##foo %1 %%2 inner diff --git a/test/runtime/samples/escaped-text/main.html b/test/runtime/samples/escaped-text/main.html index 0b3109d693..cbcb7fdbb0 100644 --- a/test/runtime/samples/escaped-text/main.html +++ b/test/runtime/samples/escaped-text/main.html @@ -1,15 +1,24 @@ +@x @@x +#foo +##foo %1 %%2
+ @x @@x + #foo + ##foo %1 %%2
+ @x @@x + #foo + ##foo %1 %%2 inner From 30f223b54c718d48b6db1d428802d799f3f96147 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 23 Sep 2017 10:40:29 -0400 Subject: [PATCH 05/64] -> v1.40.1 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a09b781568..0dbc5d255a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Svelte changelog +## 1.40.1 + +* Always use explicit closing tags with `innerHTML` ([#866](https://github.com/sveltejs/svelte/issues/866)) +* Escape text in `textContent` and `innerHTML` expressions ([#868](https://github.com/sveltejs/svelte/issues/868)) + ## 1.40.0 * Short fragment method names ([#863](https://github.com/sveltejs/svelte/pull/863)) diff --git a/package.json b/package.json index 426c440b29..88f878d877 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "1.40.0", + "version": "1.40.1", "description": "The magical disappearing UI framework", "main": "compiler/svelte.js", "files": [ From d125f771e1c355c41f7d547eefe8cc5caf6ce6de Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 23 Sep 2017 14:17:33 -0400 Subject: [PATCH 06/64] upgrade prettier; use .prettierrc --- .prettierrc | 3 +++ package.json | 4 ++-- yarn.lock | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000000..81451039fa --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +useTabs: true +singleQuote: true +trailingComma: es5 diff --git a/package.json b/package.json index 88f878d877..fee5149c7c 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "dev": "node src/shared/_build.js && rollup -c -w", "pretest": "npm run build", "prepublishOnly": "npm run lint && npm test", - "prettier": "prettier --use-tabs --single-quote --trailing-comma es5 --write \"src/**/*.ts\"" + "prettier": "prettier --write \"src/**/*.ts\"" }, "repository": { "type": "git", @@ -59,7 +59,7 @@ "nightmare": "^2.10.0", "node-resolve": "^1.3.3", "nyc": "^11.1.0", - "prettier": "^1.4.1", + "prettier": "^1.7.0", "rollup": "^0.48.2", "rollup-plugin-buble": "^0.15.0", "rollup-plugin-commonjs": "^8.0.2", diff --git a/yarn.lock b/yarn.lock index 89033f2f0b..5c87602a75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2310,8 +2310,8 @@ preserve@^0.2.0: resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" prettier@^1.4.1: - version "1.5.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.5.3.tgz#59dadc683345ec6b88f88b94ed4ae7e1da394bfe" + version "1.7.0" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.7.0.tgz#47481588f41f7c90f63938feb202ac82554e7150" pretty-bytes@^1.0.2: version "1.0.4" From e83bcb0b53804b24d45f1e6b53bed3737717391f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 27 Sep 2017 13:55:22 -0400 Subject: [PATCH 07/64] escape backslashes in CSS for custom elements - fixes #872 --- src/generators/dom/index.ts | 2 +- test/custom-elements/index.js | 4 +++- test/custom-elements/samples/escaped-css/main.html | 13 +++++++++++++ test/custom-elements/samples/escaped-css/test.js | 13 +++++++++++++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 test/custom-elements/samples/escaped-css/main.html create mode 100644 test/custom-elements/samples/escaped-css/test.js diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index bccfa3288b..8e0ec3404c 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -210,7 +210,7 @@ export default function dom( ${generator.customElement ? deindent` this.attachShadow({ mode: 'open' }); - ${css && `this.shadowRoot.innerHTML = \`\`;`} + ${css && `this.shadowRoot.innerHTML = \`\`;`} ` : (generator.stylesheet.hasStyles && options.css !== false && `if (!document.getElementById("${generator.stylesheet.id}-style")) @add_css();`) diff --git a/test/custom-elements/index.js b/test/custom-elements/index.js index 54aefa3885..917261ddec 100644 --- a/test/custom-elements/index.js +++ b/test/custom-elements/index.js @@ -50,7 +50,9 @@ describe('custom-elements', function() { fs.readdirSync('test/custom-elements/samples').forEach(dir => { if (dir[0] === '.') return; - it(dir, () => { + const solo = /\.solo$/.test(dir); + + (solo ? it.only : it)(dir, () => { return rollup({ input: `test/custom-elements/samples/${dir}/test.js`, plugins: [ diff --git a/test/custom-elements/samples/escaped-css/main.html b/test/custom-elements/samples/escaped-css/main.html new file mode 100644 index 0000000000..1f86593b8f --- /dev/null +++ b/test/custom-elements/samples/escaped-css/main.html @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/test/custom-elements/samples/escaped-css/test.js b/test/custom-elements/samples/escaped-css/test.js new file mode 100644 index 0000000000..bd148ad5a7 --- /dev/null +++ b/test/custom-elements/samples/escaped-css/test.js @@ -0,0 +1,13 @@ +import * as assert from 'assert'; +import CustomElement from './main.html'; + +export default function (target) { + new CustomElement({ + target + }); + + const icon = target.querySelector('custom-element').shadowRoot.querySelector('.icon'); + const before = getComputedStyle(icon, '::before'); + + assert.equal(before.content, JSON.stringify(String.fromCharCode(0xff))); +} \ No newline at end of file From 86a11b547b7b2f9b28da58bdf2f48bd1a1f470f7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 27 Sep 2017 14:21:00 -0400 Subject: [PATCH 08/64] =?UTF-8?q?handle=20unknown=20at-rules=20that=20are?= =?UTF-8?q?=20declaration-like=20=E2=80=94=20fixes=20#871?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/Stylesheet.ts | 19 +++++++++++++------ test/css/samples/unknown-at-rule/expected.css | 1 + test/css/samples/unknown-at-rule/input.html | 7 +++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 test/css/samples/unknown-at-rule/expected.css create mode 100644 test/css/samples/unknown-at-rule/input.html diff --git a/src/css/Stylesheet.ts b/src/css/Stylesheet.ts index f79abc1d75..c10f1938c6 100644 --- a/src/css/Stylesheet.ts +++ b/src/css/Stylesheet.ts @@ -120,7 +120,7 @@ class Declaration { } transform(code: MagicString, keyframes: Map) { - const property = this.node.property.toLowerCase(); + const property = this.node.property && this.node.property.toLowerCase(); if (property === 'animation' || property === 'animation-name') { this.node.value.children.forEach((block: Node) => { if (block.type === 'Identifier') { @@ -134,6 +134,8 @@ class Declaration { } minify(code: MagicString) { + if (!this.node.property) return; // @apply, and possibly other weird cases? + const c = this.node.start + this.node.property.length; const first = this.node.value.children ? this.node.value.children[0] : @@ -274,15 +276,21 @@ export default class Stylesheet { if (parsed.css && parsed.css.children.length) { this.hasStyles = true; - const stack: Atrule[] = []; + const stack: (Rule | Atrule)[] = []; let currentAtrule: Atrule = null; walk(this.parsed.css, { enter: (node: Node) => { if (node.type === 'Atrule') { + const last = stack[stack.length - 1]; + const atrule = new Atrule(node); stack.push(atrule); + // this is an awkward special case — @apply (and + // possibly other future constructs) + if (last && !(last instanceof Atrule)) return; + if (currentAtrule) { currentAtrule.children.push(atrule); } else { @@ -302,6 +310,7 @@ export default class Stylesheet { if (node.type === 'Rule') { const rule = new Rule(node, currentAtrule); + stack.push(rule); if (currentAtrule) { currentAtrule.children.push(rule); @@ -312,10 +321,8 @@ export default class Stylesheet { }, leave: (node: Node) => { - if (node.type === 'Atrule') { - stack.pop(); - currentAtrule = stack[stack.length - 1]; - } + if (node.type === 'Rule' || node.type === 'Atrule') stack.pop(); + if (node.type === 'Atrule') currentAtrule = stack[stack.length - 1]; } }); } else { diff --git a/test/css/samples/unknown-at-rule/expected.css b/test/css/samples/unknown-at-rule/expected.css new file mode 100644 index 0000000000..bc350108ba --- /dev/null +++ b/test/css/samples/unknown-at-rule/expected.css @@ -0,0 +1 @@ +div[svelte-xyz],[svelte-xyz] div{@apply --funky-div;} \ No newline at end of file diff --git a/test/css/samples/unknown-at-rule/input.html b/test/css/samples/unknown-at-rule/input.html new file mode 100644 index 0000000000..165a40d9bc --- /dev/null +++ b/test/css/samples/unknown-at-rule/input.html @@ -0,0 +1,7 @@ +
+ + \ No newline at end of file From 3cac20c1ef98f4685e3f15b002d46267472c9fc8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 3 Oct 2017 20:56:30 -0400 Subject: [PATCH 09/64] -> v1.40.2 --- CHANGELOG.md | 5 +++++ package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dbc5d255a..97ec780c6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Svelte changelog +## 1.40.2 + +* Ignore `@apply` and similar in CSS ([#871](https://github.com/sveltejs/svelte/issues/871)) +* Properly escape CSS in custom elements ([#872](https://github.com/sveltejs/svelte/issues/872)) + ## 1.40.1 * Always use explicit closing tags with `innerHTML` ([#866](https://github.com/sveltejs/svelte/issues/866)) diff --git a/package.json b/package.json index fee5149c7c..b10e37b95e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "1.40.1", + "version": "1.40.2", "description": "The magical disappearing UI framework", "main": "compiler/svelte.js", "files": [ From 0567d0809481be6bfe72463856a8091a57172cd3 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 4 Oct 2017 08:45:31 -0400 Subject: [PATCH 10/64] pass default onwarn and onerror handlers to user's callbacks --- README.md | 4 +-- src/generators/shared/utils/wrapModule.ts | 12 ++----- src/index.ts | 39 ++++++++++++----------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index a800a90f19..2b1ddeb2b3 100644 --- a/README.md +++ b/README.md @@ -83,8 +83,8 @@ The Svelte compiler optionally takes a second argument, an object of configurati | `css` | `true`, `false` | Whether to include code to inject your component's styles into the DOM. | `true` | | `globals` | `object`, `function` | When outputting to the `'umd'`, `'iife'` or `'eval'` formats, an object or function mapping the names of imported dependencies to the names of global variables. | `{}` | | `legacy` | `boolean` | Ensures compatibility with very old browsers, at the cost of some extra code | -| `onerror` | `function` | Specify a callback for when Svelte encounters an error while compiling the component. | (exception is thrown) | -| `onwarn` | `function` | Specify a callback for when Svelte encounters a non-fatal warning while compiling the component. | (warning is logged to console) | +| `onerror` | `function` | Specify a callback for when Svelte encounters an error while compiling the component. Passed two arguments: the error object, and another function that is Svelte's default onerror handling. | (exception is thrown) | +| `onwarn` | `function` | Specify a callback for when Svelte encounters a non-fatal warning while compiling the component. Passed two arguments: the warning object, and another function that is Svelte's default onwarn handling. | (warning is logged to console) | ## Example/starter repos diff --git a/src/generators/shared/utils/wrapModule.ts b/src/generators/shared/utils/wrapModule.ts index 77fea53446..5ab5f58326 100644 --- a/src/generators/shared/utils/wrapModule.ts +++ b/src/generators/shared/utils/wrapModule.ts @@ -272,21 +272,13 @@ function getGlobals(dependencies: Dependency[], options: CompileOptions) { const error = new Error( `Could not determine name for imported module '${d.source}' – use options.globals` ); - if (onerror) { - onerror(error); - } else { - throw error; - } + onerror(error); } else { const warning = { message: `No name was supplied for imported module '${d.source}'. Guessing '${d.name}', but you should use options.globals`, }; - if (onwarn) { - onwarn(warning); - } else { - console.warn(warning); // eslint-disable-line no-console - } + onwarn(warning); } name = d.name; diff --git a/src/index.ts b/src/index.ts index 475cfcaceb..c77c84baed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,26 +8,29 @@ import Stylesheet from './css/Stylesheet'; import { Parsed, CompileOptions, Warning } from './interfaces'; function normalizeOptions(options: CompileOptions): CompileOptions { - return assign( - { - generate: 'dom', + let normalizedOptions = assign({ generate: 'dom' }, options); + const { onwarn, onerror } = normalizedOptions; + normalizedOptions.onwarn = onwarn + ? (warning: Warning) => onwarn(warning, defaultOnwarn) + : defaultOnwarn; + normalizedOptions.onerror = onerror + ? (error: Error) => onerror(error, defaultOnerror) + : defaultOnerror; + return normalizedOptions; +} - onwarn: (warning: Warning) => { - if (warning.loc) { - console.warn( - `(${warning.loc.line}:${warning.loc.column}) – ${warning.message}` - ); // eslint-disable-line no-console - } else { - console.warn(warning.message); // eslint-disable-line no-console - } - }, +function defaultOnwarn(warning: Warning) { + if (warning.loc) { + console.warn( + `(${warning.loc.line}:${warning.loc.column}) – ${warning.message}` + ); // eslint-disable-line no-console + } else { + console.warn(warning.message); // eslint-disable-line no-console + } +} - onerror: (error: Error) => { - throw error; - }, - }, - options - ); +function defaultOnerror(error: Error) { + throw error; } export function compile(source: string, _options: CompileOptions) { From b79e37c72770b6a2648b4b3d3028d4a9c0b83dd5 Mon Sep 17 00:00:00 2001 From: Johnny Hauser Date: Thu, 5 Oct 2017 17:10:10 -0500 Subject: [PATCH 11/64] supported "muted" property as boolean on audio element --- src/generators/dom/visitors/Element/lookup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/generators/dom/visitors/Element/lookup.ts b/src/generators/dom/visitors/Element/lookup.ts index cfa7543eaa..a5096ba19c 100644 --- a/src/generators/dom/visitors/Element/lookup.ts +++ b/src/generators/dom/visitors/Element/lookup.ts @@ -128,7 +128,7 @@ const lookup = { method: { appliesTo: ['form'] }, min: { appliesTo: ['input', 'meter'] }, multiple: { appliesTo: ['input', 'select'] }, - muted: { appliesTo: ['video'] }, + muted: { appliesTo: ['audio', 'video'] }, name: { appliesTo: [ 'button', From 5d27d3fda75c45b340c0d892e80ce13220475db2 Mon Sep 17 00:00:00 2001 From: Jacob Mischka Date: Mon, 9 Oct 2017 20:38:26 -0500 Subject: [PATCH 12/64] Add array destructuring for each contexts Fixes #888 --- src/generators/dom/Block.ts | 2 + src/generators/dom/preprocess.ts | 6 ++ src/parse/state/mustache.ts | 25 ++++++- .../each-block-destructured/input.html | 3 + .../each-block-destructured/output.json | 67 +++++++++++++++++++ 5 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 test/parser/samples/each-block-destructured/input.html create mode 100644 test/parser/samples/each-block-destructured/output.json diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index 6b696b5ad5..53ae519465 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -29,6 +29,7 @@ export default class Block { name: string; expression: Node; context: string; + destructuredContexts?: string[]; comment?: string; key: string; @@ -75,6 +76,7 @@ export default class Block { this.name = options.name; this.expression = options.expression; this.context = options.context; + this.destructuredContexts = options.destructuredContexts; this.comment = options.comment; // for keyed each blocks diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index 1ac7098555..9b98539897 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -229,6 +229,12 @@ const preprocessors = { const contexts = new Map(block.contexts); contexts.set(node.context, context); + if (node.destructuredContexts) { + for (const i = 0; i < node.destructuredContexts.length; i++) { + contexts.set(node.destructuredContexts[i], `${context}[${i}]`); + } + } + const indexes = new Map(block.indexes); if (node.index) indexes.set(node.index, node.context); diff --git a/src/parse/state/mustache.ts b/src/parse/state/mustache.ts index 6fc842449c..d71642cd1f 100644 --- a/src/parse/state/mustache.ts +++ b/src/parse/state/mustache.ts @@ -161,8 +161,29 @@ export default function mustache(parser: Parser) { parser.eat('as', true); parser.requireWhitespace(); - block.context = parser.read(validIdentifier); // TODO check it's not a keyword - if (!block.context) parser.error(`Expected name`); + if (parser.eat('[')) { + parser.allowWhitespace(); + + block.destructuredContexts = []; + + do { + parser.allowWhitespace(); + const destructuredContext = parser.read(validIdentifier); + if (!destructuredContext) parser.error(`Expected name`); + block.destructuredContexts.push(destructuredContext); + parser.allowWhitespace(); + } while (parser.eat(',')); + + if (!block.destructuredContexts.length) parser.error(`Expected name`); + block.context = block.destructuredContexts.join('_'); + + parser.allowWhitespace(); + parser.eat(']', true); + } else { + block.context = parser.read(validIdentifier); // TODO check it's not a keyword + + if (!block.context) parser.error(`Expected name`); + } parser.allowWhitespace(); diff --git a/test/parser/samples/each-block-destructured/input.html b/test/parser/samples/each-block-destructured/input.html new file mode 100644 index 0000000000..7209f5503d --- /dev/null +++ b/test/parser/samples/each-block-destructured/input.html @@ -0,0 +1,3 @@ +{{#each animals as [key, value]}} +

{{key}}: {{value}}

+{{/each}} diff --git a/test/parser/samples/each-block-destructured/output.json b/test/parser/samples/each-block-destructured/output.json new file mode 100644 index 0000000000..897fec88b8 --- /dev/null +++ b/test/parser/samples/each-block-destructured/output.json @@ -0,0 +1,67 @@ +{ + "hash": 2621498076, + "html": { + "start": 0, + "end": 70, + "type": "Fragment", + "children": [ + { + "start": 0, + "end": 70, + "type": "EachBlock", + "expression": { + "type": "Identifier", + "start": 8, + "end": 15, + "name": "animals" + }, + "children": [ + { + "start": 35, + "end": 60, + "type": "Element", + "name": "p", + "attributes": [], + "children": [ + { + "start": 38, + "end": 45, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 40, + "end": 43, + "name": "key" + } + }, + { + "start": 45, + "end": 47, + "type": "Text", + "data": ": " + }, + { + "start": 47, + "end": 56, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 49, + "end": 54, + "name": "value" + } + } + ] + } + ], + "destructuredContexts": [ + "key", + "value" + ], + "context": "key_value" + } + ] + }, + "css": null, + "js": null +} \ No newline at end of file From ffbc9910274b6eab226eb0a20faacf5fcd43843b Mon Sep 17 00:00:00 2001 From: Jacob Mischka Date: Mon, 9 Oct 2017 21:05:59 -0500 Subject: [PATCH 13/64] Add missing runtime test, add contexts to SSR --- .../server-side-rendering/visitors/EachBlock.ts | 6 ++++++ .../each-block-destructured-array/_config.js | 13 +++++++++++++ .../samples/each-block-destructured-array/main.html | 3 +++ 3 files changed, 22 insertions(+) create mode 100644 test/runtime/samples/each-block-destructured-array/_config.js create mode 100644 test/runtime/samples/each-block-destructured-array/main.html diff --git a/src/generators/server-side-rendering/visitors/EachBlock.ts b/src/generators/server-side-rendering/visitors/EachBlock.ts index 10565f6bf2..09342bf26b 100644 --- a/src/generators/server-side-rendering/visitors/EachBlock.ts +++ b/src/generators/server-side-rendering/visitors/EachBlock.ts @@ -18,6 +18,12 @@ export default function visitEachBlock( const contexts = new Map(block.contexts); contexts.set(node.context, node.context); + if (node.destructuredContexts) { + for (const i = 0; i < node.destructuredContexts.length; i++) { + contexts.set(node.destructuredContexts[i], `${node.context}[${i}]`); + } + } + const indexes = new Map(block.indexes); if (node.index) indexes.set(node.index, node.context); diff --git a/test/runtime/samples/each-block-destructured-array/_config.js b/test/runtime/samples/each-block-destructured-array/_config.js new file mode 100644 index 0000000000..ab7bcfe1b7 --- /dev/null +++ b/test/runtime/samples/each-block-destructured-array/_config.js @@ -0,0 +1,13 @@ +export default { + data: { + animalPaws: { + raccoon: 'hands', + eagle: 'wings' + } + }, + + html: ` +

raccoon: hands

+

eagle: wings

+ ` +}; diff --git a/test/runtime/samples/each-block-destructured-array/main.html b/test/runtime/samples/each-block-destructured-array/main.html new file mode 100644 index 0000000000..ec553692c8 --- /dev/null +++ b/test/runtime/samples/each-block-destructured-array/main.html @@ -0,0 +1,3 @@ +{{#each Object.entries(animalPaws) as [animal, pawType]}} +

{{animal}}: {{pawType}}

+{{/each}} From a60a7e6773d3c1fab006f72876dd7ab45507fe1f Mon Sep 17 00:00:00 2001 From: Jacob Mischka Date: Mon, 9 Oct 2017 21:12:21 -0500 Subject: [PATCH 14/64] Remove Object.entries from test --- .../samples/each-block-destructured-array/_config.js | 8 ++++---- .../samples/each-block-destructured-array/main.html | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/runtime/samples/each-block-destructured-array/_config.js b/test/runtime/samples/each-block-destructured-array/_config.js index ab7bcfe1b7..cd29960426 100644 --- a/test/runtime/samples/each-block-destructured-array/_config.js +++ b/test/runtime/samples/each-block-destructured-array/_config.js @@ -1,9 +1,9 @@ export default { data: { - animalPaws: { - raccoon: 'hands', - eagle: 'wings' - } + animalPawsEntries: [ + ['raccoon', 'hands'], + ['eagle', 'wings'] + ] }, html: ` diff --git a/test/runtime/samples/each-block-destructured-array/main.html b/test/runtime/samples/each-block-destructured-array/main.html index ec553692c8..6ee90537ab 100644 --- a/test/runtime/samples/each-block-destructured-array/main.html +++ b/test/runtime/samples/each-block-destructured-array/main.html @@ -1,3 +1,3 @@ -{{#each Object.entries(animalPaws) as [animal, pawType]}} +{{#each animalPawsEntries as [animal, pawType]}}

{{animal}}: {{pawType}}

{{/each}} From 23b2817989e52665d66f3bb7ceaa43103bbdc90c Mon Sep 17 00:00:00 2001 From: Petter Ekrann Date: Wed, 11 Oct 2017 08:46:14 +0200 Subject: [PATCH 15/64] Ensure cloning of incomming data Please verify syntax --- src/generators/dom/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 8e0ec3404c..5c381b366d 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -190,10 +190,10 @@ export default function dom( `if (!options || (!options.target && !options._root)) throw new Error("'target' is a required option");`} @init(this, options); ${generator.usesRefs && `this.refs = {};`} - this._state = ${templateProperties.data - ? `@assign(%data(), options.data)` - : `options.data || {}`}; - ${generator.metaBindings} + + this._state =`@assign({},(%data||%noop)(),options.data)`; + + ${generator.metaBindings} ${computations.length && `this._recompute({ ${Array.from(computationDeps).map(dep => `${dep}: 1`).join(', ')} }, this._state);`} ${options.dev && Array.from(generator.expectedProperties).map( From 0fd823d66176b1787d89c91d8c12cab88ed7ce1c Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 15 Oct 2017 16:17:39 -0400 Subject: [PATCH 16/64] fix syntax --- src/generators/dom/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 5c381b366d..7c7c4a45dc 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -190,10 +190,8 @@ export default function dom( `if (!options || (!options.target && !options._root)) throw new Error("'target' is a required option");`} @init(this, options); ${generator.usesRefs && `this.refs = {};`} - - this._state =`@assign({},(%data||%noop)(),options.data)`; - - ${generator.metaBindings} + this._state = @assign(${templateProperties.data ? '%data()' : '{}'}, options.data); + ${generator.metaBindings} ${computations.length && `this._recompute({ ${Array.from(computationDeps).map(dep => `${dep}: 1`).join(', ')} }, this._state);`} ${options.dev && Array.from(generator.expectedProperties).map( From 2800b5cacceb10bf2c1bb3477df3104ca82f1058 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sun, 15 Oct 2017 16:17:48 -0400 Subject: [PATCH 17/64] update tests --- test/js/samples/component-static/expected-bundle.js | 2 +- test/js/samples/component-static/expected.js | 2 +- test/js/samples/computed-collapsed-if/expected-bundle.js | 2 +- test/js/samples/computed-collapsed-if/expected.js | 2 +- test/js/samples/css-media-query/expected-bundle.js | 2 +- test/js/samples/css-media-query/expected.js | 2 +- test/js/samples/css-shadow-dom-keyframes/expected-bundle.js | 2 +- test/js/samples/css-shadow-dom-keyframes/expected.js | 2 +- test/js/samples/each-block-changed-check/expected-bundle.js | 2 +- test/js/samples/each-block-changed-check/expected.js | 2 +- test/js/samples/event-handlers-custom/expected-bundle.js | 2 +- test/js/samples/event-handlers-custom/expected.js | 2 +- test/js/samples/if-block-no-update/expected-bundle.js | 2 +- test/js/samples/if-block-no-update/expected.js | 2 +- test/js/samples/if-block-simple/expected-bundle.js | 2 +- test/js/samples/if-block-simple/expected.js | 2 +- .../samples/inline-style-optimized-multiple/expected-bundle.js | 2 +- test/js/samples/inline-style-optimized-multiple/expected.js | 2 +- test/js/samples/inline-style-optimized-url/expected-bundle.js | 2 +- test/js/samples/inline-style-optimized-url/expected.js | 2 +- test/js/samples/inline-style-optimized/expected-bundle.js | 2 +- test/js/samples/inline-style-optimized/expected.js | 2 +- test/js/samples/inline-style-unoptimized/expected-bundle.js | 2 +- test/js/samples/inline-style-unoptimized/expected.js | 2 +- test/js/samples/input-without-blowback-guard/expected-bundle.js | 2 +- test/js/samples/input-without-blowback-guard/expected.js | 2 +- test/js/samples/legacy-input-type/expected-bundle.js | 2 +- test/js/samples/legacy-input-type/expected.js | 2 +- test/js/samples/legacy-quote-class/expected-bundle.js | 2 +- test/js/samples/legacy-quote-class/expected.js | 2 +- test/js/samples/media-bindings/expected-bundle.js | 2 +- test/js/samples/media-bindings/expected.js | 2 +- test/js/samples/non-imported-component/expected-bundle.js | 2 +- test/js/samples/non-imported-component/expected.js | 2 +- .../js/samples/onrender-onteardown-rewritten/expected-bundle.js | 2 +- test/js/samples/onrender-onteardown-rewritten/expected.js | 2 +- test/js/samples/setup-method/expected-bundle.js | 2 +- test/js/samples/setup-method/expected.js | 2 +- test/js/samples/use-elements-as-anchors/expected-bundle.js | 2 +- test/js/samples/use-elements-as-anchors/expected.js | 2 +- 40 files changed, 40 insertions(+), 40 deletions(-) diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 12c0a0cd4b..d26e5c6c95 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -198,7 +198,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); if (!options._root) { this._oncreate = []; diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index 039ef606ed..421a7adda6 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -33,7 +33,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); if (!options._root) { this._oncreate = []; diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 41c35ea754..d2d76eb003 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -191,7 +191,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._recompute({ x: 1 }, this._state); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index bc3fcc37d5..c2f5e3c2be 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -26,7 +26,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._recompute({ x: 1 }, this._state); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 862f721ebc..95fad711ca 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -226,7 +226,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); if (!document.getElementById("svelte-2363328337-style")) add_css(); diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 5b77893900..3c36f9c6ce 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -41,7 +41,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); if (!document.getElementById("svelte-2363328337-style")) add_css(); diff --git a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js index 4c8fad71f7..cbcd06b93b 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -205,7 +205,7 @@ class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ``; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index c004ec7df6..d921b0e79f 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -28,7 +28,7 @@ class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = ``; diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 33bd98ba74..8c0bd0b2cb 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -338,7 +338,7 @@ function create_each_block(state, comments, comment, i, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 37c12c1acd..be8a4943b5 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -141,7 +141,7 @@ function create_each_block(state, comments, comment, i, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index a712f5b742..275a0377c7 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -223,7 +223,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index 3739ada3a6..f7862efb62 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -46,7 +46,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/if-block-no-update/expected-bundle.js b/test/js/samples/if-block-no-update/expected-bundle.js index f68dbd24e3..a9077ff2ac 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -271,7 +271,7 @@ function select_block_type(state) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 6a0a4456c5..8f030e4e53 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -90,7 +90,7 @@ function select_block_type(state) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 9c99dd0275..c0ff5cc5a9 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -247,7 +247,7 @@ function create_if_block(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 9bfd8e211d..0b9fbece70 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -66,7 +66,7 @@ function create_if_block(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js index 80998f97b2..adeb003a8d 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -220,7 +220,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index a92f5d3053..77173460e2 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -39,7 +39,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js index 236aaee071..6ec70a5669 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -215,7 +215,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index e10acd8dd8..bed00356f6 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -34,7 +34,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index f8084094be..2e8ef6da17 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -215,7 +215,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index e9d42fec07..7f873e296c 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -34,7 +34,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index d0b2a2dcfe..bf78dac074 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -226,7 +226,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index b2b4f5ad53..4c4d38d2bf 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -45,7 +45,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/input-without-blowback-guard/expected-bundle.js b/test/js/samples/input-without-blowback-guard/expected-bundle.js index 792342604d..fd043c760e 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -226,7 +226,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index f9ae72b1bd..247935ffbe 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -41,7 +41,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 26f30cf194..a6b6ae4d05 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -213,7 +213,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 5309c86cfd..719f550044 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -30,7 +30,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index 3be6136b4a..b10d660076 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -238,7 +238,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index 82eebe600c..0b49103c47 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -38,7 +38,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 820db0a4fe..068c1b4b15 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -302,7 +302,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); if (!options._root) { this._oncreate = []; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 832826ffd5..bcab29fb75 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -109,7 +109,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); if (!options._root) { this._oncreate = []; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 0aefe73b06..3793f0c102 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -221,7 +221,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); if (!options._root) { this._oncreate = []; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 1f07457149..234a824e6c 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -45,7 +45,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); if (!options._root) { this._oncreate = []; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 28dafe0c0d..59fbfcf41f 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -187,7 +187,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._handlers.destroy = [ondestroy]; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index 95f923e4d4..19b85a62e0 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -22,7 +22,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._handlers.destroy = [ondestroy] diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 42eed6868b..7724d9f3ac 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -199,7 +199,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index f49817bb99..092a32ed3b 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -34,7 +34,7 @@ function create_main_fragment(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/use-elements-as-anchors/expected-bundle.js b/test/js/samples/use-elements-as-anchors/expected-bundle.js index 92e3f9bbd3..1f56c0ba7b 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -437,7 +437,7 @@ function create_if_block_4(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index f23b9ec205..d2609c45b0 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -248,7 +248,7 @@ function create_if_block_4(state, component) { function SvelteComponent(options) { init(this, options); - this._state = options.data || {}; + this._state = assign({}, options.data); this._fragment = create_main_fragment(this._state, this); From bc8847184089e7040356e7de81a26e49ce94798e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 17 Oct 2017 16:59:04 -0400 Subject: [PATCH 18/64] -> v1.41.0 --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97ec780c6f..15e7b0a205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Svelte changelog +## 1.41.0 + +* `onwarn` and `onerror` receive default handlers as second arguments ([#883](https://github.com/sveltejs/svelte/pull/883)) +* Recognise `muted` as boolean property on `