Skip to content

Commit

Permalink
Namespace objects should now be polyfilled
Browse files Browse the repository at this point in the history
This is a port of babel/babel#10372
  • Loading branch information
thiagoarrais authored and nicolo-ribaudo committed Sep 18, 2019
1 parent 54abf7a commit 849ea58
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/babel-plugin-inject-polyfills/src/index.js
Expand Up @@ -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);
},

Expand Down
30 changes: 30 additions & 0 deletions packages/babel-plugin-inject-polyfills/test/methods.js
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 849ea58

Please sign in to comment.