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]>
36 lines
883 B
JavaScript
36 lines
883 B
JavaScript
import * as babel from "@babel/core";
|
|
import vm from "vm";
|
|
import { fileURLToPath } from "url";
|
|
import path from "path";
|
|
|
|
import transformCommonJS from "../lib/index.js";
|
|
|
|
test("Re-export doesn't overwrite __esModule flag", function () {
|
|
let code = 'export * from "./dep";';
|
|
const depStub = {
|
|
__esModule: false,
|
|
};
|
|
|
|
const context = {
|
|
module: {
|
|
exports: {},
|
|
},
|
|
require: function (id) {
|
|
if (id === "./dep") return depStub;
|
|
throw new Error("Unexpected dependency: " + id);
|
|
},
|
|
};
|
|
context.exports = context.module.exports;
|
|
|
|
code = babel.transformSync(code, {
|
|
cwd: path.dirname(fileURLToPath(import.meta.url)),
|
|
plugins: [[transformCommonJS, { loose: true }]],
|
|
ast: false,
|
|
}).code;
|
|
|
|
vm.runInNewContext(code, context);
|
|
|
|
// exports.__esModule shouldn't be overwritten.
|
|
expect(context.exports.__esModule).toBe(true);
|
|
});
|