From 240291604b67a3f701f31a6fdc83a6ca7226a325 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 18 Sep 2017 10:37:51 -0400 Subject: [PATCH 1/8] refactor module wrapping --- src/generators/Generator.ts | 55 +--- src/generators/shared/utils/getGlobals.ts | 47 ---- src/generators/shared/utils/getIntro.ts | 95 ------- .../shared/utils/getModuleWrapper.ts | 253 ++++++++++++++++++ src/generators/shared/utils/getOutro.ts | 37 --- 5 files changed, 258 insertions(+), 229 deletions(-) delete mode 100644 src/generators/shared/utils/getGlobals.ts delete mode 100644 src/generators/shared/utils/getIntro.ts create mode 100644 src/generators/shared/utils/getModuleWrapper.ts delete mode 100644 src/generators/shared/utils/getOutro.ts diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 91b73b6162..e8d2ce47b0 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -8,8 +8,7 @@ import globalWhitelist from '../utils/globalWhitelist'; import reservedNames from '../utils/reservedNames'; import namespaces from '../utils/namespaces'; import { removeNode, removeObjectKey } from '../utils/removeNode'; -import getIntro from './shared/utils/getIntro'; -import getOutro from './shared/utils/getOutro'; +import getModuleWrapper from './shared/utils/getModuleWrapper'; import annotateWithScopes from '../utils/annotateWithScopes'; import clone from '../utils/clone'; import DomBlock from './dom/Block'; @@ -304,51 +303,6 @@ export default class Generator { } generate(result: string, options: CompileOptions, { name, format }: GenerateOptions ) { - if (this.imports.length) { - const statements: string[] = []; - - this.imports.forEach((declaration, i) => { - if (format === 'es') { - statements.push( - this.source.slice(declaration.start, declaration.end) - ); - return; - } - - const defaultImport = declaration.specifiers.find( - (x: Node) => - x.type === 'ImportDefaultSpecifier' || - (x.type === 'ImportSpecifier' && x.imported.name === 'default') - ); - const namespaceImport = declaration.specifiers.find( - (x: Node) => x.type === 'ImportNamespaceSpecifier' - ); - const namedImports = declaration.specifiers.filter( - (x: Node) => - x.type === 'ImportSpecifier' && x.imported.name !== 'default' - ); - - const name = defaultImport || namespaceImport - ? (defaultImport || namespaceImport).local.name - : `__import${i}`; - declaration.name = name; // hacky but makes life a bit easier later - - namedImports.forEach((specifier: Node) => { - statements.push( - `var ${specifier.local.name} = ${name}.${specifier.imported.name}` - ); - }); - - if (defaultImport) { - statements.push( - `${name} = (${name} && ${name}.__esModule) ? ${name}['default'] : ${name};` - ); - } - }); - - result = `${statements.join('\n')}\n\n${result}`; - } - const pattern = /\[✂(\d+)-(\d+)$/; const parts = result.split('✂]'); @@ -362,8 +316,9 @@ export default class Generator { }); } - const intro = getIntro(format, options, this.imports); - if (intro) addString(intro); + const { intro, outro } = getModuleWrapper(format, name, options, this.imports, this.source); + + addString(intro + '\n\n'); const { filename } = options; @@ -391,7 +346,7 @@ export default class Generator { }); addString(finalChunk); - addString('\n\n' + getOutro(format, name, options, this.imports)); + addString('\n\n' + outro); const { css, cssMap } = this.customElement ? { css: null, cssMap: null } : diff --git a/src/generators/shared/utils/getGlobals.ts b/src/generators/shared/utils/getGlobals.ts deleted file mode 100644 index eb0db21276..0000000000 --- a/src/generators/shared/utils/getGlobals.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { CompileOptions, Node } from '../../../interfaces'; - - -export default function getGlobals(imports: Node[], options: CompileOptions) { - const { globals, onerror, onwarn } = options; - const globalFn = getGlobalFn(globals); - - return imports.map(x => { - let name = globalFn(x.source.value); - - if (!name) { - if (x.name.startsWith('__import')) { - const error = new Error( - `Could not determine name for imported module '${x.source.value}' – use options.globals` - ); - if (onerror) { - onerror(error); - } else { - throw error; - } - } else { - const warning = { - message: `No name was supplied for imported module '${x.source.value}'. Guessing '${x.name}', but you should use options.globals`, - }; - - if (onwarn) { - onwarn(warning); - } else { - console.warn(warning); // eslint-disable-line no-console - } - } - - name = x.name; - } - - return name; - }); -} - -function getGlobalFn(globals: any): (id: string) => string { - if (typeof globals === 'function') return globals; - if (typeof globals === 'object') { - return id => globals[id]; - } - - return () => undefined; -} diff --git a/src/generators/shared/utils/getIntro.ts b/src/generators/shared/utils/getIntro.ts deleted file mode 100644 index 599bc5f7b3..0000000000 --- a/src/generators/shared/utils/getIntro.ts +++ /dev/null @@ -1,95 +0,0 @@ -import deindent from '../../../utils/deindent'; -import getGlobals from './getGlobals'; -import { CompileOptions, ModuleFormat, Node } from '../../../interfaces'; - -export default function getIntro( - format: ModuleFormat, - options: CompileOptions, - imports: Node[] -) { - if (format === 'es') return ''; - if (format === 'amd') return getAmdIntro(options, imports); - if (format === 'cjs') return getCjsIntro(options, imports); - if (format === 'iife') return getIifeIntro(options, imports); - if (format === 'umd') return getUmdIntro(options, imports); - if (format === 'eval') return getEvalIntro(options, imports); - - throw new Error(`Not implemented: ${format}`); -} - -function getAmdIntro(options: CompileOptions, imports: Node[]) { - const sourceString = imports.length - ? `[${imports - .map(declaration => `'${removeExtension(declaration.source.value)}'`) - .join(', ')}], ` - : ''; - - const id = options.amd && options.amd.id; - - return `define(${id - ? `"${id}", ` - : ''}${sourceString}function(${paramString(imports)}) { 'use strict';\n\n`; -} - -function getCjsIntro(options: CompileOptions, imports: Node[]) { - const requireBlock = imports - .map( - declaration => - `var ${declaration.name} = require('${declaration.source.value}');` - ) - .join('\n\n'); - - if (requireBlock) { - return `'use strict';\n\n${requireBlock}\n\n`; - } - - return `'use strict';\n\n`; -} - -function getIifeIntro(options: CompileOptions, imports: Node[]) { - if (!options.name) { - throw new Error(`Missing required 'name' option for IIFE export`); - } - - return `var ${options.name} = (function(${paramString(imports)}) { 'use strict';\n\n`; -} - -function getUmdIntro(options: CompileOptions, imports: Node[]) { - if (!options.name) { - throw new Error(`Missing required 'name' option for UMD export`); - } - - const amdId = options.amd && options.amd.id ? `'${options.amd.id}', ` : ''; - - const amdDeps = imports.length - ? `[${imports - .map(declaration => `'${removeExtension(declaration.source.value)}'`) - .join(', ')}], ` - : ''; - const cjsDeps = imports - .map(declaration => `require('${declaration.source.value}')`) - .join(', '); - const globalDeps = getGlobals(imports, options); - - return ( - deindent` - (function(global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(${cjsDeps}) : - typeof define === 'function' && define.amd ? define(${amdId}${amdDeps}factory) : - (global.${options.name} = factory(${globalDeps})); - }(this, (function (${paramString(imports)}) { 'use strict';` + '\n\n' - ); -} - -function getEvalIntro(options: CompileOptions, imports: Node[]) { - return `(function (${paramString(imports)}) { 'use strict';\n\n`; -} - -function paramString(imports: Node[]) { - return imports.map(dep => dep.name).join(', '); -} - -function removeExtension(file: string) { - const index = file.lastIndexOf('.'); - return ~index ? file.slice(0, index) : file; -} diff --git a/src/generators/shared/utils/getModuleWrapper.ts b/src/generators/shared/utils/getModuleWrapper.ts new file mode 100644 index 0000000000..ae9166122f --- /dev/null +++ b/src/generators/shared/utils/getModuleWrapper.ts @@ -0,0 +1,253 @@ +import deindent from '../../../utils/deindent'; +import { CompileOptions, ModuleFormat, Node } from '../../../interfaces'; + +interface Dependency { + name: string; + statements: string[]; + source: string; +} + +export default function getModuleWrapper( + format: ModuleFormat, + name: string, + options: CompileOptions, + imports: Node[], + source: string +) { + if (format === 'es') return getEsWrapper(name, options, imports, source); + + const dependencies = imports.map((declaration, i) => { + const defaultImport = declaration.specifiers.find( + (x: Node) => + x.type === 'ImportDefaultSpecifier' || + (x.type === 'ImportSpecifier' && x.imported.name === 'default') + ); + + const namespaceImport = declaration.specifiers.find( + (x: Node) => x.type === 'ImportNamespaceSpecifier' + ); + + const namedImports = declaration.specifiers.filter( + (x: Node) => + x.type === 'ImportSpecifier' && x.imported.name !== 'default' + ); + + const name = defaultImport || namespaceImport + ? (defaultImport || namespaceImport).local.name + : `__import${i}`; + + const statements: string[] = []; + + namedImports.forEach((specifier: Node) => { + statements.push( + `var ${specifier.local.name} = ${name}.${specifier.imported.name};` + ); + }); + + if (defaultImport) { + statements.push( + `${name} = (${name} && ${name}.__esModule) ? ${name}["default"] : ${name};` + ); + } + + return { name, statements, source: declaration.source.value }; + }); + + if (format === 'amd') return getAmdWrapper(name, options, dependencies); + if (format === 'cjs') return getCjsWrapper(name, options, dependencies); + if (format === 'iife') return getIifeWrapper(name, options, dependencies); + if (format === 'umd') return getUmdWrapper(name, options, dependencies); + if (format === 'eval') return getEvalWrapper(name, options, dependencies); + + throw new Error(`Not implemented: ${format}`); +} + +function getEsWrapper(name: string, options: CompileOptions, imports: Node[], source: string) { + const importBlock = imports + .map((declaration: Node) => source.slice(declaration.start, declaration.end)) + .join('\n'); + + return { + intro: importBlock ? importBlock + '\n\n' : '', + outro: `export default ${name};` + }; +} + +function getAmdWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { + const sourceString = dependencies.length + ? `[${dependencies.map(d => `"${removeExtension(d.source)}"`).join(', ')}], ` + : ''; + + const id = options.amd && options.amd.id; + + return { + intro: deindent` + define(${id ? `"${id}", ` : ''}${sourceString}function(${paramString(dependencies)}) { "use strict"; + + ${getCompatibilityStatements(dependencies)} + + `, + outro: deindent` + return ${name}; + });` + }; +} + +function getCjsWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { + const requireBlock = dependencies + .map(d => `var ${d.name} = require("${d.source}");`) + .join('\n\n'); + + const intro = requireBlock ? + deindent` + "use strict"; + + ${requireBlock} + ${getCompatibilityStatements(dependencies)} + + ` : + deindent` + "use strict"; + + `; + + const outro = `module.exports = ${name};` + + return { intro, outro }; +} + +function getIifeWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { + if (!options.name) { + throw new Error(`Missing required 'name' option for IIFE export`); + } + + const globals = getGlobals(dependencies, options); + + return { + intro: deindent` + var ${options.name} = (function(${paramString(dependencies)}) { "use strict"; + + ${getCompatibilityStatements(dependencies)} + + `, + + outro: `return ${name};\n\n}(${globals.join(', ')}));` + }; +} + +function getUmdWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { + if (!options.name) { + throw new Error(`Missing required 'name' option for UMD export`); + } + + const amdId = options.amd && options.amd.id ? `'${options.amd.id}', ` : ''; + + const amdDeps = dependencies.length + ? `[${dependencies.map(d => `"${removeExtension(d.source)}"`).join(', ')}], ` + : ''; + + const cjsDeps = dependencies + .map(d => `require("${d.source}")`) + .join(', '); + + const globals = getGlobals(dependencies, options); + + return { + intro: deindent` + (function(global, factory) { + typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(${cjsDeps}) : + typeof define === "function" && define.amd ? define(${amdId}${amdDeps}factory) : + (global.${options.name} = factory(${globals})); + }(this, (function (${paramString(dependencies)}) { "use strict"; + + ${getCompatibilityStatements(dependencies)} + + `, + + outro: deindent` + return ${name}; + + })));` + }; +} + +function getEvalWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { + const globals = getGlobals(dependencies, options); + + return { + intro: deindent` + (function (${paramString(dependencies)}) { "use strict"; + + ${getCompatibilityStatements(dependencies)} + + `, + + outro: `return ${name};\n\n}(${globals.join(', ')}));` + }; +} + +function paramString(dependencies: Dependency[]) { + return dependencies.map(dep => dep.name).join(', '); +} + +function removeExtension(file: string) { + const index = file.lastIndexOf('.'); + return ~index ? file.slice(0, index) : file; +} + +function getCompatibilityStatements(dependencies: Dependency[]) { + if (!dependencies.length) return null; + + const statements: string[] = []; + + dependencies.forEach(dependency => { + statements.push(...dependency.statements); + }); + + return statements.join('\n'); +} + +function getGlobals(dependencies: Dependency[], options: CompileOptions) { + const { globals, onerror, onwarn } = options; + const globalFn = getGlobalFn(globals); + + return dependencies.map(d => { + let name = globalFn(d.source); + + if (!name) { + if (d.name.startsWith('__import')) { + const error = new Error( + `Could not determine name for imported module '${d.source}' – use options.globals` + ); + if (onerror) { + onerror(error); + } else { + throw error; + } + } else { + const warning = { + message: `No name was supplied for imported module '${d.source}'. Guessing '${d.name}', but you should use options.globals`, + }; + + if (onwarn) { + onwarn(warning); + } else { + console.warn(warning); // eslint-disable-line no-console + } + } + + name = d.name; + } + + return name; + }); +} + +function getGlobalFn(globals: any): (id: string) => string { + if (typeof globals === 'function') return globals; + if (typeof globals === 'object') { + return id => globals[id]; + } + + return () => undefined; +} \ No newline at end of file diff --git a/src/generators/shared/utils/getOutro.ts b/src/generators/shared/utils/getOutro.ts deleted file mode 100644 index 682a3cc870..0000000000 --- a/src/generators/shared/utils/getOutro.ts +++ /dev/null @@ -1,37 +0,0 @@ -import getGlobals from './getGlobals'; -import { CompileOptions, Node } from '../../../interfaces'; - -export default function getOutro( - format: string, - name: string, - options: CompileOptions, - imports: Node[] -) { - if (format === 'es') { - return `export default ${name};`; - } - - if (format === 'amd') { - return `return ${name};\n\n});`; - } - - if (format === 'cjs') { - return `module.exports = ${name};`; - } - - if (format === 'iife') { - const globals = getGlobals(imports, options); - return `return ${name};\n\n}(${globals.join(', ')}));`; - } - - if (format === 'eval') { - const globals = getGlobals(imports, options); - return `return ${name};\n\n}(${globals.join(', ')}));`; - } - - if (format === 'umd') { - return `return ${name};\n\n})));`; - } - - throw new Error(`Not implemented: ${format}`); -} From abea37af7156c89aba6b434c6764acff10e7b1e3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 18 Sep 2017 11:12:10 -0400 Subject: [PATCH 2/8] wrap ES modules in an IIFE --- src/generators/Generator.ts | 4 ++-- src/generators/dom/index.ts | 15 +++++++-------- src/generators/shared/utils/getModuleWrapper.ts | 10 ++++++++-- src/interfaces.ts | 1 + test/runtime/index.js | 7 ++++--- 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index e8d2ce47b0..aadd5a10f1 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -302,7 +302,7 @@ export default class Generator { return (expression._dependencies = dependencies); } - generate(result: string, options: CompileOptions, { name, format }: GenerateOptions ) { + generate(result: string, options: CompileOptions, { banner = '', name, format }: GenerateOptions ) { const pattern = /\[✂(\d+)-(\d+)$/; const parts = result.split('✂]'); @@ -318,7 +318,7 @@ export default class Generator { const { intro, outro } = getModuleWrapper(format, name, options, this.imports, this.source); - addString(intro + '\n\n'); + addString(banner + intro + '\n\n'); const { filename } = options; diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 3aa44d8f93..4455321b61 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -326,6 +326,8 @@ export default function dom( return generator.alias(name); }); + let banner = `/* ${options.filename ? `${options.filename} ` : ``}generated by Svelte v${version} */\n`; + if (sharedPath) { const used = Array.from(usedHelpers).sort(); if (format === 'es') { @@ -334,9 +336,7 @@ export default function dom( return name !== alias ? `${name} as ${alias}` : name; }); - result = - `import { ${names.join(', ')} } from ${JSON.stringify(sharedPath)};\n\n` + - result; + banner += `import { ${names.join(', ')} } from ${JSON.stringify(sharedPath)};\n\n`; } else if (format === 'cjs') { @@ -347,7 +347,7 @@ export default function dom( requires += `\nvar ${alias} = ${SHARED}.${name};`; }); - result = `${requires}\n\n${result}`; + banner += requires + '\n\n'; } else { @@ -391,20 +391,19 @@ export default function dom( // special case const global = `_svelteTransitionManager`; - result += `\n\nvar ${generator.alias('transitionManager')} = window.${global} || (window.${global} = ${code});`; + banner += `\n\nvar ${generator.alias('transitionManager')} = window.${global} || (window.${global} = ${code});`; } else { const alias = generator.alias(expression.id.name); if (alias !== expression.id.name) code.overwrite(expression.id.start, expression.id.end, alias); - result += `\n\n${code}`; + banner += `\n\n${code}`; } }); } - result = `/* ${options.filename ? `${options.filename} ` : ``}generated by Svelte v${version} */\n\n${result}`; - return generator.generate(result, options, { + banner, name, format, }); diff --git a/src/generators/shared/utils/getModuleWrapper.ts b/src/generators/shared/utils/getModuleWrapper.ts index ae9166122f..c535990f9f 100644 --- a/src/generators/shared/utils/getModuleWrapper.ts +++ b/src/generators/shared/utils/getModuleWrapper.ts @@ -68,8 +68,14 @@ function getEsWrapper(name: string, options: CompileOptions, imports: Node[], so .join('\n'); return { - intro: importBlock ? importBlock + '\n\n' : '', - outro: `export default ${name};` + intro: deindent` + ${importBlock} + + export default (function() { + `, + outro: deindent` + return ${name}; + }());` }; } diff --git a/src/interfaces.ts b/src/interfaces.ts index 93d1b608f2..97c7879ab6 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -64,6 +64,7 @@ export interface CompileOptions { export interface GenerateOptions { name: string; format: ModuleFormat; + banner?: string; } export interface Visitor { diff --git a/test/runtime/index.js b/test/runtime/index.js index 95950b6668..0d4fbfd81c 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -73,11 +73,12 @@ describe("runtime", () => { ); const { code } = svelte.compile(source, compileOptions); const startIndex = code.indexOf("function create_main_fragment"); // may change! - if (startIndex === -1) - throw new Error("missing create_main_fragment"); + if (startIndex === -1) throw new Error("missing create_main_fragment"); + const endIndex = code.lastIndexOf("return"); const es5 = code.slice(0, startIndex).split('\n').map(x => spaces(x.length)).join('\n') + - code.slice(startIndex).replace(/export default .+/, ""); + code.slice(startIndex, endIndex); + acorn.parse(es5, { ecmaVersion: 5 }); if (/Object\.assign/.test(es5)) { From 5cd76be290736a2ba0f7385ce5ba73b2b0e977ca Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 18 Sep 2017 15:12:40 -0400 Subject: [PATCH 3/8] various fixes --- src/generators/Generator.ts | 6 +- src/generators/dom/index.ts | 46 +++++----- .../shared/utils/getModuleWrapper.ts | 89 ++++++++++++++++--- src/index.ts | 2 +- src/interfaces.ts | 2 + .../expected-bundle.js | 6 +- .../expected.js | 7 +- .../component-static/expected-bundle.js | 6 +- test/js/samples/component-static/expected.js | 7 +- .../computed-collapsed-if/expected-bundle.js | 6 +- .../samples/computed-collapsed-if/expected.js | 7 +- .../css-media-query/expected-bundle.js | 6 +- test/js/samples/css-media-query/expected.js | 7 +- .../expected-bundle.js | 6 +- .../css-shadow-dom-keyframes/expected.js | 7 +- .../expected-bundle.js | 6 +- .../each-block-changed-check/expected.js | 7 +- .../event-handlers-custom/expected-bundle.js | 6 +- .../samples/event-handlers-custom/expected.js | 7 +- .../if-block-no-update/expected-bundle.js | 6 +- .../js/samples/if-block-no-update/expected.js | 7 +- .../if-block-simple/expected-bundle.js | 6 +- test/js/samples/if-block-simple/expected.js | 7 +- .../expected-bundle.js | 6 +- .../expected.js | 7 +- .../expected-bundle.js | 6 +- .../inline-style-optimized-url/expected.js | 7 +- .../inline-style-optimized/expected-bundle.js | 6 +- .../inline-style-optimized/expected.js | 7 +- .../expected-bundle.js | 6 +- .../inline-style-unoptimized/expected.js | 7 +- .../expected-bundle.js | 6 +- .../input-without-blowback-guard/expected.js | 7 +- .../legacy-input-type/expected-bundle.js | 6 +- test/js/samples/legacy-input-type/expected.js | 7 +- .../legacy-quote-class/expected-bundle.js | 6 +- .../js/samples/legacy-quote-class/expected.js | 7 +- .../samples/media-bindings/expected-bundle.js | 6 +- test/js/samples/media-bindings/expected.js | 7 +- .../non-imported-component/expected-bundle.js | 6 +- .../non-imported-component/expected.js | 9 +- .../expected-bundle.js | 6 +- .../onrender-onteardown-rewritten/expected.js | 7 +- .../samples/setup-method/expected-bundle.js | 6 +- test/js/samples/setup-method/expected.js | 7 +- .../expected-bundle.js | 6 +- .../use-elements-as-anchors/expected.js | 7 +- 47 files changed, 311 insertions(+), 109 deletions(-) diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index aadd5a10f1..f1ff050636 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -302,7 +302,7 @@ export default class Generator { return (expression._dependencies = dependencies); } - generate(result: string, options: CompileOptions, { banner = '', name, format }: GenerateOptions ) { + generate(result: string, options: CompileOptions, { banner = '', sharedPath, helpers, name, format }: GenerateOptions ) { const pattern = /\[✂(\d+)-(\d+)$/; const parts = result.split('✂]'); @@ -316,9 +316,9 @@ export default class Generator { }); } - const { intro, outro } = getModuleWrapper(format, name, options, this.imports, this.source); + const { intro, outro } = getModuleWrapper(format, name, options, banner, sharedPath, helpers, this.imports, this.source); - addString(banner + intro + '\n\n'); + addString(intro + '\n\n'); const { filename } = options; diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 4455321b61..03e9b0636d 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -326,34 +326,20 @@ export default function dom( return generator.alias(name); }); - let banner = `/* ${options.filename ? `${options.filename} ` : ``}generated by Svelte v${version} */\n`; + let helpers; if (sharedPath) { - const used = Array.from(usedHelpers).sort(); - if (format === 'es') { - const names = used.map(name => { - const alias = generator.alias(name); - return name !== alias ? `${name} as ${alias}` : name; - }); - - banner += `import { ${names.join(', ')} } from ${JSON.stringify(sharedPath)};\n\n`; - } - - else if (format === 'cjs') { - const SHARED = '__shared'; - let requires = `var ${SHARED} = require(${JSON.stringify(sharedPath)});`; - used.forEach(name => { - const alias = generator.alias(name); - requires += `\nvar ${alias} = ${SHARED}.${name};`; - }); - - banner += requires + '\n\n'; - } - - else { + if (format !== 'es' && format !== 'cjs') { throw new Error(`Components with shared helpers must be compiled with \`format: 'es'\` or \`format: 'cjs'\``); } + const used = Array.from(usedHelpers).sort(); + helpers = used.map(name => { + const alias = generator.alias(name); + return { name, alias }; + }); } else { + let inlineHelpers = ''; + usedHelpers.forEach(key => { const str = shared[key]; const code = new MagicString(str); @@ -391,19 +377,27 @@ export default function dom( // special case const global = `_svelteTransitionManager`; - banner += `\n\nvar ${generator.alias('transitionManager')} = window.${global} || (window.${global} = ${code});`; + inlineHelpers += `var ${generator.alias('transitionManager')} = window.${global} || (window.${global} = ${code});\n\n`; } else { const alias = generator.alias(expression.id.name); if (alias !== expression.id.name) code.overwrite(expression.id.start, expression.id.end, alias); - banner += `\n\n${code}`; + inlineHelpers += `${code}\n\n`; } }); + + result = inlineHelpers + result; } + const filename = options.filename && ( + typeof process !== 'undefined' ? options.filename.replace(process.cwd(), '').replace(/^[\/\\]/, '') : options.filename + ); + return generator.generate(result, options, { - banner, + banner: `/* ${filename ? `${filename} ` : ``}generated by Svelte v${version} */`, + sharedPath, + helpers, name, format, }); diff --git a/src/generators/shared/utils/getModuleWrapper.ts b/src/generators/shared/utils/getModuleWrapper.ts index c535990f9f..6680c4896a 100644 --- a/src/generators/shared/utils/getModuleWrapper.ts +++ b/src/generators/shared/utils/getModuleWrapper.ts @@ -11,10 +11,13 @@ export default function getModuleWrapper( format: ModuleFormat, name: string, options: CompileOptions, + banner: string, + sharedPath: string, + helpers: { name: string, alias: string }[], imports: Node[], source: string ) { - if (format === 'es') return getEsWrapper(name, options, imports, source); + if (format === 'es') return getEsWrapper(name, options, banner, sharedPath, helpers, imports, source); const dependencies = imports.map((declaration, i) => { const defaultImport = declaration.specifiers.find( @@ -53,22 +56,36 @@ export default function getModuleWrapper( return { name, statements, source: declaration.source.value }; }); - if (format === 'amd') return getAmdWrapper(name, options, dependencies); - if (format === 'cjs') return getCjsWrapper(name, options, dependencies); - if (format === 'iife') return getIifeWrapper(name, options, dependencies); - if (format === 'umd') return getUmdWrapper(name, options, dependencies); - if (format === 'eval') return getEvalWrapper(name, options, dependencies); + if (format === 'amd') return getAmdWrapper(name, options, banner, dependencies); + if (format === 'cjs') return getCjsWrapper(name, options, banner, sharedPath, helpers, dependencies); + if (format === 'iife') return getIifeWrapper(name, options, banner, dependencies); + if (format === 'umd') return getUmdWrapper(name, options, banner, dependencies); + if (format === 'eval') return getEvalWrapper(name, options, banner, dependencies); throw new Error(`Not implemented: ${format}`); } -function getEsWrapper(name: string, options: CompileOptions, imports: Node[], source: string) { +function getEsWrapper( + name: string, + options: CompileOptions, + banner: string, + sharedPath: string, + helpers: { name: string, alias: string }[], + imports: Node[], + source: string +) { + const importHelpers = helpers && ( + `import { ${helpers.map(h => h.name === h.alias ? h.name : `${h.name} as ${h.alias}`).join(', ')} } from ${JSON.stringify(sharedPath)};` + ); + const importBlock = imports .map((declaration: Node) => source.slice(declaration.start, declaration.end)) .join('\n'); return { intro: deindent` + ${banner} + ${importHelpers} ${importBlock} export default (function() { @@ -79,7 +96,12 @@ function getEsWrapper(name: string, options: CompileOptions, imports: Node[], so }; } -function getAmdWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { +function getAmdWrapper( + name: string, + options: CompileOptions, + banner: string, + dependencies: Dependency[] +) { const sourceString = dependencies.length ? `[${dependencies.map(d => `"${removeExtension(d.source)}"`).join(', ')}], ` : ''; @@ -99,22 +121,41 @@ function getAmdWrapper(name: string, options: CompileOptions, dependencies: Depe }; } -function getCjsWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { +function getCjsWrapper( + name: string, + options: CompileOptions, + banner: string, + sharedPath: string, + helpers: { name: string, alias: string }[], + dependencies: Dependency[] +) { + const SHARED = '__shared'; + const helperBlock = helpers && ( + `var ${SHARED} = require(${JSON.stringify(sharedPath)});\n` + + helpers.map(helper => { + return `var ${helper.alias} = ${SHARED}.${helper.name};`; + }).join('\n') + ); + const requireBlock = dependencies .map(d => `var ${d.name} = require("${d.source}");`) .join('\n\n'); const intro = requireBlock ? deindent` + ${banner} "use strict"; + ${helperBlock} ${requireBlock} ${getCompatibilityStatements(dependencies)} ` : deindent` + ${banner} "use strict"; + ${helperBlock} `; const outro = `module.exports = ${name};` @@ -122,7 +163,12 @@ function getCjsWrapper(name: string, options: CompileOptions, dependencies: Depe return { intro, outro }; } -function getIifeWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { +function getIifeWrapper( + name: string, + options: CompileOptions, + banner: string, + dependencies: Dependency[] +) { if (!options.name) { throw new Error(`Missing required 'name' option for IIFE export`); } @@ -131,17 +177,25 @@ function getIifeWrapper(name: string, options: CompileOptions, dependencies: Dep return { intro: deindent` + ${banner} var ${options.name} = (function(${paramString(dependencies)}) { "use strict"; ${getCompatibilityStatements(dependencies)} `, - outro: `return ${name};\n\n}(${globals.join(', ')}));` + outro: deindent` + return ${name}; + }(${globals.join(', ')}));` }; } -function getUmdWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { +function getUmdWrapper( + name: string, + options: CompileOptions, + banner: string, + dependencies: Dependency[] +) { if (!options.name) { throw new Error(`Missing required 'name' option for UMD export`); } @@ -160,6 +214,7 @@ function getUmdWrapper(name: string, options: CompileOptions, dependencies: Depe return { intro: deindent` + ${banner} (function(global, factory) { typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(${cjsDeps}) : typeof define === "function" && define.amd ? define(${amdId}${amdDeps}factory) : @@ -177,18 +232,24 @@ function getUmdWrapper(name: string, options: CompileOptions, dependencies: Depe }; } -function getEvalWrapper(name: string, options: CompileOptions, dependencies: Dependency[]) { +function getEvalWrapper( + name: string, + options: CompileOptions, + banner: string, + dependencies: Dependency[] +) { const globals = getGlobals(dependencies, options); return { intro: deindent` (function (${paramString(dependencies)}) { "use strict"; + ${banner} ${getCompatibilityStatements(dependencies)} `, - outro: `return ${name};\n\n}(${globals.join(', ')}));` + outro: `return ${name};\n\n}(${globals.join(', ')}))` }; } diff --git a/src/index.ts b/src/index.ts index f2a2af1483..475cfcaceb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,7 +61,7 @@ export function create(source: string, _options: CompileOptions = {}) { } try { - return new Function('return ' + compiled.code)(); + return (0,eval)(compiled.code); } catch (err) { if (_options.onerror) { _options.onerror(err); diff --git a/src/interfaces.ts b/src/interfaces.ts index 97c7879ab6..2d876c6a9a 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -65,6 +65,8 @@ export interface GenerateOptions { name: string; format: ModuleFormat; banner?: string; + sharedPath?: string | boolean; + helpers?: { name: string, alias: string }[]; } export interface Visitor { 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 f144e884aa..29327e012f 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -190,6 +190,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { var template = (function() { return { @@ -259,4 +260,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 9e85f05595..2fba8e5f10 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; + +export default (function() { + var template = (function() { return { data: function () { @@ -70,4 +72,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 2dbef4a1b1..4f1bed2001 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -166,6 +166,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { var template = (function() { return { @@ -229,4 +230,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index e6f5d12eb7..ce6cbb836b 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, callAll, init, noop, proto } from "svelte/shared.js"; + +export default (function() { + var template = (function() { return { components: { @@ -64,4 +66,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 752455d407..71142f31d0 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -166,6 +166,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { var template = (function() { return { @@ -213,4 +214,7 @@ SvelteComponent.prototype._recompute = function _recompute(changed, state) { } }; -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 097e5557c8..9f99533706 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, differs, init, noop, proto } from "svelte/shared.js"; + +export default (function() { + var template = (function() { return { computed: { @@ -48,4 +50,5 @@ SvelteComponent.prototype._recompute = function _recompute(changed, state) { } } -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 8cc7e465d1..ca250398fa 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -186,6 +186,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); @@ -241,4 +242,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 11d1550542..a47c053601 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; + +export default (function() { + function encapsulateStyles(node) { setAttribute(node, "svelte-2363328337", ""); } @@ -56,4 +58,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file 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 4761ffe62c..a060d65078 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -186,6 +186,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var div, text; @@ -248,4 +249,7 @@ assign(SvelteComponent.prototype, proto, { } }); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 4268c29877..2a34370c23 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var div, text; @@ -63,4 +65,5 @@ assign(SvelteComponent.prototype, proto, { } }); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file 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 5f73756b77..fcaf7c56d9 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -199,6 +199,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var text, p, text_1; @@ -352,4 +353,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index d69a80fcaf..156f9462c7 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var text, p, text_1; @@ -154,4 +156,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index f779357293..72d54f01e8 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -186,6 +186,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { var template = (function() { return { @@ -250,4 +251,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, template.methods, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index eb6069e1d4..595138f596 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +export default (function() { + var template = (function() { return { methods: { @@ -65,4 +67,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, template.methods, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file 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 d68a947cdb..e9ef3903eb 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -190,6 +190,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var if_block_anchor; @@ -294,4 +295,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 38600d30d4..5cf14db148 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var if_block_anchor; @@ -105,4 +107,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 45ddba0cff..5674aaf3a0 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -190,6 +190,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var if_block_anchor; @@ -269,4 +270,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 81a5ffc975..09bab7ebdf 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var if_block_anchor; @@ -80,4 +82,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file 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 15972de8db..a4d325206e 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -182,6 +182,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var div; @@ -233,4 +234,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index e246b76808..f4129ebb38 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var div; @@ -52,4 +54,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file 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 b9fffb2f15..c0a9695ffe 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -182,6 +182,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var div; @@ -228,4 +229,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index e979cefc37..32061f4d60 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var div; @@ -47,4 +49,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 385aaa0c30..9e2e87fefa 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -182,6 +182,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var div; @@ -228,4 +229,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index 52542ce3ba..b5d35f85f5 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var div; @@ -47,4 +49,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index f031e6c0e2..032ad03c66 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -182,6 +182,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; @@ -239,4 +240,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 081c497f9e..b45ff132d2 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var div, text, div_1, div_1_style_value; @@ -58,4 +60,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file 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 99ce19c0bf..f6e03fb001 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -186,6 +186,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var input; @@ -239,4 +240,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index e5f2d4ff21..66285864ab 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var input; @@ -54,4 +56,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 35a5253a26..80875dada3 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -184,6 +184,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var input; @@ -226,4 +227,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index ccd0bc4a5f..419a68fc55 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var input; @@ -43,4 +45,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index a3edb24252..a0c302b929 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -201,6 +201,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var div; @@ -253,4 +254,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index 984e7e7c6d..05d8d6473d 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var div; @@ -53,4 +55,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 08e8a09d7c..db93324113 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -194,6 +194,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; @@ -322,4 +323,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index 05ab3147c3..527213251c 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { addListener, assign, callAll, createElement, detachNode, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; + +export default (function() { + function create_main_fragment(state, component) { var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; @@ -129,4 +131,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 817ab2c4f8..d60db003bf 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -180,6 +180,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { var template = (function() { return { @@ -254,4 +255,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index b2f77857c4..8d8759c059 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'; - /* generated by Svelte vX.Y.Z */ - import { assign, callAll, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import Imported from 'Imported.html'; + +export default (function() { var template = (function() { return { @@ -77,4 +77,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 2bec66e3e1..058818d6d5 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -166,6 +166,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { var template = (function() { return { @@ -216,4 +217,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index 6eb6b55a1e..fb02f55421 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, callAll, init, noop, proto } from "svelte/shared.js"; + +export default (function() { + var template = (function() { return { // this test should be removed in v2 @@ -51,4 +53,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 0752ea7839..1786cee000 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -166,6 +166,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { var template = (function() { return { @@ -217,4 +218,7 @@ assign(SvelteComponent.prototype, template.methods, proto); template.setup(SvelteComponent); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index dcf0b20e8d..009b432695 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { assign, init, noop, proto } from "svelte/shared.js"; + +export default (function() { + var template = (function() { return { methods: { @@ -52,4 +54,5 @@ assign(SvelteComponent.prototype, template.methods, proto); template.setup(SvelteComponent); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file 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 5a9b918376..b3fabc750c 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -190,6 +190,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ +var _actual = (function() { 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; @@ -457,4 +458,7 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; +return SvelteComponent; +}()); + +export default _actual; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 01d21caa1e..4565988e2d 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,7 +1,9 @@ /* generated by Svelte vX.Y.Z */ - import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; + +export default (function() { + 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; @@ -268,4 +270,5 @@ function SvelteComponent(options) { assign(SvelteComponent.prototype, proto); -export default SvelteComponent; \ No newline at end of file +return SvelteComponent; +}()); \ No newline at end of file From 7cc192ad4c412ba25c8c9d015965c220ee33c2ac Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 18 Sep 2017 15:33:33 -0400 Subject: [PATCH 4/8] fix test --- test/sourcemaps/samples/each-block/test.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/sourcemaps/samples/each-block/test.js b/test/sourcemaps/samples/each-block/test.js index add51d628b..d31c565ced 100644 --- a/test/sourcemaps/samples/each-block/test.js +++ b/test/sourcemaps/samples/each-block/test.js @@ -1,7 +1,8 @@ -export function test ({ assert, smc, locateInSource, locateInGenerated }) { - const expected = locateInSource( 'each' ); +export function test({ assert, code, smc, locateInSource, locateInGenerated }) { + const startIndex = code.indexOf('create_main_fragment'); - const loc = locateInGenerated( 'length' ); + const expected = locateInSource('each'); + const loc = locateInGenerated('length', startIndex ); const actual = smc.originalPositionFor({ line: loc.line + 1, From 66ae0d9c9429cc74be1c71f4bf220dfabcf7c499 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 18 Sep 2017 17:24:31 -0400 Subject: [PATCH 5/8] use textContent and innerHTML where appropriate (#23) --- src/generators/dom/preprocess.ts | 54 ++++++++++++++----- .../dom/visitors/Element/Element.ts | 51 ++++++++++++++++-- .../expected-bundle.js | 13 +---- .../css-shadow-dom-keyframes/expected.js | 7 ++- .../event-handlers-custom/expected-bundle.js | 13 +---- .../samples/event-handlers-custom/expected.js | 7 ++- .../if-block-no-update/expected-bundle.js | 18 ++----- .../js/samples/if-block-no-update/expected.js | 12 ++--- .../if-block-simple/expected-bundle.js | 13 +---- test/js/samples/if-block-simple/expected.js | 7 ++- .../expected-bundle.js | 33 +++++------- .../use-elements-as-anchors/expected.js | 33 +++++------- 12 files changed, 138 insertions(+), 123 deletions(-) diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index b993dcb43f..ff0c05e744 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -41,6 +41,13 @@ function createDebuggingComment(node: Node, generator: DomGenerator) { return `${loc} ${source.slice(c, d)}`.replace(/\n/g, ' '); } +function cannotUseInnerHTML(node: Node) { + while (node && node.canUseInnerHTML) { + node.canUseInnerHTML = false; + node = node.parent; + } +} + // 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) @@ -65,6 +72,7 @@ const preprocessors = { componentStack: Node[], stripWhitespace: boolean ) => { + cannotUseInnerHTML(node); node.var = block.getUniqueName('text'); const dependencies = block.findDependencies(node.expression); @@ -80,6 +88,7 @@ const preprocessors = { componentStack: Node[], stripWhitespace: boolean ) => { + cannotUseInnerHTML(node); node.var = block.getUniqueName('raw'); const dependencies = block.findDependencies(node.expression); @@ -114,6 +123,8 @@ const preprocessors = { stripWhitespace: boolean, nextSibling: Node ) => { + cannotUseInnerHTML(node); + const blocks: Block[] = []; let dynamic = false; let hasIntros = false; @@ -195,6 +206,7 @@ const preprocessors = { stripWhitespace: boolean, nextSibling: Node ) => { + cannotUseInnerHTML(node); node.var = block.getUniqueName(`each_block`); const dependencies = block.findDependencies(node.expression); @@ -286,10 +298,16 @@ const preprocessors = { stripWhitespace: boolean, nextSibling: Node ) => { + if (node.name === 'slot') { + cannotUseInnerHTML(node); + } + node.attributes.forEach((attribute: Node) => { if (attribute.type === 'Attribute' && attribute.value !== true) { attribute.value.forEach((chunk: Node) => { if (chunk.type !== 'Text') { + if (node.parent) cannotUseInnerHTML(node.parent); + const dependencies = block.findDependencies(chunk.expression); block.addDependencies(dependencies); @@ -307,20 +325,24 @@ const preprocessors = { } } }); - } else if (attribute.type === 'EventHandler' && attribute.expression) { - attribute.expression.arguments.forEach((arg: Node) => { - const dependencies = block.findDependencies(arg); + } else { + if (node.parent) cannotUseInnerHTML(node.parent); + + if (attribute.type === 'EventHandler' && attribute.expression) { + attribute.expression.arguments.forEach((arg: Node) => { + const dependencies = block.findDependencies(arg); + block.addDependencies(dependencies); + }); + } else if (attribute.type === 'Binding') { + const dependencies = block.findDependencies(attribute.value); block.addDependencies(dependencies); - }); - } else if (attribute.type === 'Binding') { - const dependencies = block.findDependencies(attribute.value); - block.addDependencies(dependencies); - } else if (attribute.type === 'Transition') { - if (attribute.intro) - generator.hasIntroTransitions = block.hasIntroMethod = true; - if (attribute.outro) { - generator.hasOutroTransitions = block.hasOutroMethod = true; - block.outros += 1; + } else if (attribute.type === 'Transition') { + if (attribute.intro) + generator.hasIntroTransitions = block.hasIntroMethod = true; + if (attribute.outro) { + generator.hasOutroTransitions = block.hasOutroMethod = true; + block.outros += 1; + } } } }); @@ -336,6 +358,8 @@ const preprocessors = { // so that if `foo.qux` changes, we know that we need to // mark `bar` and `baz` as dirty too if (node.name === 'select') { + cannotUseInnerHTML(node); + const value = node.attributes.find( (attribute: Node) => attribute.name === 'value' ); @@ -355,6 +379,8 @@ const preprocessors = { generator.components.has(node.name) || node.name === ':Self'; if (isComponent) { + cannotUseInnerHTML(node); + node.var = block.getUniqueName( (node.name === ':Self' ? generator.name : node.name).toLowerCase() ); @@ -365,6 +391,7 @@ const preprocessors = { } else { const slot = getStaticAttributeValue(node, 'slot'); if (slot && isChildOfComponent(node, generator)) { + cannotUseInnerHTML(node); node.slotted = true; // TODO validate slots — no nesting, no dynamic names... const component = componentStack[componentStack.length - 1]; @@ -438,6 +465,7 @@ function preprocessChildren( cleaned.forEach((child: Node, i: number) => { child.parent = node; + child.canUseInnerHTML = !generator.hydratable; const preprocessor = preprocessors[child.type]; if (preprocessor) preprocessor(generator, block, state, child, inEachBlock, elementStack, componentStack, stripWhitespace, cleaned[i + 1] || nextSibling); diff --git a/src/generators/dom/visitors/Element/Element.ts b/src/generators/dom/visitors/Element/Element.ts index 70e8ff280e..8b42d40a18 100644 --- a/src/generators/dom/visitors/Element/Element.ts +++ b/src/generators/dom/visitors/Element/Element.ts @@ -9,6 +9,7 @@ import visitBinding from './Binding'; import visitRef from './Ref'; import * as namespaces from '../../../../utils/namespaces'; import getStaticAttributeValue from '../../../../utils/getStaticAttributeValue'; +import isVoidElementName from '../../../../utils/isVoidElementName'; import addTransitions from './addTransitions'; import { DomGenerator } from '../../index'; import Block from '../../Block'; @@ -94,7 +95,6 @@ export default function visitElement( } // add CSS encapsulation attribute - // TODO add a helper for this, rather than repeating it if (node._needsCssAttribute && !generator.customElement) { generator.needsEncapsulateHelper = true; block.builders.hydrate.addLine( @@ -202,9 +202,21 @@ export default function visitElement( node.initialUpdate = node.lateUpdate = statement; } - node.children.forEach((child: Node) => { - visit(generator, block, childState, child, elementStack.concat(node), componentStack); - }); + if (!childState.namespace && node.canUseInnerHTML && node.children.length > 0) { + if (node.children.length === 1 && node.children[0].type === 'Text') { + block.builders.create.addLine( + `${name}.textContent = ${JSON.stringify(node.children[0].data)};` + ); + } else { + block.builders.create.addLine( + `${name}.innerHTML = ${JSON.stringify(node.children.map(toHTML).join(''))};` + ); + } + } else { + node.children.forEach((child: Node) => { + visit(generator, block, childState, child, elementStack.concat(node), componentStack); + }); + } if (node.lateUpdate) { block.builders.update.addLine(node.lateUpdate); @@ -221,6 +233,29 @@ export default function visitElement( block.builders.claim.addLine( `${childState.parentNodes}.forEach(@detachNode);` ); + + function toHTML(node: Node) { + if (node.type === 'Text') return node.data; + + let open = `<${node.name}`; + + if (node._needsCssAttribute) { + open += ` ${generator.stylesheet.id}`; + } + + if (node._cssRefAttribute) { + open += ` svelte-ref-${node._cssRefAttribute}`; + } + + node.attributes.forEach((attr: Node) => { + open += ` ${attr.name}${stringifyAttributeValue(attr.value)}` + }); + + if (isVoidElementName(node.name)) return open + '>'; + if (node.children.length === 0) return open + '/>'; + + return `${open}>${node.children.map(toHTML).join('')}`; + } } function getRenderStatement( @@ -263,3 +298,11 @@ function quoteProp(name: string, legacy: boolean) { if (/[^a-zA-Z_$0-9]/.test(name) || isLegacyPropName) return `"${name}"`; return name; } + +function stringifyAttributeValue(value: Node | true) { + if (value === true) return ''; + if (value.length === 0) return `=""`; + + const data = value[0].data; + return `=${JSON.stringify(data)}`; +} \ No newline at end of file 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 4761ffe62c..0ef287405a 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -13,10 +13,6 @@ function assign(target) { return target; } -function appendNode(node, target) { - target.appendChild(node); -} - function insertNode(node, target, anchor) { target.insertBefore(node, anchor); } @@ -29,10 +25,6 @@ function createElement(name) { return document.createElement(name); } -function createText(data) { - return document.createTextNode(data); -} - function blankObject() { return Object.create(null); } @@ -188,17 +180,16 @@ var proto = { /* generated by Svelte vX.Y.Z */ function create_main_fragment(state, component) { - var div, text; + var div; return { create: function() { div = createElement("div"); - text = createText("fades in"); + div.textContent = "fades in"; }, mount: function(target, anchor) { insertNode(div, target, anchor); - appendNode(text, div); }, update: noop, diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 4268c29877..87d308ea06 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,19 +1,18 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { - var div, text; + var div; return { create: function() { div = createElement("div"); - text = createText("fades in"); + div.textContent = "fades in"; }, mount: function(target, anchor) { insertNode(div, target, anchor); - appendNode(text, div); }, update: noop, diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index f779357293..220eef8b0d 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -13,10 +13,6 @@ function assign(target) { return target; } -function appendNode(node, target) { - target.appendChild(node); -} - function insertNode(node, target, anchor) { target.insertBefore(node, anchor); } @@ -29,10 +25,6 @@ function createElement(name) { return document.createElement(name); } -function createText(data) { - return document.createTextNode(data); -} - function blankObject() { return Object.create(null); } @@ -203,12 +195,12 @@ var template = (function() { }()); function create_main_fragment(state, component) { - var button, foo_handler, text; + var button, foo_handler; return { create: function() { button = createElement("button"); - text = createText("foo"); + button.textContent = "foo"; this.hydrate(); }, @@ -221,7 +213,6 @@ function create_main_fragment(state, component) { mount: function(target, anchor) { insertNode(button, target, anchor); - appendNode(text, button); }, update: noop, diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index eb6069e1d4..acc58021cf 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,6 +1,6 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; var template = (function() { return { @@ -18,12 +18,12 @@ var template = (function() { }()); function create_main_fragment(state, component) { - var button, foo_handler, text; + var button, foo_handler; return { create: function() { button = createElement("button"); - text = createText("foo"); + button.textContent = "foo"; this.hydrate(); }, @@ -36,7 +36,6 @@ function create_main_fragment(state, component) { mount: function(target, anchor) { insertNode(button, target, anchor); - appendNode(text, button); }, update: noop, 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 d68a947cdb..3c6ccb79cb 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -13,10 +13,6 @@ function assign(target) { return target; } -function appendNode(node, target) { - target.appendChild(node); -} - function insertNode(node, target, anchor) { target.insertBefore(node, anchor); } @@ -29,10 +25,6 @@ function createElement(name) { return document.createElement(name); } -function createText(data) { - return document.createTextNode(data); -} - function createComment() { return document.createComment(''); } @@ -231,17 +223,16 @@ function create_main_fragment(state, component) { // (1:0) {{#if foo}} function create_if_block(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("foo!"); + p.textContent = "foo!"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -254,17 +245,16 @@ function create_if_block(state, component) { // (3:0) {{else}} function create_if_block_1(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("not foo!"); + p.textContent = "not foo!"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 38600d30d4..272ca56261 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 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -42,17 +42,16 @@ function create_main_fragment(state, component) { // (1:0) {{#if foo}} function create_if_block(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("foo!"); + p.textContent = "foo!"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -65,17 +64,16 @@ function create_if_block(state, component) { // (3:0) {{else}} function create_if_block_1(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("not foo!"); + p.textContent = "not foo!"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 45ddba0cff..2aa8fa23d7 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -13,10 +13,6 @@ function assign(target) { return target; } -function appendNode(node, target) { - target.appendChild(node); -} - function insertNode(node, target, anchor) { target.insertBefore(node, anchor); } @@ -29,10 +25,6 @@ function createElement(name) { return document.createElement(name); } -function createText(data) { - return document.createTextNode(data); -} - function createComment() { return document.createComment(''); } @@ -234,17 +226,16 @@ function create_main_fragment(state, component) { // (1:0) {{#if foo}} function create_if_block(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("foo!"); + p.textContent = "foo!"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 81a5ffc975..136cac62a1 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,6 +1,6 @@ /* generated by Svelte vX.Y.Z */ -import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; +import { assign, createComment, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; function create_main_fragment(state, component) { var if_block_anchor; @@ -45,17 +45,16 @@ function create_main_fragment(state, component) { // (1:0) {{#if foo}} function create_if_block(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("foo!"); + p.textContent = "foo!"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { 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 5a9b918376..5b346ab81f 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -192,7 +192,7 @@ var proto = { /* generated by Svelte vX.Y.Z */ 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; + var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor; var if_block = (state.a) && create_if_block(state, component); @@ -210,14 +210,14 @@ function create_main_fragment(state, component) { if (if_block) if_block.create(); text = createText("\n\n\t"); p = createElement("p"); - text_1 = createText("this can be used as an anchor"); + p.textContent = "this can be used as an anchor"; text_2 = createText("\n\n\t"); if (if_block_1) if_block_1.create(); text_3 = createText("\n\n\t"); if (if_block_2) if_block_2.create(); text_4 = createText("\n\n\t"); p_1 = createElement("p"); - text_5 = createText("so can this"); + p_1.textContent = "so can this"; text_6 = createText("\n\n\t"); if (if_block_3) if_block_3.create(); text_8 = createText("\n\n"); @@ -230,14 +230,12 @@ function create_main_fragment(state, component) { if (if_block) if_block.mount(div, null); appendNode(text, div); appendNode(p, div); - appendNode(text_1, p); appendNode(text_2, div); if (if_block_1) if_block_1.mount(div, null); appendNode(text_3, div); if (if_block_2) if_block_2.mount(div, null); appendNode(text_4, div); appendNode(p_1, div); - appendNode(text_5, p_1); appendNode(text_6, div); if (if_block_3) if_block_3.mount(div, null); insertNode(text_8, target, anchor); @@ -330,17 +328,16 @@ function create_main_fragment(state, component) { // (2:1) {{#if a}} function create_if_block(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("a"); + p.textContent = "a"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -353,17 +350,16 @@ function create_if_block(state, component) { // (8:1) {{#if b}} function create_if_block_1(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("b"); + p.textContent = "b"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -376,17 +372,16 @@ function create_if_block_1(state, component) { // (12:1) {{#if c}} function create_if_block_2(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("c"); + p.textContent = "c"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -399,17 +394,16 @@ function create_if_block_2(state, component) { // (18:1) {{#if d}} function create_if_block_3(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("d"); + p.textContent = "d"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -422,17 +416,16 @@ function create_if_block_3(state, component) { // (25:0) {{#if e}} function create_if_block_4(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("e"); + p.textContent = "e"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 01d21caa1e..6acbe936b2 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -3,7 +3,7 @@ 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; + var div, text, p, text_2, text_3, text_4, p_1, text_6, text_8, if_block_4_anchor; var if_block = (state.a) && create_if_block(state, component); @@ -21,14 +21,14 @@ function create_main_fragment(state, component) { if (if_block) if_block.create(); text = createText("\n\n\t"); p = createElement("p"); - text_1 = createText("this can be used as an anchor"); + p.textContent = "this can be used as an anchor"; text_2 = createText("\n\n\t"); if (if_block_1) if_block_1.create(); text_3 = createText("\n\n\t"); if (if_block_2) if_block_2.create(); text_4 = createText("\n\n\t"); p_1 = createElement("p"); - text_5 = createText("so can this"); + p_1.textContent = "so can this"; text_6 = createText("\n\n\t"); if (if_block_3) if_block_3.create(); text_8 = createText("\n\n"); @@ -41,14 +41,12 @@ function create_main_fragment(state, component) { if (if_block) if_block.mount(div, null); appendNode(text, div); appendNode(p, div); - appendNode(text_1, p); appendNode(text_2, div); if (if_block_1) if_block_1.mount(div, null); appendNode(text_3, div); if (if_block_2) if_block_2.mount(div, null); appendNode(text_4, div); appendNode(p_1, div); - appendNode(text_5, p_1); appendNode(text_6, div); if (if_block_3) if_block_3.mount(div, null); insertNode(text_8, target, anchor); @@ -141,17 +139,16 @@ function create_main_fragment(state, component) { // (2:1) {{#if a}} function create_if_block(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("a"); + p.textContent = "a"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -164,17 +161,16 @@ function create_if_block(state, component) { // (8:1) {{#if b}} function create_if_block_1(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("b"); + p.textContent = "b"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -187,17 +183,16 @@ function create_if_block_1(state, component) { // (12:1) {{#if c}} function create_if_block_2(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("c"); + p.textContent = "c"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -210,17 +205,16 @@ function create_if_block_2(state, component) { // (18:1) {{#if d}} function create_if_block_3(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("d"); + p.textContent = "d"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { @@ -233,17 +227,16 @@ function create_if_block_3(state, component) { // (25:0) {{#if e}} function create_if_block_4(state, component) { - var p, text; + var p; return { create: function() { p = createElement("p"); - text = createText("e"); + p.textContent = "e"; }, mount: function(target, anchor) { insertNode(p, target, anchor); - appendNode(text, p); }, unmount: function() { From 1f9fc04d27758d973f5723ad4f02fa68d5e2f0bc Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 18 Sep 2017 21:30:05 -0400 Subject: [PATCH 6/8] simplify module wrapping --- src/generators/Generator.ts | 11 +- src/generators/dom/index.ts | 6 +- .../{getModuleWrapper.ts => wrapModule.ts} | 154 +++--- .../expected-bundle.js | 108 ++-- .../expected.js | 109 ++-- .../component-static/expected-bundle.js | 86 ++- test/js/samples/component-static/expected.js | 87 ++- .../computed-collapsed-if/expected-bundle.js | 56 +- .../samples/computed-collapsed-if/expected.js | 55 +- .../css-media-query/expected-bundle.js | 82 ++- test/js/samples/css-media-query/expected.js | 83 ++- .../expected-bundle.js | 94 ++-- .../css-shadow-dom-keyframes/expected.js | 95 ++-- .../expected-bundle.js | 248 +++++---- .../each-block-changed-check/expected.js | 251 +++++---- .../event-handlers-custom/expected-bundle.js | 78 ++- .../samples/event-handlers-custom/expected.js | 79 ++- .../if-block-no-update/expected-bundle.js | 166 +++--- .../js/samples/if-block-no-update/expected.js | 189 ++++--- .../if-block-simple/expected-bundle.js | 132 +++-- test/js/samples/if-block-simple/expected.js | 133 +++-- .../expected-bundle.js | 78 ++- .../expected.js | 79 ++- .../expected-bundle.js | 70 ++- .../inline-style-optimized-url/expected.js | 71 ++- .../inline-style-optimized/expected-bundle.js | 70 ++- .../inline-style-optimized/expected.js | 71 ++- .../expected-bundle.js | 102 ++-- .../inline-style-unoptimized/expected.js | 103 ++-- .../expected-bundle.js | 80 ++- .../input-without-blowback-guard/expected.js | 81 ++- .../legacy-input-type/expected-bundle.js | 62 ++- test/js/samples/legacy-input-type/expected.js | 63 ++- .../legacy-quote-class/expected-bundle.js | 78 ++- .../js/samples/legacy-quote-class/expected.js | 79 ++- .../samples/media-bindings/expected-bundle.js | 194 ++++--- test/js/samples/media-bindings/expected.js | 195 ++++--- .../non-imported-component/expected-bundle.js | 118 ++-- .../non-imported-component/expected.js | 118 ++-- .../expected-bundle.js | 58 +- .../onrender-onteardown-rewritten/expected.js | 59 +- .../samples/setup-method/expected-bundle.js | 44 +- test/js/samples/setup-method/expected.js | 45 +- .../expected-bundle.js | 454 ++++++++-------- .../use-elements-as-anchors/expected.js | 509 +++++++++--------- 45 files changed, 2532 insertions(+), 2651 deletions(-) rename src/generators/shared/utils/{getModuleWrapper.ts => wrapModule.ts} (68%) diff --git a/src/generators/Generator.ts b/src/generators/Generator.ts index 8ca096166f..d90cfaab38 100644 --- a/src/generators/Generator.ts +++ b/src/generators/Generator.ts @@ -8,7 +8,7 @@ import globalWhitelist from '../utils/globalWhitelist'; import reservedNames from '../utils/reservedNames'; import namespaces from '../utils/namespaces'; import { removeNode, removeObjectKey } from '../utils/removeNode'; -import getModuleWrapper from './shared/utils/getModuleWrapper'; +import wrapModule from './shared/utils/wrapModule'; import annotateWithScopes from '../utils/annotateWithScopes'; import clone from '../utils/clone'; import DomBlock from './dom/Block'; @@ -305,7 +305,9 @@ export default class Generator { generate(result: string, options: CompileOptions, { banner = '', sharedPath, helpers, name, format }: GenerateOptions ) { const pattern = /\[✂(\d+)-(\d+)$/; - const parts = result.split('✂]'); + const module = wrapModule(result, format, name, options, banner, sharedPath, helpers, this.imports, this.source); + + const parts = module.split('✂]'); const finalChunk = parts.pop(); const compiled = new Bundle({ separator: '' }); @@ -316,10 +318,6 @@ export default class Generator { }); } - const { intro, outro } = getModuleWrapper(format, name, options, banner, sharedPath, helpers, this.imports, this.source); - - addString(intro + '\n\n'); - const { filename } = options; // special case — the source file doesn't actually get used anywhere. we need @@ -346,7 +344,6 @@ export default class Generator { }); addString(finalChunk); - addString('\n\n' + outro); const { css, cssMap } = this.customElement ? { css: null, cssMap: null } : diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts index 13afa4b93a..22371c71bc 100644 --- a/src/generators/dom/index.ts +++ b/src/generators/dom/index.ts @@ -407,17 +407,17 @@ export default function dom( // special case const global = `_svelteTransitionManager`; - inlineHelpers += `var ${generator.alias('transitionManager')} = window.${global} || (window.${global} = ${code});\n\n`; + inlineHelpers += `\n\nvar ${generator.alias('transitionManager')} = window.${global} || (window.${global} = ${code});\n\n`; } else { const alias = generator.alias(expression.id.name); if (alias !== expression.id.name) code.overwrite(expression.id.start, expression.id.end, alias); - inlineHelpers += `${code}\n\n`; + inlineHelpers += `\n\n${code}`; } }); - result = inlineHelpers + result; + result += inlineHelpers; } const filename = options.filename && ( diff --git a/src/generators/shared/utils/getModuleWrapper.ts b/src/generators/shared/utils/wrapModule.ts similarity index 68% rename from src/generators/shared/utils/getModuleWrapper.ts rename to src/generators/shared/utils/wrapModule.ts index 6680c4896a..18d295ea25 100644 --- a/src/generators/shared/utils/getModuleWrapper.ts +++ b/src/generators/shared/utils/wrapModule.ts @@ -7,7 +7,10 @@ interface Dependency { source: string; } -export default function getModuleWrapper( +const wrappers = { es, amd, cjs, iife, umd, eval: expr }; + +export default function wrapModule( + code: string, format: ModuleFormat, name: string, options: CompileOptions, @@ -16,8 +19,8 @@ export default function getModuleWrapper( helpers: { name: string, alias: string }[], imports: Node[], source: string -) { - if (format === 'es') return getEsWrapper(name, options, banner, sharedPath, helpers, imports, source); +): string { + if (format === 'es') return es(code, name, options, banner, sharedPath, helpers, imports, source); const dependencies = imports.map((declaration, i) => { const defaultImport = declaration.specifiers.find( @@ -56,16 +59,17 @@ export default function getModuleWrapper( return { name, statements, source: declaration.source.value }; }); - if (format === 'amd') return getAmdWrapper(name, options, banner, dependencies); - if (format === 'cjs') return getCjsWrapper(name, options, banner, sharedPath, helpers, dependencies); - if (format === 'iife') return getIifeWrapper(name, options, banner, dependencies); - if (format === 'umd') return getUmdWrapper(name, options, banner, dependencies); - if (format === 'eval') return getEvalWrapper(name, options, banner, dependencies); + if (format === 'amd') return amd(code, name, options, banner, dependencies); + if (format === 'cjs') return cjs(code, name, options, banner, sharedPath, helpers, dependencies); + if (format === 'iife') return iife(code, name, options, banner, dependencies); + if (format === 'umd') return umd(code, name, options, banner, dependencies); + if (format === 'eval') return expr(code, name, options, banner, dependencies); throw new Error(`Not implemented: ${format}`); } -function getEsWrapper( +function es( + code: string, name: string, options: CompileOptions, banner: string, @@ -78,25 +82,25 @@ function getEsWrapper( `import { ${helpers.map(h => h.name === h.alias ? h.name : `${h.name} as ${h.alias}`).join(', ')} } from ${JSON.stringify(sharedPath)};` ); - const importBlock = imports - .map((declaration: Node) => source.slice(declaration.start, declaration.end)) - .join('\n'); + const importBlock = imports.length > 0 && ( + imports + .map((declaration: Node) => source.slice(declaration.start, declaration.end)) + .join('\n') + ); - return { - intro: deindent` - ${banner} - ${importHelpers} - ${importBlock} + return deindent` + ${banner} + ${importHelpers} + ${importBlock} - export default (function() { - `, - outro: deindent` + export default (function() { + ${code} return ${name}; - }());` - }; + }());`; } -function getAmdWrapper( +function amd( + code: string, name: string, options: CompileOptions, banner: string, @@ -108,20 +112,17 @@ function getAmdWrapper( const id = options.amd && options.amd.id; - return { - intro: deindent` - define(${id ? `"${id}", ` : ''}${sourceString}function(${paramString(dependencies)}) { "use strict"; - + return deindent` + define(${id ? `"${id}", ` : ''}${sourceString}function(${paramString(dependencies)}) { "use strict"; ${getCompatibilityStatements(dependencies)} - `, - outro: deindent` + ${code} return ${name}; - });` - }; + });`; } -function getCjsWrapper( +function cjs( + code: string, name: string, options: CompileOptions, banner: string, @@ -137,33 +138,27 @@ function getCjsWrapper( }).join('\n') ); - const requireBlock = dependencies - .map(d => `var ${d.name} = require("${d.source}");`) - .join('\n\n'); - - const intro = requireBlock ? - deindent` - ${banner} - "use strict"; - - ${helperBlock} - ${requireBlock} - ${getCompatibilityStatements(dependencies)} + const requireBlock = dependencies.length > 0 && ( + dependencies + .map(d => `var ${d.name} = require("${d.source}");`) + .join('\n\n') + ); - ` : - deindent` - ${banner} - "use strict"; + return deindent` + ${banner} + "use strict"; - ${helperBlock} - `; + ${helperBlock} + ${requireBlock} + ${getCompatibilityStatements(dependencies)} - const outro = `module.exports = ${name};` + ${code} - return { intro, outro }; + module.exports = ${name};` } -function getIifeWrapper( +function iife( + code: string, name: string, options: CompileOptions, banner: string, @@ -175,22 +170,18 @@ function getIifeWrapper( const globals = getGlobals(dependencies, options); - return { - intro: deindent` - ${banner} - var ${options.name} = (function(${paramString(dependencies)}) { "use strict"; - + return deindent` + ${banner} + var ${options.name} = (function(${paramString(dependencies)}) { "use strict"; ${getCompatibilityStatements(dependencies)} - `, - - outro: deindent` + ${code} return ${name}; - }(${globals.join(', ')}));` - }; + }(${globals.join(', ')}));`; } -function getUmdWrapper( +function umd( + code: string, name: string, options: CompileOptions, banner: string, @@ -212,27 +203,25 @@ function getUmdWrapper( const globals = getGlobals(dependencies, options); - return { - intro: deindent` - ${banner} - (function(global, factory) { - typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(${cjsDeps}) : - typeof define === "function" && define.amd ? define(${amdId}${amdDeps}factory) : - (global.${options.name} = factory(${globals})); - }(this, (function (${paramString(dependencies)}) { "use strict"; + return deindent` + ${banner} + (function(global, factory) { + typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory(${cjsDeps}) : + typeof define === "function" && define.amd ? define(${amdId}${amdDeps}factory) : + (global.${options.name} = factory(${globals})); + }(this, (function (${paramString(dependencies)}) { "use strict"; ${getCompatibilityStatements(dependencies)} - `, + ${code} - outro: deindent` return ${name}; - })));` - }; + })));`; } -function getEvalWrapper( +function expr( + code: string, name: string, options: CompileOptions, banner: string, @@ -240,17 +229,16 @@ function getEvalWrapper( ) { const globals = getGlobals(dependencies, options); - return { - intro: deindent` - (function (${paramString(dependencies)}) { "use strict"; + return deindent` + (function (${paramString(dependencies)}) { "use strict"; ${banner} ${getCompatibilityStatements(dependencies)} - `, + ${code} - outro: `return ${name};\n\n}(${globals.join(', ')}))` - }; + return ${name}; + }(${globals.join(', ')}))`; } function paramString(dependencies: Dependency[]) { 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 16eea4b1da..972c8bad71 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -191,8 +191,7 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -var template = (function() { + var template = (function() { return { data: function () { return { foo: 42 } @@ -200,67 +199,66 @@ var template = (function() { }; }()); -function encapsulateStyles(node) { - setAttribute(node, "svelte-3590263702", ""); -} - -function add_css() { - var style = createElement("style"); - style.id = 'svelte-3590263702-style'; - style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; - appendNode(style, document.head); -} + function encapsulateStyles(node) { + setAttribute(node, "svelte-3590263702", ""); + } -function create_main_fragment(state, component) { - var p, text; + function add_css() { + var style = createElement("style"); + style.id = 'svelte-3590263702-style'; + style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; + appendNode(style, document.head); + } - return { - create: function() { - p = createElement("p"); - text = createText(state.foo); - this.hydrate(); - }, - - hydrate: function() { - encapsulateStyles(p); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - update: function(changed, state) { - if (changed.foo) { - text.data = state.foo; - } - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; -} + function create_main_fragment(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText(state.foo); + this.hydrate(); + }, + + hydrate: function() { + encapsulateStyles(p); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + update: function(changed, state) { + if (changed.foo) { + text.data = state.foo; + } + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = assign(template.data(), options.data); + function SvelteComponent(options) { + init(this, options); + this._state = assign(template.data(), options.data); - if (!document.getElementById("svelte-3590263702-style")) add_css(); + if (!document.getElementById("svelte-3590263702-style")) add_css(); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 58a52bf65a..2ef55026da 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,10 +1,8 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; - export default (function() { - -var template = (function() { + var template = (function() { return { data: function () { return { foo: 42 } @@ -12,65 +10,64 @@ var template = (function() { }; }()); -function encapsulateStyles(node) { - setAttribute(node, "svelte-3590263702", ""); -} - -function add_css() { - var style = createElement("style"); - style.id = 'svelte-3590263702-style'; - style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; - appendNode(style, document.head); -} - -function create_main_fragment(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText(state.foo); - this.hydrate(); - }, - - hydrate: function() { - encapsulateStyles(p); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - update: function(changed, state) { - if (changed.foo) { - text.data = state.foo; - } - }, + function encapsulateStyles(node) { + setAttribute(node, "svelte-3590263702", ""); + } - unmount: function() { - detachNode(p); - }, + function add_css() { + var style = createElement("style"); + style.id = 'svelte-3590263702-style'; + style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; + appendNode(style, document.head); + } - destroy: noop - }; -} + function create_main_fragment(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText(state.foo); + this.hydrate(); + }, + + hydrate: function() { + encapsulateStyles(p); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + update: function(changed, state) { + if (changed.foo) { + text.data = state.foo; + } + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = assign(template.data(), options.data); + function SvelteComponent(options) { + init(this, options); + this._state = assign(template.data(), options.data); - if (!document.getElementById("svelte-3590263702-style")) add_css(); + if (!document.getElementById("svelte-3590263702-style")) add_css(); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 4f1bed2001..6b3d6488d1 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -167,8 +167,7 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -var template = (function() { + var template = (function() { return { components: { Nested: window.Nested @@ -176,61 +175,60 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { + function create_main_fragment(state, component) { - var nested = new template.components.Nested({ - _root: component._root, - data: { foo: "bar" } - }); + var nested = new template.components.Nested({ + _root: component._root, + data: { foo: "bar" } + }); - return { - create: function() { - nested._fragment.create(); - }, + return { + create: function() { + nested._fragment.create(); + }, - mount: function(target, anchor) { - nested._mount(target, anchor); - }, + mount: function(target, anchor) { + nested._mount(target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - nested._unmount(); - }, + unmount: function() { + nested._unmount(); + }, - destroy: function() { - nested.destroy(false); - } - }; -} + destroy: function() { + nested.destroy(false); + } + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - this._aftercreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - this._lock = true; - callAll(this._beforecreate); - callAll(this._oncreate); - callAll(this._aftercreate); - this._lock = false; + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index ce6cbb836b..e91a5f1db2 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -1,10 +1,8 @@ /* generated by Svelte vX.Y.Z */ import { assign, callAll, init, noop, proto } from "svelte/shared.js"; - export default (function() { - -var template = (function() { + var template = (function() { return { components: { Nested: window.Nested @@ -12,59 +10,58 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { + function create_main_fragment(state, component) { - var nested = new template.components.Nested({ - _root: component._root, - data: { foo: "bar" } - }); + var nested = new template.components.Nested({ + _root: component._root, + data: { foo: "bar" } + }); - return { - create: function() { - nested._fragment.create(); - }, + return { + create: function() { + nested._fragment.create(); + }, - mount: function(target, anchor) { - nested._mount(target, anchor); - }, + mount: function(target, anchor) { + nested._mount(target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - nested._unmount(); - }, + unmount: function() { + nested._unmount(); + }, - destroy: function() { - nested.destroy(false); - } - }; -} + destroy: function() { + nested.destroy(false); + } + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - this._aftercreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - this._lock = true; - callAll(this._beforecreate); - callAll(this._oncreate); - callAll(this._aftercreate); - this._lock = false; + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 71142f31d0..2e8615f001 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -167,8 +167,7 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -var template = (function() { + var template = (function() { return { computed: { a: x => x * 2, @@ -177,44 +176,43 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { + function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; - this._recompute({ x: 1 }, this._state); + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + this._recompute({ x: 1 }, this._state); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -SvelteComponent.prototype._recompute = function _recompute(changed, state) { - if (changed.x) { - if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; - if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; - } -}; + assign(SvelteComponent.prototype, proto); -return SvelteComponent; + SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.x) { + if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; + if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; + } + }; + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 9f99533706..5d4313c10e 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,10 +1,8 @@ /* generated by Svelte vX.Y.Z */ import { assign, differs, init, noop, proto } from "svelte/shared.js"; - export default (function() { - -var template = (function() { + var template = (function() { return { computed: { a: x => x * 2, @@ -13,42 +11,41 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { + function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; - this._recompute({ x: 1 }, this._state); + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + this._recompute({ x: 1 }, this._state); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} -assign(SvelteComponent.prototype, proto); + assign(SvelteComponent.prototype, proto); -SvelteComponent.prototype._recompute = function _recompute(changed, state) { - if (changed.x) { - if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; - if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; + SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.x) { + if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; + if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; + } } -} - -return SvelteComponent; + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 12b7d897ee..8ebbefee23 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -187,62 +187,60 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function encapsulateStyles(node) { + setAttribute(node, "svelte-2363328337", ""); + } -function encapsulateStyles(node) { - setAttribute(node, "svelte-2363328337", ""); -} - -function add_css() { - var style = createElement("style"); - style.id = 'svelte-2363328337-style'; - style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; - appendNode(style, document.head); -} + function add_css() { + var style = createElement("style"); + style.id = 'svelte-2363328337-style'; + style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; + appendNode(style, document.head); + } -function create_main_fragment(state, component) { - var div; + function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - encapsulateStyles(div); - }, + hydrate: function() { + encapsulateStyles(div); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!document.getElementById("svelte-2363328337-style")) add_css(); + if (!document.getElementById("svelte-2363328337-style")) add_css(); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index 24ca7471c4..a9bd0d538d 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,62 +1,59 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; - export default (function() { + function encapsulateStyles(node) { + setAttribute(node, "svelte-2363328337", ""); + } -function encapsulateStyles(node) { - setAttribute(node, "svelte-2363328337", ""); -} - -function add_css() { - var style = createElement("style"); - style.id = 'svelte-2363328337-style'; - style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; - appendNode(style, document.head); -} + function add_css() { + var style = createElement("style"); + style.id = 'svelte-2363328337-style'; + style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; + appendNode(style, document.head); + } -function create_main_fragment(state, component) { - var div; + function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - encapsulateStyles(div); - }, + hydrate: function() { + encapsulateStyles(div); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!document.getElementById("svelte-2363328337-style")) add_css(); + if (!document.getElementById("svelte-2363328337-style")) add_css(); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file 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 a060d65078..ebd6272c4f 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -187,69 +187,67 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var div, text; -function create_main_fragment(state, component) { - var div, text; + return { + create: function() { + div = createElement("div"); + text = createText("fades in"); + }, - return { - create: function() { - div = createElement("div"); - text = createText("fades in"); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + appendNode(text, div); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - appendNode(text, div); - }, + update: noop, - update: noop, - - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -class SvelteComponent extends HTMLElement { - constructor(options = {}) { - super(); - init(this, options); - this._state = options.data || {}; + class SvelteComponent extends HTMLElement { + constructor(options = {}) { + super(); + init(this, options); + this._state = options.data || {}; - this.attachShadow({ mode: 'open' }); - this.shadowRoot.innerHTML = ``; + this.attachShadow({ mode: 'open' }); + this.shadowRoot.innerHTML = ``; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - this._fragment.create(); - this._fragment.mount(this.shadowRoot, null); + this._fragment.create(); + this._fragment.mount(this.shadowRoot, null); - if (options.target) this._mount(options.target, options.anchor || null); - } + if (options.target) this._mount(options.target, options.anchor || null); + } - static get observedAttributes() { - return []; - } + static get observedAttributes() { + return []; + } - attributeChangedCallback(attr, oldValue, newValue) { - this.set({ [attr]: newValue }); + attributeChangedCallback(attr, oldValue, newValue) { + this.set({ [attr]: newValue }); + } } -} -customElements.define("custom-element", SvelteComponent); -assign(SvelteComponent.prototype, proto, { - _mount(target, anchor) { - target.insertBefore(this, anchor); - }, - - _unmount() { - this.parentNode.removeChild(this); - } -}); + customElements.define("custom-element", SvelteComponent); + assign(SvelteComponent.prototype, proto, { + _mount(target, anchor) { + target.insertBefore(this, anchor); + }, -return SvelteComponent; + _unmount() { + this.parentNode.removeChild(this); + } + }); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 2a34370c23..5fe9dc2db9 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,69 +1,66 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var div, text; -function create_main_fragment(state, component) { - var div, text; + return { + create: function() { + div = createElement("div"); + text = createText("fades in"); + }, - return { - create: function() { - div = createElement("div"); - text = createText("fades in"); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + appendNode(text, div); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - appendNode(text, div); - }, + update: noop, - update: noop, + unmount: function() { + detachNode(div); + }, - unmount: function() { - detachNode(div); - }, + destroy: noop + }; + } - destroy: noop - }; -} + class SvelteComponent extends HTMLElement { + constructor(options = {}) { + super(); + init(this, options); + this._state = options.data || {}; -class SvelteComponent extends HTMLElement { - constructor(options = {}) { - super(); - init(this, options); - this._state = options.data || {}; + this.attachShadow({ mode: 'open' }); + this.shadowRoot.innerHTML = ``; - this.attachShadow({ mode: 'open' }); - this.shadowRoot.innerHTML = ``; + this._fragment = create_main_fragment(this._state, this); - this._fragment = create_main_fragment(this._state, this); + this._fragment.create(); + this._fragment.mount(this.shadowRoot, null); - this._fragment.create(); - this._fragment.mount(this.shadowRoot, null); + if (options.target) this._mount(options.target, options.anchor || null); + } - if (options.target) this._mount(options.target, options.anchor || null); - } + static get observedAttributes() { + return []; + } - static get observedAttributes() { - return []; + attributeChangedCallback(attr, oldValue, newValue) { + this.set({ [attr]: newValue }); + } } - attributeChangedCallback(attr, oldValue, newValue) { - this.set({ [attr]: newValue }); - } -} - -customElements.define("custom-element", SvelteComponent); -assign(SvelteComponent.prototype, proto, { - _mount(target, anchor) { - target.insertBefore(this, anchor); - }, - - _unmount() { - this.parentNode.removeChild(this); - } -}); + customElements.define("custom-element", SvelteComponent); + assign(SvelteComponent.prototype, proto, { + _mount(target, anchor) { + target.insertBefore(this, anchor); + }, -return SvelteComponent; + _unmount() { + this.parentNode.removeChild(this); + } + }); + return SvelteComponent; }()); \ No newline at end of file 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 a9c9399b1f..1209310d42 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -200,160 +200,158 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var text, p, text_1; -function create_main_fragment(state, component) { - var text, p, text_1; + var comments = state.comments; - var comments = state.comments; + var each_blocks = []; - var each_blocks = []; + for (var i = 0; i < comments.length; i += 1) { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + } - for (var i = 0; i < comments.length; i += 1) { - each_blocks[i] = create_each_block(state, comments, comments[i], i, component); - } + return { + create: function() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].create(); + } - return { - create: function() { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].create(); - } + text = createText("\n\n"); + p = createElement("p"); + text_1 = createText(state.foo); + }, - text = createText("\n\n"); - p = createElement("p"); - text_1 = createText(state.foo); - }, + mount: function(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].mount(target, anchor); + } - mount: function(target, anchor) { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].mount(target, anchor); - } + insertNode(text, target, anchor); + insertNode(p, target, anchor); + appendNode(text_1, p); + }, + + update: function(changed, state) { + var comments = state.comments; + + if (changed.comments || changed.elapsed || changed.time) { + for (var i = 0; i < comments.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].update(changed, state, comments, comments[i], i); + } else { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i].create(); + each_blocks[i].mount(text.parentNode, text); + } + } - insertNode(text, target, anchor); - insertNode(p, target, anchor); - appendNode(text_1, p); - }, - - update: function(changed, state) { - var comments = state.comments; - - if (changed.comments || changed.elapsed || changed.time) { - for (var i = 0; i < comments.length; i += 1) { - if (each_blocks[i]) { - each_blocks[i].update(changed, state, comments, comments[i], i); - } else { - each_blocks[i] = create_each_block(state, comments, comments[i], i, component); - each_blocks[i].create(); - each_blocks[i].mount(text.parentNode, text); + for (; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); + each_blocks[i].destroy(); } + each_blocks.length = comments.length; } - for (; i < each_blocks.length; i += 1) { + if (changed.foo) { + text_1.data = state.foo; + } + }, + + unmount: function() { + for (var i = 0; i < each_blocks.length; i += 1) { each_blocks[i].unmount(); - each_blocks[i].destroy(); } - each_blocks.length = comments.length; - } - if (changed.foo) { - text_1.data = state.foo; - } - }, + detachNode(text); + detachNode(p); + }, - unmount: function() { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].unmount(); + destroy: function() { + destroyEach(each_blocks, false, 0); } + }; + } - detachNode(text); - detachNode(p); - }, - - destroy: function() { - destroyEach(each_blocks, false, 0); - } - }; -} + // (1:0) {{#each comments as comment, i}} + function create_each_block(state, comments, 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; + + return { + create: function() { + div = createElement("div"); + strong = createElement("strong"); + text = createText(i); + text_1 = createText("\n\n\t\t"); + span = createElement("span"); + text_2 = createText(text_2_value); + text_3 = createText(" wrote "); + text_4 = createText(text_4_value); + text_5 = createText(" ago:"); + text_6 = createText("\n\n\t\t"); + raw_before = createElement('noscript'); + this.hydrate(); + }, + + hydrate: function() { + div.className = "comment"; + span.className = "meta"; + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + appendNode(strong, div); + appendNode(text, strong); + appendNode(text_1, div); + appendNode(span, div); + appendNode(text_2, span); + appendNode(text_3, span); + appendNode(text_4, span); + appendNode(text_5, span); + appendNode(text_6, div); + appendNode(raw_before, div); + raw_before.insertAdjacentHTML("afterend", raw_value); + }, -// (1:0) {{#each comments as comment, i}} -function create_each_block(state, comments, 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; + update: function(changed, state, comments, comment, i) { + if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { + text_2.data = text_2_value; + } - return { - create: function() { - div = createElement("div"); - strong = createElement("strong"); - text = createText(i); - text_1 = createText("\n\n\t\t"); - span = createElement("span"); - text_2 = createText(text_2_value); - text_3 = createText(" wrote "); - text_4 = createText(text_4_value); - text_5 = createText(" ago:"); - text_6 = createText("\n\n\t\t"); - raw_before = createElement('noscript'); - this.hydrate(); - }, - - hydrate: function() { - div.className = "comment"; - span.className = "meta"; - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - appendNode(strong, div); - appendNode(text, strong); - appendNode(text_1, div); - appendNode(span, div); - appendNode(text_2, span); - appendNode(text_3, span); - appendNode(text_4, span); - appendNode(text_5, span); - appendNode(text_6, div); - appendNode(raw_before, div); - raw_before.insertAdjacentHTML("afterend", raw_value); - }, - - update: function(changed, state, comments, comment, i) { - 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))) { + text_4.data = text_4_value; + } - 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)) { + detachAfter(raw_before); + raw_before.insertAdjacentHTML("afterend", raw_value); + } + }, - if ((changed.comments) && raw_value !== (raw_value = comment.html)) { + unmount: function() { detachAfter(raw_before); - raw_before.insertAdjacentHTML("afterend", raw_value); - } - }, - - unmount: function() { - detachAfter(raw_before); - detachNode(div); - }, + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 7e87506196..4ef38aaa50 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,160 +1,157 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var text, p, text_1; -function create_main_fragment(state, component) { - var text, p, text_1; + var comments = state.comments; - var comments = state.comments; + var each_blocks = []; - var each_blocks = []; + for (var i = 0; i < comments.length; i += 1) { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + } - for (var i = 0; i < comments.length; i += 1) { - each_blocks[i] = create_each_block(state, comments, comments[i], i, component); - } + return { + create: function() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].create(); + } - return { - create: function() { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].create(); - } + text = createText("\n\n"); + p = createElement("p"); + text_1 = createText(state.foo); + }, - text = createText("\n\n"); - p = createElement("p"); - text_1 = createText(state.foo); - }, + mount: function(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].mount(target, anchor); + } - mount: function(target, anchor) { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].mount(target, anchor); - } + insertNode(text, target, anchor); + insertNode(p, target, anchor); + appendNode(text_1, p); + }, + + update: function(changed, state) { + var comments = state.comments; + + if (changed.comments || changed.elapsed || changed.time) { + for (var i = 0; i < comments.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].update(changed, state, comments, comments[i], i); + } else { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i].create(); + each_blocks[i].mount(text.parentNode, text); + } + } - insertNode(text, target, anchor); - insertNode(p, target, anchor); - appendNode(text_1, p); - }, - - update: function(changed, state) { - var comments = state.comments; - - if (changed.comments || changed.elapsed || changed.time) { - for (var i = 0; i < comments.length; i += 1) { - if (each_blocks[i]) { - each_blocks[i].update(changed, state, comments, comments[i], i); - } else { - each_blocks[i] = create_each_block(state, comments, comments[i], i, component); - each_blocks[i].create(); - each_blocks[i].mount(text.parentNode, text); + for (; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); + each_blocks[i].destroy(); } + each_blocks.length = comments.length; + } + + if (changed.foo) { + text_1.data = state.foo; } + }, - for (; i < each_blocks.length; i += 1) { + unmount: function() { + for (var i = 0; i < each_blocks.length; i += 1) { each_blocks[i].unmount(); - each_blocks[i].destroy(); } - each_blocks.length = comments.length; - } - if (changed.foo) { - text_1.data = state.foo; - } - }, + detachNode(text); + detachNode(p); + }, - unmount: function() { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].unmount(); + destroy: function() { + destroyEach(each_blocks, false, 0); } + }; + } - detachNode(text); - detachNode(p); - }, + // (1:0) {{#each comments as comment, i}} + function create_each_block(state, comments, 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; + + return { + create: function() { + div = createElement("div"); + strong = createElement("strong"); + text = createText(i); + text_1 = createText("\n\n\t\t"); + span = createElement("span"); + text_2 = createText(text_2_value); + text_3 = createText(" wrote "); + text_4 = createText(text_4_value); + text_5 = createText(" ago:"); + text_6 = createText("\n\n\t\t"); + raw_before = createElement('noscript'); + this.hydrate(); + }, + + hydrate: function() { + div.className = "comment"; + span.className = "meta"; + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + appendNode(strong, div); + appendNode(text, strong); + appendNode(text_1, div); + appendNode(span, div); + appendNode(text_2, span); + appendNode(text_3, span); + appendNode(text_4, span); + appendNode(text_5, span); + appendNode(text_6, div); + appendNode(raw_before, div); + raw_before.insertAdjacentHTML("afterend", raw_value); + }, - destroy: function() { - destroyEach(each_blocks, false, 0); - } - }; -} - -// (1:0) {{#each comments as comment, i}} -function create_each_block(state, comments, 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; - - return { - create: function() { - div = createElement("div"); - strong = createElement("strong"); - text = createText(i); - text_1 = createText("\n\n\t\t"); - span = createElement("span"); - text_2 = createText(text_2_value); - text_3 = createText(" wrote "); - text_4 = createText(text_4_value); - text_5 = createText(" ago:"); - text_6 = createText("\n\n\t\t"); - raw_before = createElement('noscript'); - this.hydrate(); - }, - - hydrate: function() { - div.className = "comment"; - span.className = "meta"; - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - appendNode(strong, div); - appendNode(text, strong); - appendNode(text_1, div); - appendNode(span, div); - appendNode(text_2, span); - appendNode(text_3, span); - appendNode(text_4, span); - appendNode(text_5, span); - appendNode(text_6, div); - appendNode(raw_before, div); - raw_before.insertAdjacentHTML("afterend", raw_value); - }, - - update: function(changed, state, comments, comment, i) { - if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { - text_2.data = text_2_value; - } + update: function(changed, state, comments, comment, i) { + 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))) { - text_4.data = text_4_value; - } + 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)) { - detachAfter(raw_before); - raw_before.insertAdjacentHTML("afterend", raw_value); - } - }, + if ((changed.comments) && raw_value !== (raw_value = comment.html)) { + detachAfter(raw_before); + raw_before.insertAdjacentHTML("afterend", raw_value); + } + }, - unmount: function() { - detachAfter(raw_before); + unmount: function() { + detachAfter(raw_before); - detachNode(div); - }, + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index 157838a962..f96f8fb00b 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -187,8 +187,7 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -var template = (function() { + var template = (function() { return { methods: { foo ( bar ) { @@ -203,55 +202,54 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { - var button, foo_handler, text; + function create_main_fragment(state, component) { + var button, foo_handler, text; - return { - create: function() { - button = createElement("button"); - text = createText("foo"); - this.hydrate(); - }, + return { + create: function() { + button = createElement("button"); + text = createText("foo"); + this.hydrate(); + }, - hydrate: function() { - foo_handler = template.events.foo.call(component, button, function(event) { - var state = component.get(); - component.foo( state.bar ); - }); - }, + hydrate: function() { + foo_handler = template.events.foo.call(component, button, function(event) { + var state = component.get(); + component.foo( state.bar ); + }); + }, - mount: function(target, anchor) { - insertNode(button, target, anchor); - appendNode(text, button); - }, + mount: function(target, anchor) { + insertNode(button, target, anchor); + appendNode(text, button); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(button); - }, + unmount: function() { + detachNode(button); + }, - destroy: function() { - foo_handler.teardown(); - } - }; -} + destroy: function() { + foo_handler.teardown(); + } + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, template.methods, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, template.methods, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index e6cfb8bf13..41f66bb1d7 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,10 +1,8 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; - export default (function() { - -var template = (function() { + var template = (function() { return { methods: { foo ( bar ) { @@ -19,53 +17,52 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { - var button, foo_handler, text; + function create_main_fragment(state, component) { + var button, foo_handler, text; - return { - create: function() { - button = createElement("button"); - text = createText("foo"); - this.hydrate(); - }, + return { + create: function() { + button = createElement("button"); + text = createText("foo"); + this.hydrate(); + }, - hydrate: function() { - foo_handler = template.events.foo.call(component, button, function(event) { - var state = component.get(); - component.foo( state.bar ); - }); - }, + hydrate: function() { + foo_handler = template.events.foo.call(component, button, function(event) { + var state = component.get(); + component.foo( state.bar ); + }); + }, - mount: function(target, anchor) { - insertNode(button, target, anchor); - appendNode(text, button); - }, + mount: function(target, anchor) { + insertNode(button, target, anchor); + appendNode(text, button); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(button); - }, + unmount: function() { + detachNode(button); + }, - destroy: function() { - foo_handler.teardown(); - } - }; -} + destroy: function() { + foo_handler.teardown(); + } + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, template.methods, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, template.methods, proto); + return SvelteComponent; }()); \ No newline at end of file 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 e9ef3903eb..b7cd0d587b 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -191,111 +191,109 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var if_block_anchor; -function create_main_fragment(state, component) { - var if_block_anchor; + var current_block_type = select_block_type(state); + var if_block = current_block_type(state, component); - var current_block_type = select_block_type(state); - var if_block = current_block_type(state, component); - - return { - create: function() { - if_block.create(); - if_block_anchor = createComment(); - }, - - mount: function(target, anchor) { - if_block.mount(target, anchor); - insertNode(if_block_anchor, target, anchor); - }, - - update: function(changed, state) { - if (current_block_type !== (current_block_type = select_block_type(state))) { + return { + create: function() { + if_block.create(); + if_block_anchor = createComment(); + }, + + mount: function(target, anchor) { + if_block.mount(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + update: function(changed, state) { + if (current_block_type !== (current_block_type = select_block_type(state))) { + if_block.unmount(); + if_block.destroy(); + if_block = current_block_type(state, component); + if_block.create(); + if_block.mount(if_block_anchor.parentNode, if_block_anchor); + } + }, + + unmount: function() { if_block.unmount(); + detachNode(if_block_anchor); + }, + + destroy: function() { if_block.destroy(); - if_block = current_block_type(state, component); - if_block.create(); - if_block.mount(if_block_anchor.parentNode, if_block_anchor); } - }, - - unmount: function() { - if_block.unmount(); - detachNode(if_block_anchor); - }, - - destroy: function() { - if_block.destroy(); - } - }; -} + }; + } -// (1:0) {{#if foo}} -function create_if_block(state, component) { - var p, text; + // (1:0) {{#if foo}} + function create_if_block(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("foo!"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("foo!"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -// (3:0) {{else}} -function create_if_block_1(state, component) { - var p, text; + // (3:0) {{else}} + function create_if_block_1(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("not foo!"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("not foo!"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function select_block_type(state) { - if (state.foo) return create_if_block; - return create_if_block_1; -} + function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 5cf14db148..5d52e1cbad 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,111 +1,108 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var if_block_anchor; -function create_main_fragment(state, component) { - var if_block_anchor; - - var current_block_type = select_block_type(state); - var if_block = current_block_type(state, component); - - return { - create: function() { - if_block.create(); - if_block_anchor = createComment(); - }, + var current_block_type = select_block_type(state); + var if_block = current_block_type(state, component); - mount: function(target, anchor) { - if_block.mount(target, anchor); - insertNode(if_block_anchor, target, anchor); - }, - - update: function(changed, state) { - if (current_block_type !== (current_block_type = select_block_type(state))) { + return { + create: function() { + if_block.create(); + if_block_anchor = createComment(); + }, + + mount: function(target, anchor) { + if_block.mount(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + update: function(changed, state) { + if (current_block_type !== (current_block_type = select_block_type(state))) { + if_block.unmount(); + if_block.destroy(); + if_block = current_block_type(state, component); + if_block.create(); + if_block.mount(if_block_anchor.parentNode, if_block_anchor); + } + }, + + unmount: function() { if_block.unmount(); + detachNode(if_block_anchor); + }, + + destroy: function() { if_block.destroy(); - if_block = current_block_type(state, component); - if_block.create(); - if_block.mount(if_block_anchor.parentNode, if_block_anchor); } - }, + }; + } - unmount: function() { - if_block.unmount(); - detachNode(if_block_anchor); - }, + // (1:0) {{#if foo}} + function create_if_block(state, component) { + var p, text; - destroy: function() { - if_block.destroy(); - } - }; -} - -// (1:0) {{#if foo}} -function create_if_block(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("foo!"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; -} - -// (3:0) {{else}} -function create_if_block_1(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("not foo!"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; -} - -function select_block_type(state) { - if (state.foo) return create_if_block; - return create_if_block_1; -} - -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; - - this._fragment = create_main_fragment(this._state, this); - - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + return { + create: function() { + p = createElement("p"); + text = createText("foo!"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; } -} -assign(SvelteComponent.prototype, proto); + // (3:0) {{else}} + function create_if_block_1(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("not foo!"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; + } + + function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; + } + + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } + } -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 5674aaf3a0..6c7e2d86b4 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -191,86 +191,84 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -function create_main_fragment(state, component) { - var if_block_anchor; - - var if_block = (state.foo) && create_if_block(state, component); - - return { - create: function() { - if (if_block) if_block.create(); - if_block_anchor = createComment(); - }, - - mount: function(target, anchor) { - if (if_block) if_block.mount(target, anchor); - insertNode(if_block_anchor, target, anchor); - }, - - update: function(changed, state) { - if (state.foo) { - if (!if_block) { - if_block = create_if_block(state, component); - if_block.create(); - if_block.mount(if_block_anchor.parentNode, if_block_anchor); + function create_main_fragment(state, component) { + var if_block_anchor; + + var if_block = (state.foo) && create_if_block(state, component); + + return { + create: function() { + if (if_block) if_block.create(); + if_block_anchor = createComment(); + }, + + mount: function(target, anchor) { + if (if_block) if_block.mount(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + update: function(changed, state) { + if (state.foo) { + if (!if_block) { + if_block = create_if_block(state, component); + if_block.create(); + if_block.mount(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + if_block.unmount(); + if_block.destroy(); + if_block = null; } - } else if (if_block) { - if_block.unmount(); - if_block.destroy(); - if_block = null; - } - }, + }, - unmount: function() { - if (if_block) if_block.unmount(); - detachNode(if_block_anchor); - }, + unmount: function() { + if (if_block) if_block.unmount(); + detachNode(if_block_anchor); + }, - destroy: function() { - if (if_block) if_block.destroy(); - } - }; -} + destroy: function() { + if (if_block) if_block.destroy(); + } + }; + } -// (1:0) {{#if foo}} -function create_if_block(state, component) { - var p, text; + // (1:0) {{#if foo}} + function create_if_block(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("foo!"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("foo!"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 09bab7ebdf..311093e0fb 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,86 +1,83 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; - export default (function() { - -function create_main_fragment(state, component) { - var if_block_anchor; - - var if_block = (state.foo) && create_if_block(state, component); - - return { - create: function() { - if (if_block) if_block.create(); - if_block_anchor = createComment(); - }, - - mount: function(target, anchor) { - if (if_block) if_block.mount(target, anchor); - insertNode(if_block_anchor, target, anchor); - }, - - update: function(changed, state) { - if (state.foo) { - if (!if_block) { - if_block = create_if_block(state, component); - if_block.create(); - if_block.mount(if_block_anchor.parentNode, if_block_anchor); + function create_main_fragment(state, component) { + var if_block_anchor; + + var if_block = (state.foo) && create_if_block(state, component); + + return { + create: function() { + if (if_block) if_block.create(); + if_block_anchor = createComment(); + }, + + mount: function(target, anchor) { + if (if_block) if_block.mount(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + update: function(changed, state) { + if (state.foo) { + if (!if_block) { + if_block = create_if_block(state, component); + if_block.create(); + if_block.mount(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + if_block.unmount(); + if_block.destroy(); + if_block = null; } - } else if (if_block) { - if_block.unmount(); - if_block.destroy(); - if_block = null; - } - }, + }, - unmount: function() { - if (if_block) if_block.unmount(); - detachNode(if_block_anchor); - }, + unmount: function() { + if (if_block) if_block.unmount(); + detachNode(if_block_anchor); + }, - destroy: function() { - if (if_block) if_block.destroy(); - } - }; -} + destroy: function() { + if (if_block) if_block.destroy(); + } + }; + } -// (1:0) {{#if foo}} -function create_if_block(state, component) { - var p, text; + // (1:0) {{#if foo}} + function create_if_block(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("foo!"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("foo!"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file 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 bc5f1d2dc2..3ebdbc1277 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -183,58 +183,56 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var div; -function create_main_fragment(state, component) { - var div; + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, - - hydrate: function() { - setStyle(div, "color", state.color); - setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, - - update: function(changed, state) { - if (changed.color) { + hydrate: function() { setStyle(div, "color", state.color); - } - - if (changed.x || changed.y) { setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); - } - }, + }, - unmount: function() { - detachNode(div); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - destroy: noop - }; -} + update: function(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + if (changed.x || changed.y) { + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + } + }, - this._fragment = create_main_fragment(this._state, this); + unmount: function() { + detachNode(div); + }, - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + destroy: noop + }; } -} -assign(SvelteComponent.prototype, proto); + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } + } -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index 505a49cb08..a23f9fdd7c 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,58 +1,55 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var div; -function create_main_fragment(state, component) { - var div; - - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, - - hydrate: function() { - setStyle(div, "color", state.color); - setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - update: function(changed, state) { - if (changed.color) { + hydrate: function() { setStyle(div, "color", state.color); - } - - if (changed.x || changed.y) { setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); - } - }, + }, - unmount: function() { - detachNode(div); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - destroy: noop - }; -} + update: function(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + if (changed.x || changed.y) { + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + } + }, - this._fragment = create_main_fragment(this._state, this); + unmount: function() { + detachNode(div); + }, - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + destroy: noop + }; } -} -assign(SvelteComponent.prototype, proto); + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } + } -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file 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 e927618dd5..105fb40076 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -183,53 +183,51 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var div; -function create_main_fragment(state, component) { - var div; + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + hydrate: function() { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + }, - hydrate: function() { - setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + update: function(changed, state) { + if (changed.data) { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + } + }, - update: function(changed, state) { - if (changed.data) { - setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); - } - }, + unmount: function() { + detachNode(div); + }, - unmount: function() { - detachNode(div); - }, - - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index 7a897321d7..2a4a108f74 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,53 +1,50 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var div; -function create_main_fragment(state, component) { - var div; - - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); - }, + hydrate: function() { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: function(changed, state) { - if (changed.data) { - setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); - } - }, + update: function(changed, state) { + if (changed.data) { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + } + }, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 3121c65fa3..90857bb9cb 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -183,53 +183,51 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var div; -function create_main_fragment(state, component) { - var div; + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + hydrate: function() { + setStyle(div, "color", state.color); + }, - hydrate: function() { - setStyle(div, "color", state.color); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + update: function(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + }, - update: function(changed, state) { - if (changed.color) { - setStyle(div, "color", state.color); - } - }, + unmount: function() { + detachNode(div); + }, - unmount: function() { - detachNode(div); - }, - - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index 3b062803ec..bb6f6dbd04 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,53 +1,50 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var div; -function create_main_fragment(state, component) { - var div; - - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - setStyle(div, "color", state.color); - }, + hydrate: function() { + setStyle(div, "color", state.color); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: function(changed, state) { - if (changed.color) { - setStyle(div, "color", state.color); - } - }, + update: function(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + }, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index bf96d84f8b..7480c32d80 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -183,64 +183,62 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -function create_main_fragment(state, component) { - var div, text, div_1, div_1_style_value; - - return { - create: function() { - div = createElement("div"); - text = createText("\n"); - div_1 = createElement("div"); - this.hydrate(); - }, - - hydrate: function() { - div.style.cssText = state.style; - div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - insertNode(text, target, anchor); - insertNode(div_1, target, anchor); - }, - - update: function(changed, state) { - if (changed.style) { + function create_main_fragment(state, component) { + var div, text, div_1, div_1_style_value; + + return { + create: function() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.hydrate(); + }, + + hydrate: function() { div.style.cssText = state.style; - } - - 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; - } - }, - - unmount: function() { - detachNode(div); - detachNode(text); - detachNode(div_1); - }, - - destroy: noop - }; -} + div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + update: function(changed, state) { + 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)) { + div_1.style.cssText = div_1_style_value; + } + }, + + unmount: function() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 7d70519f25..392f3de4be 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,64 +1,61 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; - export default (function() { - -function create_main_fragment(state, component) { - var div, text, div_1, div_1_style_value; - - return { - create: function() { - div = createElement("div"); - text = createText("\n"); - div_1 = createElement("div"); - this.hydrate(); - }, - - hydrate: function() { - div.style.cssText = state.style; - div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - insertNode(text, target, anchor); - insertNode(div_1, target, anchor); - }, - - update: function(changed, state) { - if (changed.style) { + function create_main_fragment(state, component) { + var div, text, div_1, div_1_style_value; + + return { + create: function() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.hydrate(); + }, + + hydrate: function() { div.style.cssText = state.style; - } - - 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; - } - }, - - unmount: function() { - detachNode(div); - detachNode(text); - detachNode(div_1); - }, - - destroy: noop - }; -} + div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + update: function(changed, state) { + 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)) { + div_1.style.cssText = div_1_style_value; + } + }, + + unmount: function() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file 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 1e66553ac6..41959bc510 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -187,60 +187,58 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var input; -function create_main_fragment(state, component) { - var input; - - function input_change_handler() { - component.set({ foo: input.checked }); - } + function input_change_handler() { + component.set({ foo: input.checked }); + } - return { - create: function() { - input = createElement("input"); - this.hydrate(); - }, + return { + create: function() { + input = createElement("input"); + this.hydrate(); + }, - hydrate: function() { - input.type = "checkbox"; - addListener(input, "change", input_change_handler); - }, + hydrate: function() { + input.type = "checkbox"; + addListener(input, "change", input_change_handler); + }, - mount: function(target, anchor) { - insertNode(input, target, anchor); + mount: function(target, anchor) { + insertNode(input, target, anchor); - input.checked = state.foo; - }, + input.checked = state.foo; + }, - update: function(changed, state) { - input.checked = state.foo; - }, + update: function(changed, state) { + input.checked = state.foo; + }, - unmount: function() { - detachNode(input); - }, + unmount: function() { + detachNode(input); + }, - destroy: function() { - removeListener(input, "change", input_change_handler); - } - }; -} + destroy: function() { + removeListener(input, "change", input_change_handler); + } + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index 4fa1f54137..6a8580da45 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,60 +1,57 @@ /* generated by Svelte vX.Y.Z */ import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var input; -function create_main_fragment(state, component) { - var input; - - function input_change_handler() { - component.set({ foo: input.checked }); - } + function input_change_handler() { + component.set({ foo: input.checked }); + } - return { - create: function() { - input = createElement("input"); - this.hydrate(); - }, + return { + create: function() { + input = createElement("input"); + this.hydrate(); + }, - hydrate: function() { - input.type = "checkbox"; - addListener(input, "change", input_change_handler); - }, + hydrate: function() { + input.type = "checkbox"; + addListener(input, "change", input_change_handler); + }, - mount: function(target, anchor) { - insertNode(input, target, anchor); + mount: function(target, anchor) { + insertNode(input, target, anchor); - input.checked = state.foo; - }, + input.checked = state.foo; + }, - update: function(changed, state) { - input.checked = state.foo; - }, + update: function(changed, state) { + input.checked = state.foo; + }, - unmount: function() { - detachNode(input); - }, + unmount: function() { + detachNode(input); + }, - destroy: function() { - removeListener(input, "change", input_change_handler); - } - }; -} + destroy: function() { + removeListener(input, "change", input_change_handler); + } + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index ce0814144c..163380555a 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -185,49 +185,47 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var input; -function create_main_fragment(state, component) { - var input; + return { + create: function() { + input = createElement("input"); + this.hydrate(); + }, - return { - create: function() { - input = createElement("input"); - this.hydrate(); - }, - - hydrate: function() { - setInputType(input, "search"); - }, + hydrate: function() { + setInputType(input, "search"); + }, - mount: function(target, anchor) { - insertNode(input, target, anchor); - }, + mount: function(target, anchor) { + insertNode(input, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(input); - }, + unmount: function() { + detachNode(input); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 77d1155b77..8657249f57 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,49 +1,46 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var input; -function create_main_fragment(state, component) { - var input; - - return { - create: function() { - input = createElement("input"); - this.hydrate(); - }, + return { + create: function() { + input = createElement("input"); + this.hydrate(); + }, - hydrate: function() { - setInputType(input, "search"); - }, + hydrate: function() { + setInputType(input, "search"); + }, - mount: function(target, anchor) { - insertNode(input, target, anchor); - }, + mount: function(target, anchor) { + insertNode(input, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(input); - }, + unmount: function() { + detachNode(input); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index ac3e0110b3..709f4c8e1c 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -202,59 +202,57 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var div; -function create_main_fragment(state, component) { - var div; + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, - - claim: function(nodes) { - div = claimElement(nodes, "DIV", { "class": true }, false); - var div_nodes = children(div); + claim: function(nodes) { + div = claimElement(nodes, "DIV", { "class": true }, false); + var div_nodes = children(div); - div_nodes.forEach(detachNode); - this.hydrate(); - }, + div_nodes.forEach(detachNode); + this.hydrate(); + }, - hydrate: function() { - div.className = "foo"; - }, + hydrate: function() { + div.className = "foo"; + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - var nodes = children(options.target); - options.hydrate ? this._fragment.claim(nodes) : this._fragment.create(); - nodes.forEach(detachNode); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + var nodes = children(options.target); + options.hydrate ? this._fragment.claim(nodes) : this._fragment.create(); + nodes.forEach(detachNode); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index 1870b333fc..b0e08896bb 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,59 +1,56 @@ /* generated by Svelte vX.Y.Z */ import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var div; -function create_main_fragment(state, component) { - var div; - - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - claim: function(nodes) { - div = claimElement(nodes, "DIV", { "class": true }, false); - var div_nodes = children(div); + claim: function(nodes) { + div = claimElement(nodes, "DIV", { "class": true }, false); + var div_nodes = children(div); - div_nodes.forEach(detachNode); - this.hydrate(); - }, + div_nodes.forEach(detachNode); + this.hydrate(); + }, - hydrate: function() { - div.className = "foo"; - }, + hydrate: function() { + div.className = "foo"; + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - var nodes = children(options.target); - options.hydrate ? this._fragment.claim(nodes) : this._fragment.create(); - nodes.forEach(detachNode); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + var nodes = children(options.target); + options.hydrate ? this._fragment.claim(nodes) : this._fragment.create(); + nodes.forEach(detachNode); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 6c4b2b6f46..3bf631a388 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -195,135 +195,133 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { + function create_main_fragment(state, component) { + var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; -function create_main_fragment(state, component) { - var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; + function audio_progress_loadedmetadata_handler() { + audio_updating = true; + component.set({ buffered: timeRangesToArray(audio.buffered) }); + audio_updating = false; + } - function audio_progress_loadedmetadata_handler() { - audio_updating = true; - component.set({ buffered: timeRangesToArray(audio.buffered) }); - audio_updating = false; - } + function audio_loadedmetadata_handler() { + audio_updating = true; + component.set({ seekable: timeRangesToArray(audio.seekable) }); + audio_updating = false; + } - function audio_loadedmetadata_handler() { - audio_updating = true; - component.set({ seekable: timeRangesToArray(audio.seekable) }); - audio_updating = false; - } + function audio_timeupdate_handler() { + audio_updating = true; + component.set({ played: timeRangesToArray(audio.played) }); + audio_updating = false; + } - function audio_timeupdate_handler() { - audio_updating = true; - component.set({ played: timeRangesToArray(audio.played) }); - audio_updating = false; - } + function audio_timeupdate_handler_1() { + audio_updating = true; + cancelAnimationFrame(audio_animationframe); + if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler_1); + component.set({ currentTime: audio.currentTime }); + audio_updating = false; + } - function audio_timeupdate_handler_1() { - audio_updating = true; - cancelAnimationFrame(audio_animationframe); - if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler_1); - component.set({ currentTime: audio.currentTime }); - audio_updating = false; - } + function audio_durationchange_handler() { + audio_updating = true; + component.set({ duration: audio.duration }); + audio_updating = false; + } - function audio_durationchange_handler() { - audio_updating = true; - component.set({ duration: audio.duration }); - audio_updating = false; - } + function audio_pause_handler() { + audio_updating = true; + component.set({ paused: audio.paused }); + audio_updating = false; + } - function audio_pause_handler() { - audio_updating = true; - component.set({ paused: audio.paused }); - audio_updating = false; - } + return { + create: function() { + audio = createElement("audio"); + addListener(audio, "play", audio_pause_handler); + this.hydrate(); + }, - return { - create: function() { - audio = createElement("audio"); - addListener(audio, "play", audio_pause_handler); - this.hydrate(); - }, + hydrate: function() { + component._root._beforecreate.push(audio_progress_loadedmetadata_handler); - hydrate: function() { - component._root._beforecreate.push(audio_progress_loadedmetadata_handler); + addListener(audio, "progress", audio_progress_loadedmetadata_handler); + addListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); - addListener(audio, "progress", audio_progress_loadedmetadata_handler); - addListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); + component._root._beforecreate.push(audio_loadedmetadata_handler); - component._root._beforecreate.push(audio_loadedmetadata_handler); + addListener(audio, "loadedmetadata", audio_loadedmetadata_handler); - addListener(audio, "loadedmetadata", audio_loadedmetadata_handler); + component._root._beforecreate.push(audio_timeupdate_handler); - component._root._beforecreate.push(audio_timeupdate_handler); + addListener(audio, "timeupdate", audio_timeupdate_handler); - addListener(audio, "timeupdate", audio_timeupdate_handler); + component._root._beforecreate.push(audio_timeupdate_handler_1); - component._root._beforecreate.push(audio_timeupdate_handler_1); + addListener(audio, "timeupdate", audio_timeupdate_handler_1); - addListener(audio, "timeupdate", audio_timeupdate_handler_1); + component._root._beforecreate.push(audio_durationchange_handler); - component._root._beforecreate.push(audio_durationchange_handler); + addListener(audio, "durationchange", audio_durationchange_handler); - addListener(audio, "durationchange", audio_durationchange_handler); + component._root._beforecreate.push(audio_pause_handler); - component._root._beforecreate.push(audio_pause_handler); + addListener(audio, "pause", audio_pause_handler); + }, - addListener(audio, "pause", audio_pause_handler); - }, + mount: function(target, anchor) { + insertNode(audio, target, anchor); + }, - mount: function(target, anchor) { - insertNode(audio, target, anchor); - }, + update: function(changed, state) { + if (!audio_updating && !isNaN(state.currentTime )) { + audio.currentTime = state.currentTime ; + } - update: function(changed, state) { - if (!audio_updating && !isNaN(state.currentTime )) { - audio.currentTime = state.currentTime ; - } + if (audio_paused_value !== (audio_paused_value = state.paused)) { + audio[audio_paused_value ? "pause" : "play"](); + } + }, + + unmount: function() { + detachNode(audio); + }, - if (audio_paused_value !== (audio_paused_value = state.paused)) { - audio[audio_paused_value ? "pause" : "play"](); + destroy: function() { + removeListener(audio, "progress", audio_progress_loadedmetadata_handler); + removeListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); + removeListener(audio, "loadedmetadata", audio_loadedmetadata_handler); + removeListener(audio, "timeupdate", audio_timeupdate_handler); + removeListener(audio, "timeupdate", audio_timeupdate_handler_1); + removeListener(audio, "durationchange", audio_durationchange_handler); + removeListener(audio, "pause", audio_pause_handler); + removeListener(audio, "play", audio_pause_handler); } - }, - - unmount: function() { - detachNode(audio); - }, - - destroy: function() { - removeListener(audio, "progress", audio_progress_loadedmetadata_handler); - removeListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); - removeListener(audio, "loadedmetadata", audio_loadedmetadata_handler); - removeListener(audio, "timeupdate", audio_timeupdate_handler); - removeListener(audio, "timeupdate", audio_timeupdate_handler_1); - removeListener(audio, "durationchange", audio_durationchange_handler); - removeListener(audio, "pause", audio_pause_handler); - removeListener(audio, "play", audio_pause_handler); - } - }; -} + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - callAll(this._beforecreate); + callAll(this._beforecreate); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index fc12b914c3..b7d7221469 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,135 +1,132 @@ /* generated by Svelte vX.Y.Z */ import { addListener, assign, callAll, createElement, detachNode, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; - export default (function() { + function create_main_fragment(state, component) { + var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; -function create_main_fragment(state, component) { - var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; + function audio_progress_loadedmetadata_handler() { + audio_updating = true; + component.set({ buffered: timeRangesToArray(audio.buffered) }); + audio_updating = false; + } - function audio_progress_loadedmetadata_handler() { - audio_updating = true; - component.set({ buffered: timeRangesToArray(audio.buffered) }); - audio_updating = false; - } + function audio_loadedmetadata_handler() { + audio_updating = true; + component.set({ seekable: timeRangesToArray(audio.seekable) }); + audio_updating = false; + } - function audio_loadedmetadata_handler() { - audio_updating = true; - component.set({ seekable: timeRangesToArray(audio.seekable) }); - audio_updating = false; - } + function audio_timeupdate_handler() { + audio_updating = true; + component.set({ played: timeRangesToArray(audio.played) }); + audio_updating = false; + } - function audio_timeupdate_handler() { - audio_updating = true; - component.set({ played: timeRangesToArray(audio.played) }); - audio_updating = false; - } + function audio_timeupdate_handler_1() { + audio_updating = true; + cancelAnimationFrame(audio_animationframe); + if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler_1); + component.set({ currentTime: audio.currentTime }); + audio_updating = false; + } - function audio_timeupdate_handler_1() { - audio_updating = true; - cancelAnimationFrame(audio_animationframe); - if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler_1); - component.set({ currentTime: audio.currentTime }); - audio_updating = false; - } + function audio_durationchange_handler() { + audio_updating = true; + component.set({ duration: audio.duration }); + audio_updating = false; + } - function audio_durationchange_handler() { - audio_updating = true; - component.set({ duration: audio.duration }); - audio_updating = false; - } + function audio_pause_handler() { + audio_updating = true; + component.set({ paused: audio.paused }); + audio_updating = false; + } - function audio_pause_handler() { - audio_updating = true; - component.set({ paused: audio.paused }); - audio_updating = false; - } + return { + create: function() { + audio = createElement("audio"); + addListener(audio, "play", audio_pause_handler); + this.hydrate(); + }, - return { - create: function() { - audio = createElement("audio"); - addListener(audio, "play", audio_pause_handler); - this.hydrate(); - }, + hydrate: function() { + component._root._beforecreate.push(audio_progress_loadedmetadata_handler); - hydrate: function() { - component._root._beforecreate.push(audio_progress_loadedmetadata_handler); + addListener(audio, "progress", audio_progress_loadedmetadata_handler); + addListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); - addListener(audio, "progress", audio_progress_loadedmetadata_handler); - addListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); + component._root._beforecreate.push(audio_loadedmetadata_handler); - component._root._beforecreate.push(audio_loadedmetadata_handler); + addListener(audio, "loadedmetadata", audio_loadedmetadata_handler); - addListener(audio, "loadedmetadata", audio_loadedmetadata_handler); + component._root._beforecreate.push(audio_timeupdate_handler); - component._root._beforecreate.push(audio_timeupdate_handler); + addListener(audio, "timeupdate", audio_timeupdate_handler); - addListener(audio, "timeupdate", audio_timeupdate_handler); + component._root._beforecreate.push(audio_timeupdate_handler_1); - component._root._beforecreate.push(audio_timeupdate_handler_1); + addListener(audio, "timeupdate", audio_timeupdate_handler_1); - addListener(audio, "timeupdate", audio_timeupdate_handler_1); + component._root._beforecreate.push(audio_durationchange_handler); - component._root._beforecreate.push(audio_durationchange_handler); + addListener(audio, "durationchange", audio_durationchange_handler); - addListener(audio, "durationchange", audio_durationchange_handler); + component._root._beforecreate.push(audio_pause_handler); - component._root._beforecreate.push(audio_pause_handler); + addListener(audio, "pause", audio_pause_handler); + }, - addListener(audio, "pause", audio_pause_handler); - }, + mount: function(target, anchor) { + insertNode(audio, target, anchor); + }, - mount: function(target, anchor) { - insertNode(audio, target, anchor); - }, + update: function(changed, state) { + if (!audio_updating && !isNaN(state.currentTime )) { + audio.currentTime = state.currentTime ; + } - update: function(changed, state) { - if (!audio_updating && !isNaN(state.currentTime )) { - audio.currentTime = state.currentTime ; - } + if (audio_paused_value !== (audio_paused_value = state.paused)) { + audio[audio_paused_value ? "pause" : "play"](); + } + }, - if (audio_paused_value !== (audio_paused_value = state.paused)) { - audio[audio_paused_value ? "pause" : "play"](); + unmount: function() { + detachNode(audio); + }, + + destroy: function() { + removeListener(audio, "progress", audio_progress_loadedmetadata_handler); + removeListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); + removeListener(audio, "loadedmetadata", audio_loadedmetadata_handler); + removeListener(audio, "timeupdate", audio_timeupdate_handler); + removeListener(audio, "timeupdate", audio_timeupdate_handler_1); + removeListener(audio, "durationchange", audio_durationchange_handler); + removeListener(audio, "pause", audio_pause_handler); + removeListener(audio, "play", audio_pause_handler); } - }, - - unmount: function() { - detachNode(audio); - }, - - destroy: function() { - removeListener(audio, "progress", audio_progress_loadedmetadata_handler); - removeListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); - removeListener(audio, "loadedmetadata", audio_loadedmetadata_handler); - removeListener(audio, "timeupdate", audio_timeupdate_handler); - removeListener(audio, "timeupdate", audio_timeupdate_handler_1); - removeListener(audio, "durationchange", audio_durationchange_handler); - removeListener(audio, "pause", audio_pause_handler); - removeListener(audio, "play", audio_pause_handler); - } - }; -} + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - callAll(this._beforecreate); + callAll(this._beforecreate); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index d60db003bf..443850a62a 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -181,8 +181,7 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -var template = (function() { + var template = (function() { return { components: { NonImported @@ -190,72 +189,71 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { - var text; - - var imported = new Imported({ - _root: component._root - }); + function create_main_fragment(state, component) { + var text; + + var imported = new Imported({ + _root: component._root + }); + + var nonimported = new template.components.NonImported({ + _root: component._root + }); + + return { + create: function() { + imported._fragment.create(); + text = createText("\n"); + nonimported._fragment.create(); + }, + + mount: function(target, anchor) { + imported._mount(target, anchor); + insertNode(text, target, anchor); + nonimported._mount(target, anchor); + }, + + update: noop, + + unmount: function() { + imported._unmount(); + detachNode(text); + nonimported._unmount(); + }, + + destroy: function() { + imported.destroy(false); + nonimported.destroy(false); + } + }; + } - var nonimported = new template.components.NonImported({ - _root: component._root - }); + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - return { - create: function() { - imported._fragment.create(); - text = createText("\n"); - nonimported._fragment.create(); - }, - - mount: function(target, anchor) { - imported._mount(target, anchor); - insertNode(text, target, anchor); - nonimported._mount(target, anchor); - }, - - update: noop, - - unmount: function() { - imported._unmount(); - detachNode(text); - nonimported._unmount(); - }, - - destroy: function() { - imported.destroy(false); - nonimported.destroy(false); + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; } - }; -} -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + this._fragment = create_main_fragment(this._state, this); - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - this._aftercreate = []; - } - - this._fragment = create_main_fragment(this._state, this); - - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - this._lock = true; - callAll(this._beforecreate); - callAll(this._oncreate); - callAll(this._aftercreate); - this._lock = false; + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index 8d8759c059..eec42a057e 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -3,8 +3,7 @@ import { assign, callAll, createText, detachNode, init, insertNode, noop, proto import Imported from 'Imported.html'; export default (function() { - -var template = (function() { + var template = (function() { return { components: { NonImported @@ -12,70 +11,69 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { - var text; - - var imported = new Imported({ - _root: component._root - }); - - var nonimported = new template.components.NonImported({ - _root: component._root - }); - - return { - create: function() { - imported._fragment.create(); - text = createText("\n"); - nonimported._fragment.create(); - }, - - mount: function(target, anchor) { - imported._mount(target, anchor); - insertNode(text, target, anchor); - nonimported._mount(target, anchor); - }, - - update: noop, + function create_main_fragment(state, component) { + var text; + + var imported = new Imported({ + _root: component._root + }); + + var nonimported = new template.components.NonImported({ + _root: component._root + }); + + return { + create: function() { + imported._fragment.create(); + text = createText("\n"); + nonimported._fragment.create(); + }, + + mount: function(target, anchor) { + imported._mount(target, anchor); + insertNode(text, target, anchor); + nonimported._mount(target, anchor); + }, + + update: noop, + + unmount: function() { + imported._unmount(); + detachNode(text); + nonimported._unmount(); + }, + + destroy: function() { + imported.destroy(false); + nonimported.destroy(false); + } + }; + } - unmount: function() { - imported._unmount(); - detachNode(text); - nonimported._unmount(); - }, + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - destroy: function() { - imported.destroy(false); - nonimported.destroy(false); + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; } - }; -} -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; - - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - this._aftercreate = []; - } + this._fragment = create_main_fragment(this._state, this); - this._fragment = create_main_fragment(this._state, this); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - - this._lock = true; - callAll(this._beforecreate); - callAll(this._oncreate); - callAll(this._aftercreate); - this._lock = false; + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 058818d6d5..510a76cf31 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -167,8 +167,7 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -var template = (function() { + var template = (function() { return { // this test should be removed in v2 oncreate () {}, @@ -176,48 +175,47 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { + function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._handlers.destroy = [template.ondestroy]; + this._handlers.destroy = [template.ondestroy]; - var oncreate = template.oncreate.bind(this); + var oncreate = template.oncreate.bind(this); - if (!options._root) { - this._oncreate = [oncreate]; - } else { - this._root._oncreate.push(oncreate); - } + if (!options._root) { + this._oncreate = [oncreate]; + } else { + this._root._oncreate.push(oncreate); + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - callAll(this._oncreate); + callAll(this._oncreate); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index fb02f55421..ba5c4a62ea 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,10 +1,8 @@ /* generated by Svelte vX.Y.Z */ import { assign, callAll, init, noop, proto } from "svelte/shared.js"; - export default (function() { - -var template = (function() { + var template = (function() { return { // this test should be removed in v2 oncreate () {}, @@ -12,46 +10,45 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { + function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._handlers.destroy = [template.ondestroy] + this._handlers.destroy = [template.ondestroy] - var oncreate = template.oncreate.bind(this); + var oncreate = template.oncreate.bind(this); - if (!options._root) { - this._oncreate = [oncreate]; - } else { - this._root._oncreate.push(oncreate); - } + if (!options._root) { + this._oncreate = [oncreate]; + } else { + this._root._oncreate.push(oncreate); + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - callAll(this._oncreate); + callAll(this._oncreate); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 1786cee000..5b90eb1f6a 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -167,8 +167,7 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -var template = (function() { + var template = (function() { return { methods: { foo ( bar ) { @@ -187,38 +186,37 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { + function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, template.methods, proto); -template.setup(SvelteComponent); + assign(SvelteComponent.prototype, template.methods, proto); -return SvelteComponent; + template.setup(SvelteComponent); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 009b432695..8207a4ea6e 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,10 +1,8 @@ /* generated by Svelte vX.Y.Z */ import { assign, init, noop, proto } from "svelte/shared.js"; - export default (function() { - -var template = (function() { + var template = (function() { return { methods: { foo ( bar ) { @@ -23,36 +21,35 @@ var template = (function() { }; }()); -function create_main_fragment(state, component) { + function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, template.methods, proto); -template.setup(SvelteComponent); + assign(SvelteComponent.prototype, template.methods, proto); -return SvelteComponent; + template.setup(SvelteComponent); + return SvelteComponent; }()); \ No newline at end of file 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 b3fabc750c..8d7482a7b7 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -191,274 +191,272 @@ var proto = { /* generated by Svelte vX.Y.Z */ var _actual = (function() { - -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; - - var if_block = (state.a) && create_if_block(state, component); - - var if_block_1 = (state.b) && create_if_block_1(state, component); - - var if_block_2 = (state.c) && create_if_block_2(state, component); - - var if_block_3 = (state.d) && create_if_block_3(state, component); - - var if_block_4 = (state.e) && create_if_block_4(state, component); - - return { - create: function() { - div = createElement("div"); - if (if_block) if_block.create(); - text = createText("\n\n\t"); - p = createElement("p"); - text_1 = createText("this can be used as an anchor"); - text_2 = createText("\n\n\t"); - if (if_block_1) if_block_1.create(); - text_3 = createText("\n\n\t"); - if (if_block_2) if_block_2.create(); - text_4 = createText("\n\n\t"); - p_1 = createElement("p"); - text_5 = createText("so can this"); - text_6 = createText("\n\n\t"); - if (if_block_3) if_block_3.create(); - text_8 = createText("\n\n"); - if (if_block_4) if_block_4.create(); - if_block_4_anchor = createComment(); - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - if (if_block) if_block.mount(div, null); - appendNode(text, div); - appendNode(p, div); - appendNode(text_1, p); - appendNode(text_2, div); - if (if_block_1) if_block_1.mount(div, null); - appendNode(text_3, div); - if (if_block_2) if_block_2.mount(div, null); - appendNode(text_4, div); - appendNode(p_1, div); - appendNode(text_5, p_1); - appendNode(text_6, div); - if (if_block_3) if_block_3.mount(div, null); - insertNode(text_8, target, anchor); - if (if_block_4) if_block_4.mount(target, anchor); - insertNode(if_block_4_anchor, target, anchor); - }, - - update: function(changed, state) { - if (state.a) { - if (!if_block) { - if_block = create_if_block(state, component); - if_block.create(); - if_block.mount(div, text); + 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; + + var if_block = (state.a) && create_if_block(state, component); + + var if_block_1 = (state.b) && create_if_block_1(state, component); + + var if_block_2 = (state.c) && create_if_block_2(state, component); + + var if_block_3 = (state.d) && create_if_block_3(state, component); + + var if_block_4 = (state.e) && create_if_block_4(state, component); + + return { + create: function() { + div = createElement("div"); + if (if_block) if_block.create(); + text = createText("\n\n\t"); + p = createElement("p"); + text_1 = createText("this can be used as an anchor"); + text_2 = createText("\n\n\t"); + if (if_block_1) if_block_1.create(); + text_3 = createText("\n\n\t"); + if (if_block_2) if_block_2.create(); + text_4 = createText("\n\n\t"); + p_1 = createElement("p"); + text_5 = createText("so can this"); + text_6 = createText("\n\n\t"); + if (if_block_3) if_block_3.create(); + text_8 = createText("\n\n"); + if (if_block_4) if_block_4.create(); + if_block_4_anchor = createComment(); + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + if (if_block) if_block.mount(div, null); + appendNode(text, div); + appendNode(p, div); + appendNode(text_1, p); + appendNode(text_2, div); + if (if_block_1) if_block_1.mount(div, null); + appendNode(text_3, div); + if (if_block_2) if_block_2.mount(div, null); + appendNode(text_4, div); + appendNode(p_1, div); + appendNode(text_5, p_1); + appendNode(text_6, div); + if (if_block_3) if_block_3.mount(div, null); + insertNode(text_8, target, anchor); + if (if_block_4) if_block_4.mount(target, anchor); + insertNode(if_block_4_anchor, target, anchor); + }, + + update: function(changed, state) { + if (state.a) { + if (!if_block) { + if_block = create_if_block(state, component); + if_block.create(); + if_block.mount(div, text); + } + } else if (if_block) { + if_block.unmount(); + if_block.destroy(); + if_block = null; } - } else if (if_block) { - if_block.unmount(); - if_block.destroy(); - if_block = null; - } - if (state.b) { - if (!if_block_1) { - if_block_1 = create_if_block_1(state, component); - if_block_1.create(); - if_block_1.mount(div, text_3); + if (state.b) { + if (!if_block_1) { + if_block_1 = create_if_block_1(state, component); + if_block_1.create(); + if_block_1.mount(div, text_3); + } + } else if (if_block_1) { + if_block_1.unmount(); + if_block_1.destroy(); + if_block_1 = null; } - } else if (if_block_1) { - if_block_1.unmount(); - if_block_1.destroy(); - if_block_1 = null; - } - if (state.c) { - if (!if_block_2) { - if_block_2 = create_if_block_2(state, component); - if_block_2.create(); - if_block_2.mount(div, text_4); + if (state.c) { + if (!if_block_2) { + if_block_2 = create_if_block_2(state, component); + if_block_2.create(); + if_block_2.mount(div, text_4); + } + } else if (if_block_2) { + if_block_2.unmount(); + if_block_2.destroy(); + if_block_2 = null; } - } else if (if_block_2) { - if_block_2.unmount(); - if_block_2.destroy(); - if_block_2 = null; - } - if (state.d) { - if (!if_block_3) { - if_block_3 = create_if_block_3(state, component); - if_block_3.create(); - if_block_3.mount(div, null); + if (state.d) { + if (!if_block_3) { + if_block_3 = create_if_block_3(state, component); + if_block_3.create(); + if_block_3.mount(div, null); + } + } else if (if_block_3) { + if_block_3.unmount(); + if_block_3.destroy(); + if_block_3 = null; } - } else if (if_block_3) { - if_block_3.unmount(); - if_block_3.destroy(); - if_block_3 = null; - } - if (state.e) { - if (!if_block_4) { - if_block_4 = create_if_block_4(state, component); - if_block_4.create(); - if_block_4.mount(if_block_4_anchor.parentNode, if_block_4_anchor); + if (state.e) { + if (!if_block_4) { + if_block_4 = create_if_block_4(state, component); + if_block_4.create(); + if_block_4.mount(if_block_4_anchor.parentNode, if_block_4_anchor); + } + } else if (if_block_4) { + if_block_4.unmount(); + if_block_4.destroy(); + if_block_4 = null; } - } else if (if_block_4) { - if_block_4.unmount(); - if_block_4.destroy(); - if_block_4 = null; + }, + + unmount: function() { + detachNode(div); + if (if_block) if_block.unmount(); + if (if_block_1) if_block_1.unmount(); + if (if_block_2) if_block_2.unmount(); + if (if_block_3) if_block_3.unmount(); + detachNode(text_8); + if (if_block_4) if_block_4.unmount(); + detachNode(if_block_4_anchor); + }, + + destroy: function() { + if (if_block) if_block.destroy(); + if (if_block_1) if_block_1.destroy(); + if (if_block_2) if_block_2.destroy(); + if (if_block_3) if_block_3.destroy(); + if (if_block_4) if_block_4.destroy(); } - }, - - unmount: function() { - detachNode(div); - if (if_block) if_block.unmount(); - if (if_block_1) if_block_1.unmount(); - if (if_block_2) if_block_2.unmount(); - if (if_block_3) if_block_3.unmount(); - detachNode(text_8); - if (if_block_4) if_block_4.unmount(); - detachNode(if_block_4_anchor); - }, - - destroy: function() { - if (if_block) if_block.destroy(); - if (if_block_1) if_block_1.destroy(); - if (if_block_2) if_block_2.destroy(); - if (if_block_3) if_block_3.destroy(); - if (if_block_4) if_block_4.destroy(); - } - }; -} + }; + } -// (2:1) {{#if a}} -function create_if_block(state, component) { - var p, text; + // (2:1) {{#if a}} + function create_if_block(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("a"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("a"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -// (8:1) {{#if b}} -function create_if_block_1(state, component) { - var p, text; + // (8:1) {{#if b}} + function create_if_block_1(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("b"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("b"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -// (12:1) {{#if c}} -function create_if_block_2(state, component) { - var p, text; + // (12:1) {{#if c}} + function create_if_block_2(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("c"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("c"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -// (18:1) {{#if d}} -function create_if_block_3(state, component) { - var p, text; + // (18:1) {{#if d}} + function create_if_block_3(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("d"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("d"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -// (25:0) {{#if e}} -function create_if_block_4(state, component) { - var p, text; + // (25:0) {{#if e}} + function create_if_block_4(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("e"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("e"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; -} + destroy: noop + }; + } -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } } -} - -assign(SvelteComponent.prototype, proto); -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); export default _actual; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 4565988e2d..35db8336d6 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,274 +1,271 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; - export default (function() { - -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; - - var if_block = (state.a) && create_if_block(state, component); - - var if_block_1 = (state.b) && create_if_block_1(state, component); - - var if_block_2 = (state.c) && create_if_block_2(state, component); - - var if_block_3 = (state.d) && create_if_block_3(state, component); - - var if_block_4 = (state.e) && create_if_block_4(state, component); - - return { - create: function() { - div = createElement("div"); - if (if_block) if_block.create(); - text = createText("\n\n\t"); - p = createElement("p"); - text_1 = createText("this can be used as an anchor"); - text_2 = createText("\n\n\t"); - if (if_block_1) if_block_1.create(); - text_3 = createText("\n\n\t"); - if (if_block_2) if_block_2.create(); - text_4 = createText("\n\n\t"); - p_1 = createElement("p"); - text_5 = createText("so can this"); - text_6 = createText("\n\n\t"); - if (if_block_3) if_block_3.create(); - text_8 = createText("\n\n"); - if (if_block_4) if_block_4.create(); - if_block_4_anchor = createComment(); - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - if (if_block) if_block.mount(div, null); - appendNode(text, div); - appendNode(p, div); - appendNode(text_1, p); - appendNode(text_2, div); - if (if_block_1) if_block_1.mount(div, null); - appendNode(text_3, div); - if (if_block_2) if_block_2.mount(div, null); - appendNode(text_4, div); - appendNode(p_1, div); - appendNode(text_5, p_1); - appendNode(text_6, div); - if (if_block_3) if_block_3.mount(div, null); - insertNode(text_8, target, anchor); - if (if_block_4) if_block_4.mount(target, anchor); - insertNode(if_block_4_anchor, target, anchor); - }, - - update: function(changed, state) { - if (state.a) { - if (!if_block) { - if_block = create_if_block(state, component); - if_block.create(); - if_block.mount(div, text); + 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; + + var if_block = (state.a) && create_if_block(state, component); + + var if_block_1 = (state.b) && create_if_block_1(state, component); + + var if_block_2 = (state.c) && create_if_block_2(state, component); + + var if_block_3 = (state.d) && create_if_block_3(state, component); + + var if_block_4 = (state.e) && create_if_block_4(state, component); + + return { + create: function() { + div = createElement("div"); + if (if_block) if_block.create(); + text = createText("\n\n\t"); + p = createElement("p"); + text_1 = createText("this can be used as an anchor"); + text_2 = createText("\n\n\t"); + if (if_block_1) if_block_1.create(); + text_3 = createText("\n\n\t"); + if (if_block_2) if_block_2.create(); + text_4 = createText("\n\n\t"); + p_1 = createElement("p"); + text_5 = createText("so can this"); + text_6 = createText("\n\n\t"); + if (if_block_3) if_block_3.create(); + text_8 = createText("\n\n"); + if (if_block_4) if_block_4.create(); + if_block_4_anchor = createComment(); + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + if (if_block) if_block.mount(div, null); + appendNode(text, div); + appendNode(p, div); + appendNode(text_1, p); + appendNode(text_2, div); + if (if_block_1) if_block_1.mount(div, null); + appendNode(text_3, div); + if (if_block_2) if_block_2.mount(div, null); + appendNode(text_4, div); + appendNode(p_1, div); + appendNode(text_5, p_1); + appendNode(text_6, div); + if (if_block_3) if_block_3.mount(div, null); + insertNode(text_8, target, anchor); + if (if_block_4) if_block_4.mount(target, anchor); + insertNode(if_block_4_anchor, target, anchor); + }, + + update: function(changed, state) { + if (state.a) { + if (!if_block) { + if_block = create_if_block(state, component); + if_block.create(); + if_block.mount(div, text); + } + } else if (if_block) { + if_block.unmount(); + if_block.destroy(); + if_block = null; } - } else if (if_block) { - if_block.unmount(); - if_block.destroy(); - if_block = null; - } - if (state.b) { - if (!if_block_1) { - if_block_1 = create_if_block_1(state, component); - if_block_1.create(); - if_block_1.mount(div, text_3); + if (state.b) { + if (!if_block_1) { + if_block_1 = create_if_block_1(state, component); + if_block_1.create(); + if_block_1.mount(div, text_3); + } + } else if (if_block_1) { + if_block_1.unmount(); + if_block_1.destroy(); + if_block_1 = null; } - } else if (if_block_1) { - if_block_1.unmount(); - if_block_1.destroy(); - if_block_1 = null; - } - if (state.c) { - if (!if_block_2) { - if_block_2 = create_if_block_2(state, component); - if_block_2.create(); - if_block_2.mount(div, text_4); + if (state.c) { + if (!if_block_2) { + if_block_2 = create_if_block_2(state, component); + if_block_2.create(); + if_block_2.mount(div, text_4); + } + } else if (if_block_2) { + if_block_2.unmount(); + if_block_2.destroy(); + if_block_2 = null; } - } else if (if_block_2) { - if_block_2.unmount(); - if_block_2.destroy(); - if_block_2 = null; - } - if (state.d) { - if (!if_block_3) { - if_block_3 = create_if_block_3(state, component); - if_block_3.create(); - if_block_3.mount(div, null); + if (state.d) { + if (!if_block_3) { + if_block_3 = create_if_block_3(state, component); + if_block_3.create(); + if_block_3.mount(div, null); + } + } else if (if_block_3) { + if_block_3.unmount(); + if_block_3.destroy(); + if_block_3 = null; } - } else if (if_block_3) { - if_block_3.unmount(); - if_block_3.destroy(); - if_block_3 = null; - } - if (state.e) { - if (!if_block_4) { - if_block_4 = create_if_block_4(state, component); - if_block_4.create(); - if_block_4.mount(if_block_4_anchor.parentNode, if_block_4_anchor); + if (state.e) { + if (!if_block_4) { + if_block_4 = create_if_block_4(state, component); + if_block_4.create(); + if_block_4.mount(if_block_4_anchor.parentNode, if_block_4_anchor); + } + } else if (if_block_4) { + if_block_4.unmount(); + if_block_4.destroy(); + if_block_4 = null; } - } else if (if_block_4) { - if_block_4.unmount(); - if_block_4.destroy(); - if_block_4 = null; + }, + + unmount: function() { + detachNode(div); + if (if_block) if_block.unmount(); + if (if_block_1) if_block_1.unmount(); + if (if_block_2) if_block_2.unmount(); + if (if_block_3) if_block_3.unmount(); + detachNode(text_8); + if (if_block_4) if_block_4.unmount(); + detachNode(if_block_4_anchor); + }, + + destroy: function() { + if (if_block) if_block.destroy(); + if (if_block_1) if_block_1.destroy(); + if (if_block_2) if_block_2.destroy(); + if (if_block_3) if_block_3.destroy(); + if (if_block_4) if_block_4.destroy(); } - }, - - unmount: function() { - detachNode(div); - if (if_block) if_block.unmount(); - if (if_block_1) if_block_1.unmount(); - if (if_block_2) if_block_2.unmount(); - if (if_block_3) if_block_3.unmount(); - detachNode(text_8); - if (if_block_4) if_block_4.unmount(); - detachNode(if_block_4_anchor); - }, - - destroy: function() { - if (if_block) if_block.destroy(); - if (if_block_1) if_block_1.destroy(); - if (if_block_2) if_block_2.destroy(); - if (if_block_3) if_block_3.destroy(); - if (if_block_4) if_block_4.destroy(); - } - }; -} - -// (2:1) {{#if a}} -function create_if_block(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("a"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; -} - -// (8:1) {{#if b}} -function create_if_block_1(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("b"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; -} - -// (12:1) {{#if c}} -function create_if_block_2(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("c"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; -} - -// (18:1) {{#if d}} -function create_if_block_3(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("d"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; -} - -// (25:0) {{#if e}} -function create_if_block_4(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("e"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; -} - -function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; - - this._fragment = create_main_fragment(this._state, this); - - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + }; } -} -assign(SvelteComponent.prototype, proto); + // (2:1) {{#if a}} + function create_if_block(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("a"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; + } + + // (8:1) {{#if b}} + function create_if_block_1(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("b"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; + } + + // (12:1) {{#if c}} + function create_if_block_2(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("c"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; + } + + // (18:1) {{#if d}} + function create_if_block_3(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("d"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; + } + + // (25:0) {{#if e}} + function create_if_block_4(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("e"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; + } + + function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + } + } -return SvelteComponent; + assign(SvelteComponent.prototype, proto); + return SvelteComponent; }()); \ No newline at end of file From dabc2d1fdfce646b7609c19a190fa27c58466040 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 19 Sep 2017 11:00:55 -0400 Subject: [PATCH 7/8] dont wrap ESM in IIFE --- src/generators/shared/utils/wrapModule.ts | 6 +- .../expected-bundle.js | 109 ++-- .../expected.js | 96 ++-- .../component-static/expected-bundle.js | 87 ++- test/js/samples/component-static/expected.js | 86 ++- .../computed-collapsed-if/expected-bundle.js | 57 +- .../samples/computed-collapsed-if/expected.js | 54 +- .../css-media-query/expected-bundle.js | 83 ++- test/js/samples/css-media-query/expected.js | 82 ++- .../expected-bundle.js | 95 ++-- .../css-shadow-dom-keyframes/expected.js | 94 ++-- .../expected-bundle.js | 251 +++++---- .../each-block-changed-check/expected.js | 252 +++++---- .../event-handlers-custom/expected-bundle.js | 79 ++- .../samples/event-handlers-custom/expected.js | 78 ++- .../if-block-no-update/expected-bundle.js | 167 +++--- .../js/samples/if-block-no-update/expected.js | 188 ++++--- .../if-block-simple/expected-bundle.js | 133 +++-- test/js/samples/if-block-simple/expected.js | 132 +++-- .../expected-bundle.js | 83 ++- .../expected.js | 84 ++- .../expected-bundle.js | 71 ++- .../inline-style-optimized-url/expected.js | 70 ++- .../inline-style-optimized/expected-bundle.js | 71 ++- .../inline-style-optimized/expected.js | 70 ++- .../expected-bundle.js | 103 ++-- .../inline-style-unoptimized/expected.js | 102 ++-- .../expected-bundle.js | 81 ++- .../input-without-blowback-guard/expected.js | 80 ++- .../legacy-input-type/expected-bundle.js | 63 ++- test/js/samples/legacy-input-type/expected.js | 62 ++- .../legacy-quote-class/expected-bundle.js | 79 ++- .../js/samples/legacy-quote-class/expected.js | 78 ++- .../samples/media-bindings/expected-bundle.js | 197 ++++--- test/js/samples/media-bindings/expected.js | 196 ++++--- .../non-imported-component/expected-bundle.js | 119 ++-- .../non-imported-component/expected.js | 106 ++-- .../expected-bundle.js | 59 +- .../onrender-onteardown-rewritten/expected.js | 58 +- .../samples/setup-method/expected-bundle.js | 45 +- test/js/samples/setup-method/expected.js | 44 +- .../expected-bundle.js | 455 ++++++++-------- .../use-elements-as-anchors/expected.js | 508 +++++++++--------- test/runtime/index.js | 2 +- 44 files changed, 2454 insertions(+), 2561 deletions(-) diff --git a/src/generators/shared/utils/wrapModule.ts b/src/generators/shared/utils/wrapModule.ts index 18d295ea25..77fea53446 100644 --- a/src/generators/shared/utils/wrapModule.ts +++ b/src/generators/shared/utils/wrapModule.ts @@ -93,10 +93,8 @@ function es( ${importHelpers} ${importBlock} - export default (function() { - ${code} - return ${name}; - }());`; + ${code} + export default ${name};`; } function amd( 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 972c8bad71..5d44708a27 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -190,8 +190,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - var template = (function() { +var template = (function() { return { data: function () { return { foo: 42 } @@ -199,66 +198,64 @@ var _actual = (function() { }; }()); - function encapsulateStyles(node) { - setAttribute(node, "svelte-3590263702", ""); - } +function encapsulateStyles(node) { + setAttribute(node, "svelte-3590263702", ""); +} - function add_css() { - var style = createElement("style"); - style.id = 'svelte-3590263702-style'; - style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; - appendNode(style, document.head); - } +function add_css() { + var style = createElement("style"); + style.id = 'svelte-3590263702-style'; + style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; + appendNode(style, document.head); +} - function create_main_fragment(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText(state.foo); - this.hydrate(); - }, - - hydrate: function() { - encapsulateStyles(p); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - update: function(changed, state) { - if (changed.foo) { - text.data = state.foo; - } - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; - } +function create_main_fragment(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText(state.foo); + this.hydrate(); + }, + + hydrate: function() { + encapsulateStyles(p); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + update: function(changed, state) { + if (changed.foo) { + text.data = state.foo; + } + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = assign(template.data(), options.data); +function SvelteComponent(options) { + init(this, options); + this._state = assign(template.data(), options.data); - if (!document.getElementById("svelte-3590263702-style")) add_css(); + if (!document.getElementById("svelte-3590263702-style")) add_css(); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js index 2ef55026da..83841b4eb8 100644 --- a/test/js/samples/collapses-text-around-comments/expected.js +++ b/test/js/samples/collapses-text-around-comments/expected.js @@ -1,8 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; -export default (function() { - var template = (function() { +var template = (function() { return { data: function () { return { foo: 42 } @@ -10,64 +9,63 @@ export default (function() { }; }()); - function encapsulateStyles(node) { - setAttribute(node, "svelte-3590263702", ""); - } +function encapsulateStyles(node) { + setAttribute(node, "svelte-3590263702", ""); +} - function add_css() { - var style = createElement("style"); - style.id = 'svelte-3590263702-style'; - style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; - appendNode(style, document.head); - } +function add_css() { + var style = createElement("style"); + style.id = 'svelte-3590263702-style'; + style.textContent = "p[svelte-3590263702],[svelte-3590263702] p{color:red}"; + appendNode(style, document.head); +} - function create_main_fragment(state, component) { - var p, text; +function create_main_fragment(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText(state.foo); - this.hydrate(); - }, + return { + create: function() { + p = createElement("p"); + text = createText(state.foo); + this.hydrate(); + }, - hydrate: function() { - encapsulateStyles(p); - }, + hydrate: function() { + encapsulateStyles(p); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - update: function(changed, state) { - if (changed.foo) { - text.data = state.foo; - } - }, + update: function(changed, state) { + if (changed.foo) { + text.data = state.foo; + } + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = assign(template.data(), options.data); +function SvelteComponent(options) { + init(this, options); + this._state = assign(template.data(), options.data); - if (!document.getElementById("svelte-3590263702-style")) add_css(); + if (!document.getElementById("svelte-3590263702-style")) add_css(); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/component-static/expected-bundle.js b/test/js/samples/component-static/expected-bundle.js index 6b3d6488d1..a9769110cb 100644 --- a/test/js/samples/component-static/expected-bundle.js +++ b/test/js/samples/component-static/expected-bundle.js @@ -166,8 +166,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - var template = (function() { +var template = (function() { return { components: { Nested: window.Nested @@ -175,60 +174,58 @@ var _actual = (function() { }; }()); - function create_main_fragment(state, component) { +function create_main_fragment(state, component) { - var nested = new template.components.Nested({ - _root: component._root, - data: { foo: "bar" } - }); + var nested = new template.components.Nested({ + _root: component._root, + data: { foo: "bar" } + }); - return { - create: function() { - nested._fragment.create(); - }, + return { + create: function() { + nested._fragment.create(); + }, - mount: function(target, anchor) { - nested._mount(target, anchor); - }, + mount: function(target, anchor) { + nested._mount(target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - nested._unmount(); - }, + unmount: function() { + nested._unmount(); + }, - destroy: function() { - nested.destroy(false); - } - }; - } + destroy: function() { + nested.destroy(false); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - this._aftercreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - this._lock = true; - callAll(this._beforecreate); - callAll(this._oncreate); - callAll(this._aftercreate); - this._lock = false; - } + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/component-static/expected.js b/test/js/samples/component-static/expected.js index e91a5f1db2..8a22292037 100644 --- a/test/js/samples/component-static/expected.js +++ b/test/js/samples/component-static/expected.js @@ -1,8 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { assign, callAll, init, noop, proto } from "svelte/shared.js"; -export default (function() { - var template = (function() { +var template = (function() { return { components: { Nested: window.Nested @@ -10,58 +9,57 @@ export default (function() { }; }()); - function create_main_fragment(state, component) { +function create_main_fragment(state, component) { - var nested = new template.components.Nested({ - _root: component._root, - data: { foo: "bar" } - }); + var nested = new template.components.Nested({ + _root: component._root, + data: { foo: "bar" } + }); - return { - create: function() { - nested._fragment.create(); - }, + return { + create: function() { + nested._fragment.create(); + }, - mount: function(target, anchor) { - nested._mount(target, anchor); - }, + mount: function(target, anchor) { + nested._mount(target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - nested._unmount(); - }, + unmount: function() { + nested._unmount(); + }, - destroy: function() { - nested.destroy(false); - } - }; - } + destroy: function() { + nested.destroy(false); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - this._aftercreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - this._lock = true; - callAll(this._beforecreate); - callAll(this._oncreate); - callAll(this._aftercreate); - this._lock = false; - } + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 2e8615f001..e6e9152b1e 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -166,8 +166,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - var template = (function() { +var template = (function() { return { computed: { a: x => x * 2, @@ -176,43 +175,41 @@ var _actual = (function() { }; }()); - function create_main_fragment(state, component) { +function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; - this._recompute({ x: 1 }, this._state); +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + this._recompute({ x: 1 }, this._state); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); +assign(SvelteComponent.prototype, proto); - SvelteComponent.prototype._recompute = function _recompute(changed, state) { - if (changed.x) { - if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; - if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; - } - }; - return SvelteComponent; -}()); +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.x) { + if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; + if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; + } +}; -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 5d4313c10e..7b9207a955 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -1,8 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { assign, differs, init, noop, proto } from "svelte/shared.js"; -export default (function() { - var template = (function() { +var template = (function() { return { computed: { a: x => x * 2, @@ -11,41 +10,40 @@ export default (function() { }; }()); - function create_main_fragment(state, component) { +function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; - this._recompute({ x: 1 }, this._state); +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + this._recompute({ x: 1 }, this._state); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); +assign(SvelteComponent.prototype, proto); - SvelteComponent.prototype._recompute = function _recompute(changed, state) { - if (changed.x) { - if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; - if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; - } +SvelteComponent.prototype._recompute = function _recompute(changed, state) { + if (changed.x) { + if (differs(state.a, (state.a = template.computed.a(state.x)))) changed.a = true; + if (differs(state.b, (state.b = template.computed.b(state.x)))) changed.b = true; } - return SvelteComponent; -}()); \ No newline at end of file +} +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index 8ebbefee23..e37322f9e6 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -186,61 +186,58 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function encapsulateStyles(node) { - setAttribute(node, "svelte-2363328337", ""); - } +function encapsulateStyles(node) { + setAttribute(node, "svelte-2363328337", ""); +} - function add_css() { - var style = createElement("style"); - style.id = 'svelte-2363328337-style'; - style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; - appendNode(style, document.head); - } +function add_css() { + var style = createElement("style"); + style.id = 'svelte-2363328337-style'; + style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; + appendNode(style, document.head); +} - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - encapsulateStyles(div); - }, + hydrate: function() { + encapsulateStyles(div); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!document.getElementById("svelte-2363328337-style")) add_css(); + if (!document.getElementById("svelte-2363328337-style")) add_css(); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/css-media-query/expected.js b/test/js/samples/css-media-query/expected.js index a9bd0d538d..58d4b5e991 100644 --- a/test/js/samples/css-media-query/expected.js +++ b/test/js/samples/css-media-query/expected.js @@ -1,59 +1,57 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, detachNode, init, insertNode, noop, proto, setAttribute } from "svelte/shared.js"; -export default (function() { - function encapsulateStyles(node) { - setAttribute(node, "svelte-2363328337", ""); - } +function encapsulateStyles(node) { + setAttribute(node, "svelte-2363328337", ""); +} - function add_css() { - var style = createElement("style"); - style.id = 'svelte-2363328337-style'; - style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; - appendNode(style, document.head); - } +function add_css() { + var style = createElement("style"); + style.id = 'svelte-2363328337-style'; + style.textContent = "@media(min-width: 1px){div[svelte-2363328337],[svelte-2363328337] div{color:red}}"; + appendNode(style, document.head); +} - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - encapsulateStyles(div); - }, + hydrate: function() { + encapsulateStyles(div); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!document.getElementById("svelte-2363328337-style")) add_css(); + if (!document.getElementById("svelte-2363328337-style")) add_css(); - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file 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 ebd6272c4f..22bcb5f37b 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected-bundle.js @@ -186,68 +186,65 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var div, text; +function create_main_fragment(state, component) { + var div, text; - return { - create: function() { - div = createElement("div"); - text = createText("fades in"); - }, + return { + create: function() { + div = createElement("div"); + text = createText("fades in"); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - appendNode(text, div); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + appendNode(text, div); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - class SvelteComponent extends HTMLElement { - constructor(options = {}) { - super(); - init(this, options); - this._state = options.data || {}; +class SvelteComponent extends HTMLElement { + constructor(options = {}) { + super(); + init(this, options); + this._state = options.data || {}; - this.attachShadow({ mode: 'open' }); - this.shadowRoot.innerHTML = ``; + this.attachShadow({ mode: 'open' }); + this.shadowRoot.innerHTML = ``; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - this._fragment.create(); - this._fragment.mount(this.shadowRoot, null); + this._fragment.create(); + this._fragment.mount(this.shadowRoot, null); - if (options.target) this._mount(options.target, options.anchor || null); - } + if (options.target) this._mount(options.target, options.anchor || null); + } - static get observedAttributes() { - return []; - } + static get observedAttributes() { + return []; + } - attributeChangedCallback(attr, oldValue, newValue) { - this.set({ [attr]: newValue }); - } + attributeChangedCallback(attr, oldValue, newValue) { + this.set({ [attr]: newValue }); } +} - customElements.define("custom-element", SvelteComponent); - assign(SvelteComponent.prototype, proto, { - _mount(target, anchor) { - target.insertBefore(this, anchor); - }, +customElements.define("custom-element", SvelteComponent); +assign(SvelteComponent.prototype, proto, { + _mount(target, anchor) { + target.insertBefore(this, anchor); + }, - _unmount() { - this.parentNode.removeChild(this); - } - }); - return SvelteComponent; -}()); + _unmount() { + this.parentNode.removeChild(this); + } +}); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/css-shadow-dom-keyframes/expected.js b/test/js/samples/css-shadow-dom-keyframes/expected.js index 5fe9dc2db9..6cea9a7856 100644 --- a/test/js/samples/css-shadow-dom-keyframes/expected.js +++ b/test/js/samples/css-shadow-dom-keyframes/expected.js @@ -1,66 +1,64 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var div, text; +function create_main_fragment(state, component) { + var div, text; - return { - create: function() { - div = createElement("div"); - text = createText("fades in"); - }, + return { + create: function() { + div = createElement("div"); + text = createText("fades in"); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - appendNode(text, div); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + appendNode(text, div); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - class SvelteComponent extends HTMLElement { - constructor(options = {}) { - super(); - init(this, options); - this._state = options.data || {}; +class SvelteComponent extends HTMLElement { + constructor(options = {}) { + super(); + init(this, options); + this._state = options.data || {}; - this.attachShadow({ mode: 'open' }); - this.shadowRoot.innerHTML = ``; + this.attachShadow({ mode: 'open' }); + this.shadowRoot.innerHTML = ``; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - this._fragment.create(); - this._fragment.mount(this.shadowRoot, null); + this._fragment.create(); + this._fragment.mount(this.shadowRoot, null); - if (options.target) this._mount(options.target, options.anchor || null); - } + if (options.target) this._mount(options.target, options.anchor || null); + } - static get observedAttributes() { - return []; - } + static get observedAttributes() { + return []; + } - attributeChangedCallback(attr, oldValue, newValue) { - this.set({ [attr]: newValue }); - } + attributeChangedCallback(attr, oldValue, newValue) { + this.set({ [attr]: newValue }); } +} - customElements.define("custom-element", SvelteComponent); - assign(SvelteComponent.prototype, proto, { - _mount(target, anchor) { - target.insertBefore(this, anchor); - }, +customElements.define("custom-element", SvelteComponent); +assign(SvelteComponent.prototype, proto, { + _mount(target, anchor) { + target.insertBefore(this, anchor); + }, - _unmount() { - this.parentNode.removeChild(this); - } - }); - return SvelteComponent; -}()); \ No newline at end of file + _unmount() { + this.parentNode.removeChild(this); + } +}); +export default SvelteComponent; \ No newline at end of file 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 ef42d21dae..882e55dfbb 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -198,159 +198,156 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var text, p, text_1; +function create_main_fragment(state, component) { + var text, p, text_1; - var comments = state.comments; + var comments = state.comments; - var each_blocks = []; + var each_blocks = []; - for (var i = 0; i < comments.length; i += 1) { - each_blocks[i] = create_each_block(state, comments, comments[i], i, component); - } - - return { - create: function() { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].create(); - } + for (var i = 0; i < comments.length; i += 1) { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + } - text = createText("\n\n"); - p = createElement("p"); - text_1 = createText(state.foo); - }, + return { + create: function() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].create(); + } - mount: function(target, anchor) { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].mount(target, anchor); - } + text = createText("\n\n"); + p = createElement("p"); + text_1 = createText(state.foo); + }, - insertNode(text, target, anchor); - insertNode(p, target, anchor); - appendNode(text_1, p); - }, - - update: function(changed, state) { - var comments = state.comments; - - if (changed.comments || changed.elapsed || changed.time) { - for (var i = 0; i < comments.length; i += 1) { - if (each_blocks[i]) { - each_blocks[i].update(changed, state, comments, comments[i], i); - } else { - each_blocks[i] = create_each_block(state, comments, comments[i], i, component); - each_blocks[i].create(); - each_blocks[i].mount(text.parentNode, text); - } - } + mount: function(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].mount(target, anchor); + } - for (; i < each_blocks.length; i += 1) { - each_blocks[i].unmount(); - each_blocks[i].destroy(); + insertNode(text, target, anchor); + insertNode(p, target, anchor); + appendNode(text_1, p); + }, + + update: function(changed, state) { + var comments = state.comments; + + if (changed.comments || changed.elapsed || changed.time) { + for (var i = 0; i < comments.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].update(changed, state, comments, comments[i], i); + } else { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i].create(); + each_blocks[i].mount(text.parentNode, text); } - each_blocks.length = comments.length; } - if (changed.foo) { - text_1.data = state.foo; - } - }, - - unmount: function() { - for (var i = 0; i < each_blocks.length; i += 1) { + for (; i < each_blocks.length; i += 1) { each_blocks[i].unmount(); + each_blocks[i].destroy(); } + each_blocks.length = comments.length; + } - detachNode(text); - detachNode(p); - }, + if (changed.foo) { + text_1.data = state.foo; + } + }, - destroy: function() { - destroyEach(each_blocks); + unmount: function() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); } - }; - } - // (1:0) {{#each comments as comment, i}} - function create_each_block(state, comments, 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; - - return { - create: function() { - div = createElement("div"); - strong = createElement("strong"); - text = createText(i); - text_1 = createText("\n\n\t\t"); - span = createElement("span"); - text_2 = createText(text_2_value); - text_3 = createText(" wrote "); - text_4 = createText(text_4_value); - text_5 = createText(" ago:"); - text_6 = createText("\n\n\t\t"); - raw_before = createElement('noscript'); - this.hydrate(); - }, - - hydrate: function() { - div.className = "comment"; - span.className = "meta"; - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - appendNode(strong, div); - appendNode(text, strong); - appendNode(text_1, div); - appendNode(span, div); - appendNode(text_2, span); - appendNode(text_3, span); - appendNode(text_4, span); - appendNode(text_5, span); - appendNode(text_6, div); - appendNode(raw_before, div); - raw_before.insertAdjacentHTML("afterend", raw_value); - }, + detachNode(text); + detachNode(p); + }, - update: function(changed, state, comments, comment, i) { - if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { - text_2.data = text_2_value; - } + destroy: function() { + destroyEach(each_blocks); + } + }; +} - 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; - } +// (1:0) {{#each comments as comment, i}} +function create_each_block(state, comments, 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; - if ((changed.comments) && raw_value !== (raw_value = comment.html)) { - detachAfter(raw_before); - raw_before.insertAdjacentHTML("afterend", raw_value); - } - }, + return { + create: function() { + div = createElement("div"); + strong = createElement("strong"); + text = createText(i); + text_1 = createText("\n\n\t\t"); + span = createElement("span"); + text_2 = createText(text_2_value); + text_3 = createText(" wrote "); + text_4 = createText(text_4_value); + text_5 = createText(" ago:"); + text_6 = createText("\n\n\t\t"); + raw_before = createElement('noscript'); + this.hydrate(); + }, + + hydrate: function() { + div.className = "comment"; + span.className = "meta"; + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + appendNode(strong, div); + appendNode(text, strong); + appendNode(text_1, div); + appendNode(span, div); + appendNode(text_2, span); + appendNode(text_3, span); + appendNode(text_4, span); + appendNode(text_5, span); + appendNode(text_6, div); + appendNode(raw_before, div); + raw_before.insertAdjacentHTML("afterend", raw_value); + }, + + update: function(changed, state, comments, comment, i) { + 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))) { + text_4.data = text_4_value; + } - unmount: function() { + if ((changed.comments) && raw_value !== (raw_value = comment.html)) { detachAfter(raw_before); + raw_before.insertAdjacentHTML("afterend", raw_value); + } + }, - detachNode(div); - }, + unmount: function() { + detachAfter(raw_before); - destroy: noop - }; - } + detachNode(div); + }, + + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 2f431dadaf..613fea0bf5 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -1,157 +1,155 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, createText, destroyEach, detachAfter, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var text, p, text_1; +function create_main_fragment(state, component) { + var text, p, text_1; - var comments = state.comments; + var comments = state.comments; - var each_blocks = []; + var each_blocks = []; - for (var i = 0; i < comments.length; i += 1) { - each_blocks[i] = create_each_block(state, comments, comments[i], i, component); - } - - return { - create: function() { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].create(); - } + for (var i = 0; i < comments.length; i += 1) { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + } - text = createText("\n\n"); - p = createElement("p"); - text_1 = createText(state.foo); - }, + return { + create: function() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].create(); + } - mount: function(target, anchor) { - for (var i = 0; i < each_blocks.length; i += 1) { - each_blocks[i].mount(target, anchor); - } + text = createText("\n\n"); + p = createElement("p"); + text_1 = createText(state.foo); + }, - insertNode(text, target, anchor); - insertNode(p, target, anchor); - appendNode(text_1, p); - }, - - update: function(changed, state) { - var comments = state.comments; - - if (changed.comments || changed.elapsed || changed.time) { - for (var i = 0; i < comments.length; i += 1) { - if (each_blocks[i]) { - each_blocks[i].update(changed, state, comments, comments[i], i); - } else { - each_blocks[i] = create_each_block(state, comments, comments[i], i, component); - each_blocks[i].create(); - each_blocks[i].mount(text.parentNode, text); - } - } + mount: function(target, anchor) { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].mount(target, anchor); + } - for (; i < each_blocks.length; i += 1) { - each_blocks[i].unmount(); - each_blocks[i].destroy(); + insertNode(text, target, anchor); + insertNode(p, target, anchor); + appendNode(text_1, p); + }, + + update: function(changed, state) { + var comments = state.comments; + + if (changed.comments || changed.elapsed || changed.time) { + for (var i = 0; i < comments.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].update(changed, state, comments, comments[i], i); + } else { + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i].create(); + each_blocks[i].mount(text.parentNode, text); } - each_blocks.length = comments.length; - } - - if (changed.foo) { - text_1.data = state.foo; } - }, - unmount: function() { - for (var i = 0; i < each_blocks.length; i += 1) { + for (; i < each_blocks.length; i += 1) { each_blocks[i].unmount(); + each_blocks[i].destroy(); } + each_blocks.length = comments.length; + } - detachNode(text); - detachNode(p); - }, - - destroy: function() { - destroyEach(each_blocks); + if (changed.foo) { + text_1.data = state.foo; } - }; - } + }, - // (1:0) {{#each comments as comment, i}} - function create_each_block(state, comments, 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; - - return { - create: function() { - div = createElement("div"); - strong = createElement("strong"); - text = createText(i); - text_1 = createText("\n\n\t\t"); - span = createElement("span"); - text_2 = createText(text_2_value); - text_3 = createText(" wrote "); - text_4 = createText(text_4_value); - text_5 = createText(" ago:"); - text_6 = createText("\n\n\t\t"); - raw_before = createElement('noscript'); - this.hydrate(); - }, - - hydrate: function() { - div.className = "comment"; - span.className = "meta"; - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - appendNode(strong, div); - appendNode(text, strong); - appendNode(text_1, div); - appendNode(span, div); - appendNode(text_2, span); - appendNode(text_3, span); - appendNode(text_4, span); - appendNode(text_5, span); - appendNode(text_6, div); - appendNode(raw_before, div); - raw_before.insertAdjacentHTML("afterend", raw_value); - }, + unmount: function() { + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); + } - update: function(changed, state, comments, comment, i) { - if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { - text_2.data = text_2_value; - } + detachNode(text); + detachNode(p); + }, - 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; - } + destroy: function() { + destroyEach(each_blocks); + } + }; +} + +// (1:0) {{#each comments as comment, i}} +function create_each_block(state, comments, 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; + + return { + create: function() { + div = createElement("div"); + strong = createElement("strong"); + text = createText(i); + text_1 = createText("\n\n\t\t"); + span = createElement("span"); + text_2 = createText(text_2_value); + text_3 = createText(" wrote "); + text_4 = createText(text_4_value); + text_5 = createText(" ago:"); + text_6 = createText("\n\n\t\t"); + raw_before = createElement('noscript'); + this.hydrate(); + }, + + hydrate: function() { + div.className = "comment"; + span.className = "meta"; + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + appendNode(strong, div); + appendNode(text, strong); + appendNode(text_1, div); + appendNode(span, div); + appendNode(text_2, span); + appendNode(text_3, span); + appendNode(text_4, span); + appendNode(text_5, span); + appendNode(text_6, div); + appendNode(raw_before, div); + raw_before.insertAdjacentHTML("afterend", raw_value); + }, + + update: function(changed, state, comments, comment, i) { + if ((changed.comments) && text_2_value !== (text_2_value = comment.author)) { + text_2.data = text_2_value; + } - if ((changed.comments) && raw_value !== (raw_value = comment.html)) { - detachAfter(raw_before); - raw_before.insertAdjacentHTML("afterend", raw_value); - } - }, + 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; + } - unmount: function() { + if ((changed.comments) && raw_value !== (raw_value = comment.html)) { detachAfter(raw_before); + raw_before.insertAdjacentHTML("afterend", raw_value); + } + }, - detachNode(div); - }, + unmount: function() { + detachAfter(raw_before); - destroy: noop - }; - } + detachNode(div); + }, - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + destroy: noop + }; +} - this._fragment = create_main_fragment(this._state, this); +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index f96f8fb00b..4d5e595318 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -186,8 +186,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - var template = (function() { +var template = (function() { return { methods: { foo ( bar ) { @@ -202,54 +201,52 @@ var _actual = (function() { }; }()); - function create_main_fragment(state, component) { - var button, foo_handler, text; +function create_main_fragment(state, component) { + var button, foo_handler, text; - return { - create: function() { - button = createElement("button"); - text = createText("foo"); - this.hydrate(); - }, + return { + create: function() { + button = createElement("button"); + text = createText("foo"); + this.hydrate(); + }, - hydrate: function() { - foo_handler = template.events.foo.call(component, button, function(event) { - var state = component.get(); - component.foo( state.bar ); - }); - }, + hydrate: function() { + foo_handler = template.events.foo.call(component, button, function(event) { + var state = component.get(); + component.foo( state.bar ); + }); + }, - mount: function(target, anchor) { - insertNode(button, target, anchor); - appendNode(text, button); - }, + mount: function(target, anchor) { + insertNode(button, target, anchor); + appendNode(text, button); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(button); - }, + unmount: function() { + detachNode(button); + }, - destroy: function() { - foo_handler.teardown(); - } - }; - } + destroy: function() { + foo_handler.teardown(); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, template.methods, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, template.methods, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js index 41f66bb1d7..bf656c0411 100644 --- a/test/js/samples/event-handlers-custom/expected.js +++ b/test/js/samples/event-handlers-custom/expected.js @@ -1,8 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; -export default (function() { - var template = (function() { +var template = (function() { return { methods: { foo ( bar ) { @@ -17,52 +16,51 @@ export default (function() { }; }()); - function create_main_fragment(state, component) { - var button, foo_handler, text; +function create_main_fragment(state, component) { + var button, foo_handler, text; - return { - create: function() { - button = createElement("button"); - text = createText("foo"); - this.hydrate(); - }, + return { + create: function() { + button = createElement("button"); + text = createText("foo"); + this.hydrate(); + }, - hydrate: function() { - foo_handler = template.events.foo.call(component, button, function(event) { - var state = component.get(); - component.foo( state.bar ); - }); - }, + hydrate: function() { + foo_handler = template.events.foo.call(component, button, function(event) { + var state = component.get(); + component.foo( state.bar ); + }); + }, - mount: function(target, anchor) { - insertNode(button, target, anchor); - appendNode(text, button); - }, + mount: function(target, anchor) { + insertNode(button, target, anchor); + appendNode(text, button); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(button); - }, + unmount: function() { + detachNode(button); + }, - destroy: function() { - foo_handler.teardown(); - } - }; - } + destroy: function() { + foo_handler.teardown(); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, template.methods, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, template.methods, proto); +export default SvelteComponent; \ No newline at end of file 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 b7cd0d587b..b413e274e0 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -190,110 +190,107 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var if_block_anchor; +function create_main_fragment(state, component) { + var if_block_anchor; - var current_block_type = select_block_type(state); - var if_block = current_block_type(state, component); + var current_block_type = select_block_type(state); + var if_block = current_block_type(state, component); - return { - create: function() { - if_block.create(); - if_block_anchor = createComment(); - }, - - mount: function(target, anchor) { - if_block.mount(target, anchor); - insertNode(if_block_anchor, target, anchor); - }, - - update: function(changed, state) { - if (current_block_type !== (current_block_type = select_block_type(state))) { - if_block.unmount(); - if_block.destroy(); - if_block = current_block_type(state, component); - if_block.create(); - if_block.mount(if_block_anchor.parentNode, if_block_anchor); - } - }, - - unmount: function() { + return { + create: function() { + if_block.create(); + if_block_anchor = createComment(); + }, + + mount: function(target, anchor) { + if_block.mount(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + update: function(changed, state) { + if (current_block_type !== (current_block_type = select_block_type(state))) { if_block.unmount(); - detachNode(if_block_anchor); - }, - - destroy: function() { if_block.destroy(); + if_block = current_block_type(state, component); + if_block.create(); + if_block.mount(if_block_anchor.parentNode, if_block_anchor); } - }; - } + }, - // (1:0) {{#if foo}} - function create_if_block(state, component) { - var p, text; + unmount: function() { + if_block.unmount(); + detachNode(if_block_anchor); + }, - return { - create: function() { - p = createElement("p"); - text = createText("foo!"); - }, + destroy: function() { + if_block.destroy(); + } + }; +} - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, +// (1:0) {{#if foo}} +function create_if_block(state, component) { + var p, text; - unmount: function() { - detachNode(p); - }, + return { + create: function() { + p = createElement("p"); + text = createText("foo!"); + }, - destroy: noop - }; - } + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, - // (3:0) {{else}} - function create_if_block_1(state, component) { - var p, text; + destroy: noop + }; +} - return { - create: function() { - p = createElement("p"); - text = createText("not foo!"); - }, +// (3:0) {{else}} +function create_if_block_1(state, component) { + var p, text; - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + return { + create: function() { + p = createElement("p"); + text = createText("not foo!"); + }, - unmount: function() { - detachNode(p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - destroy: noop - }; - } + unmount: function() { + detachNode(p); + }, - function select_block_type(state) { - if (state.foo) return create_if_block; - return create_if_block_1; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; +} - this._fragment = create_main_fragment(this._state, this); +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js index 5d52e1cbad..a513519061 100644 --- a/test/js/samples/if-block-no-update/expected.js +++ b/test/js/samples/if-block-no-update/expected.js @@ -1,108 +1,106 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var if_block_anchor; +function create_main_fragment(state, component) { + var if_block_anchor; - var current_block_type = select_block_type(state); - var if_block = current_block_type(state, component); + var current_block_type = select_block_type(state); + var if_block = current_block_type(state, component); - return { - create: function() { - if_block.create(); - if_block_anchor = createComment(); - }, - - mount: function(target, anchor) { - if_block.mount(target, anchor); - insertNode(if_block_anchor, target, anchor); - }, - - update: function(changed, state) { - if (current_block_type !== (current_block_type = select_block_type(state))) { - if_block.unmount(); - if_block.destroy(); - if_block = current_block_type(state, component); - if_block.create(); - if_block.mount(if_block_anchor.parentNode, if_block_anchor); - } - }, - - unmount: function() { - if_block.unmount(); - detachNode(if_block_anchor); - }, + return { + create: function() { + if_block.create(); + if_block_anchor = createComment(); + }, + + mount: function(target, anchor) { + if_block.mount(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, - destroy: function() { + update: function(changed, state) { + if (current_block_type !== (current_block_type = select_block_type(state))) { + if_block.unmount(); if_block.destroy(); + if_block = current_block_type(state, component); + if_block.create(); + if_block.mount(if_block_anchor.parentNode, if_block_anchor); } - }; - } - - // (1:0) {{#if foo}} - function create_if_block(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("foo!"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; - } - - // (3:0) {{else}} - function create_if_block_1(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("not foo!"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; - } - - function select_block_type(state) { - if (state.foo) return create_if_block; - return create_if_block_1; - } - - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + }, - this._fragment = create_main_fragment(this._state, this); + unmount: function() { + if_block.unmount(); + detachNode(if_block_anchor); + }, - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + destroy: function() { + if_block.destroy(); } + }; +} + +// (1:0) {{#if foo}} +function create_if_block(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("foo!"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; +} + +// (3:0) {{else}} +function create_if_block_1(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("not foo!"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; +} + +function select_block_type(state) { + if (state.foo) return create_if_block; + return create_if_block_1; +} + +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 6c7e2d86b4..881aafd926 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -190,85 +190,82 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var if_block_anchor; - - var if_block = (state.foo) && create_if_block(state, component); - - return { - create: function() { - if (if_block) if_block.create(); - if_block_anchor = createComment(); - }, - - mount: function(target, anchor) { - if (if_block) if_block.mount(target, anchor); - insertNode(if_block_anchor, target, anchor); - }, - - update: function(changed, state) { - if (state.foo) { - if (!if_block) { - if_block = create_if_block(state, component); - if_block.create(); - if_block.mount(if_block_anchor.parentNode, if_block_anchor); - } - } else if (if_block) { - if_block.unmount(); - if_block.destroy(); - if_block = null; - } - }, +function create_main_fragment(state, component) { + var if_block_anchor; - unmount: function() { - if (if_block) if_block.unmount(); - detachNode(if_block_anchor); - }, + var if_block = (state.foo) && create_if_block(state, component); - destroy: function() { - if (if_block) if_block.destroy(); + return { + create: function() { + if (if_block) if_block.create(); + if_block_anchor = createComment(); + }, + + mount: function(target, anchor) { + if (if_block) if_block.mount(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + update: function(changed, state) { + if (state.foo) { + if (!if_block) { + if_block = create_if_block(state, component); + if_block.create(); + if_block.mount(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + if_block.unmount(); + if_block.destroy(); + if_block = null; } - }; - } + }, - // (1:0) {{#if foo}} - function create_if_block(state, component) { - var p, text; + unmount: function() { + if (if_block) if_block.unmount(); + detachNode(if_block_anchor); + }, - return { - create: function() { - p = createElement("p"); - text = createText("foo!"); - }, + destroy: function() { + if (if_block) if_block.destroy(); + } + }; +} - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, +// (1:0) {{#if foo}} +function create_if_block(state, component) { + var p, text; - unmount: function() { - detachNode(p); - }, + return { + create: function() { + p = createElement("p"); + text = createText("foo!"); + }, - destroy: noop - }; - } + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + unmount: function() { + detachNode(p); + }, - this._fragment = create_main_fragment(this._state, this); + destroy: noop + }; +} - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js index 311093e0fb..aba8b65ee7 100644 --- a/test/js/samples/if-block-simple/expected.js +++ b/test/js/samples/if-block-simple/expected.js @@ -1,83 +1,81 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var if_block_anchor; - - var if_block = (state.foo) && create_if_block(state, component); - - return { - create: function() { - if (if_block) if_block.create(); - if_block_anchor = createComment(); - }, - - mount: function(target, anchor) { - if (if_block) if_block.mount(target, anchor); - insertNode(if_block_anchor, target, anchor); - }, - - update: function(changed, state) { - if (state.foo) { - if (!if_block) { - if_block = create_if_block(state, component); - if_block.create(); - if_block.mount(if_block_anchor.parentNode, if_block_anchor); - } - } else if (if_block) { - if_block.unmount(); - if_block.destroy(); - if_block = null; +function create_main_fragment(state, component) { + var if_block_anchor; + + var if_block = (state.foo) && create_if_block(state, component); + + return { + create: function() { + if (if_block) if_block.create(); + if_block_anchor = createComment(); + }, + + mount: function(target, anchor) { + if (if_block) if_block.mount(target, anchor); + insertNode(if_block_anchor, target, anchor); + }, + + update: function(changed, state) { + if (state.foo) { + if (!if_block) { + if_block = create_if_block(state, component); + if_block.create(); + if_block.mount(if_block_anchor.parentNode, if_block_anchor); } - }, + } else if (if_block) { + if_block.unmount(); + if_block.destroy(); + if_block = null; + } + }, - unmount: function() { - if (if_block) if_block.unmount(); - detachNode(if_block_anchor); - }, + unmount: function() { + if (if_block) if_block.unmount(); + detachNode(if_block_anchor); + }, - destroy: function() { - if (if_block) if_block.destroy(); - } - }; - } + destroy: function() { + if (if_block) if_block.destroy(); + } + }; +} - // (1:0) {{#if foo}} - function create_if_block(state, component) { - var p, text; +// (1:0) {{#if foo}} +function create_if_block(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("foo!"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("foo!"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file 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 3ebdbc1277..745f0a2f26 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-multiple/expected-bundle.js @@ -182,57 +182,54 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, - - hydrate: function() { + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, + + hydrate: function() { + setStyle(div, "color", state.color); + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, + + update: function(changed, state) { + if (changed.color) { setStyle(div, "color", state.color); - setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); - }, + } - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, - - update: function(changed, state) { - if (changed.color) { - setStyle(div, "color", state.color); - } - - if (changed.x || changed.y) { - setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); - } - }, + if (changed.x || changed.y) { + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + } + }, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized-multiple/expected.js b/test/js/samples/inline-style-optimized-multiple/expected.js index a23f9fdd7c..35de49a17c 100644 --- a/test/js/samples/inline-style-optimized-multiple/expected.js +++ b/test/js/samples/inline-style-optimized-multiple/expected.js @@ -1,55 +1,53 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var div; - - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, - - hydrate: function() { +function create_main_fragment(state, component) { + var div; + + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, + + hydrate: function() { + setStyle(div, "color", state.color); + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, + + update: function(changed, state) { + if (changed.color) { setStyle(div, "color", state.color); - setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + } - update: function(changed, state) { - if (changed.color) { - setStyle(div, "color", state.color); - } - - if (changed.x || changed.y) { - setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); - } - }, + if (changed.x || changed.y) { + setStyle(div, "transform", "translate(" + state.x + "px," + state.y + "px)"); + } + }, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file 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 105fb40076..2985f7cb15 100644 --- a/test/js/samples/inline-style-optimized-url/expected-bundle.js +++ b/test/js/samples/inline-style-optimized-url/expected-bundle.js @@ -182,52 +182,49 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); - }, + hydrate: function() { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: function(changed, state) { - if (changed.data) { - setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); - } - }, + update: function(changed, state) { + if (changed.data) { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + } + }, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized-url/expected.js b/test/js/samples/inline-style-optimized-url/expected.js index 2a4a108f74..659bc4b20b 100644 --- a/test/js/samples/inline-style-optimized-url/expected.js +++ b/test/js/samples/inline-style-optimized-url/expected.js @@ -1,50 +1,48 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); - }, + hydrate: function() { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: function(changed, state) { - if (changed.data) { - setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); - } - }, + update: function(changed, state) { + if (changed.data) { + setStyle(div, "background", "url(data:image/png;base64," + state.data + ")"); + } + }, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-optimized/expected-bundle.js b/test/js/samples/inline-style-optimized/expected-bundle.js index 90857bb9cb..fa4dfc93a9 100644 --- a/test/js/samples/inline-style-optimized/expected-bundle.js +++ b/test/js/samples/inline-style-optimized/expected-bundle.js @@ -182,52 +182,49 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - setStyle(div, "color", state.color); - }, + hydrate: function() { + setStyle(div, "color", state.color); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: function(changed, state) { - if (changed.color) { - setStyle(div, "color", state.color); - } - }, + update: function(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + }, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/inline-style-optimized/expected.js b/test/js/samples/inline-style-optimized/expected.js index bb6f6dbd04..8b07a3eaad 100644 --- a/test/js/samples/inline-style-optimized/expected.js +++ b/test/js/samples/inline-style-optimized/expected.js @@ -1,50 +1,48 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, detachNode, init, insertNode, noop, proto, setStyle } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - hydrate: function() { - setStyle(div, "color", state.color); - }, + hydrate: function() { + setStyle(div, "color", state.color); + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: function(changed, state) { - if (changed.color) { - setStyle(div, "color", state.color); - } - }, + update: function(changed, state) { + if (changed.color) { + setStyle(div, "color", state.color); + } + }, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/inline-style-unoptimized/expected-bundle.js b/test/js/samples/inline-style-unoptimized/expected-bundle.js index 7480c32d80..e0770b55c7 100644 --- a/test/js/samples/inline-style-unoptimized/expected-bundle.js +++ b/test/js/samples/inline-style-unoptimized/expected-bundle.js @@ -182,63 +182,60 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var div, text, div_1, div_1_style_value; - - return { - create: function() { - div = createElement("div"); - text = createText("\n"); - div_1 = createElement("div"); - this.hydrate(); - }, - - hydrate: function() { +function create_main_fragment(state, component) { + var div, text, div_1, div_1_style_value; + + return { + create: function() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.hydrate(); + }, + + hydrate: function() { + div.style.cssText = state.style; + div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + update: function(changed, state) { + if (changed.style) { div.style.cssText = state.style; - div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - insertNode(text, target, anchor); - insertNode(div_1, target, anchor); - }, - - update: function(changed, state) { - 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)) { - div_1.style.cssText = div_1_style_value; - } - }, - - unmount: function() { - detachNode(div); - detachNode(text); - detachNode(div_1); - }, - - destroy: noop - }; - } + } - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + 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; + } + }, - this._fragment = create_main_fragment(this._state, this); + unmount: function() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + destroy: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/inline-style-unoptimized/expected.js b/test/js/samples/inline-style-unoptimized/expected.js index 392f3de4be..9dcb2296bb 100644 --- a/test/js/samples/inline-style-unoptimized/expected.js +++ b/test/js/samples/inline-style-unoptimized/expected.js @@ -1,61 +1,59 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var div, text, div_1, div_1_style_value; - - return { - create: function() { - div = createElement("div"); - text = createText("\n"); - div_1 = createElement("div"); - this.hydrate(); - }, - - hydrate: function() { +function create_main_fragment(state, component) { + var div, text, div_1, div_1_style_value; + + return { + create: function() { + div = createElement("div"); + text = createText("\n"); + div_1 = createElement("div"); + this.hydrate(); + }, + + hydrate: function() { + div.style.cssText = state.style; + div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + insertNode(text, target, anchor); + insertNode(div_1, target, anchor); + }, + + update: function(changed, state) { + if (changed.style) { div.style.cssText = state.style; - div_1.style.cssText = div_1_style_value = "" + state.key + ": " + state.value; - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - insertNode(text, target, anchor); - insertNode(div_1, target, anchor); - }, - - update: function(changed, state) { - 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)) { - div_1.style.cssText = div_1_style_value; - } - }, - - unmount: function() { - detachNode(div); - detachNode(text); - detachNode(div_1); - }, - - destroy: noop - }; - } + } + + 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; + } + }, + + unmount: function() { + detachNode(div); + detachNode(text); + detachNode(div_1); + }, + + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file 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 41959bc510..8a0c36accc 100644 --- a/test/js/samples/input-without-blowback-guard/expected-bundle.js +++ b/test/js/samples/input-without-blowback-guard/expected-bundle.js @@ -186,59 +186,56 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var input; +function create_main_fragment(state, component) { + var input; - function input_change_handler() { - component.set({ foo: input.checked }); - } + function input_change_handler() { + component.set({ foo: input.checked }); + } - return { - create: function() { - input = createElement("input"); - this.hydrate(); - }, + return { + create: function() { + input = createElement("input"); + this.hydrate(); + }, - hydrate: function() { - input.type = "checkbox"; - addListener(input, "change", input_change_handler); - }, + hydrate: function() { + input.type = "checkbox"; + addListener(input, "change", input_change_handler); + }, - mount: function(target, anchor) { - insertNode(input, target, anchor); + mount: function(target, anchor) { + insertNode(input, target, anchor); - input.checked = state.foo; - }, + input.checked = state.foo; + }, - update: function(changed, state) { - input.checked = state.foo; - }, + update: function(changed, state) { + input.checked = state.foo; + }, - unmount: function() { - detachNode(input); - }, + unmount: function() { + detachNode(input); + }, - destroy: function() { - removeListener(input, "change", input_change_handler); - } - }; - } + destroy: function() { + removeListener(input, "change", input_change_handler); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/input-without-blowback-guard/expected.js b/test/js/samples/input-without-blowback-guard/expected.js index 6a8580da45..074a6126eb 100644 --- a/test/js/samples/input-without-blowback-guard/expected.js +++ b/test/js/samples/input-without-blowback-guard/expected.js @@ -1,57 +1,55 @@ /* generated by Svelte vX.Y.Z */ import { addListener, assign, createElement, detachNode, init, insertNode, proto, removeListener } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var input; +function create_main_fragment(state, component) { + var input; - function input_change_handler() { - component.set({ foo: input.checked }); - } + function input_change_handler() { + component.set({ foo: input.checked }); + } - return { - create: function() { - input = createElement("input"); - this.hydrate(); - }, + return { + create: function() { + input = createElement("input"); + this.hydrate(); + }, - hydrate: function() { - input.type = "checkbox"; - addListener(input, "change", input_change_handler); - }, + hydrate: function() { + input.type = "checkbox"; + addListener(input, "change", input_change_handler); + }, - mount: function(target, anchor) { - insertNode(input, target, anchor); + mount: function(target, anchor) { + insertNode(input, target, anchor); - input.checked = state.foo; - }, + input.checked = state.foo; + }, - update: function(changed, state) { - input.checked = state.foo; - }, + update: function(changed, state) { + input.checked = state.foo; + }, - unmount: function() { - detachNode(input); - }, + unmount: function() { + detachNode(input); + }, - destroy: function() { - removeListener(input, "change", input_change_handler); - } - }; - } + destroy: function() { + removeListener(input, "change", input_change_handler); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index 163380555a..6475e22fa8 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -184,48 +184,45 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var input; +function create_main_fragment(state, component) { + var input; - return { - create: function() { - input = createElement("input"); - this.hydrate(); - }, + return { + create: function() { + input = createElement("input"); + this.hydrate(); + }, - hydrate: function() { - setInputType(input, "search"); - }, + hydrate: function() { + setInputType(input, "search"); + }, - mount: function(target, anchor) { - insertNode(input, target, anchor); - }, + mount: function(target, anchor) { + insertNode(input, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(input); - }, + unmount: function() { + detachNode(input); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/legacy-input-type/expected.js b/test/js/samples/legacy-input-type/expected.js index 8657249f57..c7785c6ed4 100644 --- a/test/js/samples/legacy-input-type/expected.js +++ b/test/js/samples/legacy-input-type/expected.js @@ -1,46 +1,44 @@ /* generated by Svelte vX.Y.Z */ import { assign, createElement, detachNode, init, insertNode, noop, proto, setInputType } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var input; +function create_main_fragment(state, component) { + var input; - return { - create: function() { - input = createElement("input"); - this.hydrate(); - }, + return { + create: function() { + input = createElement("input"); + this.hydrate(); + }, - hydrate: function() { - setInputType(input, "search"); - }, + hydrate: function() { + setInputType(input, "search"); + }, - mount: function(target, anchor) { - insertNode(input, target, anchor); - }, + mount: function(target, anchor) { + insertNode(input, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(input); - }, + unmount: function() { + detachNode(input); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/legacy-quote-class/expected-bundle.js b/test/js/samples/legacy-quote-class/expected-bundle.js index 709f4c8e1c..139958519b 100644 --- a/test/js/samples/legacy-quote-class/expected-bundle.js +++ b/test/js/samples/legacy-quote-class/expected-bundle.js @@ -201,58 +201,55 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - claim: function(nodes) { - div = claimElement(nodes, "DIV", { "class": true }, false); - var div_nodes = children(div); + claim: function(nodes) { + div = claimElement(nodes, "DIV", { "class": true }, false); + var div_nodes = children(div); - div_nodes.forEach(detachNode); - this.hydrate(); - }, + div_nodes.forEach(detachNode); + this.hydrate(); + }, - hydrate: function() { - div.className = "foo"; - }, + hydrate: function() { + div.className = "foo"; + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - var nodes = children(options.target); - options.hydrate ? this._fragment.claim(nodes) : this._fragment.create(); - nodes.forEach(detachNode); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + var nodes = children(options.target); + options.hydrate ? this._fragment.claim(nodes) : this._fragment.create(); + nodes.forEach(detachNode); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/legacy-quote-class/expected.js b/test/js/samples/legacy-quote-class/expected.js index b0e08896bb..dd10330458 100644 --- a/test/js/samples/legacy-quote-class/expected.js +++ b/test/js/samples/legacy-quote-class/expected.js @@ -1,56 +1,54 @@ /* generated by Svelte vX.Y.Z */ import { assign, children, claimElement, createElement, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var div; +function create_main_fragment(state, component) { + var div; - return { - create: function() { - div = createElement("div"); - this.hydrate(); - }, + return { + create: function() { + div = createElement("div"); + this.hydrate(); + }, - claim: function(nodes) { - div = claimElement(nodes, "DIV", { "class": true }, false); - var div_nodes = children(div); + claim: function(nodes) { + div = claimElement(nodes, "DIV", { "class": true }, false); + var div_nodes = children(div); - div_nodes.forEach(detachNode); - this.hydrate(); - }, + div_nodes.forEach(detachNode); + this.hydrate(); + }, - hydrate: function() { - div.className = "foo"; - }, + hydrate: function() { + div.className = "foo"; + }, - mount: function(target, anchor) { - insertNode(div, target, anchor); - }, + mount: function(target, anchor) { + insertNode(div, target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - detachNode(div); - }, + unmount: function() { + detachNode(div); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - var nodes = children(options.target); - options.hydrate ? this._fragment.claim(nodes) : this._fragment.create(); - nodes.forEach(detachNode); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + var nodes = children(options.target); + options.hydrate ? this._fragment.claim(nodes) : this._fragment.create(); + nodes.forEach(detachNode); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/media-bindings/expected-bundle.js b/test/js/samples/media-bindings/expected-bundle.js index 3bf631a388..d784e6fabe 100644 --- a/test/js/samples/media-bindings/expected-bundle.js +++ b/test/js/samples/media-bindings/expected-bundle.js @@ -194,134 +194,131 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - function create_main_fragment(state, component) { - var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; - - function audio_progress_loadedmetadata_handler() { - audio_updating = true; - component.set({ buffered: timeRangesToArray(audio.buffered) }); - audio_updating = false; - } - - function audio_loadedmetadata_handler() { - audio_updating = true; - component.set({ seekable: timeRangesToArray(audio.seekable) }); - audio_updating = false; - } +function create_main_fragment(state, component) { + var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; - function audio_timeupdate_handler() { - audio_updating = true; - component.set({ played: timeRangesToArray(audio.played) }); - audio_updating = false; - } + function audio_progress_loadedmetadata_handler() { + audio_updating = true; + component.set({ buffered: timeRangesToArray(audio.buffered) }); + audio_updating = false; + } - function audio_timeupdate_handler_1() { - audio_updating = true; - cancelAnimationFrame(audio_animationframe); - if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler_1); - component.set({ currentTime: audio.currentTime }); - audio_updating = false; - } + function audio_loadedmetadata_handler() { + audio_updating = true; + component.set({ seekable: timeRangesToArray(audio.seekable) }); + audio_updating = false; + } - function audio_durationchange_handler() { - audio_updating = true; - component.set({ duration: audio.duration }); - audio_updating = false; - } + function audio_timeupdate_handler() { + audio_updating = true; + component.set({ played: timeRangesToArray(audio.played) }); + audio_updating = false; + } - function audio_pause_handler() { - audio_updating = true; - component.set({ paused: audio.paused }); - audio_updating = false; - } + function audio_timeupdate_handler_1() { + audio_updating = true; + cancelAnimationFrame(audio_animationframe); + if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler_1); + component.set({ currentTime: audio.currentTime }); + audio_updating = false; + } - return { - create: function() { - audio = createElement("audio"); - addListener(audio, "play", audio_pause_handler); - this.hydrate(); - }, + function audio_durationchange_handler() { + audio_updating = true; + component.set({ duration: audio.duration }); + audio_updating = false; + } - hydrate: function() { - component._root._beforecreate.push(audio_progress_loadedmetadata_handler); + function audio_pause_handler() { + audio_updating = true; + component.set({ paused: audio.paused }); + audio_updating = false; + } - addListener(audio, "progress", audio_progress_loadedmetadata_handler); - addListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); + return { + create: function() { + audio = createElement("audio"); + addListener(audio, "play", audio_pause_handler); + this.hydrate(); + }, - component._root._beforecreate.push(audio_loadedmetadata_handler); + hydrate: function() { + component._root._beforecreate.push(audio_progress_loadedmetadata_handler); - addListener(audio, "loadedmetadata", audio_loadedmetadata_handler); + addListener(audio, "progress", audio_progress_loadedmetadata_handler); + addListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); - component._root._beforecreate.push(audio_timeupdate_handler); + component._root._beforecreate.push(audio_loadedmetadata_handler); - addListener(audio, "timeupdate", audio_timeupdate_handler); + addListener(audio, "loadedmetadata", audio_loadedmetadata_handler); - component._root._beforecreate.push(audio_timeupdate_handler_1); + component._root._beforecreate.push(audio_timeupdate_handler); - addListener(audio, "timeupdate", audio_timeupdate_handler_1); + addListener(audio, "timeupdate", audio_timeupdate_handler); - component._root._beforecreate.push(audio_durationchange_handler); + component._root._beforecreate.push(audio_timeupdate_handler_1); - addListener(audio, "durationchange", audio_durationchange_handler); + addListener(audio, "timeupdate", audio_timeupdate_handler_1); - component._root._beforecreate.push(audio_pause_handler); + component._root._beforecreate.push(audio_durationchange_handler); - addListener(audio, "pause", audio_pause_handler); - }, + addListener(audio, "durationchange", audio_durationchange_handler); - mount: function(target, anchor) { - insertNode(audio, target, anchor); - }, + component._root._beforecreate.push(audio_pause_handler); - update: function(changed, state) { - if (!audio_updating && !isNaN(state.currentTime )) { - audio.currentTime = state.currentTime ; - } + addListener(audio, "pause", audio_pause_handler); + }, - if (audio_paused_value !== (audio_paused_value = state.paused)) { - audio[audio_paused_value ? "pause" : "play"](); - } - }, + mount: function(target, anchor) { + insertNode(audio, target, anchor); + }, - unmount: function() { - detachNode(audio); - }, + update: function(changed, state) { + if (!audio_updating && !isNaN(state.currentTime )) { + audio.currentTime = state.currentTime ; + } - destroy: function() { - removeListener(audio, "progress", audio_progress_loadedmetadata_handler); - removeListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); - removeListener(audio, "loadedmetadata", audio_loadedmetadata_handler); - removeListener(audio, "timeupdate", audio_timeupdate_handler); - removeListener(audio, "timeupdate", audio_timeupdate_handler_1); - removeListener(audio, "durationchange", audio_durationchange_handler); - removeListener(audio, "pause", audio_pause_handler); - removeListener(audio, "play", audio_pause_handler); + if (audio_paused_value !== (audio_paused_value = state.paused)) { + audio[audio_paused_value ? "pause" : "play"](); } - }; - } + }, + + unmount: function() { + detachNode(audio); + }, + + destroy: function() { + removeListener(audio, "progress", audio_progress_loadedmetadata_handler); + removeListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); + removeListener(audio, "loadedmetadata", audio_loadedmetadata_handler); + removeListener(audio, "timeupdate", audio_timeupdate_handler); + removeListener(audio, "timeupdate", audio_timeupdate_handler_1); + removeListener(audio, "durationchange", audio_durationchange_handler); + removeListener(audio, "pause", audio_pause_handler); + removeListener(audio, "play", audio_pause_handler); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - callAll(this._beforecreate); - } + callAll(this._beforecreate); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/media-bindings/expected.js b/test/js/samples/media-bindings/expected.js index b7d7221469..531a2a1b58 100644 --- a/test/js/samples/media-bindings/expected.js +++ b/test/js/samples/media-bindings/expected.js @@ -1,132 +1,130 @@ /* generated by Svelte vX.Y.Z */ import { addListener, assign, callAll, createElement, detachNode, init, insertNode, proto, removeListener, timeRangesToArray } from "svelte/shared.js"; -export default (function() { - function create_main_fragment(state, component) { - var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; - - function audio_progress_loadedmetadata_handler() { - audio_updating = true; - component.set({ buffered: timeRangesToArray(audio.buffered) }); - audio_updating = false; - } - - function audio_loadedmetadata_handler() { - audio_updating = true; - component.set({ seekable: timeRangesToArray(audio.seekable) }); - audio_updating = false; - } +function create_main_fragment(state, component) { + var audio, audio_updating = false, audio_animationframe, audio_paused_value = true; - function audio_timeupdate_handler() { - audio_updating = true; - component.set({ played: timeRangesToArray(audio.played) }); - audio_updating = false; - } + function audio_progress_loadedmetadata_handler() { + audio_updating = true; + component.set({ buffered: timeRangesToArray(audio.buffered) }); + audio_updating = false; + } - function audio_timeupdate_handler_1() { - audio_updating = true; - cancelAnimationFrame(audio_animationframe); - if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler_1); - component.set({ currentTime: audio.currentTime }); - audio_updating = false; - } + function audio_loadedmetadata_handler() { + audio_updating = true; + component.set({ seekable: timeRangesToArray(audio.seekable) }); + audio_updating = false; + } - function audio_durationchange_handler() { - audio_updating = true; - component.set({ duration: audio.duration }); - audio_updating = false; - } + function audio_timeupdate_handler() { + audio_updating = true; + component.set({ played: timeRangesToArray(audio.played) }); + audio_updating = false; + } - function audio_pause_handler() { - audio_updating = true; - component.set({ paused: audio.paused }); - audio_updating = false; - } + function audio_timeupdate_handler_1() { + audio_updating = true; + cancelAnimationFrame(audio_animationframe); + if (!audio.paused) audio_animationframe = requestAnimationFrame(audio_timeupdate_handler_1); + component.set({ currentTime: audio.currentTime }); + audio_updating = false; + } - return { - create: function() { - audio = createElement("audio"); - addListener(audio, "play", audio_pause_handler); - this.hydrate(); - }, + function audio_durationchange_handler() { + audio_updating = true; + component.set({ duration: audio.duration }); + audio_updating = false; + } - hydrate: function() { - component._root._beforecreate.push(audio_progress_loadedmetadata_handler); + function audio_pause_handler() { + audio_updating = true; + component.set({ paused: audio.paused }); + audio_updating = false; + } - addListener(audio, "progress", audio_progress_loadedmetadata_handler); - addListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); + return { + create: function() { + audio = createElement("audio"); + addListener(audio, "play", audio_pause_handler); + this.hydrate(); + }, - component._root._beforecreate.push(audio_loadedmetadata_handler); + hydrate: function() { + component._root._beforecreate.push(audio_progress_loadedmetadata_handler); - addListener(audio, "loadedmetadata", audio_loadedmetadata_handler); + addListener(audio, "progress", audio_progress_loadedmetadata_handler); + addListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); - component._root._beforecreate.push(audio_timeupdate_handler); + component._root._beforecreate.push(audio_loadedmetadata_handler); - addListener(audio, "timeupdate", audio_timeupdate_handler); + addListener(audio, "loadedmetadata", audio_loadedmetadata_handler); - component._root._beforecreate.push(audio_timeupdate_handler_1); + component._root._beforecreate.push(audio_timeupdate_handler); - addListener(audio, "timeupdate", audio_timeupdate_handler_1); + addListener(audio, "timeupdate", audio_timeupdate_handler); - component._root._beforecreate.push(audio_durationchange_handler); + component._root._beforecreate.push(audio_timeupdate_handler_1); - addListener(audio, "durationchange", audio_durationchange_handler); + addListener(audio, "timeupdate", audio_timeupdate_handler_1); - component._root._beforecreate.push(audio_pause_handler); + component._root._beforecreate.push(audio_durationchange_handler); - addListener(audio, "pause", audio_pause_handler); - }, + addListener(audio, "durationchange", audio_durationchange_handler); - mount: function(target, anchor) { - insertNode(audio, target, anchor); - }, + component._root._beforecreate.push(audio_pause_handler); - update: function(changed, state) { - if (!audio_updating && !isNaN(state.currentTime )) { - audio.currentTime = state.currentTime ; - } + addListener(audio, "pause", audio_pause_handler); + }, - if (audio_paused_value !== (audio_paused_value = state.paused)) { - audio[audio_paused_value ? "pause" : "play"](); - } - }, + mount: function(target, anchor) { + insertNode(audio, target, anchor); + }, - unmount: function() { - detachNode(audio); - }, + update: function(changed, state) { + if (!audio_updating && !isNaN(state.currentTime )) { + audio.currentTime = state.currentTime ; + } - destroy: function() { - removeListener(audio, "progress", audio_progress_loadedmetadata_handler); - removeListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); - removeListener(audio, "loadedmetadata", audio_loadedmetadata_handler); - removeListener(audio, "timeupdate", audio_timeupdate_handler); - removeListener(audio, "timeupdate", audio_timeupdate_handler_1); - removeListener(audio, "durationchange", audio_durationchange_handler); - removeListener(audio, "pause", audio_pause_handler); - removeListener(audio, "play", audio_pause_handler); + if (audio_paused_value !== (audio_paused_value = state.paused)) { + audio[audio_paused_value ? "pause" : "play"](); } - }; - } + }, + + unmount: function() { + detachNode(audio); + }, + + destroy: function() { + removeListener(audio, "progress", audio_progress_loadedmetadata_handler); + removeListener(audio, "loadedmetadata", audio_progress_loadedmetadata_handler); + removeListener(audio, "loadedmetadata", audio_loadedmetadata_handler); + removeListener(audio, "timeupdate", audio_timeupdate_handler); + removeListener(audio, "timeupdate", audio_timeupdate_handler_1); + removeListener(audio, "durationchange", audio_durationchange_handler); + removeListener(audio, "pause", audio_pause_handler); + removeListener(audio, "play", audio_pause_handler); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - callAll(this._beforecreate); - } + callAll(this._beforecreate); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 443850a62a..2252eb1635 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -180,8 +180,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - var template = (function() { +var template = (function() { return { components: { NonImported @@ -189,71 +188,69 @@ var _actual = (function() { }; }()); - function create_main_fragment(state, component) { - var text; - - var imported = new Imported({ - _root: component._root - }); - - var nonimported = new template.components.NonImported({ - _root: component._root - }); - - return { - create: function() { - imported._fragment.create(); - text = createText("\n"); - nonimported._fragment.create(); - }, - - mount: function(target, anchor) { - imported._mount(target, anchor); - insertNode(text, target, anchor); - nonimported._mount(target, anchor); - }, - - update: noop, - - unmount: function() { - imported._unmount(); - detachNode(text); - nonimported._unmount(); - }, - - destroy: function() { - imported.destroy(false); - nonimported.destroy(false); - } - }; - } +function create_main_fragment(state, component) { + var text; + + var imported = new Imported({ + _root: component._root + }); - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; + var nonimported = new template.components.NonImported({ + _root: component._root + }); - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - this._aftercreate = []; + return { + create: function() { + imported._fragment.create(); + text = createText("\n"); + nonimported._fragment.create(); + }, + + mount: function(target, anchor) { + imported._mount(target, anchor); + insertNode(text, target, anchor); + nonimported._mount(target, anchor); + }, + + update: noop, + + unmount: function() { + imported._unmount(); + detachNode(text); + nonimported._unmount(); + }, + + destroy: function() { + imported.destroy(false); + nonimported.destroy(false); } + }; +} - this._fragment = create_main_fragment(this._state, this); +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } - this._lock = true; - callAll(this._beforecreate); - callAll(this._oncreate); - callAll(this._aftercreate); - this._lock = false; - } + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); + + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js index eec42a057e..e424bb6ffd 100644 --- a/test/js/samples/non-imported-component/expected.js +++ b/test/js/samples/non-imported-component/expected.js @@ -2,8 +2,7 @@ import { assign, callAll, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; import Imported from 'Imported.html'; -export default (function() { - var template = (function() { +var template = (function() { return { components: { NonImported @@ -11,69 +10,68 @@ export default (function() { }; }()); - function create_main_fragment(state, component) { - var text; +function create_main_fragment(state, component) { + var text; - var imported = new Imported({ - _root: component._root - }); + var imported = new Imported({ + _root: component._root + }); - var nonimported = new template.components.NonImported({ - _root: component._root - }); + var nonimported = new template.components.NonImported({ + _root: component._root + }); - return { - create: function() { - imported._fragment.create(); - text = createText("\n"); - nonimported._fragment.create(); - }, + return { + create: function() { + imported._fragment.create(); + text = createText("\n"); + nonimported._fragment.create(); + }, - mount: function(target, anchor) { - imported._mount(target, anchor); - insertNode(text, target, anchor); - nonimported._mount(target, anchor); - }, + mount: function(target, anchor) { + imported._mount(target, anchor); + insertNode(text, target, anchor); + nonimported._mount(target, anchor); + }, - update: noop, + update: noop, - unmount: function() { - imported._unmount(); - detachNode(text); - nonimported._unmount(); - }, + unmount: function() { + imported._unmount(); + detachNode(text); + nonimported._unmount(); + }, - destroy: function() { - imported.destroy(false); - nonimported.destroy(false); - } - }; - } + destroy: function() { + imported.destroy(false); + nonimported.destroy(false); + } + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - if (!options._root) { - this._oncreate = []; - this._beforecreate = []; - this._aftercreate = []; - } + if (!options._root) { + this._oncreate = []; + this._beforecreate = []; + this._aftercreate = []; + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - this._lock = true; - callAll(this._beforecreate); - callAll(this._oncreate); - callAll(this._aftercreate); - this._lock = false; - } + this._lock = true; + callAll(this._beforecreate); + callAll(this._oncreate); + callAll(this._aftercreate); + this._lock = false; } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index 510a76cf31..bebd336b6c 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -166,8 +166,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - var template = (function() { +var template = (function() { return { // this test should be removed in v2 oncreate () {}, @@ -175,47 +174,45 @@ var _actual = (function() { }; }()); - function create_main_fragment(state, component) { +function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._handlers.destroy = [template.ondestroy]; + this._handlers.destroy = [template.ondestroy]; - var oncreate = template.oncreate.bind(this); + var oncreate = template.oncreate.bind(this); - if (!options._root) { - this._oncreate = [oncreate]; - } else { - this._root._oncreate.push(oncreate); - } + if (!options._root) { + this._oncreate = [oncreate]; + } else { + this._root._oncreate.push(oncreate); + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - callAll(this._oncreate); - } + callAll(this._oncreate); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js index ba5c4a62ea..d29f9fd752 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected.js @@ -1,8 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { assign, callAll, init, noop, proto } from "svelte/shared.js"; -export default (function() { - var template = (function() { +var template = (function() { return { // this test should be removed in v2 oncreate () {}, @@ -10,45 +9,44 @@ export default (function() { }; }()); - function create_main_fragment(state, component) { +function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._handlers.destroy = [template.ondestroy] + this._handlers.destroy = [template.ondestroy] - var oncreate = template.oncreate.bind(this); + var oncreate = template.oncreate.bind(this); - if (!options._root) { - this._oncreate = [oncreate]; - } else { - this._root._oncreate.push(oncreate); - } + if (!options._root) { + this._oncreate = [oncreate]; + } else { + this._root._oncreate.push(oncreate); + } - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); - callAll(this._oncreate); - } + callAll(this._oncreate); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index 5b90eb1f6a..85bc643281 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -166,8 +166,7 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - var template = (function() { +var template = (function() { return { methods: { foo ( bar ) { @@ -186,37 +185,35 @@ var _actual = (function() { }; }()); - function create_main_fragment(state, component) { +function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, template.methods, proto); +assign(SvelteComponent.prototype, template.methods, proto); - template.setup(SvelteComponent); - return SvelteComponent; -}()); +template.setup(SvelteComponent); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 8207a4ea6e..b3bd9fcc8e 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,8 +1,7 @@ /* generated by Svelte vX.Y.Z */ import { assign, init, noop, proto } from "svelte/shared.js"; -export default (function() { - var template = (function() { +var template = (function() { return { methods: { foo ( bar ) { @@ -21,35 +20,34 @@ export default (function() { }; }()); - function create_main_fragment(state, component) { +function create_main_fragment(state, component) { - return { - create: noop, + return { + create: noop, - mount: noop, + mount: noop, - update: noop, + update: noop, - unmount: noop, + unmount: noop, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, template.methods, proto); +assign(SvelteComponent.prototype, template.methods, proto); - template.setup(SvelteComponent); - return SvelteComponent; -}()); \ No newline at end of file +template.setup(SvelteComponent); +export default SvelteComponent; \ No newline at end of file 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 8d7482a7b7..977bdfe485 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -190,273 +190,270 @@ var proto = { }; /* generated by Svelte vX.Y.Z */ -var _actual = (function() { - 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; - - var if_block = (state.a) && create_if_block(state, component); - - var if_block_1 = (state.b) && create_if_block_1(state, component); - - var if_block_2 = (state.c) && create_if_block_2(state, component); - - var if_block_3 = (state.d) && create_if_block_3(state, component); - - var if_block_4 = (state.e) && create_if_block_4(state, component); - - return { - create: function() { - div = createElement("div"); - if (if_block) if_block.create(); - text = createText("\n\n\t"); - p = createElement("p"); - text_1 = createText("this can be used as an anchor"); - text_2 = createText("\n\n\t"); - if (if_block_1) if_block_1.create(); - text_3 = createText("\n\n\t"); - if (if_block_2) if_block_2.create(); - text_4 = createText("\n\n\t"); - p_1 = createElement("p"); - text_5 = createText("so can this"); - text_6 = createText("\n\n\t"); - if (if_block_3) if_block_3.create(); - text_8 = createText("\n\n"); - if (if_block_4) if_block_4.create(); - if_block_4_anchor = createComment(); - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - if (if_block) if_block.mount(div, null); - appendNode(text, div); - appendNode(p, div); - appendNode(text_1, p); - appendNode(text_2, div); - if (if_block_1) if_block_1.mount(div, null); - appendNode(text_3, div); - if (if_block_2) if_block_2.mount(div, null); - appendNode(text_4, div); - appendNode(p_1, div); - appendNode(text_5, p_1); - appendNode(text_6, div); - if (if_block_3) if_block_3.mount(div, null); - insertNode(text_8, target, anchor); - if (if_block_4) if_block_4.mount(target, anchor); - insertNode(if_block_4_anchor, target, anchor); - }, - - update: function(changed, state) { - if (state.a) { - if (!if_block) { - if_block = create_if_block(state, component); - if_block.create(); - if_block.mount(div, text); - } - } else if (if_block) { - if_block.unmount(); - if_block.destroy(); - if_block = null; +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; + + var if_block = (state.a) && create_if_block(state, component); + + var if_block_1 = (state.b) && create_if_block_1(state, component); + + var if_block_2 = (state.c) && create_if_block_2(state, component); + + var if_block_3 = (state.d) && create_if_block_3(state, component); + + var if_block_4 = (state.e) && create_if_block_4(state, component); + + return { + create: function() { + div = createElement("div"); + if (if_block) if_block.create(); + text = createText("\n\n\t"); + p = createElement("p"); + text_1 = createText("this can be used as an anchor"); + text_2 = createText("\n\n\t"); + if (if_block_1) if_block_1.create(); + text_3 = createText("\n\n\t"); + if (if_block_2) if_block_2.create(); + text_4 = createText("\n\n\t"); + p_1 = createElement("p"); + text_5 = createText("so can this"); + text_6 = createText("\n\n\t"); + if (if_block_3) if_block_3.create(); + text_8 = createText("\n\n"); + if (if_block_4) if_block_4.create(); + if_block_4_anchor = createComment(); + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + if (if_block) if_block.mount(div, null); + appendNode(text, div); + appendNode(p, div); + appendNode(text_1, p); + appendNode(text_2, div); + if (if_block_1) if_block_1.mount(div, null); + appendNode(text_3, div); + if (if_block_2) if_block_2.mount(div, null); + appendNode(text_4, div); + appendNode(p_1, div); + appendNode(text_5, p_1); + appendNode(text_6, div); + if (if_block_3) if_block_3.mount(div, null); + insertNode(text_8, target, anchor); + if (if_block_4) if_block_4.mount(target, anchor); + insertNode(if_block_4_anchor, target, anchor); + }, + + update: function(changed, state) { + if (state.a) { + if (!if_block) { + if_block = create_if_block(state, component); + if_block.create(); + if_block.mount(div, text); } + } else if (if_block) { + if_block.unmount(); + if_block.destroy(); + if_block = null; + } - if (state.b) { - if (!if_block_1) { - if_block_1 = create_if_block_1(state, component); - if_block_1.create(); - if_block_1.mount(div, text_3); - } - } else if (if_block_1) { - if_block_1.unmount(); - if_block_1.destroy(); - if_block_1 = null; + if (state.b) { + if (!if_block_1) { + if_block_1 = create_if_block_1(state, component); + if_block_1.create(); + if_block_1.mount(div, text_3); } + } else if (if_block_1) { + if_block_1.unmount(); + if_block_1.destroy(); + if_block_1 = null; + } - if (state.c) { - if (!if_block_2) { - if_block_2 = create_if_block_2(state, component); - if_block_2.create(); - if_block_2.mount(div, text_4); - } - } else if (if_block_2) { - if_block_2.unmount(); - if_block_2.destroy(); - if_block_2 = null; + if (state.c) { + if (!if_block_2) { + if_block_2 = create_if_block_2(state, component); + if_block_2.create(); + if_block_2.mount(div, text_4); } + } else if (if_block_2) { + if_block_2.unmount(); + if_block_2.destroy(); + if_block_2 = null; + } - if (state.d) { - if (!if_block_3) { - if_block_3 = create_if_block_3(state, component); - if_block_3.create(); - if_block_3.mount(div, null); - } - } else if (if_block_3) { - if_block_3.unmount(); - if_block_3.destroy(); - if_block_3 = null; + if (state.d) { + if (!if_block_3) { + if_block_3 = create_if_block_3(state, component); + if_block_3.create(); + if_block_3.mount(div, null); } + } else if (if_block_3) { + if_block_3.unmount(); + if_block_3.destroy(); + if_block_3 = null; + } - if (state.e) { - if (!if_block_4) { - if_block_4 = create_if_block_4(state, component); - if_block_4.create(); - if_block_4.mount(if_block_4_anchor.parentNode, if_block_4_anchor); - } - } else if (if_block_4) { - if_block_4.unmount(); - if_block_4.destroy(); - if_block_4 = null; + if (state.e) { + if (!if_block_4) { + if_block_4 = create_if_block_4(state, component); + if_block_4.create(); + if_block_4.mount(if_block_4_anchor.parentNode, if_block_4_anchor); } - }, - - unmount: function() { - detachNode(div); - if (if_block) if_block.unmount(); - if (if_block_1) if_block_1.unmount(); - if (if_block_2) if_block_2.unmount(); - if (if_block_3) if_block_3.unmount(); - detachNode(text_8); - if (if_block_4) if_block_4.unmount(); - detachNode(if_block_4_anchor); - }, - - destroy: function() { - if (if_block) if_block.destroy(); - if (if_block_1) if_block_1.destroy(); - if (if_block_2) if_block_2.destroy(); - if (if_block_3) if_block_3.destroy(); - if (if_block_4) if_block_4.destroy(); + } else if (if_block_4) { + if_block_4.unmount(); + if_block_4.destroy(); + if_block_4 = null; } - }; - } + }, + + unmount: function() { + detachNode(div); + if (if_block) if_block.unmount(); + if (if_block_1) if_block_1.unmount(); + if (if_block_2) if_block_2.unmount(); + if (if_block_3) if_block_3.unmount(); + detachNode(text_8); + if (if_block_4) if_block_4.unmount(); + detachNode(if_block_4_anchor); + }, + + destroy: function() { + if (if_block) if_block.destroy(); + if (if_block_1) if_block_1.destroy(); + if (if_block_2) if_block_2.destroy(); + if (if_block_3) if_block_3.destroy(); + if (if_block_4) if_block_4.destroy(); + } + }; +} - // (2:1) {{#if a}} - function create_if_block(state, component) { - var p, text; +// (2:1) {{#if a}} +function create_if_block(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("a"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("a"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; - } + destroy: noop + }; +} - // (8:1) {{#if b}} - function create_if_block_1(state, component) { - var p, text; +// (8:1) {{#if b}} +function create_if_block_1(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("b"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("b"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; - } + destroy: noop + }; +} - // (12:1) {{#if c}} - function create_if_block_2(state, component) { - var p, text; +// (12:1) {{#if c}} +function create_if_block_2(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("c"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("c"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; - } + destroy: noop + }; +} - // (18:1) {{#if d}} - function create_if_block_3(state, component) { - var p, text; +// (18:1) {{#if d}} +function create_if_block_3(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("d"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("d"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; - } + destroy: noop + }; +} - // (25:0) {{#if e}} - function create_if_block_4(state, component) { - var p, text; +// (25:0) {{#if e}} +function create_if_block_4(state, component) { + var p, text; - return { - create: function() { - p = createElement("p"); - text = createText("e"); - }, + return { + create: function() { + p = createElement("p"); + text = createText("e"); + }, - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, - unmount: function() { - detachNode(p); - }, + unmount: function() { + detachNode(p); + }, - destroy: noop - }; - } + destroy: noop + }; +} - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; - this._fragment = create_main_fragment(this._state, this); + this._fragment = create_main_fragment(this._state, this); - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); - } + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); +assign(SvelteComponent.prototype, proto); -export default _actual; +export default SvelteComponent; diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js index 35db8336d6..e92d7ba6b6 100644 --- a/test/js/samples/use-elements-as-anchors/expected.js +++ b/test/js/samples/use-elements-as-anchors/expected.js @@ -1,271 +1,269 @@ /* generated by Svelte vX.Y.Z */ import { appendNode, assign, createComment, createElement, createText, detachNode, init, insertNode, noop, proto } from "svelte/shared.js"; -export default (function() { - 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; - - var if_block = (state.a) && create_if_block(state, component); - - var if_block_1 = (state.b) && create_if_block_1(state, component); - - var if_block_2 = (state.c) && create_if_block_2(state, component); - - var if_block_3 = (state.d) && create_if_block_3(state, component); - - var if_block_4 = (state.e) && create_if_block_4(state, component); - - return { - create: function() { - div = createElement("div"); - if (if_block) if_block.create(); - text = createText("\n\n\t"); - p = createElement("p"); - text_1 = createText("this can be used as an anchor"); - text_2 = createText("\n\n\t"); - if (if_block_1) if_block_1.create(); - text_3 = createText("\n\n\t"); - if (if_block_2) if_block_2.create(); - text_4 = createText("\n\n\t"); - p_1 = createElement("p"); - text_5 = createText("so can this"); - text_6 = createText("\n\n\t"); - if (if_block_3) if_block_3.create(); - text_8 = createText("\n\n"); - if (if_block_4) if_block_4.create(); - if_block_4_anchor = createComment(); - }, - - mount: function(target, anchor) { - insertNode(div, target, anchor); - if (if_block) if_block.mount(div, null); - appendNode(text, div); - appendNode(p, div); - appendNode(text_1, p); - appendNode(text_2, div); - if (if_block_1) if_block_1.mount(div, null); - appendNode(text_3, div); - if (if_block_2) if_block_2.mount(div, null); - appendNode(text_4, div); - appendNode(p_1, div); - appendNode(text_5, p_1); - appendNode(text_6, div); - if (if_block_3) if_block_3.mount(div, null); - insertNode(text_8, target, anchor); - if (if_block_4) if_block_4.mount(target, anchor); - insertNode(if_block_4_anchor, target, anchor); - }, - - update: function(changed, state) { - if (state.a) { - if (!if_block) { - if_block = create_if_block(state, component); - if_block.create(); - if_block.mount(div, text); - } - } else if (if_block) { - if_block.unmount(); - if_block.destroy(); - if_block = null; +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; + + var if_block = (state.a) && create_if_block(state, component); + + var if_block_1 = (state.b) && create_if_block_1(state, component); + + var if_block_2 = (state.c) && create_if_block_2(state, component); + + var if_block_3 = (state.d) && create_if_block_3(state, component); + + var if_block_4 = (state.e) && create_if_block_4(state, component); + + return { + create: function() { + div = createElement("div"); + if (if_block) if_block.create(); + text = createText("\n\n\t"); + p = createElement("p"); + text_1 = createText("this can be used as an anchor"); + text_2 = createText("\n\n\t"); + if (if_block_1) if_block_1.create(); + text_3 = createText("\n\n\t"); + if (if_block_2) if_block_2.create(); + text_4 = createText("\n\n\t"); + p_1 = createElement("p"); + text_5 = createText("so can this"); + text_6 = createText("\n\n\t"); + if (if_block_3) if_block_3.create(); + text_8 = createText("\n\n"); + if (if_block_4) if_block_4.create(); + if_block_4_anchor = createComment(); + }, + + mount: function(target, anchor) { + insertNode(div, target, anchor); + if (if_block) if_block.mount(div, null); + appendNode(text, div); + appendNode(p, div); + appendNode(text_1, p); + appendNode(text_2, div); + if (if_block_1) if_block_1.mount(div, null); + appendNode(text_3, div); + if (if_block_2) if_block_2.mount(div, null); + appendNode(text_4, div); + appendNode(p_1, div); + appendNode(text_5, p_1); + appendNode(text_6, div); + if (if_block_3) if_block_3.mount(div, null); + insertNode(text_8, target, anchor); + if (if_block_4) if_block_4.mount(target, anchor); + insertNode(if_block_4_anchor, target, anchor); + }, + + update: function(changed, state) { + if (state.a) { + if (!if_block) { + if_block = create_if_block(state, component); + if_block.create(); + if_block.mount(div, text); } + } else if (if_block) { + if_block.unmount(); + if_block.destroy(); + if_block = null; + } - if (state.b) { - if (!if_block_1) { - if_block_1 = create_if_block_1(state, component); - if_block_1.create(); - if_block_1.mount(div, text_3); - } - } else if (if_block_1) { - if_block_1.unmount(); - if_block_1.destroy(); - if_block_1 = null; + if (state.b) { + if (!if_block_1) { + if_block_1 = create_if_block_1(state, component); + if_block_1.create(); + if_block_1.mount(div, text_3); } + } else if (if_block_1) { + if_block_1.unmount(); + if_block_1.destroy(); + if_block_1 = null; + } - if (state.c) { - if (!if_block_2) { - if_block_2 = create_if_block_2(state, component); - if_block_2.create(); - if_block_2.mount(div, text_4); - } - } else if (if_block_2) { - if_block_2.unmount(); - if_block_2.destroy(); - if_block_2 = null; + if (state.c) { + if (!if_block_2) { + if_block_2 = create_if_block_2(state, component); + if_block_2.create(); + if_block_2.mount(div, text_4); } + } else if (if_block_2) { + if_block_2.unmount(); + if_block_2.destroy(); + if_block_2 = null; + } - if (state.d) { - if (!if_block_3) { - if_block_3 = create_if_block_3(state, component); - if_block_3.create(); - if_block_3.mount(div, null); - } - } else if (if_block_3) { - if_block_3.unmount(); - if_block_3.destroy(); - if_block_3 = null; + if (state.d) { + if (!if_block_3) { + if_block_3 = create_if_block_3(state, component); + if_block_3.create(); + if_block_3.mount(div, null); } + } else if (if_block_3) { + if_block_3.unmount(); + if_block_3.destroy(); + if_block_3 = null; + } - if (state.e) { - if (!if_block_4) { - if_block_4 = create_if_block_4(state, component); - if_block_4.create(); - if_block_4.mount(if_block_4_anchor.parentNode, if_block_4_anchor); - } - } else if (if_block_4) { - if_block_4.unmount(); - if_block_4.destroy(); - if_block_4 = null; + if (state.e) { + if (!if_block_4) { + if_block_4 = create_if_block_4(state, component); + if_block_4.create(); + if_block_4.mount(if_block_4_anchor.parentNode, if_block_4_anchor); } - }, - - unmount: function() { - detachNode(div); - if (if_block) if_block.unmount(); - if (if_block_1) if_block_1.unmount(); - if (if_block_2) if_block_2.unmount(); - if (if_block_3) if_block_3.unmount(); - detachNode(text_8); - if (if_block_4) if_block_4.unmount(); - detachNode(if_block_4_anchor); - }, - - destroy: function() { - if (if_block) if_block.destroy(); - if (if_block_1) if_block_1.destroy(); - if (if_block_2) if_block_2.destroy(); - if (if_block_3) if_block_3.destroy(); - if (if_block_4) if_block_4.destroy(); + } else if (if_block_4) { + if_block_4.unmount(); + if_block_4.destroy(); + if_block_4 = null; } - }; - } - - // (2:1) {{#if a}} - function create_if_block(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("a"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; - } - - // (8:1) {{#if b}} - function create_if_block_1(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("b"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; - } - - // (12:1) {{#if c}} - function create_if_block_2(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("c"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; - } - - // (18:1) {{#if d}} - function create_if_block_3(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("d"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; - } - - // (25:0) {{#if e}} - function create_if_block_4(state, component) { - var p, text; - - return { - create: function() { - p = createElement("p"); - text = createText("e"); - }, - - mount: function(target, anchor) { - insertNode(p, target, anchor); - appendNode(text, p); - }, - - unmount: function() { - detachNode(p); - }, - - destroy: noop - }; - } - - function SvelteComponent(options) { - init(this, options); - this._state = options.data || {}; - - this._fragment = create_main_fragment(this._state, this); - - if (options.target) { - this._fragment.create(); - this._fragment.mount(options.target, options.anchor || null); + }, + + unmount: function() { + detachNode(div); + if (if_block) if_block.unmount(); + if (if_block_1) if_block_1.unmount(); + if (if_block_2) if_block_2.unmount(); + if (if_block_3) if_block_3.unmount(); + detachNode(text_8); + if (if_block_4) if_block_4.unmount(); + detachNode(if_block_4_anchor); + }, + + destroy: function() { + if (if_block) if_block.destroy(); + if (if_block_1) if_block_1.destroy(); + if (if_block_2) if_block_2.destroy(); + if (if_block_3) if_block_3.destroy(); + if (if_block_4) if_block_4.destroy(); } + }; +} + +// (2:1) {{#if a}} +function create_if_block(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("a"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; +} + +// (8:1) {{#if b}} +function create_if_block_1(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("b"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; +} + +// (12:1) {{#if c}} +function create_if_block_2(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("c"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; +} + +// (18:1) {{#if d}} +function create_if_block_3(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("d"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; +} + +// (25:0) {{#if e}} +function create_if_block_4(state, component) { + var p, text; + + return { + create: function() { + p = createElement("p"); + text = createText("e"); + }, + + mount: function(target, anchor) { + insertNode(p, target, anchor); + appendNode(text, p); + }, + + unmount: function() { + detachNode(p); + }, + + destroy: noop + }; +} + +function SvelteComponent(options) { + init(this, options); + this._state = options.data || {}; + + this._fragment = create_main_fragment(this._state, this); + + if (options.target) { + this._fragment.create(); + this._fragment.mount(options.target, options.anchor || null); } +} - assign(SvelteComponent.prototype, proto); - return SvelteComponent; -}()); \ No newline at end of file +assign(SvelteComponent.prototype, proto); +export default SvelteComponent; \ No newline at end of file diff --git a/test/runtime/index.js b/test/runtime/index.js index e46f6c8fa7..122fe645b6 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -74,7 +74,7 @@ describe("runtime", () => { const { code } = svelte.compile(source, compileOptions); const startIndex = code.indexOf("function create_main_fragment"); // may change! if (startIndex === -1) throw new Error("missing create_main_fragment"); - const endIndex = code.lastIndexOf("return"); + const endIndex = code.lastIndexOf("export default"); const es5 = code.slice(0, startIndex).split('\n').map(x => spaces(x.length)).join('\n') + code.slice(startIndex, endIndex); From 3f8a59c8dd547b792451ff5a5c0d220acf20167f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 19 Sep 2017 11:28:02 -0400 Subject: [PATCH 8/8] -> v1.39.4 --- CHANGELOG.md | 8 ++++++++ package.json | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b77fd46d40..b12a89cf82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Svelte changelog +## 1.39.4 + +* Extract shared init logic ([#855](https://github.com/sveltejs/svelte/pull/855)) +* Allow `console.*` calls in event handlers ([#782](https://github.com/sveltejs/svelte/issues/782)) +* Marker comments in output ([#823](https://github.com/sveltejs/svelte/issues/823)) +* Use `textContent` and `innerHTML` where appropriate ([#23](https://github.com/sveltejs/svelte/issues/23)) +* Various improvements to generated code + ## 1.39.3 * Allow `slot='...'` inside custom elements ([#827](https://github.com/sveltejs/svelte/issues/827)) diff --git a/package.json b/package.json index b06cacc724..a3ff6bc5f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "svelte", - "version": "1.39.3", + "version": "1.39.4", "description": "The magical disappearing UI framework", "main": "compiler/svelte.js", "files": [