From 21a07fcaf40b682eb72bdb68efbd169738419857 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Tue, 29 Jan 2019 22:08:00 -0500 Subject: [PATCH] prevent component name from conflicting with globals --- src/compile/Component.ts | 3 +-- test/runtime/index.js | 2 +- .../deconflict-component-name-with-global/_config.js | 10 ++++++++++ .../deconflict-component-name-with-global/main.html | 5 +++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 test/runtime/samples/deconflict-component-name-with-global/_config.js create mode 100644 test/runtime/samples/deconflict-component-name-with-global/main.html diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 42d3f7a449..e09f5ed0c6 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -93,8 +93,6 @@ export default class Component { options: CompileOptions, stats: Stats ) { - this.name = this.getUniqueName(name); - this.stats = stats; this.ast = ast; this.source = source; @@ -131,6 +129,7 @@ export default class Component { this.walk_module_js(); this.walk_instance_js_pre_template(); + this.name = this.getUniqueName(name); this.fragment = new Fragment(this, ast.html); this.walk_instance_js_post_template(); diff --git a/test/runtime/index.js b/test/runtime/index.js index 98daf51c2a..f320e37d6e 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -34,7 +34,7 @@ describe("runtime", () => { require.extensions[".html"] = function(module, filename) { const options = Object.assign( - { filename, name: getName(filename), format: 'cjs', sveltePath }, + { filename, name: compileOptions.name || getName(filename), format: 'cjs', sveltePath }, compileOptions ); diff --git a/test/runtime/samples/deconflict-component-name-with-global/_config.js b/test/runtime/samples/deconflict-component-name-with-global/_config.js new file mode 100644 index 0000000000..2b1efdcba6 --- /dev/null +++ b/test/runtime/samples/deconflict-component-name-with-global/_config.js @@ -0,0 +1,10 @@ +export default { + show: 1, + compileOptions: { + name: 'Set' + }, + + preserveIdentifiers: true, + + html: `

true

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

{set.has('x')}

\ No newline at end of file