Skip to content
This repository was archived by the owner on May 11, 2018. It is now read-only.

Commit b9abefe

Browse files
Revert "Add forceAllTransforms option and deprecate Uglify target (#264)"
This reverts commit 4ddd615.
1 parent 4ddd615 commit b9abefe

File tree

12 files changed

+93
-206
lines changed

12 files changed

+93
-206
lines changed

README.md

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ A query to select browsers (ex: last 2 versions, > 5%) using [browserslist](http
120120

121121
Note, browsers' results are overridden by explicit items from `targets`.
122122

123+
### `targets.uglify`
124+
125+
`number | true`
126+
127+
UglifyJS does not currently support any ES6 syntax, so if you are using Uglify to minify your code, targeting later browsers may cause Uglify to throw syntax errors.
128+
129+
To prevent these errors - specify the uglify option, which will enable all plugins and, as a result, fully compile your code to ES5. However, the `useBuiltIns` option will still work as before, and only include the polyfills that your target(s) need.
130+
131+
> NOTE: Uglify has a work-in-progress "Harmony" branch to address the lack of ES6 support, but it is not yet stable. You can follow its progress in [UglifyJS2 issue #448](https://github.com/mishoo/UglifyJS2/issues/448). If you require an alternative minifier which _does_ support ES6 syntax, we recommend using [Babili](https://github.com/babel/babili).
132+
123133
### `spec`
124134

125135
`boolean`, defaults to `false`.
@@ -249,47 +259,6 @@ import "babel-polyfill/core-js/modules/es7.string.pad-end";
249259

250260
Don't add polyfills automatically per file, or transform `import "babel-polyfill"` to individual polyfills.
251261

252-
### `forceAllTransforms`
253-
254-
`boolean`, defaults to `false`.
255-
256-
<p><details>
257-
<summary><b>Example</b></summary>
258-
259-
With Babel 7's .babelrc.js support, you can force all transforms to be run if env is set to `production`.
260-
261-
```js
262-
module.exports = {
263-
presets: [
264-
["env", {
265-
targets: {
266-
chrome: 59,
267-
edge: 13,
268-
firefox: 50,
269-
},
270-
// for uglifyjs...
271-
forceAllTransforms: process.env === "production"
272-
}],
273-
],
274-
};
275-
```
276-
</details></p>
277-
278-
279-
> NOTE: `targets.uglify` is deprecated and will be removed in the next major in
280-
favor of this.
281-
282-
By default, this preset will run all the transforms needed for the targeted
283-
environment(s). Enable this option if you want to force running _all_
284-
transforms, which is useful if the output will be run through UglifyJS or an
285-
environment that only supports ES5.
286-
287-
> NOTE: Uglify has a work-in-progress "Harmony" branch to address the lack of
288-
ES6 support, but it is not yet stable. You can follow its progress in
289-
[UglifyJS2 issue #448](https://github.com/mishoo/UglifyJS2/issues/448). If you
290-
require an alternative minifier which _does_ support ES6 syntax, we recommend
291-
using [Babili](https://github.com/babel/babili).
292-
293262
---
294263

295264
## Examples

src/index.js

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -107,42 +107,18 @@ const filterItems = (list, includes, excludes, targets, defaultItems) => {
107107
};
108108

109109
export default function buildPreset(context, opts = {}) {
110-
const {
111-
debug,
112-
exclude: optionsExclude,
113-
forceAllTransforms,
114-
include: optionsInclude,
115-
loose,
116-
moduleType,
117-
spec,
118-
targets: optionsTargets,
119-
useBuiltIns,
120-
} = normalizeOptions(opts);
121-
122-
// TODO: remove this in next major
123-
let hasUglifyTarget = false;
124-
125-
if (optionsTargets && optionsTargets.uglify) {
126-
hasUglifyTarget = true;
127-
delete optionsTargets.uglify;
110+
const validatedOptions = normalizeOptions(opts);
111+
const { debug, loose, moduleType, spec, useBuiltIns } = validatedOptions;
128112

129-
console.log("");
130-
console.log("The uglify target has been deprecated. Set the top level");
131-
console.log("option `forceAllTransforms: true` instead.");
132-
console.log("");
133-
}
134-
135-
const targets = getTargets(optionsTargets);
136-
const include = transformIncludesAndExcludes(optionsInclude);
137-
const exclude = transformIncludesAndExcludes(optionsExclude);
138-
139-
const transformTargets = forceAllTransforms || hasUglifyTarget ? {} : targets;
113+
const targets = getTargets(validatedOptions.targets);
114+
const include = transformIncludesAndExcludes(validatedOptions.include);
115+
const exclude = transformIncludesAndExcludes(validatedOptions.exclude);
140116

141117
const transformations = filterItems(
142118
pluginList,
143119
include.plugins,
144120
exclude.plugins,
145-
transformTargets,
121+
targets,
146122
);
147123

148124
let polyfills;

src/normalize-options.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,9 @@ export const validateBoolOption = (name, value, defaultValue) => {
5757

5858
export const validateLooseOption = looseOpt =>
5959
validateBoolOption("loose", looseOpt, false);
60-
6160
export const validateSpecOption = specOpt =>
6261
validateBoolOption("spec", specOpt, false);
6362

64-
export const validateForceAllTransformsOption = forceAllTransforms =>
65-
validateBoolOption("forceAllTransforms", forceAllTransforms, false);
66-
6763
export const validateModulesOption = (modulesOpt = "commonjs") => {
6864
invariant(
6965
modulesOpt === false ||
@@ -101,9 +97,6 @@ export default function normalizeOptions(opts) {
10197
return {
10298
debug: opts.debug,
10399
exclude: validateIncludesAndExcludes(opts.exclude, "exclude"),
104-
forceAllTransforms: validateForceAllTransformsOption(
105-
opts.forceAllTransforms,
106-
),
107100
include: validateIncludesAndExcludes(opts.include, "include"),
108101
loose: validateLooseOption(opts.loose),
109102
moduleType: validateModulesOption(opts.modules),

src/targets-parser.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,30 @@ const semverMin = (first: ?string, second: string): string => {
2626
};
2727

2828
const getLowestVersions = browsers => {
29-
return browsers.reduce((all, browser) => {
30-
const [browserName, browserVersion] = browser.split(" ");
31-
const normalizedBrowserName = browserNameMap[browserName];
29+
return browsers.reduce(
30+
(all, browser) => {
31+
const [browserName, browserVersion] = browser.split(" ");
32+
const normalizedBrowserName = browserNameMap[browserName];
3233

33-
if (!normalizedBrowserName) {
34-
return all;
35-
}
34+
if (!normalizedBrowserName) {
35+
return all;
36+
}
3637

37-
try {
38-
// Browser version can return as "10.0-10.2"
39-
const splitVersion = browserVersion.split("-")[0];
40-
const parsedBrowserVersion = semverify(splitVersion);
38+
try {
39+
// Browser version can return as "10.0-10.2"
40+
const splitVersion = browserVersion.split("-")[0];
41+
const parsedBrowserVersion = semverify(splitVersion);
4142

42-
all[normalizedBrowserName] = semverMin(
43-
all[normalizedBrowserName],
44-
parsedBrowserVersion,
45-
);
46-
} catch (e) {}
43+
all[normalizedBrowserName] = semverMin(
44+
all[normalizedBrowserName],
45+
parsedBrowserVersion,
46+
);
47+
} catch (e) {}
4748

48-
return all;
49-
}, {});
49+
return all;
50+
},
51+
{},
52+
);
5053
};
5154

5255
const outputDecimalWarning = (decimalTargets: Array<Object>): void => {
@@ -57,8 +60,7 @@ const outputDecimalWarning = (decimalTargets: Array<Object>): void => {
5760
console.log("Warning, the following targets are using a decimal version:");
5861
console.log("");
5962
decimalTargets.forEach(({ target, value }) =>
60-
console.log(` ${target}: ${value}`),
61-
);
63+
console.log(` ${target}: ${value}`));
6264
console.log("");
6365
console.log(
6466
"We recommend using a string for minor/patch versions to avoid numbers like 6.10",
@@ -79,7 +81,6 @@ const targetParserMap = {
7981
return [target, parsed];
8082
},
8183

82-
// TODO: Remove in next version.
8384
// Only valid value for Uglify is `true`
8485
uglify: (target, value) => [target, value === true],
8586
};

test/debug-fixtures/builtins-uglify/stdout.txt

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
1-
The uglify target has been deprecated. Set the top level
2-
option `forceAllTransforms: true` instead.
3-
41
babel-preset-env: `DEBUG` option
52

63
Using targets:
74
{
8-
"chrome": "55"
5+
"chrome": "55",
6+
"uglify": true
97
}
108

119
Modules transform: false
1210

1311
Using plugins:
14-
check-es2015-constants {}
15-
transform-es2015-arrow-functions {}
16-
transform-es2015-block-scoped-functions {}
17-
transform-es2015-block-scoping {}
18-
transform-es2015-classes {}
19-
transform-es2015-computed-properties {}
20-
transform-es2015-destructuring {}
21-
transform-es2015-duplicate-keys {}
22-
transform-es2015-for-of {}
23-
transform-es2015-function-name {}
24-
transform-es2015-literals {}
25-
transform-es2015-object-super {}
26-
transform-es2015-parameters {}
27-
transform-es2015-shorthand-properties {}
28-
transform-es2015-spread {}
29-
transform-es2015-sticky-regex {}
30-
transform-es2015-template-literals {}
31-
transform-es2015-typeof-symbol {}
32-
transform-es2015-unicode-regex {}
33-
transform-regenerator {}
34-
transform-exponentiation-operator {}
35-
transform-async-to-generator {}
36-
syntax-trailing-function-commas {"chrome":"55"}
12+
check-es2015-constants {"uglify":true}
13+
transform-es2015-arrow-functions {"uglify":true}
14+
transform-es2015-block-scoped-functions {"uglify":true}
15+
transform-es2015-block-scoping {"uglify":true}
16+
transform-es2015-classes {"uglify":true}
17+
transform-es2015-computed-properties {"uglify":true}
18+
transform-es2015-destructuring {"uglify":true}
19+
transform-es2015-duplicate-keys {"uglify":true}
20+
transform-es2015-for-of {"uglify":true}
21+
transform-es2015-function-name {"uglify":true}
22+
transform-es2015-literals {"uglify":true}
23+
transform-es2015-object-super {"uglify":true}
24+
transform-es2015-parameters {"uglify":true}
25+
transform-es2015-shorthand-properties {"uglify":true}
26+
transform-es2015-spread {"uglify":true}
27+
transform-es2015-sticky-regex {"uglify":true}
28+
transform-es2015-template-literals {"uglify":true}
29+
transform-es2015-typeof-symbol {"uglify":true}
30+
transform-es2015-unicode-regex {"uglify":true}
31+
transform-regenerator {"uglify":true}
32+
transform-exponentiation-operator {"uglify":true}
33+
transform-async-to-generator {"uglify":true}
34+
syntax-trailing-function-commas {"chrome":"55","uglify":true}
3735

3836
Polyfills
3937
=========

test/debug-fixtures/force-all-transforms/options.json

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/debug-fixtures/force-all-transforms/stdout.txt

Lines changed: 0 additions & 44 deletions
This file was deleted.

test/fixtures/preset-options/exclude-built-ins/expected.js

Whitespace-only changes.

0 commit comments

Comments
 (0)