Skip to content

Commit 1d3ecc0

Browse files
authored
Ensure export= symbol from JavaScript always has a valueDeclaration (#34553)
1 parent e8782ae commit 1d3ecc0

5 files changed

+66
-1
lines changed

src/compiler/binder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,8 @@ namespace ts {
26902690
const flags = exportAssignmentIsAlias(node)
26912691
? SymbolFlags.Alias // An export= with an EntityNameExpression or a ClassExpression exports all meanings of that identifier or class
26922692
: SymbolFlags.Property | SymbolFlags.ExportValue | SymbolFlags.ValueModule;
2693-
declareSymbol(file.symbol.exports!, file.symbol, node, flags | SymbolFlags.Assignment, SymbolFlags.None);
2693+
const symbol = declareSymbol(file.symbol.exports!, file.symbol, node, flags | SymbolFlags.Assignment, SymbolFlags.None);
2694+
setValueDeclaration(symbol, node);
26942695
}
26952696

26962697
function bindThisPropertyAssignment(node: BindablePropertyAssignmentExpression | PropertyAccessExpression | LiteralLikeElementAccessExpression) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/b.js(1,8): error TS1259: Module '"/a"' can only be default-imported using the 'esModuleInterop' flag
2+
3+
4+
==== /a.js (0 errors) ====
5+
// https://github.com/microsoft/TypeScript/issues/34481
6+
7+
8+
const alias = {};
9+
module.exports = alias;
10+
11+
==== /b.js (1 errors) ====
12+
import a from "./a";
13+
~
14+
!!! error TS1259: Module '"/a"' can only be default-imported using the 'esModuleInterop' flag
15+
!!! related TS2594 /a.js:5:1: This module is declared with using 'export =', and can only be used with a default import when using the 'esModuleInterop' flag.
16+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
=== /a.js ===
2+
// https://github.com/microsoft/TypeScript/issues/34481
3+
4+
5+
const alias = {};
6+
>alias : Symbol(alias, Decl(a.js, 3, 5))
7+
8+
module.exports = alias;
9+
>module.exports : Symbol("/a", Decl(a.js, 0, 0))
10+
>module : Symbol(export=, Decl(a.js, 3, 17))
11+
>exports : Symbol(export=, Decl(a.js, 3, 17))
12+
>alias : Symbol(alias, Decl(a.js, 3, 5))
13+
14+
=== /b.js ===
15+
import a from "./a";
16+
>a : Symbol(a, Decl(b.js, 0, 6))
17+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== /a.js ===
2+
// https://github.com/microsoft/TypeScript/issues/34481
3+
4+
5+
const alias = {};
6+
>alias : {}
7+
>{} : {}
8+
9+
module.exports = alias;
10+
>module.exports = alias : {}
11+
>module.exports : {}
12+
>module : { "/a": {}; }
13+
>exports : {}
14+
>alias : {}
15+
16+
=== /b.js ===
17+
import a from "./a";
18+
>a : any
19+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// https://github.com/microsoft/TypeScript/issues/34481
2+
3+
// @allowJs: true
4+
// @checkJs: true
5+
// @noEmit: true
6+
7+
// @Filename: /a.js
8+
const alias = {};
9+
module.exports = alias;
10+
11+
// @Filename: /b.js
12+
import a from "./a";

0 commit comments

Comments
 (0)