Skip to content

Commit

Permalink
fix(51072): skip imports in template strings
Browse files Browse the repository at this point in the history
  • Loading branch information
a-tarasyuk committed Oct 6, 2022
1 parent c18791c commit b8f479c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/services/preProcess.ts
Expand Up @@ -346,8 +346,8 @@ namespace ts {
}

if (scanner.getToken() === SyntaxKind.TemplateHead) {
const stack = [scanner.getToken()];
let token = scanner.scan();
let token = scanner.getToken();
const stack = [token];
loop: while (length(stack)) {
switch (token) {
case SyntaxKind.EndOfFileToken:
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 b8f479c

Please sign in to comment.