deconflict with globals referenced in module context

pull/2029/head
Rich Harris 6 years ago
parent 411a9f91b1
commit 5b57a17632

@ -504,7 +504,7 @@ export default class Component {
this.addSourcemapLocations(script.content);
let { scope } = createScopes(script.content);
let { scope, globals } = createScopes(script.content);
this.module_scope = scope;
scope.declarations.forEach((node, name) => {
@ -535,6 +535,17 @@ export default class Component {
}
});
globals.forEach(name => {
if (name[0] === '$') {
// TODO should this be possible?
} else {
this.add_var({
name,
global: true
});
}
});
this.extract_imports(script.content, true);
this.extract_exports(script.content, true);
remove_indentation(this.code, script.content);

@ -36,7 +36,10 @@ function validate_options(options: CompileOptions, stats: Stats) {
function get_name(filename) {
if (!filename) return null;
const parts = filename.split(/[\/\\]/);
if (/index\.\w+/.test(parts)) parts.pop();
if (parts.length > 1 && /^index\.\w+/.test(parts[parts.length - 1])) {
parts.pop();
}
const base = parts.pop()
.replace(/\..+/, "")

@ -0,0 +1,9 @@
export default {
compileOptions: {
name: 'Set'
},
preserveIdentifiers: true,
html: `<p>true</p>`
};

@ -0,0 +1,5 @@
<script context="module">
let set = new Set(['x']);
</script>
<p>{set.has('x')}</p>
Loading…
Cancel
Save