From ef787b84c934bb23e0999139914f7998390daaa0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Sep 2017 14:24:55 -0400 Subject: [PATCH 1/6] add debugging comments --- src/generators/Generator.ts | 4 ++++ src/generators/dom/Block.ts | 5 ++++ src/generators/dom/index.ts | 2 ++ src/generators/dom/preprocess.ts | 23 +++++++++++++++++++ src/generators/server-side-rendering/index.ts | 2 +- src/index.ts | 3 --- test/js/index.js | 2 +- .../expected-bundle.js | 2 ++ .../expected.js | 2 ++ .../computed-collapsed-if/expected-bundle.js | 2 ++ .../samples/computed-collapsed-if/expected.js | 2 ++ .../css-media-query/expected-bundle.js | 2 ++ test/js/samples/css-media-query/expected.js | 2 ++ .../expected-bundle.js | 2 ++ .../css-shadow-dom-keyframes/expected.js | 2 ++ .../expected-bundle.js | 3 +++ .../each-block-changed-check/expected.js | 3 +++ .../event-handlers-custom/expected-bundle.js | 2 ++ .../samples/event-handlers-custom/expected.js | 2 ++ .../if-block-no-update/expected-bundle.js | 4 ++++ .../js/samples/if-block-no-update/expected.js | 4 ++++ .../if-block-simple/expected-bundle.js | 3 +++ test/js/samples/if-block-simple/expected.js | 3 +++ .../expected-bundle.js | 2 ++ .../expected.js | 2 ++ .../expected-bundle.js | 2 ++ .../inline-style-optimized-url/expected.js | 2 ++ .../inline-style-optimized/expected-bundle.js | 2 ++ .../inline-style-optimized/expected.js | 2 ++ .../expected-bundle.js | 2 ++ .../inline-style-unoptimized/expected.js | 2 ++ .../expected-bundle.js | 2 ++ .../input-without-blowback-guard/expected.js | 2 ++ .../legacy-input-type/expected-bundle.js | 2 ++ test/js/samples/legacy-input-type/expected.js | 2 ++ .../legacy-quote-class/expected-bundle.js | 2 ++ .../js/samples/legacy-quote-class/expected.js | 2 ++ .../samples/media-bindings/expected-bundle.js | 2 ++ test/js/samples/media-bindings/expected.js | 2 ++ .../non-imported-component/expected-bundle.js | 2 ++ .../non-imported-component/expected.js | 2 ++ .../expected-bundle.js | 2 ++ .../onrender-onteardown-rewritten/expected.js | 2 ++ .../samples/setup-method/expected-bundle.js | 2 ++ test/js/samples/setup-method/expected.js | 2 ++ .../expected-bundle.js | 7 ++++++ .../use-elements-as-anchors/expected.js | 7 ++++++ 47 files changed, 134 insertions(+), 5 deletions(-) diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 48a93cc7f7..91b73b6162 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -56,6 +56,8 @@ export default class Generator { expectedProperties: Set; usesRefs: boolean; + locate: (c: number) => { line: number, column: number }; + stylesheet: Stylesheet; importedNames: Set; @@ -86,6 +88,8 @@ export default class Generator { this.bindingGroups = []; this.indirectDependencies = new Map(); + this.locate = getLocator(this.source); + // track which properties are needed, so we can provide useful info // in dev mode this.expectedProperties = new Set(); diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index 8acd99b2a8..c0fb7a2c4c 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -1,5 +1,6 @@ import CodeBuilder from '../../utils/CodeBuilder'; import deindent from '../../utils/deindent'; +import { escape } from '../../utils/stringify'; import { DomGenerator } from './index'; import { Node } from '../../interfaces'; import shared from './shared'; @@ -9,6 +10,7 @@ export interface BlockOptions { generator?: DomGenerator; expression?: Node; context?: string; + comment?: string; key?: string; contexts?: Map; indexes?: Map; @@ -27,6 +29,7 @@ export default class Block { name: string; expression: Node; context: string; + comment?: string; key: string; first: string; @@ -72,6 +75,7 @@ export default class Block { this.name = options.name; this.expression = options.expression; this.context = options.context; + this.comment = options.comment; // for keyed each blocks this.key = options.key; @@ -340,6 +344,7 @@ export default class Block { } return deindent` + ${this.comment && `// ${escape(this.comment)}`} function ${this.name}(${this.params.join(', ')}, #component${this.key ? `, ${localKey}` : ''}) { ${this.variables.size > 0 && `var ${Array.from(this.variables.keys()) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 8d82fef182..7bcee58366 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -12,6 +12,7 @@ import Generator from '../Generator'; import Stylesheet from '../../css/Stylesheet'; import preprocess from './preprocess'; import Block from './Block'; +import { version } from '../../../package.json'; import { Parsed, CompileOptions, Node } from '../../interfaces'; export class DomGenerator extends Generator { @@ -76,6 +77,7 @@ export default function dom( }); const builder = new CodeBuilder(); + builder.addBlock(`// ${options.filename ? `${options.filename} ` : ``}generated by Svelte v${version}`); const computationBuilder = new CodeBuilder(); if (computations.length) { diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index 1fdfababeb..b993dcb43f 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -22,6 +22,25 @@ function getChildState(parent: State, child = {}) { ); } +function createDebuggingComment(node: Node, generator: DomGenerator) { + const { locate, source } = generator; + + let c = node.start; + if (node.type === 'ElseBlock') { + while (source[c] !== '{') c -= 1; + c -= 1; + } + + let d = node.expression ? node.expression.end : c; + while (source[d] !== '}') d += 1; + d += 2; + + const start = locate(c); + const loc = `(${start.line + 1}:${start.column})`; + + return `${loc} ${source.slice(c, d)}`.replace(/\n/g, ' '); +} + // Whitespace inside one of these elements will not result in // a whitespace node being created in any circumstances. (This // list is almost certainly very incomplete) @@ -107,6 +126,7 @@ const preprocessors = { block.addDependencies(dependencies); node._block = block.child({ + comment: createDebuggingComment(node, generator), name: generator.getUniqueName(`create_if_block`), }); @@ -127,6 +147,7 @@ const preprocessors = { attachBlocks(node.else.children[0]); } else if (node.else) { node.else._block = block.child({ + comment: createDebuggingComment(node.else, generator), name: generator.getUniqueName(`create_if_block`), }); @@ -202,6 +223,7 @@ const preprocessors = { contextDependencies.set(node.context, dependencies); node._block = block.child({ + comment: createDebuggingComment(node, generator), name: generator.getUniqueName('create_each_block'), expression: node.expression, context: node.context, @@ -231,6 +253,7 @@ const preprocessors = { if (node.else) { node.else._block = block.child({ + comment: createDebuggingComment(node.else, generator), name: generator.getUniqueName(`${node._block.name}_else`), }); diff --git a/src/generators/server-side-rendering/index.ts b/src/generators/server-side-rendering/index.ts index 11918995e7..d624400b91 100644 --- a/src/generators/server-side-rendering/index.ts +++ b/src/generators/server-side-rendering/index.ts @@ -103,7 +103,7 @@ export default function ssr( var ${name} = {}; - ${name}.filename = ${stringify(options.filename)}; + ${options.filename && `${name}.filename = ${stringify(options.filename)}`}; ${name}.data = function() { return ${templateProperties.data ? `@template.data()` : `{}`}; diff --git a/src/index.ts b/src/index.ts index c9c4d23a1e..f2a2af1483 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,9 +12,6 @@ function normalizeOptions(options: CompileOptions): CompileOptions { { generate: 'dom', - // a filename is necessary for sourcemap generation - filename: 'SvelteComponent.html', - onwarn: (warning: Warning) => { if (warning.loc) { console.warn( diff --git a/test/js/index.js b/test/js/index.js index 581df93dd8..170c396a2e 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -71,7 +71,7 @@ describe("js", () => { expectedBundle.trim().replace(/^\s+$/gm, "") ); }).catch(err => { - console.error(err.loc); + if (err.loc) console.error(err.loc); throw err; }); }); diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index 5e61b5cb39..c359d3ea3f 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -175,6 +175,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + var template = (function() { return { data: function () { diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index dd6689737e..af560c143e 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,5 +1,7 @@ import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + var template = (function() { return { data: function () { diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 5e7b1d99c7..fa28281f01 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -151,6 +151,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + var template = (function() { return { computed: { diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 87804092f2..d07ea6b452 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,5 +1,7 @@ import { assign, differs, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + var template = (function() { return { computed: { diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index bba05e07aa..fca610b373 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -171,6 +171,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); } diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 8a70516367..d27aa6cf30 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,5 +1,7 @@ import { appendNode, assign, createElement, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); } 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 8e3fa4e47f..2bc6c1965f 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -171,6 +171,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div, text; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 87cf2940bd..2580d2ed30 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,5 +1,7 @@ import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div, text; 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 28bd3c608d..6bd30e8ac6 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -184,6 +184,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var text, p, text_1; @@ -257,6 +259,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#each comments as comment, i}} function create_each_block(state, each_block_value, comment, i, component) { var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 5fec542b69..8bc3d9af66 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,5 +1,7 @@ import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var text, p, text_1; @@ -73,6 +75,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#each comments as comment, i}} function create_each_block(state, each_block_value, comment, i, component) { var div, strong, text, text_1, span, text_2_value = comment.author, text_2, text_3, text_4_value = state.elapsed(comment.time, state.time), text_4, text_5, text_6, raw_value = comment.html, raw_before; diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 9a683c9dab..db874825c6 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -171,6 +171,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + var template = (function() { return { methods: { diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index e123de9c98..b5342613ca 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,5 +1,7 @@ import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + var template = (function() { return { methods: { 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 00418f43cc..9076a1c39b 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -175,6 +175,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var if_block_anchor; @@ -213,6 +215,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#if foo}} function create_if_block(state, component) { var p, text; @@ -235,6 +238,7 @@ function create_if_block(state, component) { }; } +// (3:0) {{else}} function create_if_block_1(state, component) { var p, text; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 619465c331..dc6eb0af02 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,5 +1,7 @@ import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var if_block_anchor; @@ -38,6 +40,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#if foo}} function create_if_block(state, component) { var p, text; @@ -60,6 +63,7 @@ function create_if_block(state, component) { }; } +// (3:0) {{else}} function create_if_block_1(state, component) { var p, text; diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 6798ecce54..ed136d6d2c 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -175,6 +175,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var if_block_anchor; @@ -216,6 +218,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#if foo}} function create_if_block(state, component) { var p, text; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index f003447f3b..3581be9e8f 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,5 +1,7 @@ import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var if_block_anchor; @@ -41,6 +43,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#if foo}} function create_if_block(state, component) { var p, text; 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 019bf5e86b..2eb97d7393 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -167,6 +167,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 540cee99bc..8ee98dd788 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,5 +1,7 @@ import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div; 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 05aa4df9d7..e82cd57b1e 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -167,6 +167,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index d5d415aafd..5cb1dea1d6 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,5 +1,7 @@ import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 91db41380b..74b25b920e 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -167,6 +167,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index e4816ffbfb..edaff13d94 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,5 +1,7 @@ import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index cfe849e3f9..5e2225497f 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -167,6 +167,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 209cc90df6..e9d67c220f 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,5 +1,7 @@ import { assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; 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 c5cfd84bec..34657df7ff 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -171,6 +171,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var input; diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index b459bdb7c8..921080a85d 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,5 +1,7 @@ import { addListener, assign, createElement, detachNode, insertNode, proto, removeListener } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var input; diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index f34e19450e..74bf748994 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -169,6 +169,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var input; diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 9f585862e1..1c8b29cc93 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,5 +1,7 @@ import { assign, createElement, detachNode, insertNode, noop, proto, setInputType } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var input; diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index bf4bf86be9..b493642b59 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -186,6 +186,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index 7eec7950fd..eae392fd13 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,5 +1,7 @@ import { assign, children, claimElement, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 8dca649745..633556871b 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -179,6 +179,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 738de4f815..de779fcd11 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,5 +1,7 @@ import { addListener, assign, callAll, createElement, detachNode, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 6d5ea4bba3..08484ebe48 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -165,6 +165,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + var template = (function() { return { components: { diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index de96d252be..fd42c6f4d0 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -2,6 +2,8 @@ import Imported from 'Imported.html'; import { assign, callAll, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + var template = (function() { return { components: { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 272f822a9e..ae542fc797 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -151,6 +151,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + var template = (function() { return { // this test should be removed in v2 diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index 32a116b3a1..9490a3377b 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,5 +1,7 @@ import { assign, callAll, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + var template = (function() { return { // this test should be removed in v2 diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 6967036e49..45dcf576b8 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -151,6 +151,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + var template = (function() { return { methods: { diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 50d2ec47c5..f1a00ca030 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,5 +1,7 @@ import { assign, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + var template = (function() { return { methods: { 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 dc41a1501f..ee4404dd6a 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -175,6 +175,8 @@ var proto = { _unmount: _unmount }; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div, text, p, text_1, text_2, text_3, text_4, p_1, text_5, text_6, text_8, if_block_4_anchor; @@ -312,6 +314,7 @@ function create_main_fragment(state, component) { }; } +// (2:1) {{#if a}} function create_if_block(state, component) { var p, text; @@ -334,6 +337,7 @@ function create_if_block(state, component) { }; } +// (8:1) {{#if b}} function create_if_block_1(state, component) { var p, text; @@ -356,6 +360,7 @@ function create_if_block_1(state, component) { }; } +// (12:1) {{#if c}} function create_if_block_2(state, component) { var p, text; @@ -378,6 +383,7 @@ function create_if_block_2(state, component) { }; } +// (18:1) {{#if d}} function create_if_block_3(state, component) { var p, text; @@ -400,6 +406,7 @@ function create_if_block_3(state, component) { }; } +// (25:0) {{#if e}} function create_if_block_4(state, component) { var p, text; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index d520ee49e6..4ee6157183 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,5 +1,7 @@ import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +// generated by Svelte v1.39.2 + function create_main_fragment(state, component) { var div, text, p, text_1, text_2, text_3, text_4, p_1, text_5, text_6, text_8, if_block_4_anchor; @@ -137,6 +139,7 @@ function create_main_fragment(state, component) { }; } +// (2:1) {{#if a}} function create_if_block(state, component) { var p, text; @@ -159,6 +162,7 @@ function create_if_block(state, component) { }; } +// (8:1) {{#if b}} function create_if_block_1(state, component) { var p, text; @@ -181,6 +185,7 @@ function create_if_block_1(state, component) { }; } +// (12:1) {{#if c}} function create_if_block_2(state, component) { var p, text; @@ -203,6 +208,7 @@ function create_if_block_2(state, component) { }; } +// (18:1) {{#if d}} function create_if_block_3(state, component) { var p, text; @@ -225,6 +231,7 @@ function create_if_block_3(state, component) { }; } +// (25:0) {{#if e}} function create_if_block_4(state, component) { var p, text; From ddbcebab4326c9e2dc50460483f3c3bc6d485c00 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Sep 2017 14:27:59 -0400 Subject: [PATCH 2/6] put version comment above imports --- src/generators/dom/index.ts | 3 ++- .../samples/collapses-text-around-comments/expected-bundle.js | 2 +- test/js/samples/collapses-text-around-comments/expected.js | 4 ++-- test/js/samples/computed-collapsed-if/expected-bundle.js | 2 +- test/js/samples/computed-collapsed-if/expected.js | 4 ++-- test/js/samples/css-media-query/expected-bundle.js | 2 +- test/js/samples/css-media-query/expected.js | 4 ++-- test/js/samples/css-shadow-dom-keyframes/expected-bundle.js | 2 +- test/js/samples/css-shadow-dom-keyframes/expected.js | 4 ++-- test/js/samples/each-block-changed-check/expected-bundle.js | 2 +- test/js/samples/each-block-changed-check/expected.js | 4 ++-- test/js/samples/event-handlers-custom/expected-bundle.js | 2 +- test/js/samples/event-handlers-custom/expected.js | 4 ++-- test/js/samples/if-block-no-update/expected-bundle.js | 2 +- test/js/samples/if-block-no-update/expected.js | 4 ++-- test/js/samples/if-block-simple/expected-bundle.js | 2 +- test/js/samples/if-block-simple/expected.js | 4 ++-- .../inline-style-optimized-multiple/expected-bundle.js | 2 +- test/js/samples/inline-style-optimized-multiple/expected.js | 4 ++-- test/js/samples/inline-style-optimized-url/expected-bundle.js | 2 +- test/js/samples/inline-style-optimized-url/expected.js | 4 ++-- test/js/samples/inline-style-optimized/expected-bundle.js | 2 +- test/js/samples/inline-style-optimized/expected.js | 4 ++-- test/js/samples/inline-style-unoptimized/expected-bundle.js | 2 +- test/js/samples/inline-style-unoptimized/expected.js | 4 ++-- .../samples/input-without-blowback-guard/expected-bundle.js | 2 +- test/js/samples/input-without-blowback-guard/expected.js | 4 ++-- test/js/samples/legacy-input-type/expected-bundle.js | 2 +- test/js/samples/legacy-input-type/expected.js | 4 ++-- test/js/samples/legacy-quote-class/expected-bundle.js | 2 +- test/js/samples/legacy-quote-class/expected.js | 4 ++-- test/js/samples/media-bindings/expected-bundle.js | 2 +- test/js/samples/media-bindings/expected.js | 4 ++-- test/js/samples/non-imported-component/expected-bundle.js | 2 +- test/js/samples/non-imported-component/expected.js | 4 ++-- .../samples/onrender-onteardown-rewritten/expected-bundle.js | 2 +- test/js/samples/onrender-onteardown-rewritten/expected.js | 4 ++-- test/js/samples/setup-method/expected-bundle.js | 2 +- test/js/samples/setup-method/expected.js | 4 ++-- test/js/samples/use-elements-as-anchors/expected-bundle.js | 2 +- test/js/samples/use-elements-as-anchors/expected.js | 4 ++-- 41 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 7bcee58366..4dc638676d 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -77,7 +77,6 @@ export default function dom( }); const builder = new CodeBuilder(); - builder.addBlock(`// ${options.filename ? `${options.filename} ` : ``}generated by Svelte v${version}`); const computationBuilder = new CodeBuilder(); if (computations.length) { @@ -407,6 +406,8 @@ export default function dom( }); } + result = `/* ${options.filename ? `${options.filename} ` : ``}generated by Svelte v${version} */\n\n${result}`; + return generator.generate(result, options, { name, format, diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index c359d3ea3f..d9449d5c66 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -175,7 +175,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ var template = (function() { return { diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index af560c143e..7a027c389d 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,6 +1,6 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; var template = (function() { return { diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index fa28281f01..8dad6f4adc 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -151,7 +151,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ var template = (function() { return { diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index d07ea6b452..60adf0376e 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,6 +1,6 @@ -import { assign, differs, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, differs, noop, proto } from "svelte/shared.js"; var template = (function() { return { diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index fca610b373..d12dbea66a 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -171,7 +171,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index d27aa6cf30..a51d9d0f7a 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,6 +1,6 @@ -import { appendNode, assign, createElement, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { appendNode, assign, createElement, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); 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 2bc6c1965f..bfcc815643 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -171,7 +171,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var div, text; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 2580d2ed30..6e4ce0a044 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,6 +1,6 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text; 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 6bd30e8ac6..17dbba5d17 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -184,7 +184,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var text, p, text_1; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 8bc3d9af66..50aea24e12 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,6 +1,6 @@ -import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var text, p, text_1; diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index db874825c6..00e24ed978 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -171,7 +171,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ var template = (function() { return { diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index b5342613ca..304ee13841 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,6 +1,6 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { 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 9076a1c39b..d67e038a00 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -175,7 +175,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var if_block_anchor; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index dc6eb0af02..45e01ab96d 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,6 +1,6 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index ed136d6d2c..8bb4ac429d 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -175,7 +175,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var if_block_anchor; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 3581be9e8f..d128a6a4ec 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,6 +1,6 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; 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 2eb97d7393..b5e54c7e6e 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -167,7 +167,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 8ee98dd788..f54ea5d785 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,6 +1,6 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; 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 e82cd57b1e..21561be133 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -167,7 +167,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index 5cb1dea1d6..cb17cedca8 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,6 +1,6 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 74b25b920e..4fcd4211a5 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -167,7 +167,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index edaff13d94..182250bf0c 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,6 +1,6 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index 5e2225497f..7ca2e8323d 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -167,7 +167,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index e9d67c220f..7fbb2eab0c 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,6 +1,6 @@ -import { assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; 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 34657df7ff..c5d2693d15 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -171,7 +171,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var input; diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index 921080a85d..1052a5cffa 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,6 +1,6 @@ -import { addListener, assign, createElement, detachNode, insertNode, proto, removeListener } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { addListener, assign, createElement, detachNode, insertNode, proto, removeListener } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 74bf748994..e96195727c 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -169,7 +169,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var input; diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 1c8b29cc93..bd2353a560 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,6 +1,6 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setInputType } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, createElement, detachNode, insertNode, noop, proto, setInputType } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index b493642b59..1ae85825e7 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -186,7 +186,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index eae392fd13..f98967ca7e 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,6 +1,6 @@ -import { assign, children, claimElement, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, children, claimElement, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 633556871b..36efc05ee0 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -179,7 +179,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index de779fcd11..02a16f72f8 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,6 +1,6 @@ -import { addListener, assign, callAll, createElement, detachNode, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { addListener, assign, callAll, createElement, detachNode, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 08484ebe48..48f69ac7d9 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -165,7 +165,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ var template = (function() { return { diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index fd42c6f4d0..61034fa15d 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,8 +1,8 @@ import Imported from 'Imported.html'; -import { assign, callAll, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, callAll, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index ae542fc797..133875e583 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -151,7 +151,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ var template = (function() { return { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index 9490a3377b..230f69cffa 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,6 +1,6 @@ -import { assign, callAll, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, callAll, noop, proto } from "svelte/shared.js"; var template = (function() { return { diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 45dcf576b8..1ee808404a 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -151,7 +151,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ var template = (function() { return { diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index f1a00ca030..5d4a7e3dac 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,6 +1,6 @@ -import { assign, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { assign, noop, proto } from "svelte/shared.js"; var template = (function() { return { 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 ee4404dd6a..1fb76590dc 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -175,7 +175,7 @@ var proto = { _unmount: _unmount }; -// generated by Svelte v1.39.2 +/* generated by Svelte v1.39.2 */ function create_main_fragment(state, component) { var div, text, p, text_1, text_2, text_3, text_4, p_1, text_5, text_6, text_8, if_block_4_anchor; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 4ee6157183..2cb72d2ce3 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,6 +1,6 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.2 */ -// generated by Svelte v1.39.2 +import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, p, text_1, text_2, text_3, text_4, p_1, text_5, text_6, text_8, if_block_4_anchor; From c47d2bd88dbf123735362e6f630ffb5ff4303c70 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Sep 2017 15:09:38 -0400 Subject: [PATCH 3/6] extract some shared init logic --- src/generators/dom/index.ts | 11 +----- src/shared/index.js | 23 +++++++++--- .../expected-bundle.js | 36 ++++++++++--------- .../expected.js | 15 ++------ .../computed-collapsed-if/expected-bundle.js | 36 ++++++++++--------- .../samples/computed-collapsed-if/expected.js | 15 ++------ .../css-media-query/expected-bundle.js | 36 ++++++++++--------- test/js/samples/css-media-query/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../css-shadow-dom-keyframes/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../each-block-changed-check/expected.js | 15 ++------ .../event-handlers-custom/expected-bundle.js | 36 ++++++++++--------- .../samples/event-handlers-custom/expected.js | 15 ++------ .../if-block-no-update/expected-bundle.js | 36 ++++++++++--------- .../js/samples/if-block-no-update/expected.js | 15 ++------ .../if-block-simple/expected-bundle.js | 36 ++++++++++--------- test/js/samples/if-block-simple/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../inline-style-optimized-url/expected.js | 15 ++------ .../inline-style-optimized/expected-bundle.js | 36 ++++++++++--------- .../inline-style-optimized/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../inline-style-unoptimized/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../input-without-blowback-guard/expected.js | 15 ++------ .../legacy-input-type/expected-bundle.js | 36 ++++++++++--------- test/js/samples/legacy-input-type/expected.js | 15 ++------ .../legacy-quote-class/expected-bundle.js | 36 ++++++++++--------- .../js/samples/legacy-quote-class/expected.js | 15 ++------ .../samples/media-bindings/expected-bundle.js | 36 ++++++++++--------- test/js/samples/media-bindings/expected.js | 15 ++------ .../non-imported-component/expected-bundle.js | 36 ++++++++++--------- .../non-imported-component/expected.js | 15 ++------ .../expected-bundle.js | 35 ++++++++++-------- .../onrender-onteardown-rewritten/expected.js | 14 ++------ .../samples/setup-method/expected-bundle.js | 36 ++++++++++--------- test/js/samples/setup-method/expected.js | 15 ++------ .../expected-bundle.js | 36 ++++++++++--------- .../use-elements-as-anchors/expected.js | 15 ++------ 42 files changed, 460 insertions(+), 592 deletions(-) diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 8d82fef182..6eaf256353 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -153,7 +153,7 @@ export default function dom( ${options.dev && `this._debugName = '${debugName}';`} ${options.dev && !generator.customElement && `if (!options || (!options.target && !options._root)) throw new Error("'target' is a required option");`} - this.options = options; + @init(this, options); ${generator.usesRefs && `this.refs = {};`} this._state = ${templateProperties.data ? `@assign(@template.data(), options.data)` @@ -168,17 +168,8 @@ export default function dom( ${generator.bindingGroups.length && `this._bindingGroups = [${Array(generator.bindingGroups.length).fill('[]').join(', ')}];`} - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); ${templateProperties.ondestroy && `this._handlers.destroy = [@template.ondestroy]`} - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; ${generator.slots.size && `this._slotted = options.slots || {};`} ${generator.customElement ? diff --git a/src/shared/index.js b/src/shared/index.js index 34d85897df..001babe349 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -46,10 +46,6 @@ export function dispatchObservers(component, group, changed, newState, oldState) } } -export function get(key) { - return key ? this._state[key] : this._state; -} - export function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -60,6 +56,25 @@ export function fire(eventName, data) { } } +export function get(key) { + return key ? this._state[key] : this._state; +} + +export function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + export function observe(key, callback, options) { var group = options && options.defer ? this._observers.post diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index 5e61b5cb39..c421eadb7d 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -72,10 +72,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -86,6 +82,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -228,20 +243,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = assign(template.data(), options.data); - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!document.getElementById("svelte-3590263702-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index dd6689737e..2ad2187e95 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; var template = (function() { return { @@ -53,20 +53,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = assign(template.data(), options.data); - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!document.getElementById("svelte-3590263702-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 5e7b1d99c7..7296201e36 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -48,10 +48,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -62,6 +58,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -176,21 +191,10 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; this._recompute({}, this._state, {}, true); - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 87804092f2..48e3445dd8 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,4 +1,4 @@ -import { assign, differs, noop, proto } from "svelte/shared.js"; +import { assign, differs, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -25,21 +25,10 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; this._recompute({}, this._state, {}, true); - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index bba05e07aa..30f8a023a9 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -68,10 +68,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -82,6 +78,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -210,20 +225,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!document.getElementById("svelte-2363328337-style")) add_css(); this._fragment = create_main_fragment(this._state, this); diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 8a70516367..4dcb8f9fb3 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); @@ -39,20 +39,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!document.getElementById("svelte-2363328337-style")) add_css(); this._fragment = create_main_fragment(this._state, this); 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 8e3fa4e47f..d19b44002d 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -68,10 +68,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -82,6 +78,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -198,20 +213,9 @@ function create_main_fragment(state, component) { class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - 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 87cf2940bd..2814d24901 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text; @@ -27,20 +27,9 @@ function create_main_fragment(state, component) { class SvelteComponent extends HTMLElement { constructor(options = {}) { super(); - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - 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 28bd3c608d..97f6371f23 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -81,10 +81,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -95,6 +91,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -322,20 +337,9 @@ function create_each_block(state, each_block_value, comment, i, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 5fec542b69..8931d83aab 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var text, p, text_1; @@ -138,20 +138,9 @@ function create_each_block(state, each_block_value, comment, i, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 9a683c9dab..5f117e9ce9 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -68,10 +68,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -82,6 +78,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -221,20 +236,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index e123de9c98..b08c6335f8 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -50,20 +50,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { 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 00418f43cc..dcc893079b 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -72,10 +72,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -86,6 +82,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -263,20 +278,9 @@ function select_block_type(state) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 619465c331..4db0d11949 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -88,20 +88,9 @@ function select_block_type(state) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 6798ecce54..6612ead376 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -72,10 +72,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -86,6 +82,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -239,20 +254,9 @@ function create_if_block(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index f003447f3b..e229b23ee8 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -64,20 +64,9 @@ function create_if_block(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { 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 019bf5e86b..190e86eb44 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -64,10 +64,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -78,6 +74,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -204,20 +219,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 540cee99bc..2ae613643e 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -37,20 +37,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { 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 05aa4df9d7..15076819cb 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -64,10 +64,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -78,6 +74,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -199,20 +214,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index d5d415aafd..de8e6ffec2 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -32,20 +32,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 91db41380b..8640267814 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -64,10 +64,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -78,6 +74,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -199,20 +214,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index e4816ffbfb..54b6de1646 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -32,20 +32,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index cfe849e3f9..f12a26da07 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -64,10 +64,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -78,6 +74,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -210,20 +225,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 209cc90df6..63c32e26cf 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; @@ -43,20 +43,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { 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 c5cfd84bec..0a9b7dc47d 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -68,10 +68,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -82,6 +78,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -210,20 +225,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index b459bdb7c8..4b987311f2 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,4 +1,4 @@ -import { addListener, assign, createElement, detachNode, insertNode, proto, removeListener } from "svelte/shared.js"; +import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -39,20 +39,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index f34e19450e..338b70b5d9 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -66,10 +66,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -80,6 +76,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -197,20 +212,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 9f585862e1..3e8b6714e0 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,4 +1,4 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setInputType } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -28,20 +28,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index bf4bf86be9..8c10d0af06 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -83,10 +83,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -97,6 +93,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -222,20 +237,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index 7eec7950fd..1a4de07a5b 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,4 +1,4 @@ -import { assign, children, claimElement, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -36,20 +36,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 8dca649745..1f78b237cc 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -76,10 +76,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -90,6 +86,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -286,20 +301,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!options._root) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 738de4f815..b19656cf34 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,4 +1,4 @@ -import { addListener, assign, callAll, createElement, detachNode, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; +import { addListener, assign, callAll, createElement, detachNode, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; @@ -107,20 +107,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!options._root) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 6d5ea4bba3..261f63dcbd 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -62,10 +62,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -76,6 +72,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -213,20 +228,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!options._root) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index de96d252be..ef6a106de7 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,6 +1,6 @@ import Imported from 'Imported.html'; -import { assign, callAll, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, callAll, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -50,20 +50,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - if (!options._root) { this._oncreate = []; this._beforecreate = []; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 272f822a9e..95e0119a24 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -48,10 +48,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -62,6 +58,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -175,21 +190,11 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); this._handlers.destroy = [template.ondestroy]; - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - var oncreate = template.oncreate.bind(this); if (!options._root) { diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index 32a116b3a1..6e2df0f9be 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,4 +1,4 @@ -import { assign, callAll, noop, proto } from "svelte/shared.js"; +import { assign, callAll, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -24,21 +24,11 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); this._handlers.destroy = [template.ondestroy] - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - var oncreate = template.oncreate.bind(this); if (!options._root) { diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 6967036e49..0f2fb2685c 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -48,10 +48,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -62,6 +58,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -186,20 +201,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 50d2ec47c5..90d98f0947 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,4 +1,4 @@ -import { assign, noop, proto } from "svelte/shared.js"; +import { assign, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -35,20 +35,9 @@ function create_main_fragment(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { 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 dc41a1501f..d3ae8b9976 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -72,10 +72,6 @@ function dispatchObservers(component, group, changed, newState, oldState) { } } -function get(key) { - return key ? this._state[key] : this._state; -} - function fire(eventName, data) { var handlers = eventName in this._handlers && this._handlers[eventName].slice(); @@ -86,6 +82,25 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { + pre: Object.create(null), + post: Object.create(null) + }; + + component._handlers = Object.create(null); + + component._root = options._root || component; + component._yield = options._yield; + component._bind = options._bind; +} + function observe(key, callback, options) { var group = options && options.defer ? this._observers.post @@ -423,20 +438,9 @@ function create_if_block_4(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index d520ee49e6..156f83674a 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,4 +1,4 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div, text, p, text_1, text_2, text_3, text_4, p_1, text_5, text_6, text_8, if_block_4_anchor; @@ -248,20 +248,9 @@ function create_if_block_4(state, component) { } function SvelteComponent(options) { - this.options = options; + init(this, options); this._state = options.data || {}; - this._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - this._handlers = Object.create(null); - - this._root = options._root || this; - this._yield = options._yield; - this._bind = options._bind; - this._fragment = create_main_fragment(this._state, this); if (options.target) { From f0a404a07cb07875f354e103db0d84d38fe2879d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Sep 2017 15:15:23 -0400 Subject: [PATCH 4/6] tighten up a bit more --- src/generators/dom/visitors/EachBlock.ts | 2 +- src/shared/index.js | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/generators/dom/visitors/EachBlock.ts b/src/generators/dom/visitors/EachBlock.ts index e0d941511e..03c0918ce0 100644 --- a/src/generators/dom/visitors/EachBlock.ts +++ b/src/generators/dom/visitors/EachBlock.ts @@ -160,7 +160,7 @@ function keyed( const last = block.getUniqueName(`${each_block}_last`); const expected = block.getUniqueName(`${each_block}_expected`); - block.addVariable(lookup, `Object.create(null)`); + block.addVariable(lookup, `@blankObject()`); block.addVariable(head); block.addVariable(last); diff --git a/src/shared/index.js b/src/shared/index.js index 001babe349..dcc2895831 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -4,6 +4,10 @@ export * from './dom.js'; export * from './transitions.js'; export * from './utils.js'; +export function blankObject() { + return Object.create(null); +} + export function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -63,13 +67,8 @@ export function get(key) { export function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; From c54e4617863e73eb92e42fb39aec3f96c5ab9d2b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 16 Sep 2017 15:20:43 -0400 Subject: [PATCH 5/6] update tests --- .../expected-bundle.js | 13 ++++++------- .../computed-collapsed-if/expected-bundle.js | 13 ++++++------- test/js/samples/css-media-query/expected-bundle.js | 13 ++++++------- .../css-shadow-dom-keyframes/expected-bundle.js | 13 ++++++------- .../each-block-changed-check/expected-bundle.js | 13 ++++++------- .../event-handlers-custom/expected-bundle.js | 13 ++++++------- .../samples/if-block-no-update/expected-bundle.js | 13 ++++++------- test/js/samples/if-block-simple/expected-bundle.js | 13 ++++++------- .../expected-bundle.js | 13 ++++++------- .../inline-style-optimized-url/expected-bundle.js | 13 ++++++------- .../inline-style-optimized/expected-bundle.js | 13 ++++++------- .../inline-style-unoptimized/expected-bundle.js | 13 ++++++------- .../input-without-blowback-guard/expected-bundle.js | 13 ++++++------- .../js/samples/legacy-input-type/expected-bundle.js | 13 ++++++------- .../samples/legacy-quote-class/expected-bundle.js | 13 ++++++------- test/js/samples/media-bindings/expected-bundle.js | 13 ++++++------- .../non-imported-component/expected-bundle.js | 13 ++++++------- .../expected-bundle.js | 13 ++++++------- test/js/samples/setup-method/expected-bundle.js | 13 ++++++------- .../use-elements-as-anchors/expected-bundle.js | 13 ++++++------- 20 files changed, 120 insertions(+), 140 deletions(-) diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index c421eadb7d..548fabf94b 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -37,6 +37,10 @@ function setAttribute(node, attribute, value) { node.setAttribute(attribute, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -89,13 +93,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 7296201e36..c511b16af4 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -13,6 +13,10 @@ function assign(target) { return target; } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -65,13 +69,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 30f8a023a9..0b5f496608 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -33,6 +33,10 @@ function setAttribute(node, attribute, value) { node.setAttribute(attribute, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -85,13 +89,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; 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 d19b44002d..5659f8d71c 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -33,6 +33,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -85,13 +89,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; 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 97f6371f23..593cb2c76a 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -46,6 +46,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -98,13 +102,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 5f117e9ce9..da43b1c1f6 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -33,6 +33,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -85,13 +89,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; 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 dcc893079b..7e04a6295b 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -37,6 +37,10 @@ function createComment() { return document.createComment(''); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -89,13 +93,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 6612ead376..4c9e853523 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -37,6 +37,10 @@ function createComment() { return document.createComment(''); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -89,13 +93,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; 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 190e86eb44..8579875048 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -29,6 +29,10 @@ function setStyle(node, key, value) { node.style.setProperty(key, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -81,13 +85,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; 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 15076819cb..9246e5da3f 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -29,6 +29,10 @@ function setStyle(node, key, value) { node.style.setProperty(key, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -81,13 +85,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 8640267814..bf1042f922 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -29,6 +29,10 @@ function setStyle(node, key, value) { node.style.setProperty(key, value); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -81,13 +85,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index f12a26da07..578be1689d 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -29,6 +29,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -81,13 +85,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; 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 0a9b7dc47d..c9222e4511 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -33,6 +33,10 @@ function removeListener(node, event, handler) { node.removeEventListener(event, handler, false); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -85,13 +89,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 338b70b5d9..55496415c4 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -31,6 +31,10 @@ function setInputType(input, type) { } catch (e) {} } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -83,13 +87,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index 8c10d0af06..41d45271af 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -48,6 +48,10 @@ function claimElement (nodes, name, attributes, svg) { return svg ? createSvgElement(name) : createElement(name); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -100,13 +104,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 1f78b237cc..39f2e2c682 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -41,6 +41,10 @@ function timeRangesToArray(ranges) { return array; } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -93,13 +97,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 261f63dcbd..33172b6954 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -27,6 +27,10 @@ function createText(data) { return document.createTextNode(data); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -79,13 +83,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 95e0119a24..76c83b2097 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -13,6 +13,10 @@ function assign(target) { return target; } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -65,13 +69,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 0f2fb2685c..c936fc549e 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -13,6 +13,10 @@ function assign(target) { return target; } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -65,13 +69,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; 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 d3ae8b9976..362c8a45fb 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -37,6 +37,10 @@ function createComment() { return document.createComment(''); } +function blankObject() { + return Object.create(null); +} + function destroy(detach) { this.destroy = noop; this.fire('destroy'); @@ -89,13 +93,8 @@ function get(key) { function init(component, options) { component.options = options; - component._observers = { - pre: Object.create(null), - post: Object.create(null) - }; - - component._handlers = Object.create(null); - + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); component._root = options._root || component; component._yield = options._yield; component._bind = options._bind; From fbc45245995a0dc5614673047e8e0285423ed359 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sun, 17 Sep 2017 12:18:23 -0400 Subject: [PATCH 6/6] remove excess parentheses --- src/utils/CodeBuilder.ts | 2 +- .../collapses-text-around-comments/expected-bundle.js | 2 +- .../js/samples/collapses-text-around-comments/expected.js | 2 +- test/js/samples/computed-collapsed-if/expected-bundle.js | 2 +- test/js/samples/computed-collapsed-if/expected.js | 2 +- .../samples/each-block-changed-check/expected-bundle.js | 8 ++++---- test/js/samples/each-block-changed-check/expected.js | 8 ++++---- .../inline-style-optimized-multiple/expected-bundle.js | 4 ++-- .../samples/inline-style-optimized-multiple/expected.js | 4 ++-- .../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 +- .../samples/inline-style-unoptimized/expected-bundle.js | 4 ++-- test/js/samples/inline-style-unoptimized/expected.js | 4 ++-- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/utils/CodeBuilder.ts b/src/utils/CodeBuilder.ts index eab930d96e..5d0477ce68 100644 --- a/src/utils/CodeBuilder.ts +++ b/src/utils/CodeBuilder.ts @@ -44,7 +44,7 @@ export default class CodeBuilder { this.result += `\n${this.indent}}`; } - this.result += `${this.last === ChunkType.Block ? '\n\n' : '\n'}${this.indent}if ( ${condition} ) {\n${body}`; + this.result += `${this.last === ChunkType.Block ? '\n\n' : '\n'}${this.indent}if (${condition}) {\n${body}`; this.lastCondition = condition; } diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index 381689510f..3ad254d588 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -230,7 +230,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.foo ) { + if (changed.foo) { text.data = state.foo; } }, diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 9f28fa8507..b80ad4e78e 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -41,7 +41,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.foo ) { + if (changed.foo) { text.data = state.foo; } }, diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 14b5ea92f9..51eaaf39bc 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -207,7 +207,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); SvelteComponent.prototype._recompute = function _recompute(changed, state, oldState, isInitial) { - if ( isInitial || changed.x ) { + if (isInitial || changed.x) { if (differs((state.a = template.computed.a(state.x)), oldState.a)) changed.a = true; if (differs((state.b = template.computed.b(state.x)), oldState.b)) changed.b = true; } diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index b95290e5fa..9a0ef1c2b4 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -42,7 +42,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); SvelteComponent.prototype._recompute = function _recompute(changed, state, oldState, isInitial) { - if ( isInitial || changed.x ) { + if (isInitial || changed.x) { if (differs((state.a = template.computed.a(state.x)), oldState.a)) changed.a = true; if (differs((state.b = template.computed.b(state.x)), oldState.b)) changed.b = true; } 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 f72914e256..f69d691333 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -253,7 +253,7 @@ function create_main_fragment(state, component) { each_block_iterations.length = each_block_value.length; } - if ( changed.foo ) { + if (changed.foo) { text_1.data = state.foo; } }, @@ -314,15 +314,15 @@ function create_each_block(state, each_block_value, comment, i, component) { }, update: function(changed, state, each_block_value, comment, i) { - if ( (changed.comments) && text_2_value !== (text_2_value = comment.author) ) { + if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { text_2.data = text_2_value; } - if ( (changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time)) ) { + if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time))) { text_4.data = text_4_value; } - if ( (changed.comments) && raw_value !== (raw_value = comment.html) ) { + if ((changed.comments) && raw_value !== (raw_value = comment.html)) { detachAfter(raw_before); raw_before.insertAdjacentHTML("afterend", raw_value); } diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 099d665310..5b30d091fc 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -55,7 +55,7 @@ function create_main_fragment(state, component) { each_block_iterations.length = each_block_value.length; } - if ( changed.foo ) { + if (changed.foo) { text_1.data = state.foo; } }, @@ -116,15 +116,15 @@ function create_each_block(state, each_block_value, comment, i, component) { }, update: function(changed, state, each_block_value, comment, i) { - if ( (changed.comments) && text_2_value !== (text_2_value = comment.author) ) { + if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { text_2.data = text_2_value; } - if ( (changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time)) ) { + if ((changed.elapsed || changed.comments || changed.time) && text_4_value !== (text_4_value = state.elapsed(comment.time, state.time))) { text_4.data = text_4_value; } - if ( (changed.comments) && raw_value !== (raw_value = comment.html) ) { + if ((changed.comments) && raw_value !== (raw_value = comment.html)) { detachAfter(raw_before); raw_before.insertAdjacentHTML("afterend", raw_value); } 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 baee24460d..6142c14afd 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -202,11 +202,11 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.color ) { + if (changed.color) { setStyle(div, "color", state.color); } - if ( changed.x || changed.y ) { + if (changed.x || changed.y) { setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); } }, diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index b8b84bccde..51f7499383 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -21,11 +21,11 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.color ) { + if (changed.color) { setStyle(div, "color", state.color); } - if ( changed.x || changed.y ) { + if (changed.x || changed.y) { setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); } }, 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 36f7e7088e..2ff763246a 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -201,7 +201,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.data ) { + if (changed.data) { setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); } }, diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index 8af7163c19..f0ada0520b 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -20,7 +20,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.data ) { + if (changed.data) { setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); } }, diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 8fc1d52c22..554be56ba4 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -201,7 +201,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.color ) { + if (changed.color) { setStyle(div, "color", state.color); } }, diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index ba05d8a693..333020c739 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -20,7 +20,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.color ) { + if (changed.color) { setStyle(div, "color", state.color); } }, diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index b37c46cc1c..5ab9d5db50 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -206,11 +206,11 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.style ) { + if (changed.style) { div.style.cssText = state.style; } - if ( (changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value) ) { + if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value)) { div_1.style.cssText = div_1_style_value; } }, diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index a8fa992ded..e61085cb37 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -25,11 +25,11 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.style ) { + if (changed.style) { div.style.cssText = state.style; } - if ( (changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value) ) { + if ((changed.key || changed.value) && div_1_style_value !== (div_1_style_value = "" + state.key + ": " + state.value)) { div_1.style.cssText = div_1_style_value; } },