Skip to content

Commit

Permalink
Import the correct ./typeof.js helper in @babel/runtime (#14081)
Browse files Browse the repository at this point in the history
  • Loading branch information
exb committed Dec 30, 2021
1 parent 2810dc6 commit f69f1a8
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -28,27 +28,33 @@ package-lock.json
/packages/babel-runtime/helpers/*.js
!/packages/babel-runtime/helpers/toArray.js
!/packages/babel-runtime/helpers/iterableToArray.js
!/packages/babel-runtime/helpers/possibleConstructorReturn.js
!/packages/babel-runtime/helpers/temporalRef.js
!/packages/babel-runtime/helpers/typeof.js
/packages/babel-runtime/helpers/esm/*.js
!/packages/babel-runtime/helpers/esm/toArray.js
!/packages/babel-runtime/helpers/esm/iterableToArray.js
!/packages/babel-runtime/helpers/esm/possibleConstructorReturn.js
!/packages/babel-runtime/helpers/esm/temporalRef.js

/packages/babel-runtime-corejs2/helpers/*.js
!/packages/babel-runtime-corejs2/helpers/toArray.js
!/packages/babel-runtime-corejs2/helpers/iterableToArray.js
!/packages/babel-runtime-corejs2/helpers/possibleConstructorReturn.js
!/packages/babel-runtime-corejs2/helpers/temporalRef.js
!/packages/babel-runtime-corejs2/helpers/typeof.js
/packages/babel-runtime-corejs2/helpers/esm/*.js
!/packages/babel-runtime-corejs2/helpers/esm/toArray.js
!/packages/babel-runtime-corejs2/helpers/esm/iterableToArray.js
!/packages/babel-runtime-corejs2/helpers/esm/possibleConstructorReturn.js
!/packages/babel-runtime-corejs2/helpers/esm/temporalRef.js
/packages/babel-runtime-corejs2/core-js/**/*.js
!/packages/babel-runtime-corejs2/core-js/map.js

/packages/babel-runtime-corejs3/helpers/*.js
!/packages/babel-runtime-corejs3/helpers/possibleConstructorReturn.js
/packages/babel-runtime-corejs3/helpers/esm/*.js
!/packages/babel-runtime-corejs3/helpers/esm/possibleConstructorReturn.js
/packages/babel-runtime-corejs3/core-js/**/*.js
/packages/babel-runtime-corejs3/core-js-stable/**/*.js

Expand Down
18 changes: 13 additions & 5 deletions packages/babel-plugin-transform-runtime/scripts/build-dist.js
Expand Up @@ -259,15 +259,23 @@ function buildHelper(

function buildRuntimeRewritePlugin(runtimeName, helperName) {
/**
* rewrite helpers imports to runtime imports
* Rewrite helper imports to load the adequate module format version
* @example
* adjustImportPath(ast`"setPrototypeOf"`)
* // returns ast`"@babel/runtime/helpers/esm/setPrototypeOf"`
* @param {*} node The string literal contains import path
* // returns ast`"./setPrototypeOf"`
* @example
* adjustImportPath(ast`"@babel/runtime/helpers/typeof"`)
* // returns ast`"./typeof"`
* @param {*} node The string literal that contains the import path
*/
function adjustImportPath(node) {
if (helpers.list.includes(node.value)) {
node.value = `./${node.value}.js`;
const helpersPath = path.join(runtimeName, "helpers");
const helper = node.value.startsWith(helpersPath)
? path.basename(node.value)
: node.value;

if (helpers.list.includes(helper)) {
node.value = `./${helper}.js`;
}
}

Expand Down
@@ -0,0 +1,11 @@
import _typeof from "./typeof.js";
import assertThisInitialized from "./assertThisInitialized.js";
export default function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

return assertThisInitialized(self);
}
@@ -0,0 +1,15 @@
var _typeof = require("./typeof.js")["default"];

var assertThisInitialized = require("./assertThisInitialized.js");

function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

return assertThisInitialized(self);
}

module.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports["default"] = module.exports;
@@ -0,0 +1,11 @@
import _typeof from "./typeof.js";
import assertThisInitialized from "./assertThisInitialized.js";
export default function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

return assertThisInitialized(self);
}
@@ -0,0 +1,15 @@
var _typeof = require("./typeof.js")["default"];

var assertThisInitialized = require("./assertThisInitialized.js");

function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

return assertThisInitialized(self);
}

module.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports["default"] = module.exports;
11 changes: 11 additions & 0 deletions packages/babel-runtime/helpers/esm/possibleConstructorReturn.js
@@ -0,0 +1,11 @@
import _typeof from "./typeof.js";
import assertThisInitialized from "./assertThisInitialized.js";
export default function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

return assertThisInitialized(self);
}
15 changes: 15 additions & 0 deletions packages/babel-runtime/helpers/possibleConstructorReturn.js
@@ -0,0 +1,15 @@
var _typeof = require("./typeof.js")["default"];

var assertThisInitialized = require("./assertThisInitialized.js");

function _possibleConstructorReturn(self, call) {
if (call && (_typeof(call) === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}

return assertThisInitialized(self);
}

module.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports["default"] = module.exports;

0 comments on commit f69f1a8

Please sign in to comment.