Enable allowSyntheticDefaultImports if esModuleInterop is enabled

Fixes #26193.
This commit is contained in:
Minh Nguyen 2018-09-04 09:02:16 +01:00
parent 45101491c0
commit aaa723e2d2
5 changed files with 64 additions and 3 deletions

View file

@ -7020,9 +7020,8 @@ namespace ts {
const moduleKind = getEmitModuleKind(compilerOptions);
return compilerOptions.allowSyntheticDefaultImports !== undefined
? compilerOptions.allowSyntheticDefaultImports
: compilerOptions.esModuleInterop
? moduleKind !== ModuleKind.None && moduleKind < ModuleKind.ES2015
: moduleKind === ModuleKind.System;
: compilerOptions.esModuleInterop ||
moduleKind === ModuleKind.System;
}
export function getEmitDeclarations(compilerOptions: CompilerOptions): boolean {

View file

@ -0,0 +1,15 @@
//// [tests/cases/compiler/esModuleInteropEnablesSyntheticDefaultImports.ts] ////
//// [a.ts]
import Namespace from "./b";
export var x = new Namespace.Foo();
//// [b.d.ts]
export class Foo {
member: string;
}
//// [a.js]
import Namespace from "./b";
export var x = new Namespace.Foo();

View file

@ -0,0 +1,18 @@
=== tests/cases/compiler/a.ts ===
import Namespace from "./b";
>Namespace : Symbol(Namespace, Decl(a.ts, 0, 6))
export var x = new Namespace.Foo();
>x : Symbol(x, Decl(a.ts, 1, 10))
>Namespace.Foo : Symbol(Namespace.Foo, Decl(b.d.ts, 0, 0))
>Namespace : Symbol(Namespace, Decl(a.ts, 0, 6))
>Foo : Symbol(Namespace.Foo, Decl(b.d.ts, 0, 0))
=== tests/cases/compiler/b.d.ts ===
export class Foo {
>Foo : Symbol(Foo, Decl(b.d.ts, 0, 0))
member: string;
>member : Symbol(Foo.member, Decl(b.d.ts, 0, 18))
}

View file

@ -0,0 +1,19 @@
=== tests/cases/compiler/a.ts ===
import Namespace from "./b";
>Namespace : typeof Namespace
export var x = new Namespace.Foo();
>x : Namespace.Foo
>new Namespace.Foo() : Namespace.Foo
>Namespace.Foo : typeof Namespace.Foo
>Namespace : typeof Namespace
>Foo : typeof Namespace.Foo
=== tests/cases/compiler/b.d.ts ===
export class Foo {
>Foo : Foo
member: string;
>member : string
}

View file

@ -0,0 +1,10 @@
// @esModuleInterop: true
// @module: es2015
// @Filename: a.ts
import Namespace from "./b";
export var x = new Namespace.Foo();
// @Filename: b.d.ts
export class Foo {
member: string;
}