@@ -1898,34 +1898,6 @@ module ts {
1898
1898
writeLine ( ) ;
1899
1899
}
1900
1900
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
-
1929
1901
function emitDeclarationFlags ( node : Declaration ) {
1930
1902
if ( node . flags & NodeFlags . Static ) {
1931
1903
if ( node . flags & NodeFlags . Private ) {
@@ -1952,8 +1924,7 @@ module ts {
1952
1924
}
1953
1925
1954
1926
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 ) ) {
1957
1928
if ( node . flags & NodeFlags . Export ) {
1958
1929
write ( "export " ) ;
1959
1930
}
@@ -1974,7 +1945,7 @@ module ts {
1974
1945
}
1975
1946
1976
1947
function emitModuleDeclaration ( node : ModuleDeclaration ) {
1977
- if ( canEmitModuleElementDeclaration ( node ) ) {
1948
+ if ( resolver . isDeclarationVisible ( node ) ) {
1978
1949
emitDeclarationFlags ( node ) ;
1979
1950
write ( "module " ) ;
1980
1951
emitSourceTextOfNode ( node . name ) ;
@@ -1997,7 +1968,7 @@ module ts {
1997
1968
}
1998
1969
1999
1970
function emitEnumDeclaration ( node : EnumDeclaration ) {
2000
- if ( canEmitModuleElementDeclaration ( node ) ) {
1971
+ if ( resolver . isDeclarationVisible ( node ) ) {
2001
1972
emitDeclarationFlags ( node ) ;
2002
1973
write ( "enum " ) ;
2003
1974
emitSourceTextOfNode ( node . name ) ;
@@ -2060,7 +2031,7 @@ module ts {
2060
2031
}
2061
2032
}
2062
2033
2063
- if ( canEmitModuleElementDeclaration ( node ) ) {
2034
+ if ( resolver . isDeclarationVisible ( node ) ) {
2064
2035
emitDeclarationFlags ( node ) ;
2065
2036
write ( "class " ) ;
2066
2037
emitSourceTextOfNode ( node . name ) ;
@@ -2084,7 +2055,7 @@ module ts {
2084
2055
}
2085
2056
2086
2057
function emitInterfaceDeclaration ( node : InterfaceDeclaration ) {
2087
- if ( canEmitModuleElementDeclaration ( node ) ) {
2058
+ if ( resolver . isDeclarationVisible ( node ) ) {
2088
2059
emitDeclarationFlags ( node ) ;
2089
2060
write ( "interface " ) ;
2090
2061
emitSourceTextOfNode ( node . name ) ;
@@ -2111,8 +2082,9 @@ module ts {
2111
2082
}
2112
2083
2113
2084
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 ) ) {
2116
2088
emitSourceTextOfNode ( node . name ) ;
2117
2089
// If optional property emit ?
2118
2090
if ( node . kind === SyntaxKind . Property && ( node . flags & NodeFlags . QuestionMark ) ) {
@@ -2126,7 +2098,7 @@ module ts {
2126
2098
}
2127
2099
2128
2100
function emitVariableStatement ( node : VariableStatement ) {
2129
- var hasDeclarationWithEmit = forEach ( node . declarations , varDeclaration => canEmitModuleElementDeclaration ( varDeclaration ) ) ;
2101
+ var hasDeclarationWithEmit = forEach ( node . declarations , varDeclaration => resolver . isDeclarationVisible ( varDeclaration ) ) ;
2130
2102
if ( hasDeclarationWithEmit ) {
2131
2103
emitDeclarationFlags ( node ) ;
2132
2104
write ( "var " ) ;
@@ -2151,8 +2123,9 @@ module ts {
2151
2123
}
2152
2124
2153
2125
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 ) ) &&
2156
2129
! resolver . isImplementationOfOverload ( node ) ) {
2157
2130
emitDeclarationFlags ( node ) ;
2158
2131
if ( node . kind === SyntaxKind . FunctionDeclaration ) {
0 commit comments