@@ -15,6 +15,32 @@ namespace ts {
15
15
hasExportStarsToExportValues : boolean ; // whether this module contains export*
16
16
}
17
17
18
+ function getNamedImportCount ( node : ImportDeclaration ) {
19
+ if ( ! ( node . importClause && node . importClause . namedBindings ) ) return 0 ;
20
+ const names = node . importClause . namedBindings ;
21
+ if ( ! names ) return 0 ;
22
+ if ( ! isNamedImports ( names ) ) return 0 ;
23
+ return names . elements . length ;
24
+ }
25
+
26
+ function containsDefaultReference ( node : NamedImportBindings ) {
27
+ if ( ! node ) return false ;
28
+ if ( ! isNamedImports ( node ) ) return false ;
29
+ return some ( node . elements , isNamedDefaultReference ) ;
30
+ }
31
+
32
+ function isNamedDefaultReference ( e : ImportSpecifier ) {
33
+ return e . propertyName && e . propertyName . escapedText === InternalSymbolName . Default ;
34
+ }
35
+
36
+ export function getImportNeedsImportStarHelper ( node : ImportDeclaration ) {
37
+ return ! ! getNamespaceDeclarationNode ( node ) || ( getNamedImportCount ( node ) > 1 && containsDefaultReference ( node . importClause . namedBindings ) ) ;
38
+ }
39
+
40
+ export function getImportNeedsImportDefaultHelper ( node : ImportDeclaration ) {
41
+ return isDefaultImport ( node ) || ( getNamedImportCount ( node ) === 1 && containsDefaultReference ( node . importClause . namedBindings ) ) ;
42
+ }
43
+
18
44
export function collectExternalModuleInfo ( sourceFile : SourceFile , resolver : EmitResolver , compilerOptions : CompilerOptions ) : ExternalModuleInfo {
19
45
const externalImports : ( ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration ) [ ] = [ ] ;
20
46
const exportSpecifiers = createMultiMap < ExportSpecifier > ( ) ;
@@ -24,6 +50,7 @@ namespace ts {
24
50
let hasExportDefault = false ;
25
51
let exportEquals : ExportAssignment = undefined ;
26
52
let hasExportStarsToExportValues = false ;
53
+ let hasImportStarOrImportDefault = false ;
27
54
28
55
for ( const node of sourceFile . statements ) {
29
56
switch ( node . kind ) {
@@ -33,6 +60,7 @@ namespace ts {
33
60
// import * as x from "mod"
34
61
// import { x, y } from "mod"
35
62
externalImports . push ( < ImportDeclaration > node ) ;
63
+ hasImportStarOrImportDefault = getImportNeedsImportStarHelper ( < ImportDeclaration > node ) || getImportNeedsImportDefaultHelper ( < ImportDeclaration > node ) ;
36
64
break ;
37
65
38
66
case SyntaxKind . ImportEqualsDeclaration :
@@ -135,7 +163,7 @@ namespace ts {
135
163
}
136
164
}
137
165
138
- const externalHelpersModuleName = getOrCreateExternalHelpersModuleNameIfNeeded ( sourceFile , compilerOptions , hasExportStarsToExportValues ) ;
166
+ const externalHelpersModuleName = getOrCreateExternalHelpersModuleNameIfNeeded ( sourceFile , compilerOptions , hasExportStarsToExportValues , hasImportStarOrImportDefault ) ;
139
167
const externalHelpersImportDeclaration = externalHelpersModuleName && createImportDeclaration (
140
168
/*decorators*/ undefined ,
141
169
/*modifiers*/ undefined ,
0 commit comments