2021-05-01 12:09:10 +03:00
|
|
|
// Helper for generating Babel fixture JSON.
|
|
|
|
// USAGE: node babelgen.js path/to/input.js > path/to/output.json
|
|
|
|
const {readFileSync} = require("fs");
|
|
|
|
const {parse} = require("@babel/parser");
|
|
|
|
|
|
|
|
const inputFile = process.argv[2];
|
|
|
|
if (!inputFile) {
|
|
|
|
console.error("Missing input file. Hint: `node babelgen.js path/to/input.js`");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const code = readFileSync(inputFile, "utf8");
|
|
|
|
|
2021-10-22 07:32:34 +03:00
|
|
|
const plugins = ["classProperties", "classStaticBlocks"];
|
2021-05-01 12:09:10 +03:00
|
|
|
if (inputFile && inputFile.endsWith(".jsx")) {
|
|
|
|
plugins.push("jsx");
|
|
|
|
}
|
|
|
|
if (inputFile && inputFile.endsWith(".ts")) {
|
|
|
|
plugins.push("typescript");
|
|
|
|
}
|
|
|
|
|
|
|
|
const babelAst = parse(code, {
|
|
|
|
plugins,
|
|
|
|
sourceType: inputFile.endsWith(".mjs") ? "module" : undefined,
|
|
|
|
// allowImportExportEverywhere: true,
|
|
|
|
});
|
|
|
|
console.log(JSON.stringify(babelAst, null, 4));
|
|
|
|
|