💻
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
import type { } from 'some-module';
Configuration file name
No response
Configuration
No configuration file
Current and expected behavior
Using this code:
const { parseAsync } = require("@babel/core");
const generate = require("@babel/generator").default;
async function main() {
const parsed = await parseAsync('import type {} from "some-module";', {
filename: "main.ts",
presets: [require.resolve("@babel/preset-typescript")],
plugins: [],
});
console.log(
generate(parsed, {sourceMaps: false}).code
);
}
main().catch(console.error);
Results in: import type "some-module";
Which is invalid typescript.
Environment
Possible solution
I've noticed that the AST for:
import type {} from "some-module";
And
import type "some-module";
is the exact same. See https://astexplorer.net/#/gist/3a6d7dc99689e175f667747004a015f4/2c079662c137fb0f3af1be0f7c04920a9d6a199a
I see 3 solutions:
- Output generate code for the AST as
import type {} from "some-module";
- Add AST properties so we know the difference between the 2
- Add support for
import type "some-module"; to typescript (and flow script?)
Additional context
This got reported in StrykerJS: stryker-mutator/stryker-js#3386
We're using babel to parse and output files as is, after which tsc might need to run.
💻
How are you using Babel?
Programmatic API (
babel.transform,babel.parse)Input code
Configuration file name
No response
Configuration
No configuration file
Current and expected behavior
Using this code:
Results in:
import type "some-module";Which is invalid typescript.
Environment
7.16.12Possible solution
I've noticed that the AST for:
And
is the exact same. See https://astexplorer.net/#/gist/3a6d7dc99689e175f667747004a015f4/2c079662c137fb0f3af1be0f7c04920a9d6a199a
I see 3 solutions:
import type {} from "some-module";import type "some-module";to typescript (and flow script?)Additional context
This got reported in StrykerJS: stryker-mutator/stryker-js#3386
We're using babel to parse and output files as is, after which
tscmight need to run.