more imported store stuff

pull/2111/head
Richard Harris 6 years ago
parent 91332c540c
commit 6ea722a18a

@ -543,30 +543,20 @@ export default class Component {
}); });
} }
if (!/Import/.test(node.type)) { this.add_var({
const kind = node.type === 'VariableDeclaration' name,
? node.kind module: true,
: node.type === 'ClassDeclaration' hoistable: true,
? 'class' writable: node.kind === 'var' || node.kind === 'let'
: 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'
});
}
}); });
globals.forEach(name => { globals.forEach((node, name) => {
if (name[0] === '$') { if (name[0] === '$') {
// TODO should this be possible? this.error(node, {
code: 'illegal-subscription',
message: `Cannot reference store value inside <script context="module">`
})
} else { } else {
this.add_var({ this.add_var({
name, name,
@ -622,7 +612,7 @@ export default class Component {
this.node_for_declaration.set(name, node); this.node_for_declaration.set(name, node);
}); });
globals.forEach(name => { globals.forEach((node, name) => {
if (this.var_lookup.has(name)) return; if (this.var_lookup.has(name)) return;
if (this.injected_reactive_declaration_vars.has(name)) { if (this.injected_reactive_declaration_vars.has(name)) {

@ -5,7 +5,7 @@ import { Node } from '../interfaces';
export function createScopes(expression: Node) { export function createScopes(expression: Node) {
const map = new WeakMap(); const map = new WeakMap();
const globals = new Set(); const globals: Map<string, Node> = new Map();
let scope = new Scope(null, false); let scope = new Scope(null, false);
walk(expression, { walk(expression, {
@ -39,8 +39,8 @@ export function createScopes(expression: Node) {
} else if (/(Class|Variable)Declaration/.test(node.type)) { } else if (/(Class|Variable)Declaration/.test(node.type)) {
scope.addDeclaration(node); scope.addDeclaration(node);
} else if (node.type === 'Identifier' && isReference(node, parent)) { } else if (node.type === 'Identifier' && isReference(node, parent)) {
if (!scope.has(node.name)) { if (!scope.has(node.name) && !globals.has(node.name)) {
globals.add(node.name); globals.set(node.name, node);
} }
} }
}, },

@ -0,0 +1,3 @@
export default {
error: `Cannot reference store value inside <script context="module">`
};

@ -0,0 +1,3 @@
import { writable } from '../../../../store.js';
export default writable(42);

@ -0,0 +1,6 @@
<script context="module">
import foo from './foo.js';
const answer = $foo;
</script>
<p>{answer}</p>

@ -0,0 +1,5 @@
export default {
html: `
<p>42</p>
`
};

@ -0,0 +1,3 @@
import { writable } from '../../../../store.js';
export default writable(42);

@ -0,0 +1,9 @@
<script context="module">
import foo from './foo.js';
</script>
<script>
const answer = $foo;
</script>
<p>{answer}</p>
Loading…
Cancel
Save