fix(51072): ts.preProcessFile finds import in template string after conditional expression with template strings (#51082)

This commit is contained in:
Oleksandr T 2022-10-07 20:33:20 +03:00 committed by GitHub
parent ad56b5ca56
commit d0bfd8caed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -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;
@ -376,7 +376,6 @@ namespace ts {
}
break;
}
token = scanner.scan();
}
nextToken();
}

View File

@ -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\";",