@@ -83,6 +83,7 @@ namespace ts {
83
83
let currentSourceFile : SourceFile ;
84
84
let refs : Map < SourceFile > ;
85
85
let libs : Map < boolean > ;
86
+ let emittedImports : readonly AnyImportSyntax [ ] | undefined ; // must be declared in container so it can be `undefined` while transformer's first pass
86
87
const resolver = context . getEmitResolver ( ) ;
87
88
const options = context . getCompilerOptions ( ) ;
88
89
const newLine = getNewLineCharacter ( options ) ;
@@ -279,7 +280,7 @@ namespace ts {
279
280
const statements = visitNodes ( node . statements , visitDeclarationStatements ) ;
280
281
let combinedStatements = setTextRange ( createNodeArray ( transformAndReplaceLatePaintedStatements ( statements ) ) , node . statements ) ;
281
282
refs . forEach ( referenceVisitor ) ;
282
- const emittedImports = filter ( combinedStatements , isAnyImportSyntax ) ;
283
+ emittedImports = filter ( combinedStatements , isAnyImportSyntax ) ;
283
284
if ( isExternalModule ( node ) && ( ! resultHasExternalModuleIndicator || ( needsScopeFixMarker && ! resultHasScopeMarker ) ) ) {
284
285
combinedStatements = setTextRange ( createNodeArray ( [ ...combinedStatements , createEmptyExports ( ) ] ) , combinedStatements ) ;
285
286
}
@@ -736,6 +737,12 @@ namespace ts {
736
737
}
737
738
const oldDiag = getSymbolAccessibilityDiagnostic ;
738
739
740
+ // Setup diagnostic-related flags before first potential `cleanup` call, otherwise
741
+ // We'd see a TDZ violation at runtime
742
+ const canProduceDiagnostic = canProduceDiagnostics ( input ) ;
743
+ const oldWithinObjectLiteralType = suppressNewDiagnosticContexts ;
744
+ let shouldEnterSuppressNewDiagnosticsContextContext = ( ( input . kind === SyntaxKind . TypeLiteral || input . kind === SyntaxKind . MappedType ) && input . parent . kind !== SyntaxKind . TypeAliasDeclaration ) ;
745
+
739
746
// Emit methods which are private as properties with no type information
740
747
if ( isMethodDeclaration ( input ) || isMethodSignature ( input ) ) {
741
748
if ( hasModifier ( input , ModifierFlags . Private ) ) {
@@ -744,17 +751,14 @@ namespace ts {
744
751
}
745
752
}
746
753
747
- const canProdiceDiagnostic = canProduceDiagnostics ( input ) ;
748
- if ( canProdiceDiagnostic && ! suppressNewDiagnosticContexts ) {
754
+ if ( canProduceDiagnostic && ! suppressNewDiagnosticContexts ) {
749
755
getSymbolAccessibilityDiagnostic = createGetSymbolAccessibilityDiagnosticForNode ( input as DeclarationDiagnosticProducing ) ;
750
756
}
751
757
752
758
if ( isTypeQueryNode ( input ) ) {
753
759
checkEntityNameVisibility ( input . exprName , enclosingDeclaration ) ;
754
760
}
755
761
756
- const oldWithinObjectLiteralType = suppressNewDiagnosticContexts ;
757
- let shouldEnterSuppressNewDiagnosticsContextContext = ( ( input . kind === SyntaxKind . TypeLiteral || input . kind === SyntaxKind . MappedType ) && input . parent . kind !== SyntaxKind . TypeAliasDeclaration ) ;
758
762
if ( shouldEnterSuppressNewDiagnosticsContextContext ) {
759
763
// We stop making new diagnostic contexts within object literal types. Unless it's an object type on the RHS of a type alias declaration. Then we do.
760
764
suppressNewDiagnosticContexts = true ;
@@ -909,13 +913,13 @@ namespace ts {
909
913
return cleanup ( visitEachChild ( input , visitDeclarationSubtree , context ) ) ;
910
914
911
915
function cleanup < T extends Node > ( returnValue : T | undefined ) : T | undefined {
912
- if ( returnValue && canProdiceDiagnostic && hasDynamicName ( input as Declaration ) ) {
916
+ if ( returnValue && canProduceDiagnostic && hasDynamicName ( input as Declaration ) ) {
913
917
checkName ( input as DeclarationDiagnosticProducing ) ;
914
918
}
915
919
if ( isEnclosingDeclaration ( input ) ) {
916
920
enclosingDeclaration = previousEnclosingDeclaration ;
917
921
}
918
- if ( canProdiceDiagnostic && ! suppressNewDiagnosticContexts ) {
922
+ if ( canProduceDiagnostic && ! suppressNewDiagnosticContexts ) {
919
923
getSymbolAccessibilityDiagnostic = oldDiag ;
920
924
}
921
925
if ( shouldEnterSuppressNewDiagnosticsContextContext ) {
0 commit comments