[preset-env] Exclude transform-typeof-symbol with loose option. (#6831)

This commit is contained in:
Artem Yavorsky 2017-11-15 22:13:59 +02:00 committed by Brian Ng
parent f3fd2ee3b2
commit de3597983a
7 changed files with 43 additions and 3 deletions

View File

@ -111,12 +111,25 @@ const getPlatformSpecificDefaultFor = (targets: Targets): ?Array<string> => {
return isAnyTarget || isWebTarget ? defaultWebIncludes : null;
};
const getOptionSpecificExcludesFor = ({
loose,
}: {
loose: boolean,
}): Array<string> => {
const defaultExcludes = [];
if (loose) {
defaultExcludes.push("transform-typeof-symbol");
}
return defaultExcludes;
};
const filterItems = (
list,
includes,
excludes,
targets,
defaultItems,
defaultIncludes,
defaultExcludes,
): Set<string> => {
const result = new Set();
@ -135,8 +148,12 @@ const filterItems = (
}
}
if (defaultItems) {
defaultItems.forEach(item => !excludes.has(item) && result.add(item));
if (defaultIncludes) {
defaultIncludes.forEach(item => !excludes.has(item) && result.add(item));
}
if (defaultExcludes) {
defaultExcludes.forEach(item => !includes.has(item) && result.delete(item));
}
return result;
@ -187,6 +204,8 @@ export default function buildPreset(
include.plugins,
exclude.plugins,
transformTargets,
null,
getOptionSpecificExcludesFor({ loose }),
);
let polyfills;

View File

@ -0,0 +1 @@
typeof Symbol();

View File

@ -0,0 +1 @@
typeof Symbol();

View File

@ -0,0 +1,7 @@
{
"presets": [
["../../../../lib", {
"loose": true
}]
]
}

View File

@ -0,0 +1,3 @@
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
_typeof(Symbol());

View File

@ -0,0 +1,8 @@
{
"presets": [
["../../../../lib", {
"loose": true,
"include": ["transform-typeof-symbol"]
}]
]
}