From 9b5589f14d4cf37166e256c82030d4360118320c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 8 Dec 2018 18:30:26 -0500 Subject: [PATCH] tweak code generation --- src/compile/Component.ts | 16 +++++++++------- .../action-custom-event-handler/expected.js | 1 + test/js/samples/dynamic-import/expected.js | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 9d2cf13a71..b9ced34baf 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -442,23 +442,25 @@ export default class Component { let a = script.content.start; while (/\s/.test(this.source[a])) a += 1; + let b = a; + let result = ''; script.content.body.forEach((node, i) => { if (this.hoistable_nodes.has(node) || this.reactive_declaration_nodes.has(node)) { - result += `[✂${a}-${node.start}✂]`; + if (a !== b) result += `[✂${a}-${b}✂]`; a = node.end; - - if (i < script.content.body.length - 1) { - while (a < this.source.length && /\s/.test(this.source[a])) a += 1; - } } + + b = node.end; }); - let b = script.content.end; + // while (/\s/.test(this.source[a - 1])) a -= 1; + + b = script.content.end; while (/\s/.test(this.source[b - 1])) b -= 1; - if (a !== b) result += `[✂${a}-${b}✂]`; + if (a < b) result += `[✂${a}-${b}✂]`; return result || null; } diff --git a/test/js/samples/action-custom-event-handler/expected.js b/test/js/samples/action-custom-event-handler/expected.js index 7692dd3195..138b0d3abc 100644 --- a/test/js/samples/action-custom-event-handler/expected.js +++ b/test/js/samples/action-custom-event-handler/expected.js @@ -72,4 +72,5 @@ class SvelteComponent extends SvelteComponent_1 { flush(); } } + export default SvelteComponent; \ No newline at end of file diff --git a/test/js/samples/dynamic-import/expected.js b/test/js/samples/dynamic-import/expected.js index 159afc1f7f..10fdb98f8d 100644 --- a/test/js/samples/dynamic-import/expected.js +++ b/test/js/samples/dynamic-import/expected.js @@ -1,5 +1,5 @@ /* generated by Svelte vX.Y.Z-alpha1 */ -import { SvelteComponent as SvelteComponent_1, init, mount_component, safe_not_equal } from "svelte/internal.js"; +import { SvelteComponent as SvelteComponent_1, init, mount_component, noop, safe_not_equal } from "svelte/internal.js"; function create_fragment(component, ctx) { var current;