Skip to content

Commit

Permalink
Fix polyfilling of X.prototype (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Mar 12, 2024
1 parent b3c3b86 commit 804d3d5
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
Expand Up @@ -30,19 +30,27 @@ export default (callProvider: CallProvider) => {
callProvider({ kind: "global", name }, path);
}

function analyzeMemberExpression(path: NodePath<t.MemberExpression>) {
const key = resolveKey(path.get("property"), path.node.computed);
return { key, handleAsMemberExpression: !!key && key !== "prototype" };
}

return {
// Symbol(), new Promise
ReferencedIdentifier(path: NodePath<t.Identifier>) {
if (path.parentPath.isMemberExpression({ object: path.node })) {
// Handled in the MemberExpression visitor
const { parentPath } = path;
if (
parentPath.isMemberExpression({ object: path.node }) &&
analyzeMemberExpression(parentPath).handleAsMemberExpression
) {
return;
}
handleReferencedIdentifier(path);
},

MemberExpression(path: NodePath<t.MemberExpression>) {
const key = resolveKey(path.get("property"), path.node.computed);
if (!key || key === "prototype") return;
const { key, handleAsMemberExpression } = analyzeMemberExpression(path);
if (!handleAsMemberExpression) return;

const object = path.get("object");
let objectIsGlobalIdentifier = object.isIdentifier();
Expand Down
@@ -0,0 +1 @@
Symbol.prototype;
@@ -0,0 +1,10 @@
{
"plugins": [
[
"@@/polyfill-corejs2",
{
"method": "usage-pure"
}
]
]
}
@@ -0,0 +1,2 @@
var _Symbol = require("core-js/library/fn/symbol/index.js");
_Symbol.prototype;
@@ -0,0 +1 @@
Symbol.prototype;
@@ -0,0 +1,10 @@
{
"plugins": [
[
"@@/polyfill-corejs3",
{
"method": "usage-pure"
}
]
]
}
@@ -0,0 +1,2 @@
var _Symbol = require("core-js-pure/stable/symbol/index.js");
_Symbol.prototype;

0 comments on commit 804d3d5

Please sign in to comment.