swc/crates/swc_estree_compat/tests/babelgen.js
Donny/강동윤 790a262c07
refactor(es/estree): Rename: babel => estree (#2846)
swc_babel_ast:
 - Rename as `swc_estree_ast`.

swc_babel_compat:
 - Rename as `swc_estree_compat`.

swc_babel_visit:
 - Rename as `swc_estree_visit`.
2021-11-24 05:34:41 +09:00

29 lines
819 B
JavaScript

// 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");
const plugins = ["classProperties", "classStaticBlocks"];
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));