@@ -2595,28 +2595,7 @@ namespace ts {
2595
2595
const containerName = getNamespaceContainerName ( node ) ;
2596
2596
2597
2597
// `exportName` is the expression used within this node's container for any exported references.
2598
- const exportName = hasModifier ( node , ModifierFlags . Export )
2599
- ? getExternalModuleOrNamespaceExportName ( currentNamespaceContainerName , node , /*allowComments*/ false , /*allowSourceMaps*/ true )
2600
- : getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true ) ;
2601
-
2602
- // x || (x = {})
2603
- // exports.x || (exports.x = {})
2604
- let moduleArg =
2605
- createLogicalOr (
2606
- exportName ,
2607
- createAssignment (
2608
- exportName ,
2609
- createObjectLiteral ( )
2610
- )
2611
- ) ;
2612
-
2613
- if ( hasNamespaceQualifiedExportName ( node ) ) {
2614
- // `localName` is the expression used within this node's containing scope for any local references.
2615
- const localName = getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true ) ;
2616
-
2617
- // x = (exports.x || (exports.x = {}))
2618
- moduleArg = createAssignment ( localName , moduleArg ) ;
2619
- }
2598
+ const localName = getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true ) ;
2620
2599
2621
2600
// (function (x) {
2622
2601
// x[x["y"] = 0] = "y";
@@ -2634,7 +2613,7 @@ namespace ts {
2634
2613
transformEnumBody ( node , containerName )
2635
2614
) ,
2636
2615
/*typeArguments*/ undefined ,
2637
- [ moduleArg ]
2616
+ [ localName ]
2638
2617
)
2639
2618
) ;
2640
2619
@@ -2742,13 +2721,13 @@ namespace ts {
2742
2721
* Determines whether an exported declaration will have a qualified export name (e.g. `f.x`
2743
2722
* or `exports.x`).
2744
2723
*/
2745
- function hasNamespaceQualifiedExportName ( node : Node ) {
2746
- return isExportOfNamespace ( node )
2747
- || ( isExternalModuleExport ( node )
2748
- && moduleKind !== ModuleKind . ES2015
2749
- && moduleKind !== ModuleKind . ESNext
2750
- && moduleKind !== ModuleKind . System ) ;
2751
- }
2724
+ // function hasNamespaceQualifiedExportName(node: Node) {
2725
+ // return isExportOfNamespace(node)
2726
+ // || (isExternalModuleExport(node)
2727
+ // && moduleKind !== ModuleKind.ES2015
2728
+ // && moduleKind !== ModuleKind.ESNext
2729
+ // && moduleKind !== ModuleKind.System);
2730
+ // }
2752
2731
2753
2732
/**
2754
2733
* Records that a declaration was emitted in the current scope, if it was the first
@@ -2789,11 +2768,35 @@ namespace ts {
2789
2768
// Emit a variable statement for the module. We emit top-level enums as a `var`
2790
2769
// declaration to avoid static errors in global scripts scripts due to redeclaration.
2791
2770
// enums in any other scope are emitted as a `let` declaration.
2771
+ const nodeModifierFlags = getModifierFlags ( node ) ;
2772
+ const nodeIsExportDefault = ( nodeModifierFlags & ModifierFlags . Export ) && ( nodeModifierFlags & ModifierFlags . Default ) ;
2773
+ function modifierVisitor ( node : Node ) : VisitResult < Node > {
2774
+ if ( modifierToFlag ( node . kind ) & ModifierFlags . TypeScriptModifier ) {
2775
+ return undefined ;
2776
+ }
2777
+ else if ( ( currentNamespace || nodeIsExportDefault ) && node . kind === SyntaxKind . ExportKeyword ) {
2778
+ return undefined ;
2779
+ }
2780
+ if ( node . kind == SyntaxKind . DefaultKeyword ) {
2781
+ return undefined ;
2782
+ }
2783
+ return node ;
2784
+ }
2785
+ const exportName = hasModifier ( node , ModifierFlags . Export )
2786
+ ? getExternalModuleOrNamespaceExportName ( currentNamespaceContainerName , node , /*allowComments*/ false , /*allowSourceMaps*/ true )
2787
+ : getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true ) ;
2788
+
2789
+ const localName = getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true ) ;
2792
2790
const statement = createVariableStatement (
2793
2791
visitNodes ( node . modifiers , modifierVisitor , isModifier ) ,
2794
2792
createVariableDeclarationList ( [
2795
2793
createVariableDeclaration (
2796
- getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true )
2794
+ localName ,
2795
+ undefined ,
2796
+ createLogicalOr (
2797
+ exportName ,
2798
+ createObjectLiteral ( )
2799
+ )
2797
2800
)
2798
2801
] , currentScope . kind === SyntaxKind . SourceFile ? NodeFlags . None : NodeFlags . Let )
2799
2802
) ;
@@ -2831,6 +2834,16 @@ namespace ts {
2831
2834
setCommentRange ( statement , node ) ;
2832
2835
setEmitFlags ( statement , EmitFlags . NoTrailingComments | EmitFlags . HasEndOfDeclarationMarker ) ;
2833
2836
statements . push ( statement ) ;
2837
+ if ( nodeIsExportDefault ) {
2838
+ statements . push ( createExportAssignment ( undefined , undefined , false , localName ) ) ;
2839
+ }
2840
+ if ( currentNamespace && ( nodeModifierFlags & ModifierFlags . Export ) ) {
2841
+ statements . push (
2842
+ createStatement (
2843
+ createAssignment ( createPropertyAccess ( currentNamespaceContainerName , localName ) , localName )
2844
+ )
2845
+ ) ;
2846
+ }
2834
2847
return true ;
2835
2848
}
2836
2849
else {
@@ -2883,28 +2896,7 @@ namespace ts {
2883
2896
const containerName = getNamespaceContainerName ( node ) ;
2884
2897
2885
2898
// `exportName` is the expression used within this node's container for any exported references.
2886
- const exportName = hasModifier ( node , ModifierFlags . Export )
2887
- ? getExternalModuleOrNamespaceExportName ( currentNamespaceContainerName , node , /*allowComments*/ false , /*allowSourceMaps*/ true )
2888
- : getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true ) ;
2889
-
2890
- // x || (x = {})
2891
- // exports.x || (exports.x = {})
2892
- let moduleArg =
2893
- createLogicalOr (
2894
- exportName ,
2895
- createAssignment (
2896
- exportName ,
2897
- createObjectLiteral ( )
2898
- )
2899
- ) ;
2900
-
2901
- if ( hasNamespaceQualifiedExportName ( node ) ) {
2902
- // `localName` is the expression used within this node's containing scope for any local references.
2903
- const localName = getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true ) ;
2904
-
2905
- // x = (exports.x || (exports.x = {}))
2906
- moduleArg = createAssignment ( localName , moduleArg ) ;
2907
- }
2899
+ const localName = getLocalName ( node , /*allowComments*/ false , /*allowSourceMaps*/ true ) ;
2908
2900
2909
2901
// (function (x_1) {
2910
2902
// x_1.y = ...;
@@ -2921,7 +2913,7 @@ namespace ts {
2921
2913
transformModuleBody ( node , containerName )
2922
2914
) ,
2923
2915
/*typeArguments*/ undefined ,
2924
- [ moduleArg ]
2916
+ [ localName ]
2925
2917
)
2926
2918
) ;
2927
2919
0 commit comments