Skip to content

Commit d0bfd8c

Browse files
authoredOct 7, 2022
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

+1-2
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

+16
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)