From 42e1c8f191294c78a75ab5406225913f2aa30a53 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Wed, 9 Oct 2019 08:36:28 -0400 Subject: [PATCH] various --- src/compiler/compile/Component.ts | 32 +------------------ src/compiler/compile/create_module.ts | 5 +++ src/compiler/compile/render_dom/Block.ts | 8 +++++ .../compile/render_dom/wrappers/Window.ts | 2 +- test/js/index.js | 2 +- test/js/samples/bind-online/expected.js | 7 ++-- 6 files changed, 18 insertions(+), 38 deletions(-) diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index 292657095d..885bf1895f 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -253,41 +253,11 @@ export default class Component { const { compile_options, name } = this; const { format = 'esm' } = compile_options; + // TODO reinstate banner (along with fragment marker comments) const banner = `/* ${ this.file ? `${this.file} ` : `` }generated by Svelte v${'__VERSION__'} */`; - // result = result - // .replace(/__svelte:self__/g, this.name) - // .replace( - // compile_options.generate === 'ssr' - // ? /(@+|#+)(\w*(?:-\w*)?)/g - // : /(@+)(\w*(?:-\w*)?)/g, - // (_match: string, sigil: string, name: string) => { - // if (sigil === '@') { - // if (name[0] === '_') { - // return this.global(name.slice(1)); - // } - - // if (!internal_exports.has(name)) { - // throw new Error( - // `compiler error: this shouldn't happen! generated code is trying to use inexistent internal '${name}'` - // ); - // } - - // if (compile_options.dev) { - // if (internal_exports.has(`${name}_dev`)) name = `${name}_dev`; - // else if (internal_exports.has(`${name}Dev`)) - // name = `${name}Dev`; - // } - - // return this.helper(name); - // } - - // return sigil.slice(1) + name; - // } - // ); - const program: any = { type: 'Program', body: result }; walk(program, { diff --git a/src/compiler/compile/create_module.ts b/src/compiler/compile/create_module.ts index 87d7da0dc7..5f2f0cebfd 100644 --- a/src/compiler/compile/create_module.ts +++ b/src/compiler/compile/create_module.ts @@ -23,6 +23,11 @@ export default function create_module( ) { const internal_path = `${sveltePath}/internal`; + helpers.sort((a, b) => { + if (a.name < b.name) return -1; + return 1; + }); + if (format === 'esm') { return esm(program, name, banner, sveltePath, internal_path, helpers, globals, imports, module_exports); } diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index c149ca642d..fba1b55165 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -352,6 +352,14 @@ export default class Block { }`; } + if (!this.renderer.component.compile_options.dev) { + // allow shorthand names + for (const name in properties) { + const property = properties[name]; + if (property) property.id = null; + } + } + const return_value: any = x`{ key: ${properties.key}, first: ${properties.first}, diff --git a/src/compiler/compile/render_dom/wrappers/Window.ts b/src/compiler/compile/render_dom/wrappers/Window.ts index ce63a431d4..90846f8a7c 100644 --- a/src/compiler/compile/render_dom/wrappers/Window.ts +++ b/src/compiler/compile/render_dom/wrappers/Window.ts @@ -167,7 +167,7 @@ export default class WindowWrapper extends Wrapper { component.partly_hoisted.push(b` function ${id}() { - ${name} = @_navigator.onLine; $$invalidate('${name}', ${name}); + $$invalidate('${name}', ${name} = @_navigator.onLine); } `); diff --git a/test/js/index.js b/test/js/index.js index 1026ea2fdc..e0fdaa1175 100644 --- a/test/js/index.js +++ b/test/js/index.js @@ -3,7 +3,7 @@ import * as fs from "fs"; import * as path from "path"; import { loadConfig, svelte } from "../helpers.js"; -describe.skip("js", () => { +describe.only("js", () => { fs.readdirSync("test/js/samples").forEach(dir => { if (dir[0] === ".") return; diff --git a/test/js/samples/bind-online/expected.js b/test/js/samples/bind-online/expected.js index 0c9faa3ef6..d42f804325 100644 --- a/test/js/samples/bind-online/expected.js +++ b/test/js/samples/bind-online/expected.js @@ -10,8 +10,7 @@ import { } from "svelte/internal"; function create_fragment(ctx) { - var dispose; - + let dispose; add_render_callback(ctx.onlinestatuschanged); return { @@ -21,12 +20,10 @@ function create_fragment(ctx) { listen(window, "offline", ctx.onlinestatuschanged) ]; }, - m: noop, p: noop, i: noop, o: noop, - d(detaching) { run_all(dispose); } @@ -37,7 +34,7 @@ function instance($$self, $$props, $$invalidate) { let online; function onlinestatuschanged() { - online = navigator.onLine; $$invalidate('online', online); + $$invalidate("online", online = navigator.onLine); } return { online, onlinestatuschanged };