Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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