New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Import the correct ./typeof.js
helper in @babel/runtime
#14081
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"`) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are injected imports for other helpers, wouldn't we want to transform them too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes they should. Not related to this PR: I realized that the generated helper will target to browserlists's default in Babel 8 since we didn't supply a target in the |
||
* // 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`; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the question?