From c0d8c1976f3b864e526a5abccc8746a7ba652b72 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 18 Jun 2019 16:04:46 -0700 Subject: [PATCH] Fix #31676 --- src/compiler/transformers/declarations.ts | 2 +- ...onEmitDefaultExportWithStaticAssignment.js | 31 ++++++++++++++++++- ...tDefaultExportWithStaticAssignment.symbols | 25 +++++++++++++++ ...mitDefaultExportWithStaticAssignment.types | 28 +++++++++++++++++ ...onEmitDefaultExportWithStaticAssignment.ts | 14 ++++++++- 5 files changed, 97 insertions(+), 3 deletions(-) diff --git a/src/compiler/transformers/declarations.ts b/src/compiler/transformers/declarations.ts index 7d1d7b73c880e..03f08b4de5441 100644 --- a/src/compiler/transformers/declarations.ts +++ b/src/compiler/transformers/declarations.ts @@ -1054,7 +1054,7 @@ namespace ts { }); const namespaceDecl = createModuleDeclaration(/*decorators*/ undefined, ensureModifiers(input, isPrivate), input.name!, createModuleBlock(declarations), NodeFlags.Namespace); - if (!hasModifier(clean, ModifierFlags.ExportDefault)) { + if (!hasModifier(clean, ModifierFlags.Default)) { return [clean, namespaceDecl]; } diff --git a/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.js b/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.js index f4d8083eca843..0edf3b6f01bae 100644 --- a/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.js +++ b/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.js @@ -18,7 +18,19 @@ Example.Foo = Foo export class Bar {} export default function Example() {} -Example.Bar = Bar +Example.Bar = Bar + +//// [index4.ts] +function A() { } + +function B() { } + +export function C() { + return null; +} + +C.A = A; +C.B = B; //// [foo.js] "use strict"; @@ -56,6 +68,17 @@ exports.Bar = Bar; function Example() { } exports["default"] = Example; Example.Bar = Bar; +//// [index4.js] +"use strict"; +exports.__esModule = true; +function A() { } +function B() { } +function C() { + return null; +} +exports.C = C; +C.A = A; +C.B = B; //// [foo.d.ts] @@ -83,3 +106,9 @@ declare namespace Example { var Bar: typeof import("./index3").Bar; } export default Example; +//// [index4.d.ts] +export declare function C(): any; +export declare namespace C { + var A: () => void; + var B: () => void; +} diff --git a/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.symbols b/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.symbols index e4588f35e888d..f65952c18d7dd 100644 --- a/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.symbols +++ b/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.symbols @@ -44,3 +44,28 @@ Example.Bar = Bar >Bar : Symbol(Example.Bar, Decl(index3.ts, 1, 36)) >Bar : Symbol(Bar, Decl(index3.ts, 0, 0)) +=== tests/cases/compiler/index4.ts === +function A() { } +>A : Symbol(A, Decl(index4.ts, 0, 0)) + +function B() { } +>B : Symbol(B, Decl(index4.ts, 0, 17)) + +export function C() { +>C : Symbol(C, Decl(index4.ts, 2, 16), Decl(index4.ts, 6, 1)) + + return null; +} + +C.A = A; +>C.A : Symbol(C.A, Decl(index4.ts, 6, 1)) +>C : Symbol(C, Decl(index4.ts, 2, 16), Decl(index4.ts, 6, 1)) +>A : Symbol(C.A, Decl(index4.ts, 6, 1)) +>A : Symbol(A, Decl(index4.ts, 0, 0)) + +C.B = B; +>C.B : Symbol(C.B, Decl(index4.ts, 8, 8)) +>C : Symbol(C, Decl(index4.ts, 2, 16), Decl(index4.ts, 6, 1)) +>B : Symbol(C.B, Decl(index4.ts, 8, 8)) +>B : Symbol(B, Decl(index4.ts, 0, 17)) + diff --git a/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.types b/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.types index 4c6636f26098e..b00ddcd68cf59 100644 --- a/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.types +++ b/tests/baselines/reference/declarationEmitDefaultExportWithStaticAssignment.types @@ -47,3 +47,31 @@ Example.Bar = Bar >Bar : typeof Bar >Bar : typeof Bar +=== tests/cases/compiler/index4.ts === +function A() { } +>A : () => void + +function B() { } +>B : () => void + +export function C() { +>C : typeof C + + return null; +>null : null +} + +C.A = A; +>C.A = A : () => void +>C.A : () => void +>C : typeof C +>A : () => void +>A : () => void + +C.B = B; +>C.B = B : () => void +>C.B : () => void +>C : typeof C +>B : () => void +>B : () => void + diff --git a/tests/cases/compiler/declarationEmitDefaultExportWithStaticAssignment.ts b/tests/cases/compiler/declarationEmitDefaultExportWithStaticAssignment.ts index 145db24086785..d6638ab8e3641 100644 --- a/tests/cases/compiler/declarationEmitDefaultExportWithStaticAssignment.ts +++ b/tests/cases/compiler/declarationEmitDefaultExportWithStaticAssignment.ts @@ -17,4 +17,16 @@ Example.Foo = Foo export class Bar {} export default function Example() {} -Example.Bar = Bar \ No newline at end of file +Example.Bar = Bar + +// @filename: index4.ts +function A() { } + +function B() { } + +export function C() { + return null; +} + +C.A = A; +C.B = B; \ No newline at end of file