Revert "make babel injectable in babel-register" (#7298)
Revert "make babel injectable in babel-register"
This commit is contained in:
commit
1ebc229fa5
@ -68,10 +68,7 @@ require("@babel/register")({
|
||||
extensions: [".es6", ".es", ".jsx", ".js", ".mjs"],
|
||||
|
||||
// Setting this to false will disable the cache.
|
||||
cache: true,
|
||||
|
||||
// Specify the version of babel-core used for transformation. (Optional)
|
||||
babel: require('@babel/core')
|
||||
cache: true
|
||||
});
|
||||
```
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import deepClone from "lodash/cloneDeep";
|
||||
import sourceMapSupport from "source-map-support";
|
||||
import * as registerCache from "./cache";
|
||||
import escapeRegExp from "lodash/escapeRegExp";
|
||||
import * as babelCore from "@babel/core";
|
||||
import * as babel from "@babel/core";
|
||||
import { OptionManager, DEFAULT_EXTENSIONS } from "@babel/core";
|
||||
import { addHook } from "pirates";
|
||||
import fs from "fs";
|
||||
@ -10,7 +10,6 @@ import path from "path";
|
||||
|
||||
const maps = {};
|
||||
const transformOpts = {};
|
||||
let babel = null;
|
||||
let piratesRevert = null;
|
||||
|
||||
function installSourceMapSupport() {
|
||||
@ -101,9 +100,6 @@ register({
|
||||
export default function register(opts?: Object = {}) {
|
||||
// Clone to avoid mutating the arguments object with the 'delete's below.
|
||||
opts = Object.assign({}, opts);
|
||||
|
||||
babel = opts.babel ? opts.babel : babelCore;
|
||||
|
||||
if (opts.extensions) hookExtensions(opts.extensions);
|
||||
|
||||
if (opts.cache === false && cache) {
|
||||
@ -114,7 +110,6 @@ export default function register(opts?: Object = {}) {
|
||||
cache = registerCache.get();
|
||||
}
|
||||
|
||||
delete opts.babel;
|
||||
delete opts.extensions;
|
||||
delete opts.cache;
|
||||
|
||||
|
||||
@ -103,36 +103,4 @@ describe("@babel/register", function() {
|
||||
chai.expect((gen_error = require(GEN_ERROR))).to.be.ok;
|
||||
chai.expect(gen_error()).to.match(/gen_error\.js:2:86/);
|
||||
});
|
||||
|
||||
it("uses custom babel when requested", () => {
|
||||
setupRegister({
|
||||
babel: {
|
||||
transform() {
|
||||
return { code: "module.exports = 'hello';" };
|
||||
},
|
||||
getEnv() {
|
||||
return {};
|
||||
},
|
||||
version: "custom",
|
||||
},
|
||||
});
|
||||
|
||||
chai.expect(require(DATA_ES2015)).to.equal("hello");
|
||||
});
|
||||
|
||||
it("resets babel on subsequent register calls", () => {
|
||||
function crash() {
|
||||
throw new Error("shouldn't be called");
|
||||
}
|
||||
|
||||
setupRegister({
|
||||
babel: {
|
||||
transform: crash,
|
||||
getEnv: crash,
|
||||
},
|
||||
});
|
||||
setupRegister();
|
||||
|
||||
chai.expect(require(DATA_ES2015)).to.be.ok;
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user