diff --git a/src/compiler/compile/Component.ts b/src/compiler/compile/Component.ts index cec01401fb..cd97c8dd8e 100644 --- a/src/compiler/compile/Component.ts +++ b/src/compiler/compile/Component.ts @@ -162,13 +162,12 @@ export default class Component { this.tag = this.name.name; } - this.walk_module_js_pre_template(); + this.walk_module_js(); this.walk_instance_js_pre_template(); this.fragment = new Fragment(this, ast.html); this.name = this.get_unique_name(name); - this.walk_module_js_post_template(); this.walk_instance_js_post_template(); if (!compile_options.customElement) this.stylesheet.reify(); @@ -517,7 +516,7 @@ export default class Component { }); } - walk_module_js_pre_template() { + walk_module_js() { const component = this; const script = this.ast.module; if (!script) return; @@ -568,6 +567,25 @@ export default class Component { }); } }); + + const { body } = script.content; + let i = body.length; + while (--i >= 0) { + const node = body[i]; + if (node.type === 'ImportDeclaration') { + this.extract_imports(node); + body.splice(i, 1); + } + + if (/^Export/.test(node.type)) { + const replacement = this.extract_exports(node); + if (replacement) { + body[i] = replacement; + } else { + body.splice(i, 1); + } + } + } } walk_instance_js_pre_template() { @@ -665,30 +683,6 @@ export default class Component { this.track_references_and_mutations(); } - walk_module_js_post_template() { - const script = this.ast.module; - if (!script) return; - - const { body } = script.content; - let i = body.length; - while (--i >= 0) { - const node = body[i]; - if (node.type === 'ImportDeclaration') { - this.extract_imports(node); - body.splice(i, 1); - } - - if (/^Export/.test(node.type)) { - const replacement = this.extract_exports(node); - if (replacement) { - body[i] = replacement; - } else { - body.splice(i, 1); - } - } - } - } - walk_instance_js_post_template() { const script = this.ast.instance; if (!script) return; diff --git a/test/runtime/samples/module-context-export/Foo.svelte b/test/runtime/samples/module-context-export/Foo.svelte new file mode 100644 index 0000000000..c992ceef52 --- /dev/null +++ b/test/runtime/samples/module-context-export/Foo.svelte @@ -0,0 +1,7 @@ + + diff --git a/test/runtime/samples/module-context-export/_config.js b/test/runtime/samples/module-context-export/_config.js new file mode 100644 index 0000000000..902501fdd4 --- /dev/null +++ b/test/runtime/samples/module-context-export/_config.js @@ -0,0 +1,3 @@ +export default { + html: `

(42)(99)

` +}; \ No newline at end of file diff --git a/test/runtime/samples/module-context-export/main.svelte b/test/runtime/samples/module-context-export/main.svelte new file mode 100644 index 0000000000..60c130ca2f --- /dev/null +++ b/test/runtime/samples/module-context-export/main.svelte @@ -0,0 +1,6 @@ + + +

({foo})({bar})

\ No newline at end of file