Skip to content

Commit

Permalink
Reference the CommonJS helpers when a file is not explicitly a module. (
Browse files Browse the repository at this point in the history
  • Loading branch information
loganfsmyth authored Aug 23, 2018
1 parent 22bcfbe commit 023044c
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 51 deletions.
6 changes: 5 additions & 1 deletion packages/babel-plugin-transform-runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ export default declare((api, options, dirname) => {
);
}

const helpersDir = useESModules ? "helpers/esm" : "helpers";
const injectCoreJS2 = `${corejsVersion}` === "2";
const moduleName = injectCoreJS2
? "@babel/runtime-corejs2"
Expand Down Expand Up @@ -145,6 +144,11 @@ export default declare((api, options, dirname) => {
const blockHoist =
isInteropHelper && !isModule(file.path) ? 4 : undefined;

const helpersDir =
useESModules && file.path.node.sourceType === "module"
? "helpers/esm"
: "helpers";

return this.addDefaultImport(
`${modulePath}/${helpersDir}/${name}`,
name,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import _classCallCheck from "@babel/runtime-corejs2/helpers/esm/classCallCheck";
import _possibleConstructorReturn from "@babel/runtime-corejs2/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime-corejs2/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime-corejs2/helpers/esm/inherits";

let Foo =
/*#__PURE__*/
function (_Bar) {
_inherits(Foo, _Bar);

function Foo() {
_classCallCheck(this, Foo);

return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments));
}

return Foo;
}(Bar);

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import _classCallCheck from "@babel/runtime-corejs2/helpers/classCallCheck";
import _possibleConstructorReturn from "@babel/runtime-corejs2/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime-corejs2/helpers/getPrototypeOf";
import _inherits from "@babel/runtime-corejs2/helpers/inherits";

let Foo =
/*#__PURE__*/
function (_Bar) {
_inherits(Foo, _Bar);

function Foo() {
_classCallCheck(this, Foo);

return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments));
}

return Foo;
}(Bar);
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var _classCallCheck = require("@babel/runtime/helpers/esm/classCallCheck");
var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");

var _possibleConstructorReturn = require("@babel/runtime/helpers/esm/possibleConstructorReturn");
var _possibleConstructorReturn = require("@babel/runtime/helpers/possibleConstructorReturn");

var _getPrototypeOf = require("@babel/runtime/helpers/esm/getPrototypeOf");
var _getPrototypeOf = require("@babel/runtime/helpers/getPrototypeOf");

var _inherits = require("@babel/runtime/helpers/esm/inherits");
var _inherits = require("@babel/runtime/helpers/inherits");

let Foo =
/*#__PURE__*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Foo extends Bar {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": [["transform-runtime", { "useESModules": true }], "transform-classes"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";

let Foo =
/*#__PURE__*/
function (_Bar) {
_inherits(Foo, _Bar);

function Foo() {
_classCallCheck(this, Foo);

return _possibleConstructorReturn(this, _getPrototypeOf(Foo).apply(this, arguments));
}

return Foo;
}(Bar);

0 comments on commit 023044c

Please sign in to comment.