Skip to content

Commit

Permalink
fix(51072): ts.preProcessFile finds import in template string after c…
Browse files Browse the repository at this point in the history
…onditional expression with template strings (#51082)
  • Loading branch information
a-tarasyuk committed Oct 7, 2022
1 parent ad56b5c commit d0bfd8c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/services/preProcess.ts
Expand Up @@ -347,8 +347,8 @@ namespace ts {

if (scanner.getToken() === SyntaxKind.TemplateHead) {
const stack = [scanner.getToken()];
let token = scanner.scan();
loop: while (length(stack)) {
const token = scanner.scan();
switch (token) {
case SyntaxKind.EndOfFileToken:
break loop;
Expand Down Expand Up @@ -376,7 +376,6 @@ namespace ts {
}
break;
}
token = scanner.scan();
}
nextToken();
}
Expand Down
16 changes: 16 additions & 0 deletions src/testRunner/unittests/services/preProcessFile.ts
Expand Up @@ -205,6 +205,22 @@ describe("unittests:: services:: PreProcessFile:", () => {
/* eslint-enable no-template-curly-in-string */
});

it("Ignores imports in template strings", () => {
/* eslint-disable no-template-curly-in-string */
test("a ? `&${a}` : `#${b}`;\n\n `import(\"${moduleSpecifier}\").${id}`;",
/*readImportFile*/ true,
/*detectJavaScriptImports*/ true,
{
referencedFiles: [],
typeReferenceDirectives: [],
libReferenceDirectives: [],
importedFiles: [],
ambientExternalModules: undefined,
isLibFile: false
});
/* eslint-enable no-template-curly-in-string */
});

it("Correctly returns imports after a template expression", () => {
/* eslint-disable no-template-curly-in-string */
test("`${foo}`; import \"./foo\";",
Expand Down

0 comments on commit d0bfd8c

Please sign in to comment.