@@ -18,25 +18,36 @@ namespace ts {
1818 }
1919
2020 if ( isExternalModule ( node ) || compilerOptions . isolatedModules ) {
21- const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded ( node , compilerOptions ) ;
22- if ( externalHelpersImportDeclaration ) {
23- const statements : Statement [ ] = [ ] ;
24- const statementOffset = addPrologue ( statements , node . statements ) ;
25- append ( statements , externalHelpersImportDeclaration ) ;
26-
27- addRange ( statements , visitNodes ( node . statements , visitor , isStatement , statementOffset ) ) ;
28- return updateSourceFileNode (
29- node ,
30- setTextRange ( createNodeArray ( statements ) , node . statements ) ) ;
31- }
32- else {
33- return visitEachChild ( node , visitor , context ) ;
21+ const result = updateExternalModule ( node ) ;
22+ if ( ! isExternalModule ( node ) || some ( result . statements , isExternalModuleIndicator ) ) {
23+ return result ;
3424 }
25+ return updateSourceFileNode (
26+ result ,
27+ setTextRange ( createNodeArray ( [ ...result . statements , createEmptyExports ( ) ] ) , result . statements ) ,
28+ ) ;
3529 }
3630
3731 return node ;
3832 }
3933
34+ function updateExternalModule ( node : SourceFile ) {
35+ const externalHelpersImportDeclaration = createExternalHelpersImportDeclarationIfNeeded ( node , compilerOptions ) ;
36+ if ( externalHelpersImportDeclaration ) {
37+ const statements : Statement [ ] = [ ] ;
38+ const statementOffset = addPrologue ( statements , node . statements ) ;
39+ append ( statements , externalHelpersImportDeclaration ) ;
40+
41+ addRange ( statements , visitNodes ( node . statements , visitor , isStatement , statementOffset ) ) ;
42+ return updateSourceFileNode (
43+ node ,
44+ setTextRange ( createNodeArray ( statements ) , node . statements ) ) ;
45+ }
46+ else {
47+ return visitEachChild ( node , visitor , context ) ;
48+ }
49+ }
50+
4051 function visitor ( node : Node ) : VisitResult < Node > {
4152 switch ( node . kind ) {
4253 case SyntaxKind . ImportEqualsDeclaration :
0 commit comments