@@ -77,64 +77,67 @@ namespace ts {
7777 let addedGlobalFileReference = false ;
7878 let allSourcesModuleElementDeclarationEmitInfo : ModuleElementDeclarationEmitInfo [ ] = [ ] ;
7979 forEach ( sourceFiles , sourceFile => {
80- if ( ! isSourceFileJavaScript ( sourceFile ) ) {
81- // Check what references need to be added
82- if ( ! compilerOptions . noResolve ) {
83- forEach ( sourceFile . referencedFiles , fileReference => {
84- const referencedFile = tryResolveScriptReference ( host , sourceFile , fileReference ) ;
85-
86- // Emit reference in dts, if the file reference was not already emitted
87- if ( referencedFile && ! contains ( emittedReferencedFiles , referencedFile ) ) {
88- // Add a reference to generated dts file,
89- // global file reference is added only
90- // - if it is not bundled emit (because otherwise it would be self reference)
91- // - and it is not already added
92- if ( writeReferencePath ( referencedFile , ! isBundledEmit && ! addedGlobalFileReference ) ) {
93- addedGlobalFileReference = true ;
94- }
95- emittedReferencedFiles . push ( referencedFile ) ;
80+ // Dont emit for javascript file
81+ if ( isSourceFileJavaScript ( sourceFile ) ) {
82+ return ;
83+ }
84+
85+ // Check what references need to be added
86+ if ( ! compilerOptions . noResolve ) {
87+ forEach ( sourceFile . referencedFiles , fileReference => {
88+ const referencedFile = tryResolveScriptReference ( host , sourceFile , fileReference ) ;
89+
90+ // Emit reference in dts, if the file reference was not already emitted
91+ if ( referencedFile && ! contains ( emittedReferencedFiles , referencedFile ) ) {
92+ // Add a reference to generated dts file,
93+ // global file reference is added only
94+ // - if it is not bundled emit (because otherwise it would be self reference)
95+ // - and it is not already added
96+ if ( writeReferencePath ( referencedFile , ! isBundledEmit && ! addedGlobalFileReference ) ) {
97+ addedGlobalFileReference = true ;
9698 }
97- } ) ;
98- }
99+ emittedReferencedFiles . push ( referencedFile ) ;
100+ }
101+ } ) ;
102+ }
99103
100- if ( ! isBundledEmit || ! isExternalModule ( sourceFile ) ) {
101- noDeclare = false ;
102- emitSourceFile ( sourceFile ) ;
103- }
104- else if ( isExternalModule ( sourceFile ) ) {
105- noDeclare = true ;
106- write ( `declare module "${ getResolvedExternalModuleName ( host , sourceFile ) } " {` ) ;
107- writeLine ( ) ;
108- increaseIndent ( ) ;
109- emitSourceFile ( sourceFile ) ;
110- decreaseIndent ( ) ;
111- write ( "}" ) ;
112- writeLine ( ) ;
113- }
104+ if ( ! isBundledEmit || ! isExternalModule ( sourceFile ) ) {
105+ noDeclare = false ;
106+ emitSourceFile ( sourceFile ) ;
107+ }
108+ else if ( isExternalModule ( sourceFile ) ) {
109+ noDeclare = true ;
110+ write ( `declare module "${ getResolvedExternalModuleName ( host , sourceFile ) } " {` ) ;
111+ writeLine ( ) ;
112+ increaseIndent ( ) ;
113+ emitSourceFile ( sourceFile ) ;
114+ decreaseIndent ( ) ;
115+ write ( "}" ) ;
116+ writeLine ( ) ;
117+ }
114118
115- // create asynchronous output for the importDeclarations
116- if ( moduleElementDeclarationEmitInfo . length ) {
117- const oldWriter = writer ;
118- forEach ( moduleElementDeclarationEmitInfo , aliasEmitInfo => {
119- if ( aliasEmitInfo . isVisible && ! aliasEmitInfo . asynchronousOutput ) {
120- Debug . assert ( aliasEmitInfo . node . kind === SyntaxKind . ImportDeclaration ) ;
121- createAndSetNewTextWriterWithSymbolWriter ( ) ;
122- Debug . assert ( aliasEmitInfo . indent === 0 || ( aliasEmitInfo . indent === 1 && isBundledEmit ) ) ;
123- for ( let i = 0 ; i < aliasEmitInfo . indent ; i ++ ) {
124- increaseIndent ( ) ;
125- }
126- writeImportDeclaration ( < ImportDeclaration > aliasEmitInfo . node ) ;
127- aliasEmitInfo . asynchronousOutput = writer . getText ( ) ;
128- for ( let i = 0 ; i < aliasEmitInfo . indent ; i ++ ) {
129- decreaseIndent ( ) ;
130- }
119+ // create asynchronous output for the importDeclarations
120+ if ( moduleElementDeclarationEmitInfo . length ) {
121+ const oldWriter = writer ;
122+ forEach ( moduleElementDeclarationEmitInfo , aliasEmitInfo => {
123+ if ( aliasEmitInfo . isVisible && ! aliasEmitInfo . asynchronousOutput ) {
124+ Debug . assert ( aliasEmitInfo . node . kind === SyntaxKind . ImportDeclaration ) ;
125+ createAndSetNewTextWriterWithSymbolWriter ( ) ;
126+ Debug . assert ( aliasEmitInfo . indent === 0 || ( aliasEmitInfo . indent === 1 && isBundledEmit ) ) ;
127+ for ( let i = 0 ; i < aliasEmitInfo . indent ; i ++ ) {
128+ increaseIndent ( ) ;
131129 }
132- } ) ;
133- setWriter ( oldWriter ) ;
130+ writeImportDeclaration ( < ImportDeclaration > aliasEmitInfo . node ) ;
131+ aliasEmitInfo . asynchronousOutput = writer . getText ( ) ;
132+ for ( let i = 0 ; i < aliasEmitInfo . indent ; i ++ ) {
133+ decreaseIndent ( ) ;
134+ }
135+ }
136+ } ) ;
137+ setWriter ( oldWriter ) ;
134138
135- allSourcesModuleElementDeclarationEmitInfo = allSourcesModuleElementDeclarationEmitInfo . concat ( moduleElementDeclarationEmitInfo ) ;
136- moduleElementDeclarationEmitInfo = [ ] ;
137- }
139+ allSourcesModuleElementDeclarationEmitInfo = allSourcesModuleElementDeclarationEmitInfo . concat ( moduleElementDeclarationEmitInfo ) ;
140+ moduleElementDeclarationEmitInfo = [ ] ;
138141 }
139142 } ) ;
140143
0 commit comments