-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
APIRelates to the public API for TypeScriptRelates to the public API for TypeScriptBugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
TypeScript Version: 3.5.0-dev.20190411
Search Terms:
preProcessFile import
Code
const ts = require('typescript');
const output = ts.preProcessFile("`${foo}`; import './test';", true, true);
console.log(output.importedFiles);
Expected behavior:
./test
should be listed in importedFiles
as an entry to the array.
Actual behavior:
It doesn't. The array is empty.
Reversing the order works though.
const ts = require('typescript');
const output = ts.preProcessFile("import './test'; `${foo}`;", true, true);
console.log(output.importedFiles);
Note this also happens on dynamic imports too.
const ts = require("typescript");
const output = ts.preProcessFile("`${foo}`; import('./test');", true, true);
console.log(output.importedFiles);
Note that these repros are short for reproducability reasons. Yes, not doing static importing at the top is silly, but I found that from my use case of something similar to this:
const foo = `${someVariable}.${someOtherVariable}`;
import('./foo').then(m => m.callFunction());
You can drill down to having the issue also reproducible with static imports and dynamic imports with promise chaining or async
, so anything import statement related?
Playground Link:
Replicated in CodeSandbox: https://codesandbox.io/embed/5zqln3nn5n.
Related Issues: None (?)
WearyMonkey, vkatushenok, joscha, samcooke98, alextreppass and 11 more
Metadata
Metadata
Assignees
Labels
APIRelates to the public API for TypeScriptRelates to the public API for TypeScriptBugA bug in TypeScriptA bug in TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issue