Skip to content

Commit 36c5803

Browse files
authored
Fix duplicate identifier error with module.exports (#24466)
A bug in checkSpecialAssignment added bogus duplicate identifier errors when using module.exports assignment to export a class. This commit fixes that.
1 parent 15bfaf1 commit 36c5803

File tree

4 files changed

+42
-1
lines changed

4 files changed

+42
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20428,7 +20428,7 @@ namespace ts {
2042820428
if (propType.symbol && propType.symbol.flags & SymbolFlags.Class) {
2042920429
const name = prop.escapedName;
2043020430
const symbol = resolveName(prop.valueDeclaration, name, SymbolFlags.Type, undefined, name, /*isUse*/ false);
20431-
if (symbol) {
20431+
if (symbol && propType.symbol !== symbol) {
2043220432
grammarErrorOnNode(symbol.declarations[0], Diagnostics.Duplicate_identifier_0, unescapeLeadingUnderscores(name));
2043320433
return grammarErrorOnNode(prop.valueDeclaration, Diagnostics.Duplicate_identifier_0, unescapeLeadingUnderscores(name));
2043420434
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=== tests/cases/conformance/salsa/bug24062.js ===
2+
// #24062
3+
class C {
4+
>C : Symbol(C, Decl(bug24062.js, 0, 0))
5+
}
6+
module.exports = {
7+
>module : Symbol(export=, Decl(bug24062.js, 2, 1))
8+
>exports : Symbol(export=, Decl(bug24062.js, 2, 1))
9+
10+
C
11+
>C : Symbol(C, Decl(bug24062.js, 3, 18))
12+
13+
};
14+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== tests/cases/conformance/salsa/bug24062.js ===
2+
// #24062
3+
class C {
4+
>C : C
5+
}
6+
module.exports = {
7+
>module.exports = { C} : { [x: string]: any; C: typeof C; }
8+
>module.exports : any
9+
>module : any
10+
>exports : any
11+
>{ C} : { [x: string]: any; C: typeof C; }
12+
13+
C
14+
>C : typeof C
15+
16+
};
17+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @checkJs: true
2+
// @allowJS: true
3+
// @noEmit: true
4+
// @Filename: bug24062.js
5+
// #24062
6+
class C {
7+
}
8+
module.exports = {
9+
C
10+
};

0 commit comments

Comments
 (0)