diff --git a/packages/babel-plugin-inject-polyfills/src/index.js b/packages/babel-plugin-inject-polyfills/src/index.js index 3ab900ff..180f61e2 100644 --- a/packages/babel-plugin-inject-polyfills/src/index.js +++ b/packages/babel-plugin-inject-polyfills/src/index.js @@ -201,7 +201,11 @@ export default declare((api, options: Options, dirname: string) => { const key = resolveKey(path.get("property"), path.node.computed); if (!key || key === "prototype") return; - const source = resolveSource(path.get("object")); + const object = path.get("object"); + const binding = object.scope.getBinding(object.node.name); + if (binding && binding.path.isImportNamespaceSpecifier()) return; + + const source = resolveSource(object); return property(source.id, key, source.placement, path); }, diff --git a/packages/babel-plugin-inject-polyfills/test/methods.js b/packages/babel-plugin-inject-polyfills/test/methods.js index 1d20a31b..868f67e9 100644 --- a/packages/babel-plugin-inject-polyfills/test/methods.js +++ b/packages/babel-plugin-inject-polyfills/test/methods.js @@ -163,6 +163,21 @@ describe("usage-global", () => { ); }); + it("ignores namespaces", () => { + const usageGlobal = jest.fn(); + + const source = ` + import * as bar from "bar"; + bar.map();`; + + transform(source, { + method: "usage-global", + providers: [provider({ usageGlobal })], + }); + + expect(usageGlobal).not.toHaveBeenCalled(); + }); + it("destructuring", () => { const usageGlobal = jest.fn(); @@ -269,6 +284,21 @@ describe("usage-pure", () => { ); }); + it("ignores namespaces", () => { + const usagePure = jest.fn(); + + const source = ` + import * as bar from "bar"; + bar.map();`; + + transform(source, { + method: "usage-pure", + providers: [provider({ usagePure })], + }); + + expect(usagePure).not.toHaveBeenCalled(); + }); + it("destructuring", () => { const usagePure = jest.fn();