diff --git a/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts b/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts index e711622c..4e5d3a89 100644 --- a/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts +++ b/packages/babel-helper-define-polyfill-provider/src/visitors/usage.ts @@ -30,19 +30,27 @@ export default (callProvider: CallProvider) => { callProvider({ kind: "global", name }, path); } + function analyzeMemberExpression(path: NodePath) { + const key = resolveKey(path.get("property"), path.node.computed); + return { key, handleAsMemberExpression: !!key && key !== "prototype" }; + } + return { // Symbol(), new Promise ReferencedIdentifier(path: NodePath) { - 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) { - 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(); diff --git a/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/input.js b/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/input.js new file mode 100644 index 00000000..86622cf6 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/input.js @@ -0,0 +1 @@ +Symbol.prototype; diff --git a/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/options.json b/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/options.json new file mode 100644 index 00000000..ab5e1c0d --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/options.json @@ -0,0 +1,10 @@ +{ + "plugins": [ + [ + "@@/polyfill-corejs2", + { + "method": "usage-pure" + } + ] + ] +} diff --git a/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/output.js b/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/output.js new file mode 100644 index 00000000..ff60e84a --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs2/test/fixtures/usage-pure/symbol-prototype/output.js @@ -0,0 +1,2 @@ +var _Symbol = require("core-js/library/fn/symbol/index.js"); +_Symbol.prototype; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/input.js b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/input.js new file mode 100644 index 00000000..86622cf6 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/input.js @@ -0,0 +1 @@ +Symbol.prototype; diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/options.json b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/options.json new file mode 100644 index 00000000..75fbdc27 --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/options.json @@ -0,0 +1,10 @@ +{ + "plugins": [ + [ + "@@/polyfill-corejs3", + { + "method": "usage-pure" + } + ] + ] +} \ No newline at end of file diff --git a/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/output.js b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/output.js new file mode 100644 index 00000000..67ae890b --- /dev/null +++ b/packages/babel-plugin-polyfill-corejs3/test/fixtures/usage-pure/symbol-prototype/output.js @@ -0,0 +1,2 @@ +var _Symbol = require("core-js-pure/stable/symbol/index.js"); +_Symbol.prototype;