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 f2ef1d32bf..768aff7a4e 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 { @@ -158,7 +159,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)` @@ -173,17 +174,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 ? @@ -410,6 +402,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/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/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/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/src/shared/index.js b/src/shared/index.js index 34d85897df..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'); @@ -46,10 +50,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 +60,20 @@ 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: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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/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/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..3ad254d588 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'); @@ -72,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(); @@ -86,6 +86,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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,6 +189,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + var template = (function() { return { data: function () { @@ -214,7 +230,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.foo ) { + if (changed.foo) { text.data = state.foo; } }, @@ -228,20 +244,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..b80ad4e78e 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,4 +1,6 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; var template = (function() { return { @@ -39,7 +41,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.foo ) { + if (changed.foo) { text.data = state.foo; } }, @@ -53,20 +55,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..51eaaf39bc 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'); @@ -48,10 +52,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 +62,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -151,6 +165,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + var template = (function() { return { computed: { @@ -176,21 +192,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) { @@ -202,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 87804092f2..9a0ef1c2b4 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,4 +1,6 @@ -import { assign, differs, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, differs, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -25,21 +27,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) { @@ -51,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/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index bba05e07aa..9ffeb2f221 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'); @@ -68,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(); @@ -82,6 +82,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -171,6 +185,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); } @@ -210,20 +226,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..a70623ec7b 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,4 +1,6 @@ -import { appendNode, assign, createElement, detachNode, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); @@ -39,20 +41,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..7e04a00dd9 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'); @@ -68,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(); @@ -82,6 +82,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -171,6 +185,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var div, text; @@ -198,20 +214,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..6d0b37f175 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,4 +1,6 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +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 +29,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..f69d691333 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'); @@ -81,10 +85,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 +95,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -184,6 +198,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var text, p, text_1; @@ -237,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; } }, @@ -257,6 +273,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; @@ -297,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); } @@ -322,20 +339,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..5b30d091fc 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,4 +1,6 @@ -import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +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; @@ -53,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; } }, @@ -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; @@ -113,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); } @@ -138,20 +141,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..022592786b 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'); @@ -68,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(); @@ -82,6 +82,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -171,6 +185,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + var template = (function() { return { methods: { @@ -221,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/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index e123de9c98..cf2bf6a8ec 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,4 +1,6 @@ -import { appendNode, assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -50,20 +52,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..8f91bf4175 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'); @@ -72,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(); @@ -86,6 +86,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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,6 +189,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var if_block_anchor; @@ -213,6 +229,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#if foo}} function create_if_block(state, component) { var p, text; @@ -235,6 +252,7 @@ function create_if_block(state, component) { }; } +// (3:0) {{else}} function create_if_block_1(state, component) { var p, text; @@ -263,20 +281,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..82e090d93e 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,4 +1,6 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +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; @@ -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; @@ -88,20 +92,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..7007f2830f 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'); @@ -72,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(); @@ -86,6 +86,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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,6 +189,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var if_block_anchor; @@ -216,6 +232,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#if foo}} function create_if_block(state, component) { var p, text; @@ -239,20 +256,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..53cf640760 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,4 +1,6 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +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; @@ -41,6 +43,7 @@ function create_main_fragment(state, component) { }; } +// (1:0) {{#if foo}} function create_if_block(state, component) { var p, text; @@ -64,20 +67,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..6142c14afd 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'); @@ -64,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(); @@ -78,6 +78,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -167,6 +181,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var div; @@ -186,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)"); } }, @@ -204,20 +220,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..51f7499383 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,4 +1,6 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -19,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)"); } }, @@ -37,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/inline-style-optimized-url/expected-bundle.js b/test/js/samples/inline-style-optimized-url/expected-bundle.js index 05aa4df9d7..2ff763246a 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'); @@ -64,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(); @@ -78,6 +78,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -167,6 +181,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var div; @@ -185,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 + ")"); } }, @@ -199,20 +215,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..f0ada0520b 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,4 +1,6 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -18,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 + ")"); } }, @@ -32,20 +34,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..554be56ba4 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'); @@ -64,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(); @@ -78,6 +78,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -167,6 +181,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var div; @@ -185,7 +201,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.color ) { + if (changed.color) { setStyle(div, "color", state.color); } }, @@ -199,20 +215,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..333020c739 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,4 +1,6 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setStyle } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -18,7 +20,7 @@ function create_main_fragment(state, component) { }, update: function(changed, state) { - if ( changed.color ) { + if (changed.color) { setStyle(div, "color", state.color); } }, @@ -32,20 +34,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..5ab9d5db50 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'); @@ -64,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(); @@ -78,6 +78,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -167,6 +181,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; @@ -190,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; } }, @@ -210,20 +226,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..e61085cb37 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,4 +1,6 @@ -import { assign, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +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; @@ -23,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; } }, @@ -43,20 +45,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..b1c6c3b8e5 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'); @@ -68,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(); @@ -82,6 +82,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -171,6 +185,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var input; @@ -210,20 +226,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..ab01d04de3 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,4 +1,6 @@ -import { addListener, assign, createElement, detachNode, insertNode, proto, removeListener } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -39,20 +41,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..c950e0ddb1 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'); @@ -66,10 +70,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 +80,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -169,6 +183,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var input; @@ -197,20 +213,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..082b8d3208 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,4 +1,6 @@ -import { assign, createElement, detachNode, insertNode, noop, proto, setInputType } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; function create_main_fragment(state, component) { var input; @@ -28,20 +30,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..9d0e225527 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'); @@ -83,10 +87,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 +97,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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,6 +200,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var div; @@ -222,20 +238,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..09d185216e 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,4 +1,6 @@ -import { assign, children, claimElement, createElement, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var div; @@ -36,20 +38,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..ce26e1ac63 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'); @@ -76,10 +80,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 +90,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -179,6 +193,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; @@ -286,20 +302,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..ca7837c41c 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,4 +1,6 @@ -import { addListener, assign, callAll, createElement, detachNode, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +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 +109,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..f1f284a01f 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'); @@ -62,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(); @@ -76,6 +76,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -165,6 +179,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + var template = (function() { return { components: { @@ -213,20 +229,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..a7c1ad99a8 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -1,6 +1,8 @@ import Imported from 'Imported.html'; -import { assign, callAll, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, callAll, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -50,20 +52,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..c1556145d3 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'); @@ -48,10 +52,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 +62,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -151,6 +165,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + var template = (function() { return { // this test should be removed in v2 @@ -175,21 +191,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..00323faf1c 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,4 +1,6 @@ -import { assign, callAll, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, callAll, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -24,21 +26,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..a5c4ff68f8 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'); @@ -48,10 +52,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 +62,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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 @@ -151,6 +165,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + var template = (function() { return { methods: { @@ -186,20 +202,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..a544e229bc 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,4 +1,6 @@ -import { assign, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +import { assign, init, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -35,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/use-elements-as-anchors/expected-bundle.js b/test/js/samples/use-elements-as-anchors/expected-bundle.js index dc41a1501f..ae00877549 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'); @@ -72,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(); @@ -86,6 +86,20 @@ function fire(eventName, data) { } } +function get(key) { + return key ? this._state[key] : this._state; +} + +function init(component, options) { + component.options = options; + + component._observers = { pre: blankObject(), post: blankObject() }; + component._handlers = blankObject(); + 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,6 +189,8 @@ var proto = { _unmount: _unmount }; +/* generated by Svelte v1.39.3 */ + 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 +328,7 @@ function create_main_fragment(state, component) { }; } +// (2:1) {{#if a}} function create_if_block(state, component) { var p, text; @@ -334,6 +351,7 @@ function create_if_block(state, component) { }; } +// (8:1) {{#if b}} function create_if_block_1(state, component) { var p, text; @@ -356,6 +374,7 @@ function create_if_block_1(state, component) { }; } +// (12:1) {{#if c}} function create_if_block_2(state, component) { var p, text; @@ -378,6 +397,7 @@ function create_if_block_2(state, component) { }; } +// (18:1) {{#if d}} function create_if_block_3(state, component) { var p, text; @@ -400,6 +420,7 @@ function create_if_block_3(state, component) { }; } +// (25:0) {{#if e}} function create_if_block_4(state, component) { var p, text; @@ -423,20 +444,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..6c18931e7a 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,4 +1,6 @@ -import { appendNode, assign, createComment, createElement, createText, detachNode, insertNode, noop, proto } from "svelte/shared.js"; +/* generated by Svelte v1.39.3 */ + +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; @@ -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; @@ -248,20 +255,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) {