Files
940b15aa3c [babel 8] Disallow synchronous usage of babel.* callback methods (#12695)
* [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]>
2022-06-05 21:26:11 +02:00

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);
});