diff --git a/src/compile/Component.ts b/src/compile/Component.ts index de960813b4..c9304ee54a 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -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); diff --git a/src/compile/index.ts b/src/compile/index.ts index 390774419d..2265d10301 100644 --- a/src/compile/index.ts +++ b/src/compile/index.ts @@ -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(/\..+/, "") diff --git a/test/runtime/samples/deconflict-component-name-with-module-global/_config.js b/test/runtime/samples/deconflict-component-name-with-module-global/_config.js new file mode 100644 index 0000000000..4b8255868e --- /dev/null +++ b/test/runtime/samples/deconflict-component-name-with-module-global/_config.js @@ -0,0 +1,9 @@ +export default { + compileOptions: { + name: 'Set' + }, + + preserveIdentifiers: true, + + html: `

true

` +}; \ No newline at end of file diff --git a/test/runtime/samples/deconflict-component-name-with-module-global/main.html b/test/runtime/samples/deconflict-component-name-with-module-global/main.html new file mode 100644 index 0000000000..a14f3e7a1e --- /dev/null +++ b/test/runtime/samples/deconflict-component-name-with-module-global/main.html @@ -0,0 +1,5 @@ + + +

{set.has('x')}

\ No newline at end of file