diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 238c1ac2b6..f57fe8a534 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -523,6 +523,7 @@ export default class Component { // TODO unindent this.extract_imports_and_exports(script.content, this.imports, this.module_exports); + remove_indentation(this.code, script.content); this.module_javascript = this.extract_javascript(script); } diff --git a/src/compile/render-ssr/index.ts b/src/compile/render-ssr/index.ts index 958af3322e..8570a5db18 100644 --- a/src/compile/render-ssr/index.ts +++ b/src/compile/render-ssr/index.ts @@ -65,6 +65,10 @@ export default function ssr( map: ${css.map ? stringify(css.map.toString()) : 'null'} };`} + ${component.module_javascript} + + ${component.fully_hoisted.length > 0 && component.fully_hoisted.join('\n\n')} + const ${name} = @create_ssr_component(($$result, $$props, $$bindings, $$slots) => { ${setup} diff --git a/src/utils/remove_indentation.ts b/src/utils/remove_indentation.ts index 7afa2d5260..2d66853f68 100644 --- a/src/utils/remove_indentation.ts +++ b/src/utils/remove_indentation.ts @@ -16,18 +16,14 @@ export function remove_indentation(code: MagicString, node: Node) { } }); - let dirty = false; + const str = code.original.slice(node.start, node.end); - const str = code.original - .slice(node.start, node.end) - .replace(pattern, (match, i) => { - const index = node.start + i; - while (excluded[0] && excluded[0].end < index) excluded.shift(); - if (excluded[0] && excluded[0].start < index) return match; + let match; + while (match = pattern.exec(str)) { + const index = node.start + match.index; + while (excluded[0] && excluded[0].end < index) excluded.shift(); + if (excluded[0] && excluded[0].start < index) continue; - dirty = true; - return ''; - }); - - if (dirty) code.overwrite(node.start, node.end, str); + code.remove(index, index + indent.length); + } } \ No newline at end of file diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/action-custom-event-handler/expected.js similarity index 100% rename from test/js/samples/event-handlers-custom/expected.js rename to test/js/samples/action-custom-event-handler/expected.js diff --git a/test/js/samples/event-handlers-custom/input.html b/test/js/samples/action-custom-event-handler/input.html similarity index 100% rename from test/js/samples/event-handlers-custom/input.html rename to test/js/samples/action-custom-event-handler/input.html diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js index 66fa150c61..9edf84deed 100644 --- a/test/js/samples/computed-collapsed-if/expected.js +++ b/test/js/samples/computed-collapsed-if/expected.js @@ -2,6 +2,8 @@ import { SvelteComponent as SvelteComponent_1, flush, init, noop, run, safe_not_equal } from "svelte/internal.js"; function create_fragment(component, ctx) { + var current; + return { c: noop, m: noop, diff --git a/test/js/samples/deconflict-globals/expected.js b/test/js/samples/deconflict-globals/expected.js index f77c8f2584..40f9096349 100644 --- a/test/js/samples/deconflict-globals/expected.js +++ b/test/js/samples/deconflict-globals/expected.js @@ -3,6 +3,8 @@ import { SvelteComponent as SvelteComponent_1, flush, init, noop, run, safe_not_ import { onMount } from "svelte"; function create_fragment(component, ctx) { + var current; + return { c: noop, m: noop, diff --git a/test/js/samples/setup-method/expected.js b/test/js/samples/setup-method/expected.js index 5b2b7cc78f..e40730a8c6 100644 --- a/test/js/samples/setup-method/expected.js +++ b/test/js/samples/setup-method/expected.js @@ -1,13 +1,9 @@ /* generated by Svelte vX.Y.Z-alpha1 */ import { SvelteComponent as SvelteComponent_1, init, noop, run, safe_not_equal } from "svelte/internal.js"; -const SOME_CONSTANT = 42; - -function foo(bar) { - console.log(bar); -} - function create_fragment(component, ctx) { + var current; + return { c: noop, m: noop, @@ -18,10 +14,16 @@ function create_fragment(component, ctx) { }; } +const SOME_CONSTANT = 42; + +function foo(bar) { + console.log(bar); +} + class SvelteComponent extends SvelteComponent_1 { constructor(options) { super(); - init(this, options, define, create_fragment, safe_not_equal); + init(this, options, noop, create_fragment, safe_not_equal); } get foo() { diff --git a/test/js/samples/ssr-no-oncreate-etc/expected.js b/test/js/samples/ssr-no-oncreate-etc/expected.js index 1335ce2942..3e8d2ecc81 100644 --- a/test/js/samples/ssr-no-oncreate-etc/expected.js +++ b/test/js/samples/ssr-no-oncreate-etc/expected.js @@ -1,6 +1,6 @@ /* generated by Svelte vX.Y.Z-alpha1 */ import { create_ssr_component } from "svelte/internal.js"; -import { onMount, onDestroy } from "svelte"; +import { onDestroy, onMount } from "svelte"; function preload(input) { return output; @@ -23,6 +23,10 @@ const SvelteComponent = create_ssr_component(($$result, $$props, $$bindings, $$s console.log('onDestroy'); }); + /* HOISTED */ + + /* HOISTED */ + return ``; }); diff --git a/test/parser/samples/textarea-children/output.json b/test/parser/samples/textarea-children/output.json index 5d345f9bfa..08f42919ed 100644 --- a/test/parser/samples/textarea-children/output.json +++ b/test/parser/samples/textarea-children/output.json @@ -9,32 +9,38 @@ "end": 61, "type": "Element", "name": "textarea", - "attributes": [], - "children": [ + "attributes": [ { - "start": 10, - "end": 40, - "type": "Text", - "data": "\n\t
not actually an element. " - }, - { - "start": 40, - "end": 45, - "type": "MustacheTag", - "expression": { - "type": "Identifier", - "start": 41, - "end": 44, - "name": "foo" - } - }, - { - "start": 45, - "end": 50, - "type": "Text", - "data": "
\n" + "type": "Attribute", + "name": "value", + "value": [ + { + "start": 10, + "end": 40, + "type": "Text", + "data": "\n\tnot actually an element. " + }, + { + "start": 40, + "end": 45, + "type": "MustacheTag", + "expression": { + "type": "Identifier", + "start": 41, + "end": 44, + "name": "foo" + } + }, + { + "start": 45, + "end": 50, + "type": "Text", + "data": "
\n" + } + ] } - ] + ], + "children": [] } ] },