mirror of
https://github.com/hanzoai/babel.git
synced 2026-09-24 16:56:45 +00:00
* [babel 8] Disallow synchronous usage of `babel.{parse,transform{,FromAst,File}}`
Disallow babel.transformFromAst synchronously
Disallow using babel.transform, babel.transformFile, babel.parse synchronously
chore: throw error behind BABEL_8_BREAKING flag
fix: use transformFromAstSync
fix: use transformSync
refactor: use Babel.transformSync in standalone
fix: use parseSync
feat: emit deprecation message on callback-less usage
chore: add tests on thrown error
call sync method on undefined callback
review comments
address review comments
chore: use loadOptionsSync for OptionManager
Co-authored-by: Huáng Jùnliàng <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
* Comment out warning for now
Co-authored-by: Pranav <[email protected]>
Co-authored-by: Nicolò Ribaudo <[email protected]>
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import fs from "fs";
|
|
import path from "path";
|
|
import { parseSync } from "../lib/index.js";
|
|
import { fileURLToPath } from "url";
|
|
import { createRequire } from "module";
|
|
|
|
const require = createRequire(import.meta.url);
|
|
|
|
function fixture(...args) {
|
|
return path.join(
|
|
path.dirname(fileURLToPath(import.meta.url)),
|
|
"fixtures",
|
|
"parse",
|
|
...args,
|
|
);
|
|
}
|
|
|
|
describe("parseSync", function () {
|
|
it("should parse using configuration from .babelrc when a filename is provided", function () {
|
|
const input = fs.readFileSync(fixture("input.js"), "utf8");
|
|
const output = require(fixture("output"));
|
|
|
|
const result = parseSync(input, {
|
|
filename: fixture("input.js"),
|
|
cwd: fixture(),
|
|
});
|
|
expect(JSON.parse(JSON.stringify(result))).toEqual(output);
|
|
});
|
|
|
|
it("should parse using passed in configuration", function () {
|
|
const input = fs.readFileSync(fixture("input.js"), "utf8");
|
|
const output = require(fixture("output.json"));
|
|
|
|
const result = parseSync(input, {
|
|
parserOpts: {
|
|
plugins: [["decorators", { decoratorsBeforeExport: false }]],
|
|
},
|
|
cwd: fixture(),
|
|
});
|
|
expect(JSON.parse(JSON.stringify(result))).toEqual(output);
|
|
});
|
|
});
|