Don't allow instance properties transformation on namespace (#10372)
This commit is contained in:
parent
6813ee02d7
commit
29734b924a
@ -113,7 +113,14 @@ export default declare((api, options, dirname) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isNamespaced(path) {
|
||||||
|
const binding = path.scope.getBinding(path.node.name);
|
||||||
|
if (!binding) return false;
|
||||||
|
return binding.path.isImportNamespaceSpecifier();
|
||||||
|
}
|
||||||
|
|
||||||
function maybeNeedsPolyfill(path, methods, name) {
|
function maybeNeedsPolyfill(path, methods, name) {
|
||||||
|
if (isNamespaced(path.get("object"))) return false;
|
||||||
if (!methods[name].types) return true;
|
if (!methods[name].types) return true;
|
||||||
|
|
||||||
const typeAnnotation = path.get("object").getTypeAnnotation();
|
const typeAnnotation = path.get("object").getTypeAnnotation();
|
||||||
|
|||||||
@ -0,0 +1,2 @@
|
|||||||
|
import * as bar from "bar";
|
||||||
|
bar.map();
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"plugins": [["transform-runtime", { "corejs": 3 }]]
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
import * as bar from "bar";
|
||||||
|
bar.map();
|
||||||
@ -15,6 +15,7 @@ import {
|
|||||||
isPolyfillSource,
|
isPolyfillSource,
|
||||||
getImportSource,
|
getImportSource,
|
||||||
getRequireSource,
|
getRequireSource,
|
||||||
|
isNamespaced,
|
||||||
} from "../../utils";
|
} from "../../utils";
|
||||||
import { logUsagePolyfills } from "../../debug";
|
import { logUsagePolyfills } from "../../debug";
|
||||||
|
|
||||||
@ -102,6 +103,9 @@ export default function(
|
|||||||
const { node } = path;
|
const { node } = path;
|
||||||
const { object, property } = node;
|
const { object, property } = node;
|
||||||
|
|
||||||
|
// ignore namespace
|
||||||
|
if (isNamespaced(path.get("object"))) return;
|
||||||
|
|
||||||
let evaluatedPropType = object.name;
|
let evaluatedPropType = object.name;
|
||||||
let propertyName = property.name;
|
let propertyName = property.name;
|
||||||
let instanceType = "";
|
let instanceType = "";
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import {
|
|||||||
isPolyfillSource,
|
isPolyfillSource,
|
||||||
getImportSource,
|
getImportSource,
|
||||||
getRequireSource,
|
getRequireSource,
|
||||||
|
isNamespaced,
|
||||||
} from "../../utils";
|
} from "../../utils";
|
||||||
import { logUsagePolyfills } from "../../debug";
|
import { logUsagePolyfills } from "../../debug";
|
||||||
|
|
||||||
@ -98,7 +99,7 @@ export default function(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return { builtIn, instanceType };
|
return { builtIn, instanceType, isNamespaced: isNamespaced(path) };
|
||||||
}
|
}
|
||||||
|
|
||||||
const addAndRemovePolyfillImports = {
|
const addAndRemovePolyfillImports = {
|
||||||
@ -230,7 +231,8 @@ export default function(
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.addPropertyDependencies = function(source = {}, key) {
|
this.addPropertyDependencies = function(source = {}, key) {
|
||||||
const { builtIn, instanceType } = source;
|
const { builtIn, instanceType, isNamespaced } = source;
|
||||||
|
if (isNamespaced) return;
|
||||||
if (PossibleGlobalObjects.has(builtIn)) {
|
if (PossibleGlobalObjects.has(builtIn)) {
|
||||||
this.addBuiltInDependencies(key);
|
this.addBuiltInDependencies(key);
|
||||||
} else if (has(StaticProperties, builtIn)) {
|
} else if (has(StaticProperties, builtIn)) {
|
||||||
|
|||||||
@ -162,3 +162,10 @@ export function getModulePath(mod: string): string {
|
|||||||
export function createImport(path: NodePath, mod: string) {
|
export function createImport(path: NodePath, mod: string) {
|
||||||
return addSideEffect(path, getModulePath(mod));
|
return addSideEffect(path, getModulePath(mod));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isNamespaced(path: NodePath) {
|
||||||
|
if (!path.node) return false;
|
||||||
|
const binding = path.scope.getBinding(path.node.name);
|
||||||
|
if (!binding) return false;
|
||||||
|
return binding.path.isImportNamespaceSpecifier();
|
||||||
|
}
|
||||||
|
|||||||
2
packages/babel-preset-env/test/fixtures/corejs2/usage-modules-namespaced/input.mjs
vendored
Normal file
2
packages/babel-preset-env/test/fixtures/corejs2/usage-modules-namespaced/input.mjs
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import * as ns from "ns";
|
||||||
|
ns.map;
|
||||||
12
packages/babel-preset-env/test/fixtures/corejs2/usage-modules-namespaced/options.json
vendored
Normal file
12
packages/babel-preset-env/test/fixtures/corejs2/usage-modules-namespaced/options.json
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
[
|
||||||
|
"../../../../lib",
|
||||||
|
{
|
||||||
|
"modules": false,
|
||||||
|
"useBuiltIns": "usage",
|
||||||
|
"corejs": 2
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
3
packages/babel-preset-env/test/fixtures/corejs2/usage-modules-namespaced/output.mjs
vendored
Normal file
3
packages/babel-preset-env/test/fixtures/corejs2/usage-modules-namespaced/output.mjs
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import * as ns from "ns";
|
||||||
|
ns.map;
|
||||||
|
|
||||||
2
packages/babel-preset-env/test/fixtures/corejs3/usage-modules-namespaced/input.mjs
vendored
Normal file
2
packages/babel-preset-env/test/fixtures/corejs3/usage-modules-namespaced/input.mjs
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import * as ns from "ns";
|
||||||
|
ns.map;
|
||||||
12
packages/babel-preset-env/test/fixtures/corejs3/usage-modules-namespaced/options.json
vendored
Normal file
12
packages/babel-preset-env/test/fixtures/corejs3/usage-modules-namespaced/options.json
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
[
|
||||||
|
"../../../../lib",
|
||||||
|
{
|
||||||
|
"modules": false,
|
||||||
|
"useBuiltIns": "usage",
|
||||||
|
"corejs": 3
|
||||||
|
}
|
||||||
|
]
|
||||||
|
]
|
||||||
|
}
|
||||||
2
packages/babel-preset-env/test/fixtures/corejs3/usage-modules-namespaced/output.mjs
vendored
Normal file
2
packages/babel-preset-env/test/fixtures/corejs3/usage-modules-namespaced/output.mjs
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import * as ns from "ns";
|
||||||
|
ns.map;
|
||||||
Loading…
x
Reference in New Issue
Block a user