@@ -1898,34 +1898,6 @@ module ts {
18981898 writeLine ( ) ;
18991899 }
19001900
1901- function isModuleElementExternallyVisible ( node : Declaration ) {
1902- if ( node . flags & NodeFlags . Export ) {
1903- // Exported member - emit this declaration
1904- return true ;
1905- }
1906-
1907- // If this node is in external module, check if this is export assigned
1908- var moduleDeclaration = getContainerOfModuleElementDeclaration ( node ) ;
1909- if ( ( moduleDeclaration . flags & NodeFlags . ExternalModule ) || // Source file with external module flag
1910- // Ambient external module declaration
1911- ( moduleDeclaration . kind === SyntaxKind . ModuleDeclaration && ( < ModuleDeclaration > moduleDeclaration ) . name . kind === SyntaxKind . StringLiteral ) ) {
1912- return resolver . isReferencedInExportAssignment ( node ) ;
1913- }
1914-
1915- return false ;
1916- }
1917-
1918- function canEmitModuleElementDeclaration ( node : Declaration ) {
1919- if ( isModuleElementExternallyVisible ( node ) ) {
1920- // Either exported module element or is referenced in export assignment
1921- return true ;
1922- }
1923-
1924- // emit the declaration if this is in global scope source file
1925- var moduleDeclaration = getContainerOfModuleElementDeclaration ( node ) ;
1926- return moduleDeclaration . kind === SyntaxKind . SourceFile && ! ( moduleDeclaration . flags & NodeFlags . ExternalModule ) ;
1927- }
1928-
19291901 function emitDeclarationFlags ( node : Declaration ) {
19301902 if ( node . flags & NodeFlags . Static ) {
19311903 if ( node . flags & NodeFlags . Private ) {
@@ -1952,8 +1924,7 @@ module ts {
19521924 }
19531925
19541926 function emitImportDeclaration ( node : ImportDeclaration ) {
1955- // TODO(shkamat): Emit if import decl is used to declare type in this context
1956- if ( isModuleElementExternallyVisible ( node ) ) {
1927+ if ( resolver . isDeclarationVisible ( node ) ) {
19571928 if ( node . flags & NodeFlags . Export ) {
19581929 write ( "export " ) ;
19591930 }
@@ -1974,7 +1945,7 @@ module ts {
19741945 }
19751946
19761947 function emitModuleDeclaration ( node : ModuleDeclaration ) {
1977- if ( canEmitModuleElementDeclaration ( node ) ) {
1948+ if ( resolver . isDeclarationVisible ( node ) ) {
19781949 emitDeclarationFlags ( node ) ;
19791950 write ( "module " ) ;
19801951 emitSourceTextOfNode ( node . name ) ;
@@ -1997,7 +1968,7 @@ module ts {
19971968 }
19981969
19991970 function emitEnumDeclaration ( node : EnumDeclaration ) {
2000- if ( canEmitModuleElementDeclaration ( node ) ) {
1971+ if ( resolver . isDeclarationVisible ( node ) ) {
20011972 emitDeclarationFlags ( node ) ;
20021973 write ( "enum " ) ;
20031974 emitSourceTextOfNode ( node . name ) ;
@@ -2060,7 +2031,7 @@ module ts {
20602031 }
20612032 }
20622033
2063- if ( canEmitModuleElementDeclaration ( node ) ) {
2034+ if ( resolver . isDeclarationVisible ( node ) ) {
20642035 emitDeclarationFlags ( node ) ;
20652036 write ( "class " ) ;
20662037 emitSourceTextOfNode ( node . name ) ;
@@ -2084,7 +2055,7 @@ module ts {
20842055 }
20852056
20862057 function emitInterfaceDeclaration ( node : InterfaceDeclaration ) {
2087- if ( canEmitModuleElementDeclaration ( node ) ) {
2058+ if ( resolver . isDeclarationVisible ( node ) ) {
20882059 emitDeclarationFlags ( node ) ;
20892060 write ( "interface " ) ;
20902061 emitSourceTextOfNode ( node . name ) ;
@@ -2111,8 +2082,9 @@ module ts {
21112082 }
21122083
21132084 function emitVariableDeclaration ( node : VariableDeclaration ) {
2114- // If we are emitting property it isnt moduleElement and doesnt need canEmitModuleElement check
2115- if ( node . kind !== SyntaxKind . VariableDeclaration || canEmitModuleElementDeclaration ( node ) ) {
2085+ // If we are emitting property it isnt moduleElement and hence we already know it needs to be emitted
2086+ // so there is no check needed to see if declaration is visible
2087+ if ( node . kind !== SyntaxKind . VariableDeclaration || resolver . isDeclarationVisible ( node ) ) {
21162088 emitSourceTextOfNode ( node . name ) ;
21172089 // If optional property emit ?
21182090 if ( node . kind === SyntaxKind . Property && ( node . flags & NodeFlags . QuestionMark ) ) {
@@ -2126,7 +2098,7 @@ module ts {
21262098 }
21272099
21282100 function emitVariableStatement ( node : VariableStatement ) {
2129- var hasDeclarationWithEmit = forEach ( node . declarations , varDeclaration => canEmitModuleElementDeclaration ( varDeclaration ) ) ;
2101+ var hasDeclarationWithEmit = forEach ( node . declarations , varDeclaration => resolver . isDeclarationVisible ( varDeclaration ) ) ;
21302102 if ( hasDeclarationWithEmit ) {
21312103 emitDeclarationFlags ( node ) ;
21322104 write ( "var " ) ;
@@ -2151,8 +2123,9 @@ module ts {
21512123 }
21522124
21532125 function emitFunctionDeclaration ( node : FunctionDeclaration ) {
2154- // If we are emitting Method/Constructor it isnt moduleElement and doesnt need canEmitModuleElement check
2155- if ( ( node . kind !== SyntaxKind . FunctionDeclaration || canEmitModuleElementDeclaration ( node ) ) &&
2126+ // If we are emitting Method/Constructor it isnt moduleElement and hence already determined to be emitting
2127+ // so no need to verify if the declaration is visible
2128+ if ( ( node . kind !== SyntaxKind . FunctionDeclaration || resolver . isDeclarationVisible ( node ) ) &&
21562129 ! resolver . isImplementationOfOverload ( node ) ) {
21572130 emitDeclarationFlags ( node ) ;
21582131 if ( node . kind === SyntaxKind . FunctionDeclaration ) {
0 commit comments