Skip to content

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

@jakebailey

Description

@jakebailey

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions