diff --git a/src/ast/variables/ExportDefaultVariable.ts b/src/ast/variables/ExportDefaultVariable.ts index e2ecada0204..7d31cefab03 100644 --- a/src/ast/variables/ExportDefaultVariable.ts +++ b/src/ast/variables/ExportDefaultVariable.ts @@ -37,6 +37,15 @@ export default class ExportDefaultVariable extends LocalVariable { } } + forbidName(name: string) { + const original = this.getOriginalVariable(); + if (original === this) { + super.forbidName(name); + } else { + original.forbidName(name); + } + } + getAssignedVariableName(): string | null { return (this.originalId && this.originalId.name) || null; } diff --git a/test/function/samples/class-name-conflict2/_config.js b/test/function/samples/class-name-conflict-2/_config.js similarity index 100% rename from test/function/samples/class-name-conflict2/_config.js rename to test/function/samples/class-name-conflict-2/_config.js diff --git a/test/function/samples/class-name-conflict2/bar.js b/test/function/samples/class-name-conflict-2/bar.js similarity index 100% rename from test/function/samples/class-name-conflict2/bar.js rename to test/function/samples/class-name-conflict-2/bar.js diff --git a/test/function/samples/class-name-conflict2/declaration.js b/test/function/samples/class-name-conflict-2/declaration.js similarity index 100% rename from test/function/samples/class-name-conflict2/declaration.js rename to test/function/samples/class-name-conflict-2/declaration.js diff --git a/test/function/samples/class-name-conflict2/expression.js b/test/function/samples/class-name-conflict-2/expression.js similarity index 100% rename from test/function/samples/class-name-conflict2/expression.js rename to test/function/samples/class-name-conflict-2/expression.js diff --git a/test/function/samples/class-name-conflict2/foo.js b/test/function/samples/class-name-conflict-2/foo.js similarity index 100% rename from test/function/samples/class-name-conflict2/foo.js rename to test/function/samples/class-name-conflict-2/foo.js diff --git a/test/function/samples/class-name-conflict2/main.js b/test/function/samples/class-name-conflict-2/main.js similarity index 100% rename from test/function/samples/class-name-conflict2/main.js rename to test/function/samples/class-name-conflict-2/main.js diff --git a/test/function/samples/class-name-conflict-3/_config.js b/test/function/samples/class-name-conflict-3/_config.js new file mode 100644 index 00000000000..922cad01591 --- /dev/null +++ b/test/function/samples/class-name-conflict-3/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not shadow variables when preserving class names' +}; diff --git a/test/function/samples/class-name-conflict-3/foo.js b/test/function/samples/class-name-conflict-3/foo.js new file mode 100644 index 00000000000..7804111002d --- /dev/null +++ b/test/function/samples/class-name-conflict-3/foo.js @@ -0,0 +1 @@ +export default class Foo {} diff --git a/test/function/samples/class-name-conflict-3/main.js b/test/function/samples/class-name-conflict-3/main.js new file mode 100644 index 00000000000..22b9b90b33a --- /dev/null +++ b/test/function/samples/class-name-conflict-3/main.js @@ -0,0 +1,14 @@ +import Bar from './foo'; + +const wrapper = () => { + class Foo extends Bar { + static assertName() { + assert.strictEqual(this.name, 'Foo'); + assert.strictEqual(super.name, 'Foo'); + } + } + + return Foo; +}; + +wrapper().assertName(); diff --git a/test/function/samples/class-name-conflict-4/_config.js b/test/function/samples/class-name-conflict-4/_config.js new file mode 100644 index 00000000000..922cad01591 --- /dev/null +++ b/test/function/samples/class-name-conflict-4/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'does not shadow variables when preserving class names' +}; diff --git a/test/function/samples/class-name-conflict-4/foo.js b/test/function/samples/class-name-conflict-4/foo.js new file mode 100644 index 00000000000..03e6dcc163e --- /dev/null +++ b/test/function/samples/class-name-conflict-4/foo.js @@ -0,0 +1,5 @@ +var Foo = class {}; + +export default Foo; + +Foo = 'reassigned'; diff --git a/test/function/samples/class-name-conflict-4/main.js b/test/function/samples/class-name-conflict-4/main.js new file mode 100644 index 00000000000..70152e988cc --- /dev/null +++ b/test/function/samples/class-name-conflict-4/main.js @@ -0,0 +1,14 @@ +import Bar from './reexport'; + +const wrapper = () => { + class Foo extends Bar { + static assertName() { + assert.strictEqual(this.name, 'Foo'); + assert.strictEqual(super.name, 'Foo'); + } + } + + return Foo; +}; + +wrapper().assertName(); diff --git a/test/function/samples/class-name-conflict-4/reexport.js b/test/function/samples/class-name-conflict-4/reexport.js new file mode 100644 index 00000000000..ee90f7e3084 --- /dev/null +++ b/test/function/samples/class-name-conflict-4/reexport.js @@ -0,0 +1,2 @@ +import Foo from './foo'; +export default Foo;