Skip to content

Commit d0bfd8c

Browse files
authored
fix(51072): ts.preProcessFile finds import in template string after conditional expression with template strings (#51082)
1 parent ad56b5c commit d0bfd8c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/services/preProcess.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ namespace ts {
347347

348348
if (scanner.getToken() === SyntaxKind.TemplateHead) {
349349
const stack = [scanner.getToken()];
350-
let token = scanner.scan();
351350
loop: while (length(stack)) {
351+
const token = scanner.scan();
352352
switch (token) {
353353
case SyntaxKind.EndOfFileToken:
354354
break loop;
@@ -376,7 +376,6 @@ namespace ts {
376376
}
377377
break;
378378
}
379-
token = scanner.scan();
380379
}
381380
nextToken();
382381
}

src/testRunner/unittests/services/preProcessFile.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,22 @@ describe("unittests:: services:: PreProcessFile:", () => {
205205
/* eslint-enable no-template-curly-in-string */
206206
});
207207

208+
it("Ignores imports in template strings", () => {
209+
/* eslint-disable no-template-curly-in-string */
210+
test("a ? `&${a}` : `#${b}`;\n\n `import(\"${moduleSpecifier}\").${id}`;",
211+
/*readImportFile*/ true,
212+
/*detectJavaScriptImports*/ true,
213+
{
214+
referencedFiles: [],
215+
typeReferenceDirectives: [],
216+
libReferenceDirectives: [],
217+
importedFiles: [],
218+
ambientExternalModules: undefined,
219+
isLibFile: false
220+
});
221+
/* eslint-enable no-template-curly-in-string */
222+
});
223+
208224
it("Correctly returns imports after a template expression", () => {
209225
/* eslint-disable no-template-curly-in-string */
210226
test("`${foo}`; import \"./foo\";",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy