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

ts.preProcessFile finds import in template string after conditional expression with template strings #51072

Closed
jakebailey opened this issue Oct 5, 2022 · 2 comments · Fixed by #51082
Labels
Bug A bug in TypeScript
Milestone

Comments

@jakebailey
Copy link
Member

Bug Report

🔎 Search Terms

preProcessFile template string conditional expression

🕗 Version & Regression Information

  • This is the behavior in every version I tried.

💻 Code

a ? `&${a}` : `#${b}`;

`import("${moduleSpecifier}").${id}`;

🙁 Actual behavior

{
  referencedFiles: [],
  typeReferenceDirectives: [],
  libReferenceDirectives: [],
  importedFiles: [ { fileName: '${moduleSpecifier}', pos: 32, end: 50 } ],
  isLibFile: false,
  ambientExternalModules: undefined
}

🙂 Expected behavior

{
  referencedFiles: [],
  typeReferenceDirectives: [],
  libReferenceDirectives: [],
  importedFiles: [],
  isLibFile: false,
  ambientExternalModules: undefined
}

This is somewhat similar to #47597 or #30878. I found this while fixing monaco for the module transform, which has a higher emit target that enables template strings. See: https://github.com/microsoft/TypeScript-Make-Monaco-Builds/actions/runs/3187364358/jobs/5198859864#step:7:343

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 5, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Oct 5, 2022
@a-tarasyuk
Copy link
Contributor

@jakebailey Do we need to skip this import or add it to importedFiles ? This issue #30878 is that preProcessFile didn't process imports after the template strings.

@jakebailey
Copy link
Member Author

Definitely skip; this is just text in a string, and the "filename" being found is not syntactically valid at all.

preProcessFile should behave exactly as though it has been implemented by running the full parser and then extracting the import expression nodes, but faster, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
3 participants