@@ -6139,14 +6139,11 @@ namespace ts {
6139
6139
}
6140
6140
6141
6141
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.
6146
6144
sourceFile . externalModuleIndicator =
6147
- ! ( sourceFile . flags & NodeFlags . PossiblyContainsImportMeta ) ?
6148
- forEach ( sourceFile . statements , isAnExternalModuleIndicatorNode ) :
6149
- walkTreeForExternalModuleIndicators ( sourceFile ) ;
6145
+ forEach ( sourceFile . statements , isAnExternalModuleIndicatorNode ) ||
6146
+ getImportMetaIfNecessary ( sourceFile ) ;
6150
6147
}
6151
6148
6152
6149
function isAnExternalModuleIndicatorNode ( node : Node ) {
@@ -6155,13 +6152,22 @@ namespace ts {
6155
6152
|| node . kind === SyntaxKind . ImportDeclaration
6156
6153
|| node . kind === SyntaxKind . ExportAssignment
6157
6154
|| node . kind === SyntaxKind . ExportDeclaration
6158
- || isMetaProperty ( node ) && node . keywordToken === SyntaxKind . ImportKeyword && node . name . escapedText === "meta"
6159
6155
? node
6160
6156
: undefined ;
6161
6157
}
6162
6158
6159
+ function getImportMetaIfNecessary ( sourceFile : SourceFile ) {
6160
+ return sourceFile . flags & NodeFlags . PossiblyContainsImportMeta ?
6161
+ walkTreeForExternalModuleIndicators ( sourceFile ) :
6162
+ undefined ;
6163
+ }
6164
+
6163
6165
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" ;
6165
6171
}
6166
6172
6167
6173
const enum ParsingContext {
0 commit comments