Skip to content

Commit a5326e6

Browse files
Merge pull request #26866 from NMinhNguyen/allowSyntheticDefaultImports-if-esModuleInterop
Enable allowSyntheticDefaultImports if esModuleInterop is enabled
2 parents fc54a2c + aaa723e commit a5326e6

5 files changed

+64
-3
lines changed

src/compiler/utilities.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7077,9 +7077,8 @@ namespace ts {
70777077
const moduleKind = getEmitModuleKind(compilerOptions);
70787078
return compilerOptions.allowSyntheticDefaultImports !== undefined
70797079
? compilerOptions.allowSyntheticDefaultImports
7080-
: compilerOptions.esModuleInterop
7081-
? moduleKind !== ModuleKind.None && moduleKind < ModuleKind.ES2015
7082-
: moduleKind === ModuleKind.System;
7080+
: compilerOptions.esModuleInterop ||
7081+
moduleKind === ModuleKind.System;
70837082
}
70847083

70857084
export function getEmitDeclarations(compilerOptions: CompilerOptions): boolean {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [tests/cases/compiler/esModuleInteropEnablesSyntheticDefaultImports.ts] ////
2+
3+
//// [a.ts]
4+
import Namespace from "./b";
5+
export var x = new Namespace.Foo();
6+
7+
//// [b.d.ts]
8+
export class Foo {
9+
member: string;
10+
}
11+
12+
13+
//// [a.js]
14+
import Namespace from "./b";
15+
export var x = new Namespace.Foo();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/a.ts ===
2+
import Namespace from "./b";
3+
>Namespace : Symbol(Namespace, Decl(a.ts, 0, 6))
4+
5+
export var x = new Namespace.Foo();
6+
>x : Symbol(x, Decl(a.ts, 1, 10))
7+
>Namespace.Foo : Symbol(Namespace.Foo, Decl(b.d.ts, 0, 0))
8+
>Namespace : Symbol(Namespace, Decl(a.ts, 0, 6))
9+
>Foo : Symbol(Namespace.Foo, Decl(b.d.ts, 0, 0))
10+
11+
=== tests/cases/compiler/b.d.ts ===
12+
export class Foo {
13+
>Foo : Symbol(Foo, Decl(b.d.ts, 0, 0))
14+
15+
member: string;
16+
>member : Symbol(Foo.member, Decl(b.d.ts, 0, 18))
17+
}
18+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/a.ts ===
2+
import Namespace from "./b";
3+
>Namespace : typeof Namespace
4+
5+
export var x = new Namespace.Foo();
6+
>x : Namespace.Foo
7+
>new Namespace.Foo() : Namespace.Foo
8+
>Namespace.Foo : typeof Namespace.Foo
9+
>Namespace : typeof Namespace
10+
>Foo : typeof Namespace.Foo
11+
12+
=== tests/cases/compiler/b.d.ts ===
13+
export class Foo {
14+
>Foo : Foo
15+
16+
member: string;
17+
>member : string
18+
}
19+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @esModuleInterop: true
2+
// @module: es2015
3+
// @Filename: a.ts
4+
import Namespace from "./b";
5+
export var x = new Namespace.Foo();
6+
7+
// @Filename: b.d.ts
8+
export class Foo {
9+
member: string;
10+
}

0 commit comments

Comments
 (0)