@@ -6139,14 +6139,11 @@ namespace ts {
61396139 }
61406140
61416141 function setExternalModuleIndicator ( sourceFile : SourceFile ) {
6142- // Usually we'd like to avoid a full tree walk, but it's possible
6143- // that we have a deeper external module indicator (e.g. `import.meta`,
6144- // and possibly nested import statements in the future).
6145- // Ideally the first few statements will be an import/export anyway.
6142+ // Try to use the first top-level import/export when available, then
6143+ // fall back to looking for an 'import.meta' somewhere in the tree if necessary.
61466144 sourceFile . externalModuleIndicator =
6147- ! ( sourceFile . flags & NodeFlags . PossiblyContainsImportMeta ) ?
6148- forEach ( sourceFile . statements , isAnExternalModuleIndicatorNode ) :
6149- walkTreeForExternalModuleIndicators ( sourceFile ) ;
6145+ forEach ( sourceFile . statements , isAnExternalModuleIndicatorNode ) ||
6146+ getImportMetaIfNecessary ( sourceFile ) ;
61506147 }
61516148
61526149 function isAnExternalModuleIndicatorNode ( node : Node ) {
@@ -6155,13 +6152,22 @@ namespace ts {
61556152 || node . kind === SyntaxKind . ImportDeclaration
61566153 || node . kind === SyntaxKind . ExportAssignment
61576154 || node . kind === SyntaxKind . ExportDeclaration
6158- || isMetaProperty ( node ) && node . keywordToken === SyntaxKind . ImportKeyword && node . name . escapedText === "meta"
61596155 ? node
61606156 : undefined ;
61616157 }
61626158
6159+ function getImportMetaIfNecessary ( sourceFile : SourceFile ) {
6160+ return sourceFile . flags & NodeFlags . PossiblyContainsImportMeta ?
6161+ walkTreeForExternalModuleIndicators ( sourceFile ) :
6162+ undefined ;
6163+ }
6164+
61636165 function walkTreeForExternalModuleIndicators ( node : Node ) : Node {
6164- return isAnExternalModuleIndicatorNode ( node ) ? node : forEachChild ( node , walkTreeForExternalModuleIndicators ) ;
6166+ return isImportMeta ( node ) ? node : forEachChild ( node , walkTreeForExternalModuleIndicators ) ;
6167+ }
6168+
6169+ function isImportMeta ( node : Node ) : boolean {
6170+ return isMetaProperty ( node ) && node . keywordToken === SyntaxKind . ImportKeyword && node . name . escapedText === "meta" ;
61656171 }
61666172
61676173 const enum ParsingContext {
0 commit comments