From 0a8a5a1c7800aa961ce23b9f8fc6c9ae843dd5b9 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 5 Dec 2021 02:26:53 -0500 Subject: [PATCH] fix(es/typescript): transform namespace with multiple identifiers in name (#2952) swc_ecma_transforms_typescript: - Allow using typescript namespace with mutli-identifer name. (Closes #2810) --- .../input.ts/es2015.1.normal/output.js | 18 ++ .../input.ts/es2015.2.minified/output.js | 9 +- .../input.ts/es5.1.normal/output.js | 18 ++ .../input.ts/es5.2.minified/output.js | 8 +- .../input.ts/es2015.1.normal/output.js | 30 ++- .../input.ts/es2015.2.minified/output.js | 14 +- .../input.ts/es5.1.normal/output.js | 30 ++- .../input.ts/es5.2.minified/output.js | 11 +- .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 31 +++ .../input.ts/es2015.2.minified/output.js | 19 +- .../input.ts/es5.1.normal/output.js | 31 +++ .../input.ts/es5.2.minified/output.js | 25 +- .../input.ts/es2015.1.normal/output.js | 32 +++ .../input.ts/es2015.2.minified/output.js | 19 +- .../input.ts/es5.1.normal/output.js | 32 +++ .../input.ts/es5.2.minified/output.js | 25 +- .../input.ts/es2015.1.normal/output.js | 31 +++ .../input.ts/es2015.2.minified/output.js | 19 +- .../input.ts/es5.1.normal/output.js | 31 +++ .../input.ts/es5.2.minified/output.js | 25 +- .../input.ts/es2015.1.normal/output.js | 20 +- .../input.ts/es2015.2.minified/output.js | 10 +- .../input.ts/es5.1.normal/output.js | 22 +- .../input.ts/es5.2.minified/output.js | 13 +- .../input.ts/es2015.1.normal/output.js | 16 ++ .../input.ts/es2015.2.minified/output.js | 8 + .../input.ts/es5.1.normal/output.js | 18 ++ .../input.ts/es5.2.minified/output.js | 9 + .../input.ts/es2015.1.normal/output.js | 32 ++- .../input.ts/es2015.2.minified/output.js | 20 +- .../input.ts/es5.1.normal/output.js | 34 ++- .../input.ts/es5.2.minified/output.js | 31 ++- .../input.ts/es2015.1.normal/output.js | 20 +- .../input.ts/es2015.2.minified/output.js | 15 +- .../input.ts/es5.1.normal/output.js | 20 +- .../input.ts/es5.2.minified/output.js | 14 +- .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 10 + .../input.ts/es2015.2.minified/output.js | 7 + .../input.ts/es5.1.normal/output.js | 10 + .../input.ts/es5.2.minified/output.js | 7 + .../input.ts/es2015.1.normal/output.js | 35 ++- .../input.ts/es2015.2.minified/output.js | 20 +- .../input.ts/es5.1.normal/output.js | 37 ++- .../input.ts/es5.2.minified/output.js | 32 ++- .../input.ts/es2015.1.normal/output.js | 10 +- .../input.ts/es2015.2.minified/output.js | 9 +- .../input.ts/es5.1.normal/output.js | 10 +- .../input.ts/es5.2.minified/output.js | 9 +- .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 14 + .../input.ts/es2015.2.minified/output.js | 6 + .../input.ts/es5.1.normal/output.js | 24 ++ .../input.ts/es5.2.minified/output.js | 36 ++- .../input.ts/es2015.1.normal/output.js | 14 + .../input.ts/es2015.2.minified/output.js | 6 + .../input.ts/es5.1.normal/output.js | 24 ++ .../input.ts/es5.2.minified/output.js | 45 +++- .../input.ts/es2015.1.normal/output.js | 37 +++ .../input.ts/es2015.2.minified/output.js | 18 ++ .../input.ts/es5.1.normal/output.js | 37 +++ .../input.ts/es5.2.minified/output.js | 20 ++ .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../input.ts/es2015.1.normal/output.js | 0 .../input.ts/es5.1.normal/output.js | 0 .../src/strip.rs | 247 ++++++++++++------ .../tests/strip.rs | 22 ++ 106 files changed, 1305 insertions(+), 201 deletions(-) create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName2/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName2/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames2/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames2/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceThatIndirectlyInheritsFromItself/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceThatIndirectlyInheritsFromItself/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportInterfaceWithInaccessibleTypeInIndexerTypeAnnotations/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportInterfaceWithInaccessibleTypeInIndexerTypeAnnotations/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es2015.2.minified/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration7/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration7/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es2015.2.minified/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es2015.2.minified/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es2015.2.minified/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es5.2.minified/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3/input.ts/es5.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2/input.ts/es2015.1.normal/output.js create mode 100644 crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2/input.ts/es5.1.normal/output.js diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es2015.1.normal/output.js index 8f6690feeda..a00d820e6df 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es2015.1.normal/output.js @@ -57,5 +57,23 @@ var m; var m1; (function(m1) { var x; + let m21; + (function(m2) { + let m3; + (function(m3) { + var b = x; // new scope - number | boolean | string + var y; + if (typeof x === "string") { + y = x // string; + ; + } else { + y = typeof x === "boolean" ? x.toString() // boolean + : x.toString(); // number + } + })(m3 || (m3 = { + })); + m2.m3 = m3; + })(m21 || (m21 = { + })); })(m1 || (m1 = { })); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es2015.2.minified/output.js index 60254b7d517..87f615b0baa 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es2015.2.minified/output.js @@ -1,8 +1,15 @@ -var m; +var m, m1; !function(m) { var x; let m2; m2 || (m2 = { }), "string" == typeof x || ("boolean" == typeof x, x.toString()); }(m || (m = { +})), (function(m1) { + var x, m2; + let m21, m3; + m2 = m21 || (m21 = { + }), m3 || (m3 = { + }), "string" == typeof x || ("boolean" == typeof x, x.toString()), m2.m3 = m3; +})(m1 || (m1 = { })); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es5.1.normal/output.js index 2056f4b6283..0215096154e 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es5.1.normal/output.js @@ -57,5 +57,23 @@ var m; var m1; (function(m1) { var x; + var m21; + (function(m2) { + var m3; + (function(m3) { + var b = x; // new scope - number | boolean | string + var y; + if (typeof x === "string") { + y = x // string; + ; + } else { + y = typeof x === "boolean" ? x.toString() // boolean + : x.toString(); // number + } + })(m3 || (m3 = { + })); + m2.m3 = m3; + })(m21 || (m21 = { + })); })(m1 || (m1 = { })); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es5.2.minified/output.js index 54d84e5003f..388d89bf0ed 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInFunctionAndModuleBlock/input.ts/es5.2.minified/output.js @@ -1,7 +1,13 @@ -var m; +var m, m1; !function(m) { var x, m2; m2 || (m2 = { }), "string" == typeof x || ("boolean" == typeof x, x.toString()); }(m || (m = { +})), (function(m1) { + var x, m2, m21, m3; + m21 = m2 || (m2 = { + }), m3 || (m3 = { + }), "string" == typeof x || ("boolean" == typeof x, x.toString()), m21.m3 = m3; +})(m1 || (m1 = { })); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es2015.1.normal/output.js index ce9359e61c9..551babb4391 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es2015.1.normal/output.js @@ -31,7 +31,7 @@ var m2; var var2; var var3; let m31; - (function(m3) { + (function(m32) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // local variables from outer module declaration @@ -51,9 +51,35 @@ var m2; } else { strOrNum = var5; // string | number } - m3.var5 = var5; + m32.var5 = var5; })(m31 || (m31 = { })); m21.var3 = var3; })(m2 || (m2 = { })); +// Dotted module +var m3; +(function(m33) { + let m41; + (function(m4) { + // global vars in function declaration + num = typeof var1 === "string" && var1.length; // string + // variables in module declaration + var var2; + if (typeof var2 === "string") { + num = var2.length; // string + } else { + num = var2; // number + } + var var3; + if (typeof var3 === "string") { + strOrNum = var3; // string | number + } else { + strOrNum = var3; // string | number + } + m4.var3 = var3; + })(m41 || (m41 = { + })); + m33.m4 = m41; +})(m3 || (m3 = { +})); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es2015.2.minified/output.js index 377de6a2350..20cdfb94422 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es2015.2.minified/output.js @@ -1,12 +1,18 @@ -var num, strOrNum, var1, m1, m2; +var num, strOrNum, var1, m1, m2, m3; !function(m11) { var var2, var3; num = "string" == typeof var1 && var1.length, num = "string" == typeof var2 ? var2.length : var2, "string" == typeof var3, strOrNum = var3, m11.var3 = var3; }(m1 || (m1 = { })), (function(m21) { - var var2, var3, m3, var4, var5; + var var2, var3, m32, var4, var5; let m31; - m3 = m31 || (m31 = { - }), num = "string" == typeof var1 && var1.length, num = "string" == typeof var2 && var2.length, strOrNum = "string" == typeof var3 && var3, num = "string" == typeof var4 ? var4.length : var4, "string" == typeof var5, strOrNum = var5, m3.var5 = var5, m21.var3 = var3; + m32 = m31 || (m31 = { + }), num = "string" == typeof var1 && var1.length, num = "string" == typeof var2 && var2.length, strOrNum = "string" == typeof var3 && var3, num = "string" == typeof var4 ? var4.length : var4, "string" == typeof var5, strOrNum = var5, m32.var5 = var5, m21.var3 = var3; })(m2 || (m2 = { +})), (function(m33) { + var m4, var2, var3; + let m41; + m4 = m41 || (m41 = { + }), num = "string" == typeof var1 && var1.length, num = "string" == typeof var2 ? var2.length : var2, "string" == typeof var3, strOrNum = var3, m4.var3 = var3, m33.m4 = m41; +})(m3 || (m3 = { })); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es5.1.normal/output.js index 4aa429cd96d..210fbd8b4de 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es5.1.normal/output.js @@ -31,7 +31,7 @@ var m2; var var2; var var3; var m31; - (function(m3) { + (function(m32) { // global vars in function declaration num = typeof var1 === "string" && var1.length; // string // local variables from outer module declaration @@ -51,9 +51,35 @@ var m2; } else { strOrNum = var5; // string | number } - m3.var5 = var5; + m32.var5 = var5; })(m31 || (m31 = { })); m21.var3 = var3; })(m2 || (m2 = { })); +// Dotted module +var m3; +(function(m33) { + var m41; + (function(m4) { + // global vars in function declaration + num = typeof var1 === "string" && var1.length; // string + // variables in module declaration + var var2; + if (typeof var2 === "string") { + num = var2.length; // string + } else { + num = var2; // number + } + var var3; + if (typeof var3 === "string") { + strOrNum = var3; // string | number + } else { + strOrNum = var3; // string | number + } + m4.var3 = var3; + })(m41 || (m41 = { + })); + m33.m4 = m41; +})(m3 || (m3 = { +})); diff --git a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es5.2.minified/output.js index e9ff21dd9c3..b2512b34ba1 100644 --- a/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/expressions/typeGuards/typeGuardsInModule/input.ts/es5.2.minified/output.js @@ -1,11 +1,16 @@ -var num, strOrNum, var1, m1, m2; +var num, strOrNum, var1, m1, m2, m3; !function(m11) { var var2, var3; num = "string" == typeof var1 && var1.length, num = "string" == typeof var2 ? var2.length : var2, "string" == typeof var3, strOrNum = var3, m11.var3 = var3; }(m1 || (m1 = { })), (function(m21) { - var var2, var3, m3, m31, var4, var5; - m31 = m3 || (m3 = { + var var2, var3, m32, m31, var4, var5; + m31 = m32 || (m32 = { }), num = "string" == typeof var1 && var1.length, num = "string" == typeof var2 && var2.length, strOrNum = "string" == typeof var3 && var3, num = "string" == typeof var4 ? var4.length : var4, "string" == typeof var5, strOrNum = var5, m31.var5 = var5, m21.var3 = var3; })(m2 || (m2 = { +})), (function(m33) { + var m4, m41, var2, var3; + m41 = m4 || (m4 = { + }), num = "string" == typeof var1 && var1.length, num = "string" == typeof var2 ? var2.length : var2, "string" == typeof var3, strOrNum = var3, m41.var3 = var3, m33.m4 = m4; +})(m3 || (m3 = { })); diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName2/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName2/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/genericAndNonGenericInterfaceWithTheSameName2/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames2/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames2/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames2/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesDifferingByTypeParameterName2/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithDifferentConstraints/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/declarationMerging/twoGenericInterfacesWithTheSameNameButDifferentArity/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceThatIndirectlyInheritsFromItself/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceThatIndirectlyInheritsFromItself/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceThatIndirectlyInheritsFromItself/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceThatIndirectlyInheritsFromItself/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/interfaces/interfaceDeclarations/interfaceWithMultipleBaseTypes/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es2015.1.normal/output.js index b43a444c4e8..094311ca568 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es2015.1.normal/output.js @@ -1,3 +1,34 @@ +// @filename: class.ts +var X; +(function(X1) { + let Y1; + (function(Y) { + class Point { + constructor(x, y){ + this.x = x; + this.y = y; + } + } + Y.Point = Point; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + let Y2; + (function(Y) { + let Point1; + (function(Point) { + Point.Origin = new Point1(0, 0); + })(Point1 || (Point1 = { + })); + Y.Point = Point1; + })(Y2 || (Y2 = { + })); + X2.Y = Y2; +})(X || (X = { +})); // @filename: test.ts //var cl: { x: number; y: number; } var cl = new X.Y.Point(1, 1); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es2015.2.minified/output.js index e9760041eeb..c8bc1b19c49 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es2015.2.minified/output.js @@ -1,4 +1,21 @@ -new X.Y.Point(1, 1), X.Y.Point.Origin; +var X; +!function(X1) { + let Y; + (Y || (Y = { + })).Point = class { + constructor(x, y){ + this.x = x, this.y = y; + } + }, X1.Y = Y; +}(X || (X = { +})), (function(X2) { + var Y; + let Y1, Point; + Y = Y1 || (Y1 = { + }), (Point || (Point = { + })).Origin = new Point(0, 0), Y.Point = Point, X2.Y = Y1; +})(X || (X = { +})), new X.Y.Point(1, 1), X.Y.Point.Origin; class A { } (A || (A = { diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es5.1.normal/output.js index a84dd964477..f86068e2684 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es5.1.normal/output.js @@ -3,6 +3,37 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +// @filename: class.ts +var X; +(function(X1) { + var Y1; + (function(Y) { + var Point = function Point(x, y) { + "use strict"; + _classCallCheck(this, Point); + this.x = x; + this.y = y; + }; + Y.Point = Point; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + var Y2; + (function(Y) { + var Point1; + (function(Point) { + Point.Origin = new Point1(0, 0); + })(Point1 || (Point1 = { + })); + Y.Point = Point1; + })(Y2 || (Y2 = { + })); + X2.Y = Y2; +})(X || (X = { +})); // @filename: test.ts //var cl: { x: number; y: number; } var cl = new X.Y.Point(1, 1); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es5.2.minified/output.js index 5c92efb1b19..38a1062309f 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRoot/input.ts/es5.2.minified/output.js @@ -1,9 +1,24 @@ -new X.Y.Point(1, 1), X.Y.Point.Origin; -var A = function() { +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); +} +!function(X1) { + var Y, Y1, Point; + Y1 = Y || (Y = { + }), Point = function(x, y) { + "use strict"; + _classCallCheck(this, Point), this.x = x, this.y = y; + }, Y1.Point = Point, X1.Y = Y; +}(X || (X = { +})), (function(X2) { + var Y, Y2, Point; + Y2 = Y || (Y = { + }), (Point || (Point = { + })).Origin = new Point(0, 0), Y2.Point = Point, X2.Y = Y; +})(X || (X = { +})), new X.Y.Point(1, 1), X.Y.Point.Origin; +var X, A = function() { "use strict"; - !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, A); + _classCallCheck(this, A); }; (A || (A = { })).Instance = new A(), A.Instance, new A(); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es2015.1.normal/output.js index b43a444c4e8..c950a3d3cee 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es2015.1.normal/output.js @@ -1,3 +1,35 @@ +// @target: ES6 +// @filename: class.ts +var X; +(function(X1) { + let Y1; + (function(Y) { + class Point { + constructor(x, y){ + this.x = x; + this.y = y; + } + } + Y.Point = Point; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + let Y2; + (function(Y) { + let Point1; + (function(Point) { + Point.Origin = new Point1(0, 0); + })(Point1 || (Point1 = { + })); + Y.Point = Point1; + })(Y2 || (Y2 = { + })); + X2.Y = Y2; +})(X || (X = { +})); // @filename: test.ts //var cl: { x: number; y: number; } var cl = new X.Y.Point(1, 1); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es2015.2.minified/output.js index e9760041eeb..c8bc1b19c49 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es2015.2.minified/output.js @@ -1,4 +1,21 @@ -new X.Y.Point(1, 1), X.Y.Point.Origin; +var X; +!function(X1) { + let Y; + (Y || (Y = { + })).Point = class { + constructor(x, y){ + this.x = x, this.y = y; + } + }, X1.Y = Y; +}(X || (X = { +})), (function(X2) { + var Y; + let Y1, Point; + Y = Y1 || (Y1 = { + }), (Point || (Point = { + })).Origin = new Point(0, 0), Y.Point = Point, X2.Y = Y1; +})(X || (X = { +})), new X.Y.Point(1, 1), X.Y.Point.Origin; class A { } (A || (A = { diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es5.1.normal/output.js index a84dd964477..c4b893608b5 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es5.1.normal/output.js @@ -3,6 +3,38 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +// @target: ES6 +// @filename: class.ts +var X; +(function(X1) { + var Y1; + (function(Y) { + var Point = function Point(x, y) { + "use strict"; + _classCallCheck(this, Point); + this.x = x; + this.y = y; + }; + Y.Point = Point; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + var Y2; + (function(Y) { + var Point1; + (function(Point) { + Point.Origin = new Point1(0, 0); + })(Point1 || (Point1 = { + })); + Y.Point = Point1; + })(Y2 || (Y2 = { + })); + X2.Y = Y2; +})(X || (X = { +})); // @filename: test.ts //var cl: { x: number; y: number; } var cl = new X.Y.Point(1, 1); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es5.2.minified/output.js index 5c92efb1b19..38a1062309f 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ClassAndModuleWithSameNameAndCommonRootES6/input.ts/es5.2.minified/output.js @@ -1,9 +1,24 @@ -new X.Y.Point(1, 1), X.Y.Point.Origin; -var A = function() { +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); +} +!function(X1) { + var Y, Y1, Point; + Y1 = Y || (Y = { + }), Point = function(x, y) { + "use strict"; + _classCallCheck(this, Point), this.x = x, this.y = y; + }, Y1.Point = Point, X1.Y = Y; +}(X || (X = { +})), (function(X2) { + var Y, Y2, Point; + Y2 = Y || (Y = { + }), (Point || (Point = { + })).Origin = new Point(0, 0), Y2.Point = Point, X2.Y = Y; +})(X || (X = { +})), new X.Y.Point(1, 1), X.Y.Point.Origin; +var X, A = function() { "use strict"; - !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, A); + _classCallCheck(this, A); }; (A || (A = { })).Instance = new A(), A.Instance, new A(); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es2015.1.normal/output.js index 43f21137048..c68d14ce807 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es2015.1.normal/output.js @@ -1,3 +1,34 @@ +// @Filename: module.ts +var X; +(function(X1) { + let Y1; + (function(Y) { + let Point1; + (function(Point) { + Point.Origin = new Point1(0, 0); + })(Point1 || (Point1 = { + })); + Y.Point = Point1; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + let Y2; + (function(Y) { + class Point { + constructor(x, y){ + this.x = x; + this.y = y; + } + } + Y.Point = Point; + })(Y2 || (Y2 = { + })); + X2.Y = Y2; +})(X || (X = { +})); (function(A1) { A1.Instance = new A(); })(A || (A = { diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es2015.2.minified/output.js index 4aca3ef1218..a246e333f9d 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es2015.2.minified/output.js @@ -1,4 +1,21 @@ -(A || (A = { +var X; +!function(X1) { + var Y; + let Y1, Point; + Y = Y1 || (Y1 = { + }), (Point || (Point = { + })).Origin = new Point(0, 0), Y.Point = Point, X1.Y = Y1; +}(X || (X = { +})), (function(X2) { + let Y; + (Y || (Y = { + })).Point = class { + constructor(x, y){ + this.x = x, this.y = y; + } + }, X2.Y = Y; +})(X || (X = { +})), (A || (A = { })).Instance = new A(); class A { } diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es5.1.normal/output.js index a5248df4a46..da96987f39b 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es5.1.normal/output.js @@ -3,6 +3,37 @@ function _classCallCheck(instance, Constructor) { throw new TypeError("Cannot call a class as a function"); } } +// @Filename: module.ts +var X; +(function(X1) { + var Y1; + (function(Y) { + var Point1; + (function(Point) { + Point.Origin = new Point1(0, 0); + })(Point1 || (Point1 = { + })); + Y.Point = Point1; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + var Y2; + (function(Y) { + var Point = function Point(x, y) { + "use strict"; + _classCallCheck(this, Point); + this.x = x; + this.y = y; + }; + Y.Point = Point; + })(Y2 || (Y2 = { + })); + X2.Y = Y2; +})(X || (X = { +})); (function(A1) { A1.Instance = new A(); })(A || (A = { diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es5.2.minified/output.js index 7f26e66f1ce..0a7acca67e4 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/ModuleAndClassWithSameNameAndCommonRoot/input.ts/es5.2.minified/output.js @@ -1,8 +1,23 @@ -(A || (A = { +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); +} +!function(X1) { + var Y, Y1, Point; + Y1 = Y || (Y = { + }), (Point || (Point = { + })).Origin = new Point(0, 0), Y1.Point = Point, X1.Y = Y; +}(X || (X = { +})), (function(X2) { + var Y, Y2, Point; + Y2 = Y || (Y = { + }), Point = function(x, y) { + "use strict"; + _classCallCheck(this, Point), this.x = x, this.y = y; + }, Y2.Point = Point, X2.Y = Y; +})(X || (X = { +})), (A || (A = { })).Instance = new A(); -var A = function A() { +var X, A = function A() { "use strict"; - !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, A); + _classCallCheck(this, A); }; diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es2015.1.normal/output.js index ee44b8a2ed5..9f575326ac5 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es2015.1.normal/output.js @@ -22,6 +22,22 @@ var p; var X; (function(X1) { let Y1; + (function(Y) { + let Z1; + (function(Z) { + class Line { + } + Z.Line = Line; + })(Z1 || (Z1 = { + })); + Y.Z = Z1; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + let Y2; (function(Y) { let Z; (function(Z) { @@ -30,9 +46,9 @@ var X; })(Z || (Z = { })); Y.Z = Z; - })(Y1 || (Y1 = { + })(Y2 || (Y2 = { })); - X1.Y = Y1; + X2.Y = Y2; })(X || (X = { })); // ensure merges as expected diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es2015.2.minified/output.js index 4cd998ab949..a2063fe71d1 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es2015.2.minified/output.js @@ -2,8 +2,16 @@ var A, X; (A || (A = { })).Point = class { }, (function(X1) { + var Y; + let Y1, Z; + Y = Y1 || (Y1 = { + }), (Z || (Z = { + })).Line = class { + }, Y.Z = Z, X1.Y = Y1; +})(X || (X = { +})), (function(X2) { let Y, Z; (Y || (Y = { - })).Z = Z, X1.Y = Y; + })).Z = Z, X2.Y = Y; })(X || (X = { })); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es5.1.normal/output.js index 506117e684b..8ea6b8f4a9a 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es5.1.normal/output.js @@ -53,6 +53,24 @@ var p; var X; (function(X1) { var Y1; + (function(Y) { + var Z1; + (function(Z) { + var Line = function Line() { + "use strict"; + _classCallCheck(this, Line); + }; + Z.Line = Line; + })(Z1 || (Z1 = { + })); + Y.Z = Z1; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + var Y2; (function(Y) { var Z; (function(Z) { @@ -63,9 +81,9 @@ var X; })(Z || (Z = { })); Y.Z = Z; - })(Y1 || (Y1 = { + })(Y2 || (Y2 = { })); - X1.Y = Y1; + X2.Y = Y2; })(X || (X = { })); // ensure merges as expected diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es5.2.minified/output.js index d5452a1f858..c950fcde6b4 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName/input.ts/es5.2.minified/output.js @@ -36,12 +36,21 @@ function _defineProperties(target, props) { }(); })(A || (A = { })), (function(X1) { - var Y, Y1, Z, Line; + var Y, Y1, Z, Z1, Line; Y1 = Y || (Y = { + }), Z1 = Z || (Z = { + }), Line = function() { + "use strict"; + _classCallCheck(this, Line); + }, Z1.Line = Line, Y1.Z = Z, X1.Y = Y; +})(X || (X = { +})), (function(X2) { + var Y, Y2, Z, Line; + Y2 = Y || (Y = { }), Z || (Z = { }), Line = function() { "use strict"; _classCallCheck(this, Line); - }, Y1.Z = Z, X1.Y = Y; + }, Y2.Z = Z, X2.Y = Y; })(X || (X = { })); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es2015.1.normal/output.js index 0affa693ef0..3065585f4c6 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es2015.1.normal/output.js @@ -28,3 +28,19 @@ var X; X1.Y = Y1; })(X || (X = { })); +(function(X2) { + let Y2; + (function(Y) { + let Z2; + (function(Z) { + class Line { + } + Z.Line = Line; + })(Z2 || (Z2 = { + })); + Y.Z = Z2; + })(Y2 || (Y2 = { + })); + X2.Y = Y2; +})(X || (X = { +})); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es2015.2.minified/output.js index 4ded2684026..21d8c5ca46e 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es2015.2.minified/output.js @@ -11,4 +11,12 @@ var A, X; })).Line = class { }, Y.Z = Z, X1.Y = Y1; })(X || (X = { +})), (function(X2) { + var Y; + let Y2, Z; + Y = Y2 || (Y2 = { + }), (Z || (Z = { + })).Line = class { + }, Y.Z = Z, X2.Y = Y2; +})(X || (X = { })); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es5.1.normal/output.js index cbdcdf9545c..67f1d1d7ac5 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es5.1.normal/output.js @@ -39,3 +39,21 @@ var X; X1.Y = Y1; })(X || (X = { })); +(function(X2) { + var Y2; + (function(Y) { + var Z2; + (function(Z) { + var Line = function Line() { + "use strict"; + _classCallCheck(this, Line); + }; + Z.Line = Line; + })(Z2 || (Z2 = { + })); + Y.Z = Z2; + })(Y2 || (Y2 = { + })); + X2.Y = Y2; +})(X || (X = { +})); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es5.2.minified/output.js index 6dce57cf01b..8183fe0821b 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName/input.ts/es5.2.minified/output.js @@ -25,4 +25,13 @@ function _classCallCheck(instance, Constructor) { _classCallCheck(this, Line); }, Z1.Line = Line, Y1.Z = Z, X1.Y = Y; })(X || (X = { +})), (function(X2) { + var Y, Y2, Z, Z2, Line; + Y2 = Y || (Y = { + }), Z2 = Z || (Z = { + }), Line = function() { + "use strict"; + _classCallCheck(this, Line); + }, Z2.Line = Line, Y2.Z = Z, X2.Y = Y; +})(X || (X = { })); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es2015.1.normal/output.js index dd79f978ead..5da702260fb 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es2015.1.normal/output.js @@ -1,11 +1,21 @@ var A; -(function(A) { +(function(A1) { let B1; (function(B) { var x1; B.x = x1; })(B1 || (B1 = { })); + A1.B = B1; +})(A || (A = { +})); +(function(A) { + let B2; + (function(B) { + var x2; + B.x = x2; + })(B2 || (B2 = { + })); })(A || (A = { })); // ensure the right var decl is exported @@ -13,7 +23,7 @@ var x; var x = A.B.x; var X; (function(X1) { - let Y; + let Y1; (function(Y) { let Z1; (function(Z) { @@ -22,9 +32,25 @@ var X; Z.Line = Line; })(Z1 || (Z1 = { })); + Y.Z = Z1; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + let Y; + (function(Y) { + let Z2; + (function(Z) { + class Line { + } + Z.Line = Line; + })(Z2 || (Z2 = { + })); })(Y || (Y = { })); - X1.Y = Y; + X2.Y = Y; })(X || (X = { })); // make sure merging works as expected diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es2015.2.minified/output.js index 05e54c5dd91..d9b05c33e1c 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es2015.2.minified/output.js @@ -1,15 +1,29 @@ var A, X; -!function(A) { +!function(A1) { + var x; + let B; + (B || (B = { + })).x = x, A1.B = B; +}(A || (A = { +})), (function(A) { var x; let B; (B || (B = { })).x = x; -}(A || (A = { +})(A || (A = { })), A.B.x, (function(X1) { + var Y; + let Y1, Z; + Y = Y1 || (Y1 = { + }), (Z || (Z = { + })).Line = class { + }, Y.Z = Z, X1.Y = Y1; +})(X || (X = { +})), (function(X2) { let Y, Z; Y || (Y = { }), (Z || (Z = { })).Line = class { - }, X1.Y = Y; + }, X2.Y = Y; })(X || (X = { })); diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es5.1.normal/output.js index 3cc84c69ea7..9a896d1147b 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es5.1.normal/output.js @@ -4,13 +4,23 @@ function _classCallCheck(instance, Constructor) { } } var A; -(function(A) { +(function(A1) { var B1; (function(B) { var x1; B.x = x1; })(B1 || (B1 = { })); + A1.B = B1; +})(A || (A = { +})); +(function(A) { + var B2; + (function(B) { + var x2; + B.x = x2; + })(B2 || (B2 = { + })); })(A || (A = { })); // ensure the right var decl is exported @@ -18,7 +28,7 @@ var x; var x = A.B.x; var X; (function(X1) { - var Y; + var Y1; (function(Y) { var Z1; (function(Z) { @@ -29,9 +39,27 @@ var X; Z.Line = Line; })(Z1 || (Z1 = { })); + Y.Z = Z1; + })(Y1 || (Y1 = { + })); + X1.Y = Y1; +})(X || (X = { +})); +(function(X2) { + var Y; + (function(Y) { + var Z2; + (function(Z) { + var Line = function Line() { + "use strict"; + _classCallCheck(this, Line); + }; + Z.Line = Line; + })(Z2 || (Z2 = { + })); })(Y || (Y = { })); - X1.Y = Y; + X2.Y = Y; })(X || (X = { })); // make sure merging works as expected diff --git a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es5.2.minified/output.js index bab0f9078c0..627b7dd4cf4 100644 --- a/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedModulesOfTheSameName/input.ts/es5.2.minified/output.js @@ -1,18 +1,33 @@ var A, X; -!function(A) { +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); +} +!function(A1) { + var B, x; + (B || (B = { + })).x = x, A1.B = B; +}(A || (A = { +})), (function(A) { var B, x; (B || (B = { })).x = x; -}(A || (A = { +})(A || (A = { })), A.B.x, (function(X1) { - var Y, Z, Z1, Line; - Y || (Y = { + var Y, Y1, Z, Z1, Line; + Y1 = Y || (Y = { }), Z1 = Z || (Z = { }), Line = function() { "use strict"; - !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, Line); - }, Z1.Line = Line, X1.Y = Y; + _classCallCheck(this, Line); + }, Z1.Line = Line, Y1.Z = Z, X1.Y = Y; +})(X || (X = { +})), (function(X2) { + var Y, Z, Z2, Line; + Y || (Y = { + }), Z2 = Z || (Z = { + }), Line = function() { + "use strict"; + _classCallCheck(this, Line); + }, Z2.Line = Line, X2.Y = Y; })(X || (X = { })); diff --git a/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es2015.1.normal/output.js index 67da3d6bdc7..ed2c9a2287d 100644 --- a/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es2015.1.normal/output.js @@ -22,7 +22,7 @@ var X; (function(X2) { var X1 = 13; let Y2; - (function(Y) { + (function(Y3) { var Y1 = 13; let Z; (function(Z) { @@ -31,12 +31,28 @@ var X; var Z1 = 12; })(Z || (Z = { })); - Y.Z = Z; + Y3.Z = Z; })(Y2 || (Y2 = { })); X2.Y = Y2; })(X || (X = { })); +var Y; +(function(Y5) { + let Y4; + (function(Y6) { + let Y4; + (function(Y4) { + Y4[Y4["Red"] = 0] = "Red"; + Y4[Y4["Blue"] = 1] = "Blue"; + })(Y4 || (Y4 = { + })); + Y6.Y = Y4; + })(Y4 || (Y4 = { + })); + Y5.Y = Y4; +})(Y || (Y = { +})); // no collision, since interface doesn't // generate code. var D; diff --git a/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es2015.2.minified/output.js index 940c26a6cee..f8f9922b4fe 100644 --- a/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es2015.2.minified/output.js @@ -1,8 +1,15 @@ -var X, D; +var X, Y, D; !function(X1) { - let Y, Z; - (Y || (Y = { - })).Z = Z, X1.Y = Y; + let Y1, Z; + (Y1 || (Y1 = { + })).Z = Z, X1.Y = Y1; }(X || (X = { +})), (function(Y4) { + var Y2, Y3; + let Y3, Y3; + Y2 = Y3 || (Y3 = { + }), (Y3 = Y3 || (Y3 = { + }))[Y3.Red = 0] = "Red", Y3[Y3.Blue = 1] = "Blue", Y2.Y = Y3, Y4.Y = Y3; +})(Y || (Y = { })), (D || (D = { })).E = "hello"; diff --git a/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es5.1.normal/output.js index 57740673e21..bb098c89a91 100644 --- a/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es5.1.normal/output.js @@ -27,7 +27,7 @@ var X; (function(X2) { var X1 = 13; var Y2; - (function(Y) { + (function(Y3) { var Y1 = 13; var Z; (function(Z) { @@ -36,12 +36,28 @@ var X; var Z1 = 12; })(Z || (Z = { })); - Y.Z = Z; + Y3.Z = Z; })(Y2 || (Y2 = { })); X2.Y = Y2; })(X || (X = { })); +var Y; +(function(Y5) { + var Y4; + (function(Y6) { + var Y4; + (function(Y4) { + Y4[Y4["Red"] = 0] = "Red"; + Y4[Y4["Blue"] = 1] = "Blue"; + })(Y4 || (Y4 = { + })); + Y6.Y = Y4; + })(Y4 || (Y4 = { + })); + Y5.Y = Y4; +})(Y || (Y = { +})); // no collision, since interface doesn't // generate code. var D; diff --git a/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es5.2.minified/output.js index 08f319e0d4b..b54c7e4b960 100644 --- a/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/codeGeneration/nameCollision/input.ts/es5.2.minified/output.js @@ -1,4 +1,4 @@ -var B, X, D; +var B, X, Y, D; !function(B) { var B1 = function() { "use strict"; @@ -8,9 +8,15 @@ var B, X, D; }; }(B || (B = { })), (function(X1) { - var Y, Z; - (Y || (Y = { - })).Z = Z, X1.Y = Y; + var Y1, Z; + (Y1 || (Y1 = { + })).Z = Z, X1.Y = Y1; })(X || (X = { +})), (function(Y4) { + var Y2, Y3, Y2, Y2; + Y3 = Y2 || (Y2 = { + }), (Y2 = Y2 || (Y2 = { + }))[Y2.Red = 0] = "Red", Y2[Y2.Blue = 1] = "Blue", Y3.Y = Y2, Y4.Y = Y2; +})(Y || (Y = { })), (D || (D = { })).E = "hello"; diff --git a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportInterfaceWithInaccessibleTypeInIndexerTypeAnnotations/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportInterfaceWithInaccessibleTypeInIndexerTypeAnnotations/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportInterfaceWithInaccessibleTypeInIndexerTypeAnnotations/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/exportDeclarations/ExportInterfaceWithInaccessibleTypeInIndexerTypeAnnotations/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es2015.1.normal/output.js index d9dacc4a23a..e9c4ecd6017 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es2015.1.normal/output.js @@ -1 +1,11 @@ let namespace = 10; +var a; +(function(a1) { + let b1; + (function(b) { + b.c = 20; + })(b1 || (b1 = { + })); + a1.b = b1; +})(a || (a = { +})); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es2015.2.minified/output.js new file mode 100644 index 00000000000..41a1fea839e --- /dev/null +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es2015.2.minified/output.js @@ -0,0 +1,7 @@ +var a; +!function(a1) { + let b; + (b || (b = { + })).c = 20, a1.b = b; +}(a || (a = { +})); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es5.1.normal/output.js index 808db67f43d..597b359f39d 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es5.1.normal/output.js @@ -1 +1,11 @@ var namespace = 10; +var a; +(function(a1) { + var b1; + (function(b) { + b.c = 20; + })(b1 || (b1 = { + })); + a1.b = b1; +})(a || (a = { +})); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es5.2.minified/output.js index e69de29bb2d..7ddc51d19af 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/asiPreventsParsingAsNamespace05/input.ts/es5.2.minified/output.js @@ -0,0 +1,7 @@ +var a; +!function(a1) { + var b; + (b || (b = { + })).c = 20, a1.b = b; +}(a || (a = { +})); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es2015.1.normal/output.js index c261712afff..93446372141 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es2015.1.normal/output.js @@ -2,22 +2,49 @@ var A; (function(A1) { let B1; (function(B) { - class C { - } - B.C = C; + let C1; + (function(C) { + class Point { + } + C.Point = Point; + })(C1 || (C1 = { + })); + B.C = C1; })(B1 || (B1 = { })); A1.B = B1; })(A || (A = { })); +(function(A2) { + let B2; + (function(B) { + class C { + } + B.C = C; + })(B2 || (B2 = { + })); + A2.B = B2; +})(A || (A = { +})); var M2; (function(M21) { let X1; (function(X) { - var Point; + class Point { + } X.Point = Point; })(X1 || (X1 = { })); M21.X = X1; })(M2 || (M2 = { })); +(function(M22) { + let X2; + (function(X) { + var Point; + X.Point = Point; + })(X2 || (X2 = { + })); + M22.X = X2; +})(M2 || (M2 = { +})); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es2015.2.minified/output.js index 796f06105e0..9a691b4fbc6 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es2015.2.minified/output.js @@ -1,14 +1,28 @@ var A, M2; !function(A1) { + var B; + let B1, C; + B = B1 || (B1 = { + }), (C || (C = { + })).Point = class { + }, B.C = C, A1.B = B1; +}(A || (A = { +})), (function(A2) { let B; (B || (B = { })).C = class { - }, A1.B = B; -}(A || (A = { + }, A2.B = B; +})(A || (A = { })), (function(M21) { + let X; + (X || (X = { + })).Point = class { + }, M21.X = X; +})(M2 || (M2 = { +})), (function(M22) { var Point; let X; (X || (X = { - })).Point = Point, M21.X = X; + })).Point = Point, M22.X = X; })(M2 || (M2 = { })); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es5.1.normal/output.js index 5093060d7dd..27ef1ea0d5e 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es5.1.normal/output.js @@ -6,25 +6,56 @@ function _classCallCheck(instance, Constructor) { var A; (function(A1) { var B1; + (function(B) { + var C1; + (function(C) { + var Point = function Point() { + "use strict"; + _classCallCheck(this, Point); + }; + C.Point = Point; + })(C1 || (C1 = { + })); + B.C = C1; + })(B1 || (B1 = { + })); + A1.B = B1; +})(A || (A = { +})); +(function(A2) { + var B2; (function(B) { var C = function C() { "use strict"; _classCallCheck(this, C); }; B.C = C; - })(B1 || (B1 = { + })(B2 || (B2 = { })); - A1.B = B1; + A2.B = B2; })(A || (A = { })); var M2; (function(M21) { var X1; (function(X) { - var Point; + var Point = function Point() { + "use strict"; + _classCallCheck(this, Point); + }; X.Point = Point; })(X1 || (X1 = { })); M21.X = X1; })(M2 || (M2 = { })); +(function(M22) { + var X2; + (function(X) { + var Point; + X.Point = Point; + })(X2 || (X2 = { + })); + M22.X = X2; +})(M2 || (M2 = { +})); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es5.2.minified/output.js index db5e4ceddc0..534d14d04b9 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/invalidNestedModules/input.ts/es5.2.minified/output.js @@ -1,17 +1,35 @@ var A, M2; +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); +} !function(A1) { - var B, B1, C; + var B, B1, C, C1, Point; B1 = B || (B = { + }), C1 = C || (C = { + }), Point = function() { + "use strict"; + _classCallCheck(this, Point); + }, C1.Point = Point, B1.C = C, A1.B = B; +}(A || (A = { +})), (function(A2) { + var B, B2, C; + B2 = B || (B = { }), C = function() { "use strict"; - !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C); - }, B1.C = C, A1.B = B; -}(A || (A = { + _classCallCheck(this, C); + }, B2.C = C, A2.B = B; +})(A || (A = { })), (function(M21) { + var X, X1, Point; + X1 = X || (X = { + }), Point = function() { + "use strict"; + _classCallCheck(this, Point); + }, X1.Point = Point, M21.X = X; +})(M2 || (M2 = { +})), (function(M22) { var X, Point; (X || (X = { - })).Point = Point, M21.X = X; + })).Point = Point, M22.X = X; })(M2 || (M2 = { })); diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es2015.1.normal/output.js index 2545d73af7e..2a4f1f267d7 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es2015.1.normal/output.js @@ -1,5 +1,4 @@ -var A; -(function(A1) { +(function(A) { let B; (function(B) { var Point = { @@ -8,18 +7,17 @@ var A; }; // bug 832088: could not find module 'C' })(B || (B = { })); - A1.B = B; + A.B = B; })(A || (A = { })); -var M2; -(function(M21) { +(function(M2) { let X1; (function(X) { var Point; X.Point = Point; })(X1 || (X1 = { })); - M21.X = X1; + M2.X = X1; })(M2 || (M2 = { })); var m = M2.X; diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es2015.2.minified/output.js index a5b2d28a881..ebe7b79bdce 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es2015.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es2015.2.minified/output.js @@ -1,12 +1,11 @@ -var A, M2; -!function(A1) { +!function(A) { let B; - A1.B = B; + A.B = B; }(A || (A = { -})), (function(M21) { +})), (function(M2) { var Point; let X; (X || (X = { - })).Point = Point, M21.X = X; + })).Point = Point, M2.X = X; })(M2 || (M2 = { })), M2.X.Point; diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es5.1.normal/output.js index 1c735e9a9bc..ac408fa6bec 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es5.1.normal/output.js @@ -1,5 +1,4 @@ -var A; -(function(A1) { +(function(A) { var B; (function(B) { var Point = { @@ -8,18 +7,17 @@ var A; }; // bug 832088: could not find module 'C' })(B || (B = { })); - A1.B = B; + A.B = B; })(A || (A = { })); -var M2; -(function(M21) { +(function(M2) { var X1; (function(X) { var Point; X.Point = Point; })(X1 || (X1 = { })); - M21.X = X1; + M2.X = X1; })(M2 || (M2 = { })); var m = M2.X; diff --git a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es5.2.minified/output.js index dfc89e2167e..abaee6cf5e3 100644 --- a/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/internalModules/moduleDeclarations/nestedModules/input.ts/es5.2.minified/output.js @@ -1,11 +1,10 @@ -var A, M2; -!function(A1) { +!function(A) { var B; - A1.B = B; + A.B = B; }(A || (A = { -})), (function(M21) { +})), (function(M2) { var X, Point; (X || (X = { - })).Point = Point, M21.X = X; + })).Point = Point, M2.X = X; })(M2 || (M2 = { })), M2.X.Point; diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration7/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration7/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration7/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/FunctionDeclarations/parserFunctionDeclaration7/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/ModuleDeclarations/parserModuleDeclaration4/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es2015.1.normal/output.js index e5498720be7..359ddec1a3c 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es2015.1.normal/output.js @@ -3,3 +3,17 @@ class C { super.foo(); } } +var M1; +(function(M11) { + let M2; + (function(M2) { + class C { + foo() { + super.foo(); + } + } + })(M2 || (M2 = { + })); + M11.M2 = M2; +})(M1 || (M1 = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es2015.2.minified/output.js new file mode 100644 index 00000000000..e7944c9f1d6 --- /dev/null +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es2015.2.minified/output.js @@ -0,0 +1,6 @@ +var M1; +!function(M11) { + let M2; + M11.M2 = M2; +}(M1 || (M1 = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es5.1.normal/output.js index 45c12f5af19..16c64b1c815 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es5.1.normal/output.js @@ -61,3 +61,27 @@ var C = /*#__PURE__*/ function() { ]); return C; }(); +var M1; +(function(M11) { + var M2; + (function(M2) { + var C = /*#__PURE__*/ function() { + "use strict"; + function C() { + _classCallCheck(this, C); + } + _createClass(C, [ + { + key: "foo", + value: function foo() { + _get(_getPrototypeOf(C.prototype), "foo", this).call(this); + } + } + ]); + return C; + }(); + })(M2 || (M2 = { + })); + M11.M2 = M2; +})(M1 || (M1 = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es5.2.minified/output.js index 552242abf50..61675fac801 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression1/input.ts/es5.2.minified/output.js @@ -1,9 +1,15 @@ +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); +} function _defineProperties(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { + return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; +} function _get(target, property, receiver) { return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function _get(target, property, receiver) { var base = _superPropBase(target, property); @@ -22,20 +28,36 @@ function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var C = function() { +var M1, C = function() { "use strict"; - var Constructor, protoProps, staticProps; function C() { - !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C); + _classCallCheck(this, C); } - return Constructor = C, protoProps = [ + return _createClass(C, [ { key: "foo", value: function() { _get(_getPrototypeOf(C.prototype), "foo", this).call(this); } } - ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), C; + ]), C; }(); +!function(M11) { + var M2, C; + M2 || (M2 = { + }), C = (function() { + "use strict"; + function C() { + _classCallCheck(this, C); + } + return _createClass(C, [ + { + key: "foo", + value: function() { + _get(_getPrototypeOf(C.prototype), "foo", this).call(this); + } + } + ]), C; + })(), M11.M2 = M2; +}(M1 || (M1 = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es2015.1.normal/output.js index 37473e74c43..00bf1038b0f 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es2015.1.normal/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es2015.1.normal/output.js @@ -3,3 +3,17 @@ class C { super.foo = 1; } } +var M1; +(function(M11) { + let M2; + (function(M2) { + class C { + foo() { + super.foo = 1; + } + } + })(M2 || (M2 = { + })); + M11.M2 = M2; +})(M1 || (M1 = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es2015.2.minified/output.js new file mode 100644 index 00000000000..e7944c9f1d6 --- /dev/null +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es2015.2.minified/output.js @@ -0,0 +1,6 @@ +var M1; +!function(M11) { + let M2; + M11.M2 = M2; +}(M1 || (M1 = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es5.1.normal/output.js index 834ae5c492f..5633ade18b0 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es5.1.normal/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es5.1.normal/output.js @@ -96,3 +96,27 @@ var C = /*#__PURE__*/ function() { ]); return C; }(); +var M1; +(function(M11) { + var M2; + (function(M2) { + var C = /*#__PURE__*/ function() { + "use strict"; + function C() { + _classCallCheck(this, C); + } + _createClass(C, [ + { + key: "foo", + value: function foo() { + _set(_getPrototypeOf(C.prototype), "foo", 1, this, true); + } + } + ]); + return C; + }(); + })(M2 || (M2 = { + })); + M11.M2 = M2; +})(M1 || (M1 = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es5.2.minified/output.js index ea70c1b567e..a463e71aa0c 100644 --- a/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es5.2.minified/output.js +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/SuperExpressions/parserSuperExpression4/input.ts/es5.2.minified/output.js @@ -1,9 +1,15 @@ +function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); +} function _defineProperties(target, props) { for(var i = 0; i < props.length; i++){ var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || !1, descriptor.configurable = !0, "value" in descriptor && (descriptor.writable = !0), Object.defineProperty(target, descriptor.key, descriptor); } } +function _createClass(Constructor, protoProps, staticProps) { + return protoProps && _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), Constructor; +} function _getPrototypeOf(o) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); @@ -28,27 +34,44 @@ function set(target, property, value, receiver) { return !0; }, set(target, property, value, receiver); } +function _set(target, property, value, receiver, isStrict) { + if (!set(target, property, value, receiver || target) && isStrict) throw new Error("failed to set property"); + return value; +} function _superPropBase(object, property) { for(; !Object.prototype.hasOwnProperty.call(object, property) && null !== (object = _getPrototypeOf(object));); return object; } -var C = function() { +var M1, C = function() { "use strict"; - var Constructor, protoProps, staticProps; function C() { - !function(instance, Constructor) { - if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function"); - }(this, C); + _classCallCheck(this, C); } - return Constructor = C, protoProps = [ + return _createClass(C, [ { key: "foo", value: function() { - !function(target, property, value, receiver, isStrict) { - if (!set(target, property, value, receiver || target) && isStrict) throw new Error("failed to set property"); - return value; - }(_getPrototypeOf(C.prototype), "foo", 1, this, !0); + _set(_getPrototypeOf(C.prototype), "foo", 1, this, !0); } } - ], _defineProperties(Constructor.prototype, protoProps), staticProps && _defineProperties(Constructor, staticProps), C; + ]), C; }(); +!function(M11) { + var M2, C; + M2 || (M2 = { + }), C = (function() { + "use strict"; + function C() { + _classCallCheck(this, C); + } + return _createClass(C, [ + { + key: "foo", + value: function() { + _set(_getPrototypeOf(C.prototype), "foo", 1, this, !0); + } + } + ]), C; + })(), M11.M2 = M2; +}(M1 || (M1 = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..7f09aaebba9 --- /dev/null +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es2015.1.normal/output.js @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. +// See LICENSE.txt in the project root for complete license information. +/// +var TypeScript; +(function(TypeScript1) { + let AstWalkerWithDetailCallback1; + (function(AstWalkerWithDetailCallback) { + function walk(script, callback) { + var pre = (cur, parent)=>{ + walker.options.goChildren = AstWalkerCallback(true, cur, callback); + return cur; + }; + var post = (cur, parent)=>{ + AstWalkerCallback(false, cur, callback); + return cur; + }; + var walker = TypeScript.getAstWalkerFactory().getWalker(pre, post); + walker.walk(script, null); + } + AstWalkerWithDetailCallback.walk = walk; + function AstWalkerCallback(pre, ast, callback) { + // See if the Callback needs to be handled using specific one or default one + var nodeType = ast.nodeType; + var callbackString = NodeType._map[nodeType] + "Callback"; + if (callback[callbackString]) { + return callback[callbackString](pre, ast); + } + if (callback.DefaultCallback) { + return callback.DefaultCallback(pre, ast); + } + return true; + } + })(AstWalkerWithDetailCallback1 || (AstWalkerWithDetailCallback1 = { + })); + TypeScript1.AstWalkerWithDetailCallback = AstWalkerWithDetailCallback1; +})(TypeScript || (TypeScript = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es2015.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es2015.2.minified/output.js new file mode 100644 index 00000000000..e6dbcf55bb1 --- /dev/null +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es2015.2.minified/output.js @@ -0,0 +1,18 @@ +var TypeScript; +!function(TypeScript1) { + let AstWalkerWithDetailCallback1; + !function(AstWalkerWithDetailCallback) { + function AstWalkerCallback(pre, ast, callback) { + var nodeType = ast.nodeType, callbackString = NodeType._map[nodeType] + "Callback"; + return callback[callbackString] ? callback[callbackString](pre, ast) : !callback.DefaultCallback || callback.DefaultCallback(pre, ast); + } + AstWalkerWithDetailCallback.walk = function(script, callback) { + var pre = (cur, parent)=>(walker.options.goChildren = AstWalkerCallback(!0, cur, callback), cur) + , post = (cur, parent)=>(AstWalkerCallback(!1, cur, callback), cur) + , walker = TypeScript.getAstWalkerFactory().getWalker(pre, post); + walker.walk(script, null); + }; + }(AstWalkerWithDetailCallback1 || (AstWalkerWithDetailCallback1 = { + })), TypeScript1.AstWalkerWithDetailCallback = AstWalkerWithDetailCallback1; +}(TypeScript || (TypeScript = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..4e0198f30bb --- /dev/null +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es5.1.normal/output.js @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. +// See LICENSE.txt in the project root for complete license information. +/// +var TypeScript; +(function(TypeScript1) { + var AstWalkerWithDetailCallback1; + (function(AstWalkerWithDetailCallback) { + function walk(script, callback) { + var pre = function(cur, parent) { + walker.options.goChildren = AstWalkerCallback(true, cur, callback); + return cur; + }; + var post = function(cur, parent) { + AstWalkerCallback(false, cur, callback); + return cur; + }; + var walker = TypeScript.getAstWalkerFactory().getWalker(pre, post); + walker.walk(script, null); + } + AstWalkerWithDetailCallback.walk = walk; + function AstWalkerCallback(pre, ast, callback) { + // See if the Callback needs to be handled using specific one or default one + var nodeType = ast.nodeType; + var callbackString = NodeType._map[nodeType] + "Callback"; + if (callback[callbackString]) { + return callback[callbackString](pre, ast); + } + if (callback.DefaultCallback) { + return callback.DefaultCallback(pre, ast); + } + return true; + } + })(AstWalkerWithDetailCallback1 || (AstWalkerWithDetailCallback1 = { + })); + TypeScript1.AstWalkerWithDetailCallback = AstWalkerWithDetailCallback1; +})(TypeScript || (TypeScript = { +})); diff --git a/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es5.2.minified/output.js b/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es5.2.minified/output.js new file mode 100644 index 00000000000..62a37b2efa9 --- /dev/null +++ b/crates/swc/tests/tsc-references/parser/ecmascript5/parserRealSource13/input.ts/es5.2.minified/output.js @@ -0,0 +1,20 @@ +var TypeScript; +!function(TypeScript1) { + var AstWalkerWithDetailCallback1; + !function(AstWalkerWithDetailCallback) { + function AstWalkerCallback(pre, ast, callback) { + var nodeType = ast.nodeType, callbackString = NodeType._map[nodeType] + "Callback"; + return callback[callbackString] ? callback[callbackString](pre, ast) : !callback.DefaultCallback || callback.DefaultCallback(pre, ast); + } + AstWalkerWithDetailCallback.walk = function(script, callback) { + var pre = function(cur, parent) { + return walker.options.goChildren = AstWalkerCallback(!0, cur, callback), cur; + }, post = function(cur, parent) { + return AstWalkerCallback(!1, cur, callback), cur; + }, walker = TypeScript.getAstWalkerFactory().getWalker(pre, post); + walker.walk(script, null); + }; + }(AstWalkerWithDetailCallback1 || (AstWalkerWithDetailCallback1 = { + })), TypeScript1.AstWalkerWithDetailCallback = AstWalkerWithDetailCallback1; +}(TypeScript || (TypeScript = { +})); diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithCallSignaturesWithSpecializedSignatures/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithConstructSignaturesWithSpecializedSignatures/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericCallSignaturesWithOptionalParameters/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithGenericConstructSignaturesWithOptionalParameters/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithNumericIndexer2/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers2/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithObjectMembers3/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2/input.ts/es2015.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2/input.ts/es2015.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2/input.ts/es5.1.normal/output.js b/crates/swc/tests/tsc-references/types/typeRelationships/subtypesAndSuperTypes/subtypingWithStringIndexer2/input.ts/es5.1.normal/output.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs index 423d21857e5..ef23009de65 100644 --- a/crates/swc_ecma_transforms_typescript/src/strip.rs +++ b/crates/swc_ecma_transforms_typescript/src/strip.rs @@ -1086,32 +1086,183 @@ where if module.global || module.declare { return None; } - let module_span = module.span; + let module_span = module.span; let module_name = match module.id { TsModuleName::Ident(i) => i, TsModuleName::Str(_) => return None, }; + let body = module.body?; - let mut body = match body { - TsNamespaceBody::TsModuleBlock(body) => body, - TsNamespaceBody::TsNamespaceDecl(_) => return None, + let var = self.create_uninit_var(module_name.span, module_name.to_id()); + let private_name = private_ident!(module_name.sym.clone()); + let body_stmts = match body { + TsNamespaceBody::TsModuleBlock(block) => { + self.handle_ts_module_block(block, &private_name) + } + TsNamespaceBody::TsNamespaceDecl(decl) => { + self.handle_ts_namespace_decl(decl, &private_name) + } + }?; + + self.get_namespace_var_decl_and_call_expr(var, body_stmts, &module_name, &private_name) + .map(|(mut var, stmt)| { + if let Some(var) = var.as_mut() { + // for comments + var.span = module_span; + // ensure it's a var if top level + if module_name.span.ctxt == self.top_level_ctxt { + var.kind = VarDeclKind::Var; + } + } + (var.map(Decl::Var), stmt) + }) + } + + fn handle_ts_namespace_decl( + &mut self, + decl: TsNamespaceDecl, + parent_private_name: &Ident, + ) -> Option> { + let private_name = private_ident!(decl.id.sym.clone()); + // we'll always create a variable in this scenario + let var_id = Ident::new(decl.id.sym.clone(), DUMMY_SP.with_ctxt(decl.id.span.ctxt)); + let var = VarDeclarator { + span: DUMMY_SP, + name: Pat::Ident(BindingIdent { + id: var_id.clone(), + type_ann: None, + }), + init: None, + definite: false, }; - let mut init_stmts = vec![]; + let body_stmts = match *decl.body { + TsNamespaceBody::TsModuleBlock(block) => { + self.handle_ts_module_block(block, &private_name) + } + TsNamespaceBody::TsNamespaceDecl(decl) => { + self.handle_ts_namespace_decl(decl, &private_name) + } + }?; - let var = self.create_uninit_var(module_name.span, module_name.to_id()); + let (var_decl, init_stmt) = self.get_namespace_var_decl_and_call_expr( + Some(var), + body_stmts, + &decl.id, + &private_name, + )?; + let mut stmts = Vec::new(); + stmts.extend(var_decl.map(Decl::Var).map(Stmt::Decl)); + stmts.push(init_stmt); + // the `Parent.Current = Current` statement + stmts.push(Stmt::Expr(ExprStmt { + span: DUMMY_SP, + expr: Box::new({ + let mut prop = decl.id.clone(); + prop.span.ctxt = SyntaxContext::empty(); + Expr::Assign(AssignExpr { + span: DUMMY_SP, + op: op!("="), + left: PatOrExpr::Expr(Box::new(Expr::Member(MemberExpr { + span: DUMMY_SP, + obj: parent_private_name.clone().as_obj(), + prop: Box::new(Expr::Ident(prop)), + computed: false, + }))), + right: Box::new(Expr::Ident(var_id)), + }) + }), + })); - // This makes body valid javascript. - body.body.visit_mut_with(self); - if body.body.is_empty() { + Some(stmts) + } + + fn get_namespace_var_decl_and_call_expr( + &self, + var: Option, + body_stmts: Vec, + module_name: &Ident, + private_name: &Ident, + ) -> Option<(Option, Stmt)> { + let init_fn_expr = FnExpr { + ident: None, + function: Function { + params: vec![Param { + span: DUMMY_SP, + decorators: Default::default(), + pat: Pat::Ident(private_name.clone().into()), + }], + decorators: Default::default(), + span: DUMMY_SP, + body: Some(BlockStmt { + span: DUMMY_SP, + stmts: body_stmts, + }), + is_generator: false, + is_async: false, + type_params: Default::default(), + return_type: Default::default(), + }, + }; + + let init_arg = BinExpr { + span: DUMMY_SP, + left: Box::new(Expr::Ident(module_name.clone())), + op: op!("||"), + right: Box::new(Expr::Assign(AssignExpr { + span: DUMMY_SP, + op: op!("="), + left: PatOrExpr::Pat(Box::new(Pat::Ident(module_name.clone().into()))), + right: Box::new(Expr::Object(ObjectLit { + span: DUMMY_SP, + props: Default::default(), + })), + })), + }; + + let initializer = Box::new(Expr::Call(CallExpr { + span: DUMMY_SP, + callee: init_fn_expr.as_callee(), + args: vec![init_arg.as_arg()], + type_args: Default::default(), + })); + + Some(( + var.map(|var| VarDecl { + span: DUMMY_SP, + kind: if module_name.span.ctxt != self.top_level_ctxt { + VarDeclKind::Let + } else { + VarDeclKind::Var + }, + declare: false, + decls: vec![var], + }), + Stmt::Expr(ExprStmt { + span: DUMMY_SP, + expr: initializer, + }), + )) + } + + fn handle_ts_module_block( + &mut self, + mut block: TsModuleBlock, + private_module_name: &Ident, + ) -> Option> { + // Make the body valid javascript. + block.body.visit_mut_with(self); + + // Now check if it's empty as statements like interfaces might have been removed + if block.body.is_empty() { return None; } - let private_name = private_ident!(module_name.sym.clone()); let mut delayed_vars = vec![]; + let mut init_stmts = vec![]; - for item in body.body { + for item in block.body { // Drop match item { @@ -1151,7 +1302,7 @@ where let left = PatOrExpr::Expr(Box::new(Expr::Member(MemberExpr { span: DUMMY_SP, - obj: private_name.clone().as_obj(), + obj: private_module_name.clone().as_obj(), prop: Box::new(Expr::Ident(name.id.clone())), computed: false, }))); @@ -1164,8 +1315,10 @@ where }))) } _ => { - let pat = - Box::new(create_prop_pat(&private_name, decl.name)); + let pat = Box::new(create_prop_pat( + &private_module_name, + decl.name, + )); // Destructure the variable. exprs.push(Box::new(Expr::Assign(AssignExpr { span: DUMMY_SP, @@ -1203,7 +1356,7 @@ where // let left = PatOrExpr::Expr(Box::new(Expr::Member(MemberExpr { span: DUMMY_SP, - obj: private_name.clone().as_obj(), + obj: private_module_name.clone().as_obj(), prop: Box::new(Expr::Ident(decl_name.clone())), computed: false, }))); @@ -1242,7 +1395,7 @@ where op: op!("="), left: PatOrExpr::Expr(Box::new(Expr::Member(MemberExpr { span: DUMMY_SP, - obj: private_name.clone().as_obj(), + obj: private_module_name.clone().as_obj(), prop: Box::new(Expr::Ident(prop)), computed: false, }))), @@ -1255,67 +1408,7 @@ where })) } - let init_fn_expr = FnExpr { - ident: None, - function: Function { - params: vec![Param { - span: DUMMY_SP, - decorators: Default::default(), - pat: Pat::Ident(private_name.clone().into()), - }], - decorators: Default::default(), - span: DUMMY_SP, - body: Some(BlockStmt { - span: DUMMY_SP, - stmts: init_stmts, - }), - is_generator: false, - is_async: false, - type_params: Default::default(), - return_type: Default::default(), - }, - }; - - let init_arg = BinExpr { - span: DUMMY_SP, - left: Box::new(Expr::Ident(module_name.clone())), - op: op!("||"), - right: Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - op: op!("="), - left: PatOrExpr::Pat(Box::new(Pat::Ident(module_name.clone().into()))), - right: Box::new(Expr::Object(ObjectLit { - span: DUMMY_SP, - props: Default::default(), - })), - })), - }; - - let initializer = Box::new(Expr::Call(CallExpr { - span: DUMMY_SP, - callee: init_fn_expr.as_callee(), - args: vec![init_arg.as_arg()], - type_args: Default::default(), - })); - - Some(( - var.map(|var| { - Decl::Var(VarDecl { - span: module_span, - kind: if module_name.span.ctxt != self.top_level_ctxt { - VarDeclKind::Let - } else { - VarDeclKind::Var - }, - declare: false, - decls: vec![var], - }) - }), - Stmt::Expr(ExprStmt { - span: DUMMY_SP, - expr: initializer, - }), - )) + Some(init_stmts) } } diff --git a/crates/swc_ecma_transforms_typescript/tests/strip.rs b/crates/swc_ecma_transforms_typescript/tests/strip.rs index 71a2a58a196..d916720e61e 100644 --- a/crates/swc_ecma_transforms_typescript/tests/strip.rs +++ b/crates/swc_ecma_transforms_typescript/tests/strip.rs @@ -3498,6 +3498,28 @@ to!( " ); +to!( + namespace_003, + " + namespace Test.Inner { + export const c = 3; + } + namespace Test.Other { + export interface Test {} + } + ", + " + var Test; + (function (Test1) { + let Inner1; + (function (Inner) { + Inner.c = 3; + })(Inner1 || (Inner1 = {})); + Test1.Inner = Inner1; + })(Test || (Test = {})); + " +); + to!( issue_1329, "