Compare commits
16 Commits
harmony-v2
...
harmony-v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e2290b29c | ||
|
|
97d0fc271d | ||
|
|
6b2f34769a | ||
|
|
48ffbef51d | ||
|
|
c0f3feae9f | ||
|
|
a00040dd93 | ||
|
|
ee95c1b38b | ||
|
|
4bceb85cbf | ||
|
|
7906033e82 | ||
|
|
4bf21ce5c1 | ||
|
|
44d6b47bdc | ||
|
|
30a75049f5 | ||
|
|
a3cc3a9b87 | ||
|
|
96f8befdd7 | ||
|
|
cd58635dcc | ||
|
|
274331d0ea |
@@ -5,7 +5,6 @@ node_js:
|
|||||||
- "0.12"
|
- "0.12"
|
||||||
- "4"
|
- "4"
|
||||||
- "6"
|
- "6"
|
||||||
- "7"
|
|
||||||
env:
|
env:
|
||||||
- UGLIFYJS_TEST_ALL=1
|
- UGLIFYJS_TEST_ALL=1
|
||||||
matrix:
|
matrix:
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ There's also an
|
|||||||
[in-browser online demo](http://lisperator.net/uglifyjs/#demo) (for Firefox,
|
[in-browser online demo](http://lisperator.net/uglifyjs/#demo) (for Firefox,
|
||||||
Chrome and probably Safari).
|
Chrome and probably Safari).
|
||||||
|
|
||||||
Note: release versions of `uglify-js` only support ECMAScript 5 (ES5). If you wish to minify
|
#### Note:
|
||||||
|
- release versions of `uglify-js` only support ECMAScript 5 (ES5). If you wish to minify
|
||||||
ES2015+ (ES6+) code then please use the [harmony](#harmony) development branch.
|
ES2015+ (ES6+) code then please use the [harmony](#harmony) development branch.
|
||||||
|
- Node 7 has a known performance regression and runs `uglify-js` twice as slow.
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
-------
|
||||||
|
|||||||
108
lib/compress.js
108
lib/compress.js
@@ -132,6 +132,11 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
},
|
},
|
||||||
|
info: function() {
|
||||||
|
if (this.options.warnings == "verbose") {
|
||||||
|
AST_Node.warn.apply(AST_Node, arguments);
|
||||||
|
}
|
||||||
|
},
|
||||||
warn: function(text, props) {
|
warn: function(text, props) {
|
||||||
if (this.options.warnings) {
|
if (this.options.warnings) {
|
||||||
// only emit unique warnings
|
// only emit unique warnings
|
||||||
@@ -629,12 +634,24 @@ merge(Compressor.prototype, {
|
|||||||
|| node instanceof AST_IterationStatement
|
|| node instanceof AST_IterationStatement
|
||||||
|| (parent instanceof AST_If && node !== parent.condition)
|
|| (parent instanceof AST_If && node !== parent.condition)
|
||||||
|| (parent instanceof AST_Conditional && node !== parent.condition)
|
|| (parent instanceof AST_Conditional && node !== parent.condition)
|
||||||
|
|| (node instanceof AST_SymbolRef
|
||||||
|
&& !are_references_in_scope(node.definition(), self))
|
||||||
|| (parent instanceof AST_Binary
|
|| (parent instanceof AST_Binary
|
||||||
&& (parent.operator == "&&" || parent.operator == "||")
|
&& (parent.operator == "&&" || parent.operator == "||")
|
||||||
&& node === parent.right)
|
&& node === parent.right)
|
||||||
|| (parent instanceof AST_Switch && node !== parent.expression)) {
|
|| (parent instanceof AST_Switch && node !== parent.expression)) {
|
||||||
return side_effects_encountered = unwind = true, node;
|
return side_effects_encountered = unwind = true, node;
|
||||||
}
|
}
|
||||||
|
function are_references_in_scope(def, scope) {
|
||||||
|
if (def.orig.length === 1
|
||||||
|
&& def.orig[0] instanceof AST_SymbolDefun) return true;
|
||||||
|
if (def.scope.get_defun_scope() !== scope) return false;
|
||||||
|
var refs = def.references;
|
||||||
|
for (var i = 0, len = refs.length; i < len; i++) {
|
||||||
|
if (refs[i].scope.get_defun_scope() !== scope) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function postorder(node) {
|
function postorder(node) {
|
||||||
if (unwind) return node;
|
if (unwind) return node;
|
||||||
@@ -679,7 +696,7 @@ merge(Compressor.prototype, {
|
|||||||
// Further optimize statement after substitution.
|
// Further optimize statement after substitution.
|
||||||
stat.reset_opt_flags(compressor);
|
stat.reset_opt_flags(compressor);
|
||||||
|
|
||||||
compressor.warn("Collapsing " + (is_constant ? "constant" : "variable") +
|
compressor.info("Collapsing " + (is_constant ? "constant" : "variable") +
|
||||||
" " + var_name + " [{file}:{line},{col}]", node.start);
|
" " + var_name + " [{file}:{line},{col}]", node.start);
|
||||||
CHANGED = true;
|
CHANGED = true;
|
||||||
return value;
|
return value;
|
||||||
@@ -1933,7 +1950,7 @@ merge(Compressor.prototype, {
|
|||||||
sym.__unused = true;
|
sym.__unused = true;
|
||||||
if (trim) {
|
if (trim) {
|
||||||
a.pop();
|
a.pop();
|
||||||
compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
|
compressor[sym.unreferenced() ? "warn" : "info"]("Dropping unused function argument {name} [{file}:{line},{col}]", {
|
||||||
name : sym.name,
|
name : sym.name,
|
||||||
file : sym.start.file,
|
file : sym.start.file,
|
||||||
line : sym.start.line,
|
line : sym.start.line,
|
||||||
@@ -1949,7 +1966,7 @@ merge(Compressor.prototype, {
|
|||||||
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
if ((node instanceof AST_Defun || node instanceof AST_DefClass) && node !== self) {
|
||||||
var keep = (node.name.definition().id in in_use_ids) || !drop_funcs && node.name.definition().global;
|
var keep = (node.name.definition().id in in_use_ids) || !drop_funcs && node.name.definition().global;
|
||||||
if (!keep) {
|
if (!keep) {
|
||||||
compressor.warn("Dropping unused function {name} [{file}:{line},{col}]", {
|
compressor[node.name.unreferenced() ? "warn" : "info"]("Dropping unused function {name} [{file}:{line},{col}]", {
|
||||||
name : node.name.name,
|
name : node.name.name,
|
||||||
file : node.name.start.file,
|
file : node.name.start.file,
|
||||||
line : node.name.start.line,
|
line : node.name.start.line,
|
||||||
@@ -1976,7 +1993,7 @@ merge(Compressor.prototype, {
|
|||||||
compressor.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", w);
|
compressor.warn("Side effects in initialization of unused variable {name} [{file}:{line},{col}]", w);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
compressor.warn("Dropping unused variable {name} [{file}:{line},{col}]", w);
|
compressor[def.name.unreferenced() ? "warn" : "info"]("Dropping unused variable {name} [{file}:{line},{col}]", w);
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
// place uninitialized names at the start
|
// place uninitialized names at the start
|
||||||
@@ -2791,7 +2808,7 @@ merge(Compressor.prototype, {
|
|||||||
if (self.args.length != 1) {
|
if (self.args.length != 1) {
|
||||||
return make_node(AST_Array, self, {
|
return make_node(AST_Array, self, {
|
||||||
elements: self.args
|
elements: self.args
|
||||||
}).transform(compressor);
|
}).optimize(compressor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Object":
|
case "Object":
|
||||||
@@ -2809,7 +2826,7 @@ merge(Compressor.prototype, {
|
|||||||
left: self.args[0],
|
left: self.args[0],
|
||||||
operator: "+",
|
operator: "+",
|
||||||
right: make_node(AST_String, self, { value: "" })
|
right: make_node(AST_String, self, { value: "" })
|
||||||
}).transform(compressor);
|
}).optimize(compressor);
|
||||||
break;
|
break;
|
||||||
case "Number":
|
case "Number":
|
||||||
if (self.args.length == 0) return make_node(AST_Number, self, {
|
if (self.args.length == 0) return make_node(AST_Number, self, {
|
||||||
@@ -2818,7 +2835,7 @@ merge(Compressor.prototype, {
|
|||||||
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
|
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
|
||||||
expression: self.args[0],
|
expression: self.args[0],
|
||||||
operator: "+"
|
operator: "+"
|
||||||
}).transform(compressor);
|
}).optimize(compressor);
|
||||||
case "Boolean":
|
case "Boolean":
|
||||||
if (self.args.length == 0) return make_node(AST_False, self);
|
if (self.args.length == 0) return make_node(AST_False, self);
|
||||||
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
|
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
|
||||||
@@ -2827,7 +2844,7 @@ merge(Compressor.prototype, {
|
|||||||
operator: "!"
|
operator: "!"
|
||||||
}),
|
}),
|
||||||
operator: "!"
|
operator: "!"
|
||||||
}).transform(compressor);
|
}).optimize(compressor);
|
||||||
break;
|
break;
|
||||||
case "Function":
|
case "Function":
|
||||||
// new Function() => function(){}
|
// new Function() => function(){}
|
||||||
@@ -2897,7 +2914,7 @@ merge(Compressor.prototype, {
|
|||||||
left: make_node(AST_String, self, { value: "" }),
|
left: make_node(AST_String, self, { value: "" }),
|
||||||
operator: "+",
|
operator: "+",
|
||||||
right: exp.expression
|
right: exp.expression
|
||||||
}).transform(compressor);
|
}).optimize(compressor);
|
||||||
}
|
}
|
||||||
else if (exp instanceof AST_Dot && exp.expression instanceof AST_Array && exp.property == "join") EXIT: {
|
else if (exp instanceof AST_Dot && exp.expression instanceof AST_Array && exp.property == "join") EXIT: {
|
||||||
var separator;
|
var separator;
|
||||||
@@ -2951,7 +2968,7 @@ merge(Compressor.prototype, {
|
|||||||
left : prev,
|
left : prev,
|
||||||
right : el
|
right : el
|
||||||
});
|
});
|
||||||
}, first).transform(compressor);
|
}, first).optimize(compressor);
|
||||||
}
|
}
|
||||||
// need this awkward cloning to not affect original element
|
// need this awkward cloning to not affect original element
|
||||||
// best_of will decide which one to get through.
|
// best_of will decide which one to get through.
|
||||||
@@ -2961,6 +2978,16 @@ merge(Compressor.prototype, {
|
|||||||
node.expression.expression.elements = elements;
|
node.expression.expression.elements = elements;
|
||||||
return best_of(compressor, self, node);
|
return best_of(compressor, self, node);
|
||||||
}
|
}
|
||||||
|
else if (exp instanceof AST_Dot && exp.expression.is_string(compressor) && exp.property == "charAt") {
|
||||||
|
var arg = self.args[0];
|
||||||
|
var index = arg ? arg.evaluate(compressor) : 0;
|
||||||
|
if (index !== arg) {
|
||||||
|
return make_node(AST_Sub, exp, {
|
||||||
|
expression: exp.expression,
|
||||||
|
property: make_node_from_constant(index | 0, arg || exp)
|
||||||
|
}).optimize(compressor);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (exp instanceof AST_Function && !self.expression.is_generator) {
|
if (exp instanceof AST_Function && !self.expression.is_generator) {
|
||||||
if (exp.body[0] instanceof AST_Return) {
|
if (exp.body[0] instanceof AST_Return) {
|
||||||
@@ -3129,14 +3156,6 @@ merge(Compressor.prototype, {
|
|||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
function has_side_effects_or_prop_access(node, compressor) {
|
|
||||||
var save_pure_getters = compressor.option("pure_getters");
|
|
||||||
compressor.options.pure_getters = false;
|
|
||||||
var ret = node.has_side_effects(compressor);
|
|
||||||
compressor.options.pure_getters = save_pure_getters;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
AST_Binary.DEFMETHOD("lift_sequences", function(compressor){
|
AST_Binary.DEFMETHOD("lift_sequences", function(compressor){
|
||||||
if (compressor.option("sequences")) {
|
if (compressor.option("sequences")) {
|
||||||
if (this.left instanceof AST_Seq) {
|
if (this.left instanceof AST_Seq) {
|
||||||
@@ -3144,18 +3163,23 @@ merge(Compressor.prototype, {
|
|||||||
var x = seq.to_array();
|
var x = seq.to_array();
|
||||||
this.left = x.pop();
|
this.left = x.pop();
|
||||||
x.push(this);
|
x.push(this);
|
||||||
seq = AST_Seq.from_array(x).transform(compressor);
|
return AST_Seq.from_array(x).optimize(compressor);
|
||||||
return seq;
|
|
||||||
}
|
}
|
||||||
if (this.right instanceof AST_Seq
|
if (this.right instanceof AST_Seq && !this.left.has_side_effects(compressor)) {
|
||||||
&& this instanceof AST_Assign
|
var assign = this.operator == "=" && this.left instanceof AST_SymbolRef;
|
||||||
&& !has_side_effects_or_prop_access(this.left, compressor)) {
|
var root = this.right;
|
||||||
var seq = this.right;
|
var cursor, seq = root;
|
||||||
var x = seq.to_array();
|
while (assign || !seq.car.has_side_effects(compressor)) {
|
||||||
this.right = x.pop();
|
cursor = seq;
|
||||||
x.push(this);
|
if (seq.cdr instanceof AST_Seq) {
|
||||||
seq = AST_Seq.from_array(x).transform(compressor);
|
seq = seq.cdr;
|
||||||
return seq;
|
} else break;
|
||||||
|
}
|
||||||
|
if (cursor) {
|
||||||
|
this.right = cursor.cdr;
|
||||||
|
cursor.cdr = this;
|
||||||
|
return root.optimize(compressor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
@@ -3190,32 +3214,6 @@ merge(Compressor.prototype, {
|
|||||||
reverse();
|
reverse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (/^[!=]==?$/.test(self.operator)) {
|
|
||||||
if (self.left instanceof AST_SymbolRef && self.right instanceof AST_Conditional) {
|
|
||||||
if (self.right.consequent instanceof AST_SymbolRef
|
|
||||||
&& self.right.consequent.definition() === self.left.definition()) {
|
|
||||||
if (/^==/.test(self.operator)) return self.right.condition;
|
|
||||||
if (/^!=/.test(self.operator)) return self.right.condition.negate(compressor);
|
|
||||||
}
|
|
||||||
if (self.right.alternative instanceof AST_SymbolRef
|
|
||||||
&& self.right.alternative.definition() === self.left.definition()) {
|
|
||||||
if (/^==/.test(self.operator)) return self.right.condition.negate(compressor);
|
|
||||||
if (/^!=/.test(self.operator)) return self.right.condition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (self.right instanceof AST_SymbolRef && self.left instanceof AST_Conditional) {
|
|
||||||
if (self.left.consequent instanceof AST_SymbolRef
|
|
||||||
&& self.left.consequent.definition() === self.right.definition()) {
|
|
||||||
if (/^==/.test(self.operator)) return self.left.condition;
|
|
||||||
if (/^!=/.test(self.operator)) return self.left.condition.negate(compressor);
|
|
||||||
}
|
|
||||||
if (self.left.alternative instanceof AST_SymbolRef
|
|
||||||
&& self.left.alternative.definition() === self.right.definition()) {
|
|
||||||
if (/^==/.test(self.operator)) return self.left.condition.negate(compressor);
|
|
||||||
if (/^!=/.test(self.operator)) return self.left.condition;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
self = self.lift_sequences(compressor);
|
self = self.lift_sequences(compressor);
|
||||||
if (compressor.option("comparisons")) switch (self.operator) {
|
if (compressor.option("comparisons")) switch (self.operator) {
|
||||||
|
|||||||
99
lib/parse.js
99
lib/parse.js
@@ -2467,12 +2467,52 @@ function parse($TEXT, options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function is_assignable(expr) {
|
function is_assignable(expr) {
|
||||||
if (!options.strict) return true;
|
return expr instanceof AST_PropAccess || expr instanceof AST_SymbolRef;
|
||||||
if (expr instanceof AST_This) return false;
|
|
||||||
if (expr instanceof AST_Super) return false;
|
|
||||||
return (expr instanceof AST_PropAccess || expr instanceof AST_Symbol);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function to_destructuring(node) {
|
||||||
|
if (node instanceof AST_Object) {
|
||||||
|
node = new AST_Destructuring({
|
||||||
|
start: node.start,
|
||||||
|
names: node.properties.map(to_destructuring),
|
||||||
|
is_array: false,
|
||||||
|
end: node.end
|
||||||
|
});
|
||||||
|
} else if (node instanceof AST_Array) {
|
||||||
|
var names = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < node.elements.length; i++) {
|
||||||
|
// Only allow expansion as last element
|
||||||
|
if (node.elements[i] instanceof AST_Expansion) {
|
||||||
|
if (i + 1 !== node.elements.length) {
|
||||||
|
token_error(node.elements[i].start, "Spread must the be last element in destructuring array");
|
||||||
|
}
|
||||||
|
node.elements[i].expression = to_destructuring(node.elements[i].expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
names.push(to_destructuring(node.elements[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
node = new AST_Destructuring({
|
||||||
|
start: node.start,
|
||||||
|
names: names,
|
||||||
|
is_array: true,
|
||||||
|
end: node.end
|
||||||
|
});
|
||||||
|
} else if (node instanceof AST_ObjectProperty) {
|
||||||
|
node.value = to_destructuring(node.value);
|
||||||
|
} else if (node instanceof AST_Assign) {
|
||||||
|
node = new AST_DefaultAssign({
|
||||||
|
start: node.start,
|
||||||
|
left: node.left,
|
||||||
|
operator: "=",
|
||||||
|
right: node.right,
|
||||||
|
end: node.end
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
// In ES6, AssignmentExpression can also be an ArrowFunction
|
// In ES6, AssignmentExpression can also be an ArrowFunction
|
||||||
var maybe_assign = function(no_in) {
|
var maybe_assign = function(no_in) {
|
||||||
var start = S.token;
|
var start = S.token;
|
||||||
@@ -2506,56 +2546,7 @@ function parse($TEXT, options) {
|
|||||||
var val = S.token.value;
|
var val = S.token.value;
|
||||||
|
|
||||||
if (is("operator") && ASSIGNMENT(val)) {
|
if (is("operator") && ASSIGNMENT(val)) {
|
||||||
if (is_assignable(left)) {
|
if (is_assignable(left) || (left = to_destructuring(left)) instanceof AST_Destructuring) {
|
||||||
|
|
||||||
var walk = function(node) {
|
|
||||||
var newNode;
|
|
||||||
if (node instanceof AST_Object) {
|
|
||||||
newNode = new AST_Destructuring({
|
|
||||||
start: node.start,
|
|
||||||
names: node.properties.map(walk),
|
|
||||||
is_array: false,
|
|
||||||
end: node.end
|
|
||||||
});
|
|
||||||
node = newNode;
|
|
||||||
} else if (node instanceof AST_Array) {
|
|
||||||
var names = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < node.elements.length; i++) {
|
|
||||||
// Only allow expansion as last element
|
|
||||||
if (node.elements[i] instanceof AST_Expansion) {
|
|
||||||
if (i + 1 !== node.elements.length) {
|
|
||||||
token_error(node.elements[i].start, "Spread must the be last element in destructuring array");
|
|
||||||
}
|
|
||||||
node.elements[i].expression = walk(node.elements[i].expression);
|
|
||||||
}
|
|
||||||
|
|
||||||
names.push(walk(node.elements[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
newNode = new AST_Destructuring({
|
|
||||||
start: node.start,
|
|
||||||
names: names,
|
|
||||||
is_array: true,
|
|
||||||
end: node.end
|
|
||||||
});
|
|
||||||
node = newNode;
|
|
||||||
} else if (node instanceof AST_ObjectProperty) {
|
|
||||||
node.value = walk(node.value);
|
|
||||||
} else if (node instanceof AST_Assign) {
|
|
||||||
node = new AST_DefaultAssign({
|
|
||||||
start: node.start,
|
|
||||||
left: node.left,
|
|
||||||
operator: "=",
|
|
||||||
right: node.right,
|
|
||||||
end: node.end
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
left = walk(left);
|
|
||||||
|
|
||||||
next();
|
next();
|
||||||
return new AST_Assign({
|
return new AST_Assign({
|
||||||
start : start,
|
start : start,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
"homepage": "http://lisperator.net/uglifyjs",
|
"homepage": "http://lisperator.net/uglifyjs",
|
||||||
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"version": "2.8.13",
|
"version": "2.8.15",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.8.0"
|
"node": ">=0.8.0"
|
||||||
},
|
},
|
||||||
@@ -30,7 +30,6 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"source-map": "~0.5.1",
|
"source-map": "~0.5.1",
|
||||||
"uglify-to-browserify": "~1.0.0",
|
|
||||||
"yargs": "~3.10.0"
|
"yargs": "~3.10.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -40,13 +39,15 @@
|
|||||||
"estraverse": "~1.5.1",
|
"estraverse": "~1.5.1",
|
||||||
"mocha": "~2.3.4"
|
"mocha": "~2.3.4"
|
||||||
},
|
},
|
||||||
|
"optionalDependencies": {
|
||||||
|
"uglify-to-browserify": "~1.0.0"
|
||||||
|
},
|
||||||
"browserify": {
|
"browserify": {
|
||||||
"transform": [
|
"transform": [
|
||||||
"uglify-to-browserify"
|
"uglify-to-browserify"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"shrinkwrap": "rm ./npm-shrinkwrap.json; rm -rf ./node_modules; npm i && npm shrinkwrap && npm outdated",
|
|
||||||
"test": "node test/run-tests.js"
|
"test": "node test/run-tests.js"
|
||||||
},
|
},
|
||||||
"keywords": ["uglify", "uglify-js", "minify", "minifier"]
|
"keywords": ["uglify", "uglify-js", "minify", "minifier"]
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ collapse_vars_side_effects_1: {
|
|||||||
z = i += 4;
|
z = i += 4;
|
||||||
log(x, z, y, i);
|
log(x, z, y, i);
|
||||||
}
|
}
|
||||||
|
f1(), f2(), f3(), f4();
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
function f1() {
|
function f1() {
|
||||||
@@ -73,7 +74,9 @@ collapse_vars_side_effects_1: {
|
|||||||
y = i += 3;
|
y = i += 3;
|
||||||
log(x, i += 4, y, i);
|
log(x, i += 4, y, i);
|
||||||
}
|
}
|
||||||
|
f1(), f2(), f3(), f4();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse_vars_side_effects_2: {
|
collapse_vars_side_effects_2: {
|
||||||
@@ -823,6 +826,7 @@ collapse_vars_repeated: {
|
|||||||
console.log(e + "!");
|
console.log(e + "!");
|
||||||
})("!");
|
})("!");
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse_vars_closures: {
|
collapse_vars_closures: {
|
||||||
@@ -1109,6 +1113,7 @@ collapse_vars_eval_and_with: {
|
|||||||
return function() { with (o) console.log(a) };
|
return function() { with (o) console.log(a) };
|
||||||
})()();
|
})()();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse_vars_constants: {
|
collapse_vars_constants: {
|
||||||
@@ -1168,6 +1173,7 @@ collapse_vars_arguments: {
|
|||||||
(function(){console.log(arguments);})(7, 1);
|
(function(){console.log(arguments);})(7, 1);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
collapse_vars_short_circuit: {
|
collapse_vars_short_circuit: {
|
||||||
@@ -1317,6 +1323,7 @@ collapse_vars_regexp: {
|
|||||||
console.log(result[0]);
|
console.log(result[0]);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1537: {
|
issue_1537: {
|
||||||
@@ -1507,3 +1514,110 @@ issue_1605_2: {
|
|||||||
(new Object).p = 1;
|
(new Object).p = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_1631_1: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var pc = 0;
|
||||||
|
function f(x) {
|
||||||
|
pc = 200;
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
|
function x() {
|
||||||
|
var t = f();
|
||||||
|
pc += t;
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
console.log(x());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(x) {
|
||||||
|
return pc = 200, 100;
|
||||||
|
}
|
||||||
|
function x() {
|
||||||
|
var t = f();
|
||||||
|
return pc += t;
|
||||||
|
}
|
||||||
|
var pc = 0;
|
||||||
|
console.log(x());
|
||||||
|
}
|
||||||
|
expect_stdout: "300"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1631_2: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 0, b = 1;
|
||||||
|
function f() {
|
||||||
|
a = 2;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
function g() {
|
||||||
|
var t = f();
|
||||||
|
b = a + t;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return a = 2, 4;
|
||||||
|
}
|
||||||
|
function g() {
|
||||||
|
var t = f();
|
||||||
|
return b = a + t;
|
||||||
|
}
|
||||||
|
var a = 0, b = 1;
|
||||||
|
console.log(g());
|
||||||
|
}
|
||||||
|
expect_stdout: "6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_1631_3: {
|
||||||
|
options = {
|
||||||
|
cascade: true,
|
||||||
|
collapse_vars: true,
|
||||||
|
hoist_funs: true,
|
||||||
|
join_vars: true,
|
||||||
|
sequences: true,
|
||||||
|
side_effects: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function g() {
|
||||||
|
var a = 0, b = 1;
|
||||||
|
function f() {
|
||||||
|
a = 2;
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
var t = f();
|
||||||
|
b = a + t;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function g() {
|
||||||
|
function f() {
|
||||||
|
return a = 2, 4;
|
||||||
|
}
|
||||||
|
var a = 0, b = 1, t = f();
|
||||||
|
return b = a + t;
|
||||||
|
}
|
||||||
|
console.log(g());
|
||||||
|
}
|
||||||
|
expect_stdout: "6"
|
||||||
|
}
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ concat_2: {
|
|||||||
"1" + "2" + "3"
|
"1" + "2" + "3"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_3: {
|
concat_3: {
|
||||||
@@ -79,6 +80,7 @@ concat_3: {
|
|||||||
1 + 2 + "3" + "4" + "5"
|
1 + 2 + "3" + "4" + "5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_4: {
|
concat_4: {
|
||||||
@@ -107,6 +109,7 @@ concat_4: {
|
|||||||
1 + "2" + "3" + "4" + "5"
|
1 + "2" + "3" + "4" + "5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_5: {
|
concat_5: {
|
||||||
@@ -135,6 +138,7 @@ concat_5: {
|
|||||||
"1" + 2 + "3" + "4" + "5"
|
"1" + 2 + "3" + "4" + "5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_6: {
|
concat_6: {
|
||||||
@@ -163,6 +167,7 @@ concat_6: {
|
|||||||
"1" + "2" + "3" + "4" + "5"
|
"1" + "2" + "3" + "4" + "5"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_7: {
|
concat_7: {
|
||||||
@@ -188,6 +193,7 @@ concat_7: {
|
|||||||
x += "foo"
|
x += "foo"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
concat_8: {
|
concat_8: {
|
||||||
@@ -213,4 +219,5 @@ concat_8: {
|
|||||||
x += "foo"
|
x += "foo"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -797,3 +797,99 @@ no_evaluate: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
equality_conditionals_false: {
|
||||||
|
options = {
|
||||||
|
conditionals: false,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a == (b ? a : a),
|
||||||
|
a == (b ? a : c),
|
||||||
|
a != (b ? a : a),
|
||||||
|
a != (b ? a : c),
|
||||||
|
a === (b ? a : a),
|
||||||
|
a === (b ? a : c),
|
||||||
|
a !== (b ? a : a),
|
||||||
|
a !== (b ? a : c)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
f(0, 0, 0);
|
||||||
|
f(0, true, 0);
|
||||||
|
f(1, 2, 3);
|
||||||
|
f(1, null, 3);
|
||||||
|
f(NaN);
|
||||||
|
f(NaN, "foo");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a == (b ? a : a),
|
||||||
|
a == (b ? a : c),
|
||||||
|
a != (b ? a : a),
|
||||||
|
a != (b ? a : c),
|
||||||
|
a === (b ? a : a),
|
||||||
|
a === (b ? a : c),
|
||||||
|
a !== (b ? a : a),
|
||||||
|
a !== (b ? a : c)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
f(0, 0, 0),
|
||||||
|
f(0, true, 0),
|
||||||
|
f(1, 2, 3),
|
||||||
|
f(1, null, 3),
|
||||||
|
f(NaN),
|
||||||
|
f(NaN, "foo");
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
equality_conditionals_true: {
|
||||||
|
options = {
|
||||||
|
conditionals: true,
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
a == (b ? a : a),
|
||||||
|
a == (b ? a : c),
|
||||||
|
a != (b ? a : a),
|
||||||
|
a != (b ? a : c),
|
||||||
|
a === (b ? a : a),
|
||||||
|
a === (b ? a : c),
|
||||||
|
a !== (b ? a : a),
|
||||||
|
a !== (b ? a : c)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
f(0, 0, 0);
|
||||||
|
f(0, true, 0);
|
||||||
|
f(1, 2, 3);
|
||||||
|
f(1, null, 3);
|
||||||
|
f(NaN);
|
||||||
|
f(NaN, "foo");
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(a, b, c) {
|
||||||
|
console.log(
|
||||||
|
(b, a == a),
|
||||||
|
a == (b ? a : c),
|
||||||
|
(b, a != a),
|
||||||
|
a != (b ? a : c),
|
||||||
|
(b, a === a),
|
||||||
|
a === (b ? a : c),
|
||||||
|
(b, a !== a),
|
||||||
|
a !== (b ? a : c)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
f(0, 0, 0),
|
||||||
|
f(0, true, 0),
|
||||||
|
f(1, 2, 3),
|
||||||
|
f(1, null, 3),
|
||||||
|
f(NaN),
|
||||||
|
f(NaN, "foo");
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|||||||
@@ -162,4 +162,5 @@ regexp_literal_not_const: {
|
|||||||
while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]);
|
while (result = REGEXP_LITERAL.exec("acdabcdeabbb")) console.log(result[0]);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ dead_code_constant_boolean_should_warn_more: {
|
|||||||
var x = 10, y;
|
var x = 10, y;
|
||||||
var moo;
|
var moo;
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_block_decls_die: {
|
dead_code_block_decls_die: {
|
||||||
@@ -135,6 +136,7 @@ dead_code_const_declaration: {
|
|||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation: {
|
dead_code_const_annotation: {
|
||||||
@@ -162,6 +164,7 @@ dead_code_const_annotation: {
|
|||||||
var moo;
|
var moo;
|
||||||
function bar() {}
|
function bar() {}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation_regex: {
|
dead_code_const_annotation_regex: {
|
||||||
@@ -185,6 +188,7 @@ dead_code_const_annotation_regex: {
|
|||||||
var CONST_FOO_ANN = !1;
|
var CONST_FOO_ANN = !1;
|
||||||
CONST_FOO_ANN && console.log('reachable');
|
CONST_FOO_ANN && console.log('reachable');
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dead_code_const_annotation_complex_scope: {
|
dead_code_const_annotation_complex_scope: {
|
||||||
@@ -230,4 +234,5 @@ dead_code_const_annotation_complex_scope: {
|
|||||||
var meat = 'beef';
|
var meat = 'beef';
|
||||||
var pork = 'bad';
|
var pork = 'bad';
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -200,6 +200,7 @@ negative_zero: {
|
|||||||
1 / (-0)
|
1 / (-0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
positive_zero: {
|
positive_zero: {
|
||||||
@@ -220,6 +221,7 @@ positive_zero: {
|
|||||||
1 / (0)
|
1 / (0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
pow: {
|
pow: {
|
||||||
@@ -337,6 +339,7 @@ unsafe_constant: {
|
|||||||
(void 0).a
|
(void 0).a
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object: {
|
unsafe_object: {
|
||||||
@@ -360,6 +363,7 @@ unsafe_object: {
|
|||||||
1..b + 1
|
1..b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object_nested: {
|
unsafe_object_nested: {
|
||||||
@@ -383,6 +387,7 @@ unsafe_object_nested: {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object_complex: {
|
unsafe_object_complex: {
|
||||||
@@ -406,6 +411,7 @@ unsafe_object_complex: {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object_repeated: {
|
unsafe_object_repeated: {
|
||||||
@@ -429,6 +435,7 @@ unsafe_object_repeated: {
|
|||||||
1..b + 1
|
1..b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_object_accessor: {
|
unsafe_object_accessor: {
|
||||||
@@ -478,6 +485,7 @@ unsafe_function: {
|
|||||||
({a:{b:1},b:function(){}}).a.b + 1
|
({a:{b:1},b:function(){}}).a.b + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_integer_key: {
|
unsafe_integer_key: {
|
||||||
@@ -505,6 +513,7 @@ unsafe_integer_key: {
|
|||||||
1["1"] + 1
|
1["1"] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_integer_key_complex: {
|
unsafe_integer_key_complex: {
|
||||||
@@ -532,6 +541,7 @@ unsafe_integer_key_complex: {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_float_key: {
|
unsafe_float_key: {
|
||||||
@@ -559,6 +569,7 @@ unsafe_float_key: {
|
|||||||
1["3.14"] + 1
|
1["3.14"] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_float_key_complex: {
|
unsafe_float_key_complex: {
|
||||||
@@ -586,6 +597,7 @@ unsafe_float_key_complex: {
|
|||||||
2
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_array: {
|
unsafe_array: {
|
||||||
@@ -621,6 +633,7 @@ unsafe_array: {
|
|||||||
(void 0)[1] + 1
|
(void 0)[1] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_string: {
|
unsafe_string: {
|
||||||
@@ -648,6 +661,7 @@ unsafe_string: {
|
|||||||
"11"
|
"11"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_array_bad_index: {
|
unsafe_array_bad_index: {
|
||||||
@@ -669,6 +683,7 @@ unsafe_array_bad_index: {
|
|||||||
[1, 2, 3, 4][3.14] + 1
|
[1, 2, 3, 4][3.14] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_string_bad_index: {
|
unsafe_string_bad_index: {
|
||||||
@@ -690,6 +705,7 @@ unsafe_string_bad_index: {
|
|||||||
"1234"[3.14] + 1
|
"1234"[3.14] + 1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_prototype_function: {
|
unsafe_prototype_function: {
|
||||||
@@ -736,6 +752,7 @@ call_args: {
|
|||||||
console.log(1);
|
console.log(1);
|
||||||
+(1, 1);
|
+(1, 1);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
call_args_drop_param: {
|
call_args_drop_param: {
|
||||||
@@ -757,6 +774,7 @@ call_args_drop_param: {
|
|||||||
console.log(1);
|
console.log(1);
|
||||||
+(b, 1);
|
+(b, 1);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
in_boolean_context: {
|
in_boolean_context: {
|
||||||
@@ -794,4 +812,74 @@ in_boolean_context: {
|
|||||||
(foo(), !1)
|
(foo(), !1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_charAt: {
|
||||||
|
options = {
|
||||||
|
evaluate : true,
|
||||||
|
unsafe : true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
"1234" + 1,
|
||||||
|
"1234".charAt(0) + 1,
|
||||||
|
"1234".charAt(6 - 5) + 1,
|
||||||
|
("12" + "34").charAt(0) + 1,
|
||||||
|
("12" + "34").charAt(6 - 5) + 1,
|
||||||
|
[1, 2, 3, 4].join("").charAt(0) + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
"12341",
|
||||||
|
"11",
|
||||||
|
"21",
|
||||||
|
"11",
|
||||||
|
"21",
|
||||||
|
"11"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_charAt_bad_index: {
|
||||||
|
options = {
|
||||||
|
evaluate : true,
|
||||||
|
unsafe : true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
"1234".charAt() + 1,
|
||||||
|
"1234".charAt("a") + 1,
|
||||||
|
"1234".charAt(3.14) + 1
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
"11",
|
||||||
|
"11",
|
||||||
|
"41"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect_stdout: true
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe_charAt_noop: {
|
||||||
|
options = {
|
||||||
|
evaluate : true,
|
||||||
|
unsafe : true
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(
|
||||||
|
s.charAt(0),
|
||||||
|
"string".charAt(x)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(
|
||||||
|
s.charAt(0),
|
||||||
|
"string".charAt(x)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ iifes_returning_constants_keep_fargs_true: {
|
|||||||
console.log(6);
|
console.log(6);
|
||||||
console.log((a(), b(), 6));
|
console.log((a(), b(), 6));
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
iifes_returning_constants_keep_fargs_false: {
|
iifes_returning_constants_keep_fargs_false: {
|
||||||
@@ -73,6 +74,7 @@ iifes_returning_constants_keep_fargs_false: {
|
|||||||
console.log(6);
|
console.log(6);
|
||||||
console.log((a(), b(), 6));
|
console.log((a(), b(), 6));
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_485_crashing_1530: {
|
issue_485_crashing_1530: {
|
||||||
|
|||||||
@@ -47,22 +47,6 @@ html_comment_in_greater_than_or_equal: {
|
|||||||
expect_exact: "function f(a,b){return a-- >=b}";
|
expect_exact: "function f(a,b){return a-- >=b}";
|
||||||
}
|
}
|
||||||
|
|
||||||
html_comment_in_right_shift_assign: {
|
|
||||||
input: {
|
|
||||||
// Note: illegal javascript
|
|
||||||
function f(a, b) { return a-- >>= b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>=b}";
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_zero_fill_right_shift_assign: {
|
|
||||||
input: {
|
|
||||||
// Note: illegal javascript
|
|
||||||
function f(a, b) { return a-- >>>= b; }
|
|
||||||
}
|
|
||||||
expect_exact: "function f(a,b){return a-- >>>=b}";
|
|
||||||
}
|
|
||||||
|
|
||||||
html_comment_in_string_literal: {
|
html_comment_in_string_literal: {
|
||||||
input: {
|
input: {
|
||||||
function f() { return "<!--HTML-->comment in<!--string literal-->"; }
|
function f() { return "<!--HTML-->comment in<!--string literal-->"; }
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ non_hoisted_function_after_return_2a: {
|
|||||||
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
hoist_funs: false, dead_code: true, conditionals: true, comparisons: true,
|
||||||
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
evaluate: true, booleans: true, loops: true, unused: true, keep_fargs: true,
|
||||||
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
if_return: true, join_vars: true, cascade: true, side_effects: true,
|
||||||
collapse_vars: false, passes: 2
|
collapse_vars: false, passes: 2, warnings: "verbose"
|
||||||
}
|
}
|
||||||
input: {
|
input: {
|
||||||
function foo(x) {
|
function foo(x) {
|
||||||
@@ -75,7 +75,7 @@ non_hoisted_function_after_return_2a: {
|
|||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:53,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:56,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
"WARN: Dropping unused variable b [test/compress/issue-1034.js:51,20]",
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]"
|
"WARN: Dropping unused variable c [test/compress/issue-1034.js:53,16]",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,8 +114,5 @@ non_hoisted_function_after_return_2b: {
|
|||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:97,12]",
|
||||||
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,12]",
|
"WARN: Declarations in unreachable code! [test/compress/issue-1034.js:97,12]",
|
||||||
"WARN: Dropping unreachable code [test/compress/issue-1034.js:101,12]",
|
"WARN: Dropping unreachable code [test/compress/issue-1034.js:101,12]",
|
||||||
"WARN: Dropping unused variable b [test/compress/issue-1034.js:95,20]",
|
|
||||||
"WARN: Dropping unused variable c [test/compress/issue-1034.js:97,16]"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,4 +46,5 @@ string_plus_optimization: {
|
|||||||
}
|
}
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ issue_1321_no_debug: {
|
|||||||
x["a"] = 2 * x.b;
|
x["a"] = 2 * x.b;
|
||||||
console.log(x.b, x["a"]);
|
console.log(x.b, x["a"]);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1321_debug: {
|
issue_1321_debug: {
|
||||||
@@ -33,6 +34,7 @@ issue_1321_debug: {
|
|||||||
x["_$foo$_"] = 2 * x.a;
|
x["_$foo$_"] = 2 * x.a;
|
||||||
console.log(x.a, x["_$foo$_"]);
|
console.log(x.a, x["_$foo$_"]);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1321_with_quoted: {
|
issue_1321_with_quoted: {
|
||||||
@@ -51,4 +53,5 @@ issue_1321_with_quoted: {
|
|||||||
x["b"] = 2 * x.a;
|
x["b"] = 2 * x.a;
|
||||||
console.log(x.a, x["b"]);
|
console.log(x.a, x["b"]);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,4 +42,5 @@ conditional_false_stray_else_in_loop: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: "for(var i=1;i<=4;++i)if(!(i<=2))console.log(i);"
|
expect_exact: "for(var i=1;i<=4;++i)if(!(i<=2))console.log(i);"
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ same_variable_in_multiple_for_loop: {
|
|||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
cascade: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
collapse_vars: true
|
collapse_vars: true,
|
||||||
};
|
}
|
||||||
mangle = {};
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
let a = 100;
|
let a = 100;
|
||||||
@@ -38,6 +38,7 @@ same_variable_in_multiple_for_loop: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
same_variable_in_multiple_forOf: {
|
same_variable_in_multiple_forOf: {
|
||||||
@@ -55,9 +56,9 @@ same_variable_in_multiple_forOf: {
|
|||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
cascade: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
collapse_vars: true
|
collapse_vars: true,
|
||||||
};
|
}
|
||||||
mangle = {};
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
var test = [ "a", "b", "c" ];
|
var test = [ "a", "b", "c" ];
|
||||||
for (let tmp of test) {
|
for (let tmp of test) {
|
||||||
@@ -75,10 +76,11 @@ same_variable_in_multiple_forOf: {
|
|||||||
console.log(o);
|
console.log(o);
|
||||||
let e;
|
let e;
|
||||||
e = [ "e", "f", "g" ];
|
e = [ "e", "f", "g" ];
|
||||||
for (let o of e)
|
for (let o of e)
|
||||||
console.log(o);
|
console.log(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
same_variable_in_multiple_forIn: {
|
same_variable_in_multiple_forIn: {
|
||||||
@@ -96,9 +98,9 @@ same_variable_in_multiple_forIn: {
|
|||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
cascade: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
collapse_vars: true
|
collapse_vars: true,
|
||||||
};
|
}
|
||||||
mangle = {};
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
var test = [ "a", "b", "c" ];
|
var test = [ "a", "b", "c" ];
|
||||||
for (let tmp in test) {
|
for (let tmp in test) {
|
||||||
@@ -120,6 +122,7 @@ same_variable_in_multiple_forIn: {
|
|||||||
console.log(o);
|
console.log(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
different_variable_in_multiple_for_loop: {
|
different_variable_in_multiple_for_loop: {
|
||||||
@@ -137,9 +140,9 @@ different_variable_in_multiple_for_loop: {
|
|||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
cascade: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
collapse_vars: true
|
collapse_vars: true,
|
||||||
};
|
}
|
||||||
mangle = {};
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
let a = 100;
|
let a = 100;
|
||||||
@@ -162,6 +165,7 @@ different_variable_in_multiple_for_loop: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
different_variable_in_multiple_forOf: {
|
different_variable_in_multiple_forOf: {
|
||||||
@@ -179,9 +183,9 @@ different_variable_in_multiple_forOf: {
|
|||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
cascade: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
collapse_vars: true
|
collapse_vars: true,
|
||||||
};
|
}
|
||||||
mangle = {};
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
var test = [ "a", "b", "c" ];
|
var test = [ "a", "b", "c" ];
|
||||||
for (let tmp of test) {
|
for (let tmp of test) {
|
||||||
@@ -203,6 +207,7 @@ different_variable_in_multiple_forOf: {
|
|||||||
console.log(o);
|
console.log(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
different_variable_in_multiple_forIn: {
|
different_variable_in_multiple_forIn: {
|
||||||
@@ -220,9 +225,9 @@ different_variable_in_multiple_forIn: {
|
|||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
cascade: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
collapse_vars: true
|
collapse_vars: true,
|
||||||
};
|
}
|
||||||
mangle = {};
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
var test = [ "a", "b", "c" ];
|
var test = [ "a", "b", "c" ];
|
||||||
for (let tmp in test) {
|
for (let tmp in test) {
|
||||||
@@ -244,6 +249,7 @@ different_variable_in_multiple_forIn: {
|
|||||||
console.log(o);
|
console.log(o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
more_variable_in_multiple_for: {
|
more_variable_in_multiple_for: {
|
||||||
@@ -261,9 +267,9 @@ more_variable_in_multiple_for: {
|
|||||||
join_vars: true,
|
join_vars: true,
|
||||||
cascade: true,
|
cascade: true,
|
||||||
side_effects: true,
|
side_effects: true,
|
||||||
collapse_vars: true
|
collapse_vars: true,
|
||||||
};
|
}
|
||||||
mangle = {};
|
mangle = {}
|
||||||
input: {
|
input: {
|
||||||
for (let a = 9, i = 0; i < 20; i += a) {
|
for (let a = 9, i = 0; i < 20; i += a) {
|
||||||
let b = a++ + i;
|
let b = a++ + i;
|
||||||
@@ -281,5 +287,5 @@ more_variable_in_multiple_for: {
|
|||||||
console.log(o, c, e, l, f);
|
console.log(o, c, e, l, f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ dead_code_const_annotation_regex: {
|
|||||||
var CONST_FOO_ANN = !1;
|
var CONST_FOO_ANN = !1;
|
||||||
if (CONST_FOO_ANN) console.log('reachable');
|
if (CONST_FOO_ANN) console.log('reachable');
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
drop_console_2: {
|
drop_console_2: {
|
||||||
@@ -225,6 +226,7 @@ issue_1254_negate_iife_true: {
|
|||||||
})()();
|
})()();
|
||||||
}
|
}
|
||||||
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1254_negate_iife_nested: {
|
issue_1254_negate_iife_nested: {
|
||||||
@@ -240,6 +242,7 @@ issue_1254_negate_iife_nested: {
|
|||||||
})()()()()();
|
})()()()()();
|
||||||
}
|
}
|
||||||
expect_exact: '(function(){return function(){console.log("test")}})()()()()();'
|
expect_exact: '(function(){return function(){console.log("test")}})()()()()();'
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
conditional: {
|
conditional: {
|
||||||
|
|||||||
@@ -29,4 +29,5 @@ dont_mangle_arguments: {
|
|||||||
})(5,6,7);
|
})(5,6,7);
|
||||||
}
|
}
|
||||||
expect_exact: "(function(){var arguments=arguments,o=9;console.log(o,arguments)})(5,6,7);"
|
expect_exact: "(function(){var arguments=arguments,o=9;console.log(o,arguments)})(5,6,7);"
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ eval_collapse_vars: {
|
|||||||
eval("console.log(a);");
|
eval("console.log(a);");
|
||||||
})(eval);
|
})(eval);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
eval_unused: {
|
eval_unused: {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ labels_1: {
|
|||||||
expect: {
|
expect: {
|
||||||
foo || console.log("bar");
|
foo || console.log("bar");
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
labels_2: {
|
labels_2: {
|
||||||
@@ -40,6 +41,7 @@ labels_3: {
|
|||||||
for (var i = 0; i < 5; ++i)
|
for (var i = 0; i < 5; ++i)
|
||||||
i < 3 || console.log(i);
|
i < 3 || console.log(i);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
labels_4: {
|
labels_4: {
|
||||||
@@ -54,6 +56,7 @@ labels_4: {
|
|||||||
for (var i = 0; i < 5; ++i)
|
for (var i = 0; i < 5; ++i)
|
||||||
i < 3 || console.log(i);
|
i < 3 || console.log(i);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
labels_5: {
|
labels_5: {
|
||||||
|
|||||||
@@ -166,6 +166,7 @@ keep_collapse_const_in_own_block_scope: {
|
|||||||
console.log(i);
|
console.log(i);
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
keep_collapse_const_in_own_block_scope_2: {
|
keep_collapse_const_in_own_block_scope_2: {
|
||||||
@@ -186,6 +187,7 @@ keep_collapse_const_in_own_block_scope_2: {
|
|||||||
console.log(i);
|
console.log(i);
|
||||||
console.log(c);
|
console.log(c);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluate: {
|
evaluate: {
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ negate_iife_3_evaluate: {
|
|||||||
expect: {
|
expect: {
|
||||||
console.log(true);
|
console.log(true);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
negate_iife_3_side_effects: {
|
negate_iife_3_side_effects: {
|
||||||
@@ -111,6 +112,7 @@ negate_iife_3_off_evaluate: {
|
|||||||
expect: {
|
expect: {
|
||||||
console.log(true);
|
console.log(true);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
negate_iife_4: {
|
negate_iife_4: {
|
||||||
@@ -243,6 +245,7 @@ negate_iife_nested: {
|
|||||||
}(7);
|
}(7);
|
||||||
}).f();
|
}).f();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
negate_iife_nested_off: {
|
negate_iife_nested_off: {
|
||||||
@@ -275,6 +278,7 @@ negate_iife_nested_off: {
|
|||||||
})(7);
|
})(7);
|
||||||
}).f();
|
}).f();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
negate_iife_issue_1073: {
|
negate_iife_issue_1073: {
|
||||||
@@ -299,6 +303,7 @@ negate_iife_issue_1073: {
|
|||||||
};
|
};
|
||||||
}(7))();
|
}(7))();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1254_negate_iife_false: {
|
issue_1254_negate_iife_false: {
|
||||||
@@ -313,6 +318,7 @@ issue_1254_negate_iife_false: {
|
|||||||
})()();
|
})()();
|
||||||
}
|
}
|
||||||
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
expect_exact: '(function(){return function(){console.log("test")}})()();'
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1254_negate_iife_true: {
|
issue_1254_negate_iife_true: {
|
||||||
@@ -327,6 +333,7 @@ issue_1254_negate_iife_true: {
|
|||||||
})()();
|
})()();
|
||||||
}
|
}
|
||||||
expect_exact: '!function(){return function(){console.log("test")}}()();'
|
expect_exact: '!function(){return function(){console.log("test")}}()();'
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1254_negate_iife_nested: {
|
issue_1254_negate_iife_nested: {
|
||||||
@@ -341,6 +348,7 @@ issue_1254_negate_iife_nested: {
|
|||||||
})()()()()();
|
})()()()()();
|
||||||
}
|
}
|
||||||
expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
|
expect_exact: '!function(){return function(){console.log("test")}}()()()()();'
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1288: {
|
issue_1288: {
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ reduce_vars: {
|
|||||||
})();
|
})();
|
||||||
console.log(2);
|
console.log(2);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
modified: {
|
modified: {
|
||||||
@@ -166,7 +167,7 @@ modified: {
|
|||||||
console.log(A ? 'yes' : 'no');
|
console.log(A ? 'yes' : 'no');
|
||||||
console.log(B ? 'yes' : 'no');
|
console.log(B ? 'yes' : 'no');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe_evaluate: {
|
unsafe_evaluate: {
|
||||||
@@ -401,6 +402,7 @@ iife: {
|
|||||||
console.log(0, 1 * b, 5);
|
console.log(0, 1 * b, 5);
|
||||||
}(1, 2, 3);
|
}(1, 2, 3);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
iife_new: {
|
iife_new: {
|
||||||
@@ -420,6 +422,7 @@ iife_new: {
|
|||||||
console.log(0, 1 * b, 5);
|
console.log(0, 1 * b, 5);
|
||||||
}(1, 2, 3);
|
}(1, 2, 3);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
multi_def: {
|
multi_def: {
|
||||||
@@ -707,6 +710,7 @@ toplevel_on: {
|
|||||||
expect: {
|
expect: {
|
||||||
console.log(3);
|
console.log(3);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
toplevel_off: {
|
toplevel_off: {
|
||||||
@@ -724,6 +728,7 @@ toplevel_off: {
|
|||||||
var x = 3;
|
var x = 3;
|
||||||
console.log(x);
|
console.log(x);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
toplevel_on_loops_1: {
|
toplevel_on_loops_1: {
|
||||||
@@ -751,6 +756,7 @@ toplevel_on_loops_1: {
|
|||||||
})();
|
})();
|
||||||
while (x);
|
while (x);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
toplevel_off_loops_1: {
|
toplevel_off_loops_1: {
|
||||||
@@ -779,6 +785,7 @@ toplevel_off_loops_1: {
|
|||||||
bar();
|
bar();
|
||||||
while (x);
|
while (x);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
toplevel_on_loops_2: {
|
toplevel_on_loops_2: {
|
||||||
@@ -1121,6 +1128,7 @@ defun_label: {
|
|||||||
}(2));
|
}(2));
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
double_reference: {
|
double_reference: {
|
||||||
@@ -1164,6 +1172,7 @@ iife_arguments_1: {
|
|||||||
return f;
|
return f;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
iife_arguments_2: {
|
iife_arguments_2: {
|
||||||
@@ -1186,6 +1195,7 @@ iife_arguments_2: {
|
|||||||
}() === arguments[0]);
|
}() === arguments[0]);
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
iife_eval_1: {
|
iife_eval_1: {
|
||||||
@@ -1207,6 +1217,7 @@ iife_eval_1: {
|
|||||||
return f;
|
return f;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
iife_eval_2: {
|
iife_eval_2: {
|
||||||
@@ -1230,6 +1241,7 @@ iife_eval_2: {
|
|||||||
console.log(x() === eval("x"));
|
console.log(x() === eval("x"));
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
iife_func_side_effects: {
|
iife_func_side_effects: {
|
||||||
@@ -1326,6 +1338,7 @@ issue_1595_4: {
|
|||||||
if (a) iife(a - 1, b, c);
|
if (a) iife(a - 1, b, c);
|
||||||
})(3, 4, 5);
|
})(3, 4, 5);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1606: {
|
issue_1606: {
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ do_screw_try_catch_undefined: {
|
|||||||
return void 0===o
|
return void 0===o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
dont_screw_try_catch_undefined: {
|
dont_screw_try_catch_undefined: {
|
||||||
@@ -156,6 +157,7 @@ dont_screw_try_catch_undefined: {
|
|||||||
return n === undefined
|
return n === undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
reduce_vars: {
|
reduce_vars: {
|
||||||
@@ -208,6 +210,7 @@ issue_1586_1: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
issue_1586_2: {
|
issue_1586_2: {
|
||||||
@@ -226,4 +229,5 @@ issue_1586_2: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
expect_exact: "function f(){try{}catch(c){console.log(c.message)}}"
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ make_sequences_4: {
|
|||||||
switch (x = 5, y) {}
|
switch (x = 5, y) {}
|
||||||
with (x = 5, obj);
|
with (x = 5, obj);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
lift_sequences_1: {
|
lift_sequences_1: {
|
||||||
@@ -103,15 +104,18 @@ lift_sequences_1: {
|
|||||||
lift_sequences_2: {
|
lift_sequences_2: {
|
||||||
options = { sequences: true, evaluate: true };
|
options = { sequences: true, evaluate: true };
|
||||||
input: {
|
input: {
|
||||||
var foo, bar;
|
var foo = 1, bar;
|
||||||
foo.x = (foo = {}, 10);
|
foo.x = (foo = {}, 10);
|
||||||
bar = (bar = {}, 10);
|
bar = (bar = {}, 10);
|
||||||
|
console.log(foo, bar);
|
||||||
}
|
}
|
||||||
expect: {
|
expect: {
|
||||||
var foo, bar;
|
var foo = 1, bar;
|
||||||
foo.x = (foo = {}, 10),
|
foo.x = (foo = {}, 10),
|
||||||
bar = {}, bar = 10;
|
bar = {}, bar = 10,
|
||||||
|
console.log(foo, bar);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
lift_sequences_3: {
|
lift_sequences_3: {
|
||||||
@@ -138,6 +142,23 @@ lift_sequences_4: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lift_sequences_5: {
|
||||||
|
options = {
|
||||||
|
sequences: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = 2, b;
|
||||||
|
a *= (b, a = 4, 3);
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = 2, b;
|
||||||
|
b, a *= (a = 4, 3),
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "6"
|
||||||
|
}
|
||||||
|
|
||||||
for_sequences: {
|
for_sequences: {
|
||||||
options = { sequences: true };
|
options = { sequences: true };
|
||||||
input: {
|
input: {
|
||||||
@@ -230,6 +251,7 @@ negate_iife_for: {
|
|||||||
for (!function() {}(), i = 0; i < 5; i++) console.log(i);
|
for (!function() {}(), i = 0; i < 5; i++) console.log(i);
|
||||||
for (function() {}(); i < 5; i++) console.log(i);
|
for (function() {}(); i < 5; i++) console.log(i);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
iife: {
|
iife: {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ booleans_evaluate: {
|
|||||||
console.log(!0, !0);
|
console.log(!0, !0);
|
||||||
console.log(!1, !1);
|
console.log(!1, !1);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
booleans_global_defs: {
|
booleans_global_defs: {
|
||||||
@@ -29,6 +30,7 @@ booleans_global_defs: {
|
|||||||
expect: {
|
expect: {
|
||||||
console.log(!0);
|
console.log(!0);
|
||||||
}
|
}
|
||||||
|
expect_stdout: true
|
||||||
}
|
}
|
||||||
|
|
||||||
condition_evaluate: {
|
condition_evaluate: {
|
||||||
|
|||||||
1
test/input/issue-1632/^{foo}[bar](baz)+$.js
Normal file
1
test/input/issue-1632/^{foo}[bar](baz)+$.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
console.log(x);
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
var Uglify = require('../../');
|
var Uglify = require('../../');
|
||||||
var assert = require("assert");
|
var assert = require("assert");
|
||||||
|
var path = require("path");
|
||||||
|
|
||||||
describe("minify() with input file globs", function() {
|
describe("minify() with input file globs", function() {
|
||||||
it("minify() with one input file glob string.", function() {
|
it("minify() with one input file glob string.", function() {
|
||||||
var result = Uglify.minify("test/input/issue-1242/foo.*");
|
var result = Uglify.minify("test/input/issue-1242/foo.*");
|
||||||
assert.strictEqual(result.code, 'function foo(o){print("Foo:",2*o)}var print=console.log.bind(console);');
|
assert.strictEqual(result.code, 'function foo(o){var n=2*o;print("Foo:",n)}var print=console.log.bind(console);');
|
||||||
});
|
});
|
||||||
it("minify() with an array of one input file glob.", function() {
|
it("minify() with an array of one input file glob.", function() {
|
||||||
var result = Uglify.minify([
|
var result = Uglify.minify([
|
||||||
@@ -19,6 +20,39 @@ describe("minify() with input file globs", function() {
|
|||||||
], {
|
], {
|
||||||
compress: { toplevel: true }
|
compress: { toplevel: true }
|
||||||
});
|
});
|
||||||
assert.strictEqual(result.code, 'var print=console.log.bind(console);print("qux",function(n){return 3*n}(3),function(n){return n/2}(12)),function(n){print("Foo:",2*n)}(11);');
|
assert.strictEqual(result.code, 'var print=console.log.bind(console),a=function(n){return 3*n}(3),b=function(n){return n/2}(12);print("qux",a,b),function(n){var o=2*n;print("Foo:",o)}(11);');
|
||||||
|
});
|
||||||
|
it("should throw with non-matching glob string", function() {
|
||||||
|
var glob = "test/input/issue-1242/blah.*";
|
||||||
|
assert.strictEqual(Uglify.simple_glob(glob).length, 1);
|
||||||
|
assert.strictEqual(Uglify.simple_glob(glob)[0], glob);
|
||||||
|
assert.throws(function() {
|
||||||
|
Uglify.minify(glob);
|
||||||
|
}, "should throw file not found");
|
||||||
|
});
|
||||||
|
it('"?" in glob string should not match "/"', function() {
|
||||||
|
var glob = "test/input?issue-1242/foo.*";
|
||||||
|
assert.strictEqual(Uglify.simple_glob(glob).length, 1);
|
||||||
|
assert.strictEqual(Uglify.simple_glob(glob)[0], glob);
|
||||||
|
assert.throws(function() {
|
||||||
|
Uglify.minify(glob);
|
||||||
|
}, "should throw file not found");
|
||||||
|
});
|
||||||
|
it("should handle special characters in glob string", function() {
|
||||||
|
var result = Uglify.minify("test/input/issue-1632/^{*}[???](*)+$.??");
|
||||||
|
assert.strictEqual(result.code, "console.log(x);");
|
||||||
|
});
|
||||||
|
it("should handle array of glob strings - matching and otherwise", function() {
|
||||||
|
var dir = "test/input/issue-1242";
|
||||||
|
var matches = Uglify.simple_glob([
|
||||||
|
path.join(dir, "b*.es5"),
|
||||||
|
path.join(dir, "z*.es5"),
|
||||||
|
path.join(dir, "*.js"),
|
||||||
|
]);
|
||||||
|
assert.strictEqual(matches.length, 4);
|
||||||
|
assert.strictEqual(matches[0], path.join(dir, "bar.es5"));
|
||||||
|
assert.strictEqual(matches[1], path.join(dir, "baz.es5"));
|
||||||
|
assert.strictEqual(matches[2], path.join(dir, "z*.es5"));
|
||||||
|
assert.strictEqual(matches[3], path.join(dir, "qux.js"));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var UglifyJS = require(".."),
|
|||||||
escodegen = require("escodegen"),
|
escodegen = require("escodegen"),
|
||||||
esfuzz = require("esfuzz"),
|
esfuzz = require("esfuzz"),
|
||||||
estraverse = require("estraverse"),
|
estraverse = require("estraverse"),
|
||||||
prefix = Array(20).join("\b") + " ";
|
prefix = "\r ";
|
||||||
|
|
||||||
// Normalizes input AST for UglifyJS in order to get correct comparison.
|
// Normalizes input AST for UglifyJS in order to get correct comparison.
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ module.exports = function(options) {
|
|||||||
var ast1 = normalizeInput(esfuzz.generate({
|
var ast1 = normalizeInput(esfuzz.generate({
|
||||||
maxDepth: options.maxDepth
|
maxDepth: options.maxDepth
|
||||||
}));
|
}));
|
||||||
|
|
||||||
var ast2 =
|
var ast2 =
|
||||||
UglifyJS
|
UglifyJS
|
||||||
.AST_Node
|
.AST_Node
|
||||||
|
|||||||
@@ -11,6 +11,17 @@ var vm = require("vm");
|
|||||||
var tests_dir = path.dirname(module.filename);
|
var tests_dir = path.dirname(module.filename);
|
||||||
var failures = 0;
|
var failures = 0;
|
||||||
var failed_files = {};
|
var failed_files = {};
|
||||||
|
var same_stdout = ~process.version.lastIndexOf("v0.12.", 0) ? function(expected, actual) {
|
||||||
|
if (typeof expected != typeof actual) return false;
|
||||||
|
if (typeof expected != "string") {
|
||||||
|
if (expected.name != actual.name) return false;
|
||||||
|
expected = expected.message.slice(expected.message.lastIndexOf("\n") + 1);
|
||||||
|
actual = actual.message.slice(actual.message.lastIndexOf("\n") + 1);
|
||||||
|
}
|
||||||
|
return expected == actual;
|
||||||
|
} : function(expected, actual) {
|
||||||
|
return typeof expected == typeof actual && expected.toString() == actual.toString();
|
||||||
|
};
|
||||||
|
|
||||||
run_compress_tests();
|
run_compress_tests();
|
||||||
if (failures) {
|
if (failures) {
|
||||||
@@ -103,7 +114,7 @@ function run_compress_tests() {
|
|||||||
U.AST_Node.warn_function = function(text) {
|
U.AST_Node.warn_function = function(text) {
|
||||||
warnings_emitted.push("WARN: " + text);
|
warnings_emitted.push("WARN: " + text);
|
||||||
};
|
};
|
||||||
options.warnings = true;
|
if (!options.warnings) options.warnings = true;
|
||||||
}
|
}
|
||||||
var cmp = new U.Compressor(options, true);
|
var cmp = new U.Compressor(options, true);
|
||||||
var output_options = test.beautify || {};
|
var output_options = test.beautify || {};
|
||||||
@@ -172,7 +183,7 @@ function run_compress_tests() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (test.expect_stdout) {
|
if (test.expect_stdout) {
|
||||||
var stdout = run_code(input_code);
|
var stdout = run_code(make_code(input, output_options));
|
||||||
if (test.expect_stdout === true) {
|
if (test.expect_stdout === true) {
|
||||||
test.expect_stdout = stdout;
|
test.expect_stdout = stdout;
|
||||||
}
|
}
|
||||||
@@ -336,7 +347,3 @@ function run_code(code) {
|
|||||||
process.stdout.write = original_write;
|
process.stdout.write = original_write;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function same_stdout(expected, actual) {
|
|
||||||
return typeof expected == typeof actual && expected.toString() == actual.toString();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,6 +18,6 @@ exports["tokenizer"] = tokenizer;
|
|||||||
exports["is_identifier"] = is_identifier;
|
exports["is_identifier"] = is_identifier;
|
||||||
exports["SymbolDef"] = SymbolDef;
|
exports["SymbolDef"] = SymbolDef;
|
||||||
|
|
||||||
if (typeof DEBUG !== "undefined" && DEBUG) {
|
if (global.UGLIFY_DEBUG) {
|
||||||
exports["EXPECT_DIRECTIVE"] = EXPECT_DIRECTIVE;
|
exports["EXPECT_DIRECTIVE"] = EXPECT_DIRECTIVE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
var path = require("path");
|
var path = require("path");
|
||||||
var fs = require("fs");
|
var fs = require("fs");
|
||||||
|
|
||||||
var FILES = exports.FILES = [
|
var UglifyJS = exports;
|
||||||
|
var FILES = UglifyJS.FILES = [
|
||||||
"../lib/utils.js",
|
"../lib/utils.js",
|
||||||
"../lib/ast.js",
|
"../lib/ast.js",
|
||||||
"../lib/parse.js",
|
"../lib/parse.js",
|
||||||
@@ -20,17 +21,14 @@ var FILES = exports.FILES = [
|
|||||||
"../lib/propmangle.js",
|
"../lib/propmangle.js",
|
||||||
"./exports.js",
|
"./exports.js",
|
||||||
].map(function(file){
|
].map(function(file){
|
||||||
return fs.realpathSync(path.join(path.dirname(__filename), file));
|
return require.resolve(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
var UglifyJS = exports;
|
new Function("MOZ_SourceMap", "exports", FILES.map(function(file){
|
||||||
|
|
||||||
new Function("MOZ_SourceMap", "exports", "DEBUG", FILES.map(function(file){
|
|
||||||
return fs.readFileSync(file, "utf8");
|
return fs.readFileSync(file, "utf8");
|
||||||
}).join("\n\n"))(
|
}).join("\n\n"))(
|
||||||
require("source-map"),
|
require("source-map"),
|
||||||
UglifyJS,
|
UglifyJS
|
||||||
!!global.UGLIFY_DEBUG
|
|
||||||
);
|
);
|
||||||
|
|
||||||
UglifyJS.AST_Node.warn_function = function(txt) {
|
UglifyJS.AST_Node.warn_function = function(txt) {
|
||||||
@@ -46,7 +44,7 @@ function read_source_map(code) {
|
|||||||
return JSON.parse(new Buffer(match[2], "base64"));
|
return JSON.parse(new Buffer(match[2], "base64"));
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.minify = function(files, options) {
|
UglifyJS.minify = function(files, options) {
|
||||||
options = UglifyJS.defaults(options, {
|
options = UglifyJS.defaults(options, {
|
||||||
spidermonkey : false,
|
spidermonkey : false,
|
||||||
outSourceMap : null,
|
outSourceMap : null,
|
||||||
@@ -181,7 +179,7 @@ exports.minify = function(files, options) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// exports.describe_ast = function() {
|
// UglifyJS.describe_ast = function() {
|
||||||
// function doitem(ctor) {
|
// function doitem(ctor) {
|
||||||
// var sub = {};
|
// var sub = {};
|
||||||
// ctor.SUBCLASSES.forEach(function(ctor){
|
// ctor.SUBCLASSES.forEach(function(ctor){
|
||||||
@@ -195,7 +193,7 @@ exports.minify = function(files, options) {
|
|||||||
// return doitem(UglifyJS.AST_Node).sub;
|
// return doitem(UglifyJS.AST_Node).sub;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
exports.describe_ast = function() {
|
UglifyJS.describe_ast = function() {
|
||||||
var out = UglifyJS.OutputStream({ beautify: true });
|
var out = UglifyJS.OutputStream({ beautify: true });
|
||||||
function doitem(ctor) {
|
function doitem(ctor) {
|
||||||
out.print("AST_" + ctor.TYPE);
|
out.print("AST_" + ctor.TYPE);
|
||||||
@@ -249,13 +247,13 @@ function readReservedFile(filename, reserved) {
|
|||||||
return reserved;
|
return reserved;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.readReservedFile = readReservedFile;
|
UglifyJS.readReservedFile = readReservedFile;
|
||||||
|
|
||||||
exports.readDefaultReservedFile = function(reserved) {
|
UglifyJS.readDefaultReservedFile = function(reserved) {
|
||||||
return readReservedFile(path.join(__dirname, "domprops.json"), reserved);
|
return readReservedFile(require.resolve("./domprops.json"), reserved);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.readNameCache = function(filename, key) {
|
UglifyJS.readNameCache = function(filename, key) {
|
||||||
var cache = null;
|
var cache = null;
|
||||||
if (filename) {
|
if (filename) {
|
||||||
try {
|
try {
|
||||||
@@ -273,7 +271,7 @@ exports.readNameCache = function(filename, key) {
|
|||||||
return cache;
|
return cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.writeNameCache = function(filename, key, cache) {
|
UglifyJS.writeNameCache = function(filename, key, cache) {
|
||||||
if (filename) {
|
if (filename) {
|
||||||
var data;
|
var data;
|
||||||
try {
|
try {
|
||||||
@@ -294,13 +292,9 @@ exports.writeNameCache = function(filename, key, cache) {
|
|||||||
// Example: "foo/bar/*baz??.*.js"
|
// Example: "foo/bar/*baz??.*.js"
|
||||||
// Argument `glob` may be a string or an array of strings.
|
// Argument `glob` may be a string or an array of strings.
|
||||||
// Returns an array of strings. Garbage in, garbage out.
|
// Returns an array of strings. Garbage in, garbage out.
|
||||||
exports.simple_glob = function simple_glob(glob) {
|
UglifyJS.simple_glob = function simple_glob(glob) {
|
||||||
var results = [];
|
|
||||||
if (Array.isArray(glob)) {
|
if (Array.isArray(glob)) {
|
||||||
glob.forEach(function(elem) {
|
return [].concat.apply([], glob.map(simple_glob));
|
||||||
results = results.concat(simple_glob(elem));
|
|
||||||
});
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
if (glob.match(/\*|\?/)) {
|
if (glob.match(/\*|\?/)) {
|
||||||
var dir = path.dirname(glob);
|
var dir = path.dirname(glob);
|
||||||
@@ -308,28 +302,19 @@ exports.simple_glob = function simple_glob(glob) {
|
|||||||
var entries = fs.readdirSync(dir);
|
var entries = fs.readdirSync(dir);
|
||||||
} catch (ex) {}
|
} catch (ex) {}
|
||||||
if (entries) {
|
if (entries) {
|
||||||
var pattern = "^" + (path.basename(glob)
|
var pattern = "^" + path.basename(glob)
|
||||||
.replace(/\(/g, "\\(")
|
.replace(/[.+^$[\]\\(){}]/g, "\\$&")
|
||||||
.replace(/\)/g, "\\)")
|
|
||||||
.replace(/\{/g, "\\{")
|
|
||||||
.replace(/\}/g, "\\}")
|
|
||||||
.replace(/\[/g, "\\[")
|
|
||||||
.replace(/\]/g, "\\]")
|
|
||||||
.replace(/\+/g, "\\+")
|
|
||||||
.replace(/\^/g, "\\^")
|
|
||||||
.replace(/\$/g, "\\$")
|
|
||||||
.replace(/\*/g, "[^/\\\\]*")
|
.replace(/\*/g, "[^/\\\\]*")
|
||||||
.replace(/\./g, "\\.")
|
.replace(/\?/g, "[^/\\\\]") + "$";
|
||||||
.replace(/\?/g, ".")) + "$";
|
|
||||||
var mod = process.platform === "win32" ? "i" : "";
|
var mod = process.platform === "win32" ? "i" : "";
|
||||||
var rx = new RegExp(pattern, mod);
|
var rx = new RegExp(pattern, mod);
|
||||||
for (var i in entries) {
|
var results = entries.filter(function(name) {
|
||||||
if (rx.test(entries[i]))
|
return rx.test(name);
|
||||||
results.push(dir + "/" + entries[i]);
|
}).map(function(name) {
|
||||||
}
|
return path.join(dir, name);
|
||||||
|
});
|
||||||
|
if (results.length) return results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (results.length === 0)
|
return [ glob ];
|
||||||
results = [ glob ];
|
|
||||||
return results;
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user