unify CLI & API under minify() (#1811)

- rename `screw_ie8` to `ie8`
- rename `mangle.except` to `mangle.reserved`
- rename `mangle.properties.ignore_quoted` to `mangle.properties.keep_quoted` 
- compact `sourceMap` options
- more stringent verification on input `options`
- toplevel shorthands
  - `ie8`
  - `keep_fnames`
  - `toplevel`
  - `warnings`
- support arrays and unquoted string values on CLI
- drop `fromString` from `minify()`
  - `minify()` no longer handles any `fs` operations
- unify order of operations for `mangle_properties()` on CLI & API
  - `bin/uglifyjs` used to `mangle_properties()` before even `Compressor`
  - `minify()` used to `mangle_properties()` after `Compressor` but before `mangle_names()`
  - both will now do `Compressor`, `mangle_names()` then `mangle_properties()`
- `options.parse` / `--parse` for parser options beyond `bare_returns`
- add `mangle.properties.builtins` to disable built-in reserved list
  - disable with `--mangle-props builtins` on CLI
- `warnings` now off by default
- add `--warn` and `--verbose` on CLI
- drop `--enclose`
- drop `--export-all`
- drop `--reserved-file`
  - use `--mangle reserved` instead
- drop `--reserve-domprops`
  - enabled by default, disable with `--mangle-props domprops`
- drop `--prefix`
  - use `--source-map base` instead
- drop `--lint`
- remove `bin/extract-props.js`
- limit exposure of internal APIs
- update documentations

closes #96
closes #102
closes #136
closes #166
closes #243
closes #254
closes #261
closes #311
closes #700
closes #748
closes #912
closes #1072
closes #1366
fixes #101
fixes #123
fixes #124
fixes #263
fixes #379
fixes #419
fixes #423
fixes #461
fixes #465
fixes #576
fixes #737
fixes #772
fixes #958
fixes #1036
fixes #1142
fixes #1175
fixes #1220
fixes #1223
fixes #1280
fixes #1359
fixes #1368
This commit is contained in:
Alex Lam S.L
2017-04-15 23:50:50 +08:00
committed by GitHub
parent 32deb365d5
commit ec443e422c
43 changed files with 6566 additions and 7402 deletions

View File

@@ -61,6 +61,7 @@ function Compressor(options, false_by_default) {
global_defs : {},
hoist_funs : !false_by_default,
hoist_vars : false,
ie8 : false,
if_return : !false_by_default,
join_vars : !false_by_default,
keep_fargs : true,
@@ -73,7 +74,6 @@ function Compressor(options, false_by_default) {
pure_getters : !false_by_default && "strict",
pure_funcs : null,
reduce_vars : !false_by_default,
screw_ie8 : true,
sequences : !false_by_default,
side_effects : !false_by_default,
switches : !false_by_default,
@@ -84,7 +84,7 @@ function Compressor(options, false_by_default) {
unsafe_math : false,
unsafe_proto : false,
unused : !false_by_default,
warnings : true,
warnings : false,
}, true);
var pure_funcs = this.options["pure_funcs"];
if (typeof pure_funcs == "function") {
@@ -1138,7 +1138,7 @@ merge(Compressor.prototype, {
/* -----[ boolean/negation helpers ]----- */
// methods to determine whether an expression has a boolean result type
(function (def){
(function(def){
var unary_bool = [ "!", "delete" ];
var binary_bool = [ "in", "instanceof", "==", "!=", "===", "!==", "<", "<=", ">=", ">" ];
def(AST_Node, return_false);
@@ -1166,7 +1166,7 @@ merge(Compressor.prototype, {
});
// methods to determine if an expression has a numeric result type
(function (def){
(function(def){
def(AST_Node, return_false);
def(AST_Number, return_true);
var unary = makePredicate("+ - ~ ++ --");
@@ -1194,7 +1194,7 @@ merge(Compressor.prototype, {
});
// methods to determine if an expression has a string result type
(function (def){
(function(def){
def(AST_Node, return_false);
def(AST_String, return_true);
def(AST_UnaryPrefix, function(){
@@ -1224,7 +1224,7 @@ merge(Compressor.prototype, {
if (parent instanceof AST_Assign && parent.left === node) return node;
}
(function (def){
(function(def){
AST_Node.DEFMETHOD("resolve_defines", function(compressor) {
if (!compressor.option("global_defs")) return;
var def = this._find_defs(compressor, "");
@@ -1305,7 +1305,7 @@ merge(Compressor.prototype, {
}
// methods to evaluate a constant expression
(function (def){
(function(def){
// If the node has been successfully reduced to a constant,
// then its value is returned; otherwise the element itself
// is returned.
@@ -2767,10 +2767,11 @@ merge(Compressor.prototype, {
return arg.value;
}).join(",") + "){" + self.args[self.args.length - 1].value + "})()";
var ast = parse(code);
ast.figure_out_scope({ screw_ie8: compressor.option("screw_ie8") });
var mangle = { ie8: compressor.option("ie8") };
ast.figure_out_scope(mangle);
var comp = new Compressor(compressor.options);
ast = ast.transform(comp);
ast.figure_out_scope({ screw_ie8: compressor.option("screw_ie8") });
ast.figure_out_scope(mangle);
ast.mangle_names();
var fun;
try {
@@ -3216,7 +3217,7 @@ merge(Compressor.prototype, {
&& self.right.operator == "typeof") {
var expr = self.right.expression;
if (expr instanceof AST_SymbolRef ? !expr.undeclared()
: !(expr instanceof AST_PropAccess) || compressor.option("screw_ie8")) {
: !(expr instanceof AST_PropAccess && compressor.option("ie8"))) {
self.right = expr;
self.left = make_node(AST_Undefined, self.left).optimize(compressor);
if (self.operator.length == 2) self.operator += "=";
@@ -3540,7 +3541,7 @@ merge(Compressor.prototype, {
return def.optimize(compressor);
}
// testing against !self.scope.uses_with first is an optimization
if (compressor.option("screw_ie8")
if (!compressor.option("ie8")
&& self.undeclared()
&& (!self.scope.uses_with || !compressor.find_parent(AST_With))) {
switch (self.name) {
@@ -3860,7 +3861,7 @@ merge(Compressor.prototype, {
var prop = self.property;
if (prop instanceof AST_String && compressor.option("properties")) {
prop = prop.getValue();
if (RESERVED_WORDS(prop) ? compressor.option("screw_ie8") : is_identifier_string(prop)) {
if (RESERVED_WORDS(prop) ? !compressor.option("ie8") : is_identifier_string(prop)) {
return make_node(AST_Dot, self, {
expression : self.expression,
property : prop
@@ -3887,7 +3888,7 @@ merge(Compressor.prototype, {
return def.optimize(compressor);
}
var prop = self.property;
if (RESERVED_WORDS(prop) && !compressor.option("screw_ie8")) {
if (RESERVED_WORDS(prop) && compressor.option("ie8")) {
return make_node(AST_Sub, self, {
expression : self.expression,
property : make_node(AST_String, self, {