diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 905f81d60f..5ba5e223e4 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -433,7 +433,7 @@ export default class Component { }); } - extract_imports(content, is_module: boolean) { + extract_imports(content) { const { code } = this; content.body.forEach(node => { @@ -441,26 +441,11 @@ export default class Component { // imports need to be hoisted out of the IIFE removeNode(code, content.start, content.end, content.body, node); this.imports.push(node); - - node.specifiers.forEach((specifier: Node) => { - if (specifier.local.name[0] === '$') { - this.error(specifier.local, { - code: 'illegal-declaration', - message: `The $ prefix is reserved, and cannot be used for variable and import names` - }); - } - - this.add_var({ - name: specifier.local.name, - module: is_module, - hoistable: true - }); - }); } }); } - extract_exports(content, is_module: boolean) { + extract_exports(content) { const { code } = this; content.body.forEach(node => { @@ -558,30 +543,20 @@ export default class Component { }); } - if (!/Import/.test(node.type)) { - const kind = node.type === 'VariableDeclaration' - ? node.kind - : node.type === 'ClassDeclaration' - ? 'class' - : node.type === 'FunctionDeclaration' - ? 'function' - : null; - - // sanity check - if (!kind) throw new Error(`Unknown declaration type ${node.type}`); - - this.add_var({ - name, - module: true, - hoistable: true, - writable: kind === 'var' || kind === 'let' - }); - } + this.add_var({ + name, + module: true, + hoistable: true, + writable: node.kind === 'var' || node.kind === 'let' + }); }); - globals.forEach(name => { + globals.forEach((node, name) => { if (name[0] === '$') { - // TODO should this be possible? + this.error(node, { + code: 'illegal-subscription', + message: `Cannot reference store value inside + +
{answer}
\ No newline at end of file diff --git a/test/runtime/samples/store-imported-module/_config.js b/test/runtime/samples/store-imported-module/_config.js new file mode 100644 index 0000000000..c2d471a329 --- /dev/null +++ b/test/runtime/samples/store-imported-module/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` +42
+ ` +}; \ No newline at end of file diff --git a/test/runtime/samples/store-imported-module/foo.js b/test/runtime/samples/store-imported-module/foo.js new file mode 100644 index 0000000000..340c3e6bd8 --- /dev/null +++ b/test/runtime/samples/store-imported-module/foo.js @@ -0,0 +1,3 @@ +import { writable } from '../../../../store.js'; + +export default writable(42); \ No newline at end of file diff --git a/test/runtime/samples/store-imported-module/main.svelte b/test/runtime/samples/store-imported-module/main.svelte new file mode 100644 index 0000000000..8710e3d1c6 --- /dev/null +++ b/test/runtime/samples/store-imported-module/main.svelte @@ -0,0 +1,9 @@ + + + + +{answer}
\ No newline at end of file diff --git a/test/runtime/samples/store-imported/_config.js b/test/runtime/samples/store-imported/_config.js new file mode 100644 index 0000000000..c2d471a329 --- /dev/null +++ b/test/runtime/samples/store-imported/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` +42
+ ` +}; \ No newline at end of file diff --git a/test/runtime/samples/store-imported/foo.js b/test/runtime/samples/store-imported/foo.js new file mode 100644 index 0000000000..340c3e6bd8 --- /dev/null +++ b/test/runtime/samples/store-imported/foo.js @@ -0,0 +1,3 @@ +import { writable } from '../../../../store.js'; + +export default writable(42); \ No newline at end of file diff --git a/test/runtime/samples/store-imported/main.svelte b/test/runtime/samples/store-imported/main.svelte new file mode 100644 index 0000000000..dc1199a83d --- /dev/null +++ b/test/runtime/samples/store-imported/main.svelte @@ -0,0 +1,6 @@ + + +{answer}
\ No newline at end of file