fix runtime plugin helper generation - fixes #2726
This commit is contained in:
parent
6ccee750e3
commit
41ccee89c9
@ -271,7 +271,8 @@ export default class File extends Store {
|
|||||||
let generator = this.get("helperGenerator");
|
let generator = this.get("helperGenerator");
|
||||||
let runtime = this.get("helpersNamespace");
|
let runtime = this.get("helpersNamespace");
|
||||||
if (generator) {
|
if (generator) {
|
||||||
return generator(name);
|
let res = generator(name);
|
||||||
|
if (res) return res;
|
||||||
} else if (runtime) {
|
} else if (runtime) {
|
||||||
let id = t.identifier(t.toIdentifier(name));
|
let id = t.identifier(t.toIdentifier(name));
|
||||||
return t.memberExpression(runtime, id);
|
return t.memberExpression(runtime, id);
|
||||||
|
|||||||
1
packages/babel-core/test/fixtures/transformation/runtime/class/actual.js
vendored
Normal file
1
packages/babel-core/test/fixtures/transformation/runtime/class/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
class Foo {}
|
||||||
5
packages/babel-core/test/fixtures/transformation/runtime/class/expected.js
vendored
Normal file
5
packages/babel-core/test/fixtures/transformation/runtime/class/expected.js
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import _classCallCheck from "babel-runtime/helpers/classCallCheck";
|
||||||
|
|
||||||
|
let Foo = function Foo() {
|
||||||
|
_classCallCheck(this, Foo);
|
||||||
|
};
|
||||||
3
packages/babel-core/test/fixtures/transformation/runtime/class/options.json
vendored
Normal file
3
packages/babel-core/test/fixtures/transformation/runtime/class/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-runtime", "transform-es2015-classes"]
|
||||||
|
}
|
||||||
2
packages/babel-core/test/fixtures/transformation/runtime/modules/actual.js
vendored
Normal file
2
packages/babel-core/test/fixtures/transformation/runtime/modules/actual.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import foo from "bar";
|
||||||
|
foo;
|
||||||
9
packages/babel-core/test/fixtures/transformation/runtime/modules/expected.js
vendored
Normal file
9
packages/babel-core/test/fixtures/transformation/runtime/modules/expected.js
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
var _bar = require("bar");
|
||||||
|
|
||||||
|
var _bar2 = _interopRequireDefault(_bar);
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
|
_bar2.default;
|
||||||
3
packages/babel-core/test/fixtures/transformation/runtime/modules/options.json
vendored
Normal file
3
packages/babel-core/test/fixtures/transformation/runtime/modules/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-runtime", "transform-es2015-modules-commonjs"]
|
||||||
|
}
|
||||||
@ -7,14 +7,18 @@ export default function ({ types: t }) {
|
|||||||
return Object.prototype.hasOwnProperty.call(obj, key);
|
return Object.prototype.hasOwnProperty.call(obj, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let HELPER_BLACKLIST = ["interopRequireWildcard", "interopRequireDefault"];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pre(file, state) {
|
pre(file) {
|
||||||
state.set("helperGenerator", function (name) {
|
file.set("helperGenerator", function (name) {
|
||||||
return state.addImport(`${RUNTIME_MODULE_NAME}/helpers/${name}`, "default", name);
|
if (HELPER_BLACKLIST.indexOf(name) < 0) {
|
||||||
|
return file.addImport(`${RUNTIME_MODULE_NAME}/helpers/${name}`, "default", name);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
state.setDynamic("regeneratorIdentifier", function () {
|
this.setDynamic("regeneratorIdentifier", function () {
|
||||||
return state.addImport(`${RUNTIME_MODULE_NAME}/regenerator`, "default", "regeneratorRuntime");
|
return file.addImport(`${RUNTIME_MODULE_NAME}/regenerator`, "default", "regeneratorRuntime");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user