Skip to content

Commit

Permalink
Don't allow instance properties transformation on namespace for `usag…
Browse files Browse the repository at this point in the history
…e` plugin
  • Loading branch information
rhyzx committed Sep 1, 2019
1 parent 7b441bb commit f4f1e4c
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 2 deletions.
Expand Up @@ -15,6 +15,7 @@ import {
isPolyfillSource,
getImportSource,
getRequireSource,
isNamespaced,
} from "../../utils";
import { logUsagePolyfills } from "../../debug";

Expand Down Expand Up @@ -102,6 +103,9 @@ export default function(
const { node } = path;
const { object, property } = node;

// ignore namespace
if (isNamespaced(path.get("object"))) return;

let evaluatedPropType = object.name;
let propertyName = property.name;
let instanceType = "";
Expand Down
Expand Up @@ -21,6 +21,7 @@ import {
isPolyfillSource,
getImportSource,
getRequireSource,
isNamespaced,
} from "../../utils";
import { logUsagePolyfills } from "../../debug";

Expand Down Expand Up @@ -98,7 +99,7 @@ export default function(
}
}
}
return { builtIn, instanceType };
return { builtIn, instanceType, isNamespaced: isNamespaced(path) };
}

const addAndRemovePolyfillImports = {
Expand Down Expand Up @@ -230,7 +231,8 @@ export default function(
};

this.addPropertyDependencies = function(source = {}, key) {
const { builtIn, instanceType } = source;
const { builtIn, instanceType, isNamespaced } = source;
if (isNamespaced) return;
if (PossibleGlobalObjects.has(builtIn)) {
this.addBuiltInDependencies(key);
} else if (has(StaticProperties, builtIn)) {
Expand Down
6 changes: 6 additions & 0 deletions packages/babel-preset-env/src/utils.js
Expand Up @@ -162,3 +162,9 @@ export function getModulePath(mod: string): string {
export function createImport(path: NodePath, mod: string) {
return addSideEffect(path, getModulePath(mod));
}

export function isNamespaced(path: NodePath) {
const binding = path.scope.getBinding(path.node.name);
if (!binding) return false;
return binding.path.isImportNamespaceSpecifier();
}
@@ -0,0 +1,2 @@
import * as ns from "ns";
ns.map;
@@ -0,0 +1,12 @@
{
"presets": [
[
"../../../../lib",
{
"modules": false,
"useBuiltIns": "usage",
"corejs": 2
}
]
]
}
@@ -0,0 +1,3 @@
import * as ns from "ns";
ns.map;

@@ -0,0 +1,2 @@
import * as ns from "ns";
ns.map;
@@ -0,0 +1,12 @@
{
"presets": [
[
"../../../../lib",
{
"modules": false,
"useBuiltIns": "usage",
"corejs": 3
}
]
]
}
@@ -0,0 +1,2 @@
import * as ns from "ns";
ns.map;

0 comments on commit f4f1e4c

Please sign in to comment.