Compare commits

...

34 Commits

Author SHA1 Message Date
Mihai Bazon
547561a568 v2.4.5 2013-11-28 13:15:27 +02:00
Mihai Bazon
c16d538ce7 Add --noerr to turn off argument name checking
for now only used for keys passed to `-c` or `-b`.
2013-11-28 13:15:01 +02:00
Mihai Bazon
73d082df2e v2.4.4 2013-11-27 14:24:26 +02:00
Mihai Bazon
50b8d7272c Fix faulty compression
`String(x + 5)` is not always the same as `x + "5"`.  Overlooked that. :-(

Close #350
2013-11-20 21:13:16 +02:00
Mihai Bazon
7d11b96f48 Only descend twice after drop_unused if it's the same node type.
Fix #345
2013-11-08 11:57:17 +02:00
Mihai Bazon
eab99a1c3d Better fix for #343
We can in fact lift sequences, but only if the operation is assignment and
the left-hand side has no side effects nor property access -- that should
guarantee that whatever we place before it cannot affect the sense of the
assignment.

Dropped contrived test case (too hard to support it now), added a more
meaningful one.
2013-11-06 10:48:48 +02:00
Mihai Bazon
19e2fb134d v2.4.3 2013-11-06 10:21:29 +02:00
Mihai Bazon
f4919e3a25 Do not lift sequence from right-hand side of binary operation. Fix #343 2013-11-06 10:18:28 +02:00
Mihai Bazon
bb700daa4c v2.4.2 2013-11-03 23:41:07 +02:00
Mihai Bazon
263577d5eb [README] Fix #278 2013-10-30 14:13:30 +02:00
Mihai Bazon
63287c0e68 Workaround for Safari bug
Close #313
2013-10-30 13:59:59 +02:00
Mihai Bazon
c5ed2292bf Fix parsing setters/getters (allow keywords for name).
The "key" property was always "set" or "get", which didn't make much sense.
Now it'll be the actual name of the setter/getter (AST_Node), and the
AST_Accessor object itself, which represents the function, won't store any
name.

Close #319
2013-10-30 11:50:22 +02:00
Mihai Bazon
b70670b69f Fix regression after e4c5302406
`x * (y * z)` ==> `x * y * z` -- the better place to do this is in the
compressor rather than codegen.
2013-10-30 10:45:58 +02:00
Mihai Bazon
9dd97605bc indentation 2013-10-30 10:44:50 +02:00
Mihai Bazon
e4c5302406 Fix output for x = 2 * (a % b / b * c)
(issue #337)
2013-10-30 09:11:55 +02:00
Mihai Bazon
bea3d90771 minor 2013-10-30 09:10:56 +02:00
Richard van Velzen
785c6064cc Disallow reversal where lhs has higher or equal precedence
Fixes #267
2013-10-29 21:37:36 +01:00
Mihai Bazon
b214d3786f Fix typo 2013-10-29 15:53:54 +02:00
Mihai Bazon
7cf79c302b Fix reading arguments
i.e. read `-c unsafe,unsafe-comps` as `-c unsafe=true,unsafe_comps=true`
2013-10-29 14:01:26 +02:00
Mihai Bazon
a14c6b6574 Avoid shadowing name of function expression with function argument
Close #179, #326, #327
2013-10-29 13:18:09 +02:00
Mihai Bazon
f1b7094a57 Add "preamble" output option
Close #335
2013-10-29 11:09:18 +02:00
Mihai Bazon
0358e376f0 Fix codegen for when comments_before is undefined.
Fix #333
2013-10-28 09:39:29 +02:00
Mihai Bazon
b47f7b76b9 Merge branch 'master' of github.com:mishoo/UglifyJS2 2013-10-27 10:03:01 +02:00
Mihai Bazon
582cc55cff Display number of failed tests and corresponding files 2013-10-27 10:02:44 +02:00
Mihai Bazon
8979579e55 Merge pull request #330 from markjaquith/master
Unit test to detect issue in 8d14efe for #126 that causes aggressive parenthesis removal, functional differences
2013-10-27 01:01:57 -07:00
Mihai Bazon
0d6e08c541 Merge pull request #331 from rvanvelzen/rhs-strings-fix
Fix RHS concat (raised in #330)
2013-10-27 01:01:11 -07:00
Richard van Velzen
e2daee9a65 Fix RHS concat (raised in #330)
When attempting to concat the left-side of the rhs, make sure the rhs is
a string.
2013-10-26 18:44:52 +02:00
Mark Jaquith
9cd118ca3d Add a unit test for issue-126
Add a unit test to test to test for aggressive parenthesis removal that causes functional changes.
2013-10-25 16:28:15 -04:00
Mihai Bazon
cfd5c6155c Merge pull request #325 from rvanvelzen/fix-269
Fix #269
2013-10-24 02:39:07 -07:00
Richard van Velzen
1a5a4bd631 Fix #269
Shorten most primitives where possible. Also optimize some edge cases.
2013-10-24 11:08:33 +02:00
Mihai Bazon
63e1a8e1fd Merge pull request #323 from rvanvelzen/undefined-drop-vars-fix
Fix #280
2013-10-23 13:58:09 -07:00
Richard van Velzen
7055af8221 Fix #280
The `init` of the `ForStatement` is not a `BlockStatement` before it was
descended. The descend has to happen first, and *then* the actual
checks.
2013-10-23 22:26:04 +02:00
Mihai Bazon
aafe2e1db3 Merge pull request #322 from rvanvelzen/test-exit-code-1
Add an exit code to the test suite
2013-10-23 11:37:36 -07:00
Richard van Velzen
118105db43 Add an exit code to the test suite
By adding the exit code 1 (or any other non-zero exit code) `npm test`
will know the tests didn't perform correctly. This way it's easier to
know if pull requests are good or bad.
2013-10-23 20:24:58 +02:00
14 changed files with 265 additions and 69 deletions

View File

@@ -87,6 +87,10 @@ The available options are:
Note that currently not *all* comments can be kept when
compression is on, because of dead code removal or
cascading statements into sequences. [string]
--preamble Preamble to prepend to the output. You can use this to
insert a comment, for example for licensing information.
This will not be parsed, but the source map will adjust
for its presence.
--stats Display operations run time on STDERR. [boolean]
--acorn Use Acorn for parsing. [boolean]
--spidermonkey Assume input files are SpiderMonkey AST format (as JSON).
@@ -257,7 +261,7 @@ when this flag is on:
- `String(exp)` or `exp.toString()` → `"" + exp`
- `new Object/RegExp/Function/Error/Array (...)` → we discard the `new`
- `typeof foo == "undefined"` → `foo === void 0`
- `void 0` → `"undefined"` (if there is a variable named "undefined" in
- `void 0` → `undefined` (if there is a variable named "undefined" in
scope; we do it because the variable name will be mangled, typically
reduced to a single character).
@@ -328,6 +332,10 @@ can pass additional arguments that control the code output:
you pass `false` then whenever possible we will use a newline instead of a
semicolon, leading to more readable output of uglified code (size before
gzip could be smaller; size after gzip insignificantly larger).
- `preamble` (default `null`) -- when passed it must be a string and
it will be prepended to the output literally. The source map will
adjust for this text. Can be used to insert a comment containing
licensing information, for example.
### Keeping copyright notices or other comments

View File

@@ -48,6 +48,10 @@ You can optionally pass one of the following arguments to this flag:\n\
Note that currently not *all* comments can be kept when compression is on, \
because of dead code removal or cascading statements into sequences.")
.describe("preamble", "Preamble to prepend to the output. You can use this to insert a \
comment, for example for licensing information. This will not be \
parsed, but the source map will adjust for its presence.")
.describe("stats", "Display operations run time on STDERR.")
.describe("acorn", "Use Acorn for parsing.")
.describe("spidermonkey", "Assume input files are SpiderMonkey AST format (as JSON).")
@@ -58,6 +62,7 @@ You need to pass an argument to this option to specify the name that your module
.describe("lint", "Display some scope warnings")
.describe("v", "Verbose")
.describe("V", "Print version number and exit.")
.describe("noerr", "Don't throw an error for unknown options in -c, -b or -m.")
.alias("p", "prefix")
.alias("o", "output")
@@ -92,6 +97,7 @@ You need to pass an argument to this option to specify the name that your module
.boolean("spidermonkey")
.boolean("lint")
.boolean("V")
.boolean("noerr")
.wrap(80)
@@ -100,6 +106,12 @@ You need to pass an argument to this option to specify the name that your module
normalize(ARGS);
if (ARGS.noerr) {
UglifyJS.DefaultsError.croak = function(msg, defs) {
sys.error("WARN: " + msg);
};
}
if (ARGS.version || ARGS.V) {
var json = require("../package.json");
sys.puts(json.name + ' ' + json.version);
@@ -134,7 +146,8 @@ if (ARGS.r) {
}
var OUTPUT_OPTIONS = {
beautify: BEAUTIFY ? true : false
beautify: BEAUTIFY ? true : false,
preamble: ARGS.preamble || null,
};
if (ARGS.screw_ie8) {
@@ -251,7 +264,6 @@ async.eachLimit(files, 1, function (file, cb) {
else if (ARGS.acorn) {
TOPLEVEL = acorn.parse(code, {
locations : true,
trackComments : true,
sourceFile : file,
program : TOPLEVEL
});
@@ -377,7 +389,7 @@ function getOptions(x, constants) {
if (x !== true) {
var ast;
try {
ast = UglifyJS.parse(x);
ast = UglifyJS.parse(x, { expression: true });
} catch(ex) {
if (ex instanceof UglifyJS.JS_Parse_Error) {
sys.error("Error parsing arguments in: " + x);
@@ -385,8 +397,6 @@ function getOptions(x, constants) {
}
}
ast.walk(new UglifyJS.TreeWalker(function(node){
if (node instanceof UglifyJS.AST_Toplevel) return; // descend
if (node instanceof UglifyJS.AST_SimpleStatement) return; // descend
if (node instanceof UglifyJS.AST_Seq) return; // descend
if (node instanceof UglifyJS.AST_Assign) {
var name = node.left.print_to_string({ beautify: false }).replace(/-/g, "_");
@@ -396,6 +406,11 @@ function getOptions(x, constants) {
ret[name] = value;
return true; // no descend
}
if (node instanceof UglifyJS.AST_Symbol || node instanceof UglifyJS.AST_Binary) {
var name = node.print_to_string({ beautify: false }).replace(/-/g, "_");
ret[name] = true;
return true; // no descend
}
sys.error(node.TYPE)
sys.error("Error parsing arguments in: " + x);
process.exit(1);

View File

@@ -371,7 +371,7 @@ var AST_Lambda = DEFNODE("Lambda", "name argnames uses_arguments", {
}, AST_Scope);
var AST_Accessor = DEFNODE("Accessor", null, {
$documentation: "A setter/getter function"
$documentation: "A setter/getter function. The `name` property is always null."
}, AST_Lambda);
var AST_Function = DEFNODE("Function", null, {
@@ -756,7 +756,7 @@ var AST_Object = DEFNODE("Object", "properties", {
var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
$documentation: "Base class for literal object properties",
$propdoc: {
key: "[string] the property name; it's always a plain string in our AST, no matter if it was a string, number or identifier in original code",
key: "[string] the property name converted to a string for ObjectKeyVal. For setters and getters this is an arbitrary AST_Node.",
value: "[AST_Node] property value. For setters and getters this is an AST_Function."
},
_walk: function(visitor) {

View File

@@ -85,14 +85,16 @@ merge(Compressor.prototype, {
},
before: function(node, descend, in_list) {
if (node._squeezed) return node;
var was_scope = false;
if (node instanceof AST_Scope) {
node.drop_unused(this);
node = node.hoist_declarations(this);
was_scope = true;
}
descend(node, this);
node = node.optimize(this);
if (node instanceof AST_Scope) {
if (was_scope && node instanceof AST_Scope) {
node.drop_unused(this);
descend(node, this);
}
node._squeezed = true;
return node;
@@ -1082,18 +1084,23 @@ merge(Compressor.prototype, {
}
return node;
}
if (node instanceof AST_For && node.init instanceof AST_BlockStatement) {
if (node instanceof AST_For) {
descend(node, this);
// certain combination of unused name + side effect leads to:
// https://github.com/mishoo/UglifyJS2/issues/44
// that's an invalid AST.
// We fix it at this stage by moving the `var` outside the `for`.
var body = node.init.body.slice(0, -1);
node.init = node.init.body.slice(-1)[0].body;
body.push(node);
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
body: body
});
if (node.init instanceof AST_BlockStatement) {
// certain combination of unused name + side effect leads to:
// https://github.com/mishoo/UglifyJS2/issues/44
// that's an invalid AST.
// We fix it at this stage by moving the `var` outside the `for`.
var body = node.init.body.slice(0, -1);
node.init = node.init.body.slice(-1)[0].body;
body.push(node);
return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, {
body: body
});
}
}
if (node instanceof AST_Scope && node !== self)
return node;
@@ -1614,7 +1621,7 @@ merge(Compressor.prototype, {
if (self.args.length != 1) {
return make_node(AST_Array, self, {
elements: self.args
});
}).transform(compressor);
}
break;
case "Object":
@@ -1628,11 +1635,30 @@ merge(Compressor.prototype, {
if (self.args.length == 0) return make_node(AST_String, self, {
value: ""
});
return make_node(AST_Binary, self, {
if (self.args.length <= 1) return make_node(AST_Binary, self, {
left: self.args[0],
operator: "+",
right: make_node(AST_String, self, { value: "" })
}).transform(compressor);
break;
case "Number":
if (self.args.length == 0) return make_node(AST_Number, self, {
value: 0
});
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
expression: self.args[0],
operator: "+"
}).transform(compressor);
case "Boolean":
if (self.args.length == 0) return make_node(AST_False, self);
if (self.args.length == 1) return make_node(AST_UnaryPrefix, self, {
expression: make_node(AST_UnaryPrefix, null, {
expression: self.args[0],
operator: "!"
}),
operator: "!"
}).transform(compressor);
break;
case "Function":
if (all(self.args, function(x){ return x instanceof AST_String })) {
// quite a corner-case, but we can handle it:
@@ -1840,6 +1866,14 @@ merge(Compressor.prototype, {
return self.evaluate(compressor)[0];
});
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){
if (compressor.option("sequences")) {
if (this.left instanceof AST_Seq) {
@@ -1851,8 +1885,8 @@ merge(Compressor.prototype, {
return seq;
}
if (this.right instanceof AST_Seq
&& !(this.operator == "||" || this.operator == "&&")
&& !this.left.has_side_effects(compressor)) {
&& this instanceof AST_Assign
&& !has_side_effects_or_prop_access(this.left, compressor)) {
var seq = this.right;
var x = seq.to_array();
this.right = x.pop();
@@ -1882,7 +1916,11 @@ merge(Compressor.prototype, {
// if right is a constant, whatever side effects the
// left side might have could not influence the
// result. hence, force switch.
reverse(null, true);
if (!(self.left instanceof AST_Binary
&& PRECEDENCE[self.left.operator] >= PRECEDENCE[self.operator])) {
reverse(null, true);
}
}
if (/^[!=]==?$/.test(self.operator)) {
if (self.left instanceof AST_SymbolRef && self.right instanceof AST_Conditional) {
@@ -2032,7 +2070,8 @@ merge(Compressor.prototype, {
&& self.left.right instanceof AST_Constant
&& self.right instanceof AST_Binary
&& self.right.operator == "+"
&& self.right.left instanceof AST_Constant) {
&& self.right.left instanceof AST_Constant
&& self.right.is_string(compressor)) {
self = make_node(AST_Binary, self, {
operator: "+",
left: make_node(AST_Binary, self.left, {
@@ -2049,6 +2088,19 @@ merge(Compressor.prototype, {
}
}
}
// x * (y * z) ==> x * y * z
if (self.right instanceof AST_Binary
&& self.right.operator == self.operator
&& (self.operator == "*" || self.operator == "&&" || self.operator == "||"))
{
self.left = make_node(AST_Binary, self.left, {
operator : self.operator,
left : self.left,
right : self.right.left
});
self.right = self.right.right;
return self.transform(compressor);
}
return self.evaluate(compressor)[0];
});

View File

@@ -61,6 +61,7 @@ function OutputStream(options) {
comments : false,
preserve_line : false,
screw_ie8 : false,
preamble : null,
}, true);
var indentation = 0;
@@ -299,6 +300,10 @@ function OutputStream(options) {
return OUTPUT;
};
if (options.preamble) {
print(options.preamble.replace(/\r\n?|[\n\u2028\u2029]|\s*$/g, "\n"));
}
var stack = [];
return {
get : get,
@@ -378,14 +383,15 @@ function OutputStream(options) {
var start = self.start;
if (start && !start._comments_dumped) {
start._comments_dumped = true;
var comments = start.comments_before;
var comments = start.comments_before || [];
// XXX: ugly fix for https://github.com/mishoo/UglifyJS2/issues/112
// if this node is `return` or `throw`, we cannot allow comments before
// the returned or thrown value.
if (self instanceof AST_Exit &&
self.value && self.value.start.comments_before.length > 0) {
comments = (comments || []).concat(self.value.start.comments_before);
if (self instanceof AST_Exit && self.value
&& self.value.start.comments_before
&& self.value.start.comments_before.length > 0) {
comments = comments.concat(self.value.start.comments_before);
self.value.start.comments_before = [];
}
@@ -475,11 +481,7 @@ function OutputStream(options) {
var so = this.operator, sp = PRECEDENCE[so];
if (pp > sp
|| (pp == sp
&& this === p.right
&& !(so == po &&
(so == "*" ||
so == "&&" ||
so == "||")))) {
&& this === p.right)) {
return true;
}
}
@@ -506,8 +508,17 @@ function OutputStream(options) {
});
PARENS(AST_Call, function(output){
var p = output.parent();
return p instanceof AST_New && p.expression === this;
var p = output.parent(), p1;
if (p instanceof AST_New && p.expression === this)
return true;
// workaround for Safari bug.
// https://bugs.webkit.org/show_bug.cgi?id=123506
return this.expression instanceof AST_Function
&& p instanceof AST_PropAccess
&& p.expression === this
&& (p1 = output.parent(1)) instanceof AST_Assign
&& p1.left === p;
});
PARENS(AST_New, function(output){
@@ -1064,10 +1075,14 @@ function OutputStream(options) {
});
DEFPRINT(AST_ObjectSetter, function(self, output){
output.print("set");
output.space();
self.key.print(output);
self.value._do_print(output, true);
});
DEFPRINT(AST_ObjectGetter, function(self, output){
output.print("get");
output.space();
self.key.print(output);
self.value._do_print(output, true);
});
DEFPRINT(AST_Symbol, function(self, output){

View File

@@ -579,10 +579,10 @@ var UNARY_POSTFIX = makePredicate([ "--", "++" ]);
var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
var PRECEDENCE = (function(a, ret){
for (var i = 0, n = 1; i < a.length; ++i, ++n) {
for (var i = 0; i < a.length; ++i) {
var b = a[i];
for (var j = 0; j < b.length; ++j) {
ret[b[j]] = n;
ret[b[j]] = i + 1;
}
}
return ret;
@@ -789,7 +789,7 @@ function parse($TEXT, options) {
return for_();
case "function":
return function_(true);
return function_(AST_Defun);
case "if":
return if_();
@@ -933,19 +933,12 @@ function parse($TEXT, options) {
});
};
var function_ = function(in_statement, ctor) {
var is_accessor = ctor === AST_Accessor;
var name = (is("name") ? as_symbol(in_statement
? AST_SymbolDefun
: is_accessor
? AST_SymbolAccessor
: AST_SymbolLambda)
: is_accessor && (is("string") || is("num")) ? as_atom_node()
: null);
var function_ = function(ctor) {
var in_statement = ctor === AST_Defun;
var name = is("name") ? as_symbol(in_statement ? AST_SymbolDefun : AST_SymbolLambda) : null;
if (in_statement && !name)
unexpected();
expect("(");
if (!ctor) ctor = in_statement ? AST_Defun : AST_Function;
return new ctor({
name: name,
argnames: (function(first, a){
@@ -1116,7 +1109,9 @@ function parse($TEXT, options) {
var tok = S.token, ret;
switch (tok.type) {
case "name":
return as_symbol(AST_SymbolRef);
case "keyword":
ret = _make_symbol(AST_SymbolRef);
break;
case "num":
ret = new AST_Number({ start: tok, end: tok, value: tok.value });
break;
@@ -1167,7 +1162,7 @@ function parse($TEXT, options) {
}
if (is("keyword", "function")) {
next();
var func = function_(false);
var func = function_(AST_Function);
func.start = start;
func.end = prev();
return subscripts(func, allow_calls);
@@ -1215,8 +1210,8 @@ function parse($TEXT, options) {
if (name == "get") {
a.push(new AST_ObjectGetter({
start : start,
key : name,
value : function_(false, AST_Accessor),
key : as_atom_node(),
value : function_(AST_Accessor),
end : prev()
}));
continue;
@@ -1224,8 +1219,8 @@ function parse($TEXT, options) {
if (name == "set") {
a.push(new AST_ObjectSetter({
start : start,
key : name,
value : function_(false, AST_Accessor),
key : as_atom_node(),
value : function_(AST_Accessor),
end : prev()
}));
continue;
@@ -1273,17 +1268,21 @@ function parse($TEXT, options) {
}
};
function _make_symbol(type) {
var name = S.token.value;
return new (name == "this" ? AST_This : type)({
name : String(name),
start : S.token,
end : S.token
});
};
function as_symbol(type, noerror) {
if (!is("name")) {
if (!noerror) croak("Name expected");
return null;
}
var name = S.token.value;
var sym = new (name == "this" ? AST_This : type)({
name : String(S.token.value),
start : S.token,
end : S.token
});
var sym = _make_symbol(type);
next();
return sym;
};

View File

@@ -64,9 +64,9 @@ SymbolDef.prototype = {
mangle: function(options) {
if (!this.mangled_name && !this.unmangleable(options)) {
var s = this.scope;
if (this.orig[0] instanceof AST_SymbolLambda && !options.screw_ie8)
if (!options.screw_ie8 && this.orig[0] instanceof AST_SymbolLambda)
s = s.parent_scope;
this.mangled_name = s.next_mangled(options);
this.mangled_name = s.next_mangled(options, this);
}
}
};
@@ -256,6 +256,19 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
}
});
AST_Function.DEFMETHOD("next_mangled", function(options, def){
// #179, #326
// in Safari strict mode, something like (function x(x){...}) is a syntax error;
// a function expression's argument cannot shadow the function expression's name
var tricky_def = def.orig[0] instanceof AST_SymbolFunarg && this.name && this.name.definition();
while (true) {
var name = AST_Lambda.prototype.next_mangled.call(this, options, def);
if (!(tricky_def && tricky_def.mangled_name == name))
return name;
}
});
AST_Scope.DEFMETHOD("references", function(sym){
if (sym instanceof AST_Symbol) sym = sym.definition();
return this.enclosed.indexOf(sym) < 0 ? null : sym;

View File

@@ -86,12 +86,16 @@ function DefaultsError(msg, defs) {
this.defs = defs;
};
DefaultsError.croak = function(msg, defs) {
throw new DefaultsError(msg, defs);
};
function defaults(args, defs, croak) {
if (args === true)
args = {};
var ret = args || {};
if (croak) for (var i in ret) if (ret.hasOwnProperty(i) && !defs.hasOwnProperty(i))
throw new DefaultsError("`" + i + "` is not a supported option", defs);
DefaultsError.croak("`" + i + "` is not a supported option", defs);
for (var i in defs) if (defs.hasOwnProperty(i)) {
ret[i] = (args && args.hasOwnProperty(i)) ? args[i] : defs[i];
}

View File

@@ -3,7 +3,7 @@
"description": "JavaScript parser, mangler/compressor and beautifier toolkit",
"homepage": "http://lisperator.net/uglifyjs",
"main": "tools/node.js",
"version": "2.4.1",
"version": "2.4.5",
"engines": { "node" : ">=0.4.0" },
"maintainers": [{
"name": "Mihai Bazon",

View File

@@ -10,6 +10,7 @@ concatenate_rhs_strings: {
foo(bar() + 123 + "Hello" + "World" + ("Foo" + "Bar"));
foo("Foo" + "Bar" + bar() + 123 + "Hello" + "World" + ("Foo" + "Bar"));
foo("Hello" + bar() + 123 + "World");
foo(bar() + 'Foo' + (10 + parseInt('10')));
}
expect: {
foo(bar() + 123 + "HelloWorld");
@@ -18,5 +19,6 @@ concatenate_rhs_strings: {
foo(bar() + 123 + "HelloWorldFooBar");
foo("FooBar" + bar() + "123HelloWorldFooBar");
foo("Hello" + bar() + "123World");
foo(bar() + 'Foo' + (10 + parseInt('10')));
}
}

View File

@@ -0,0 +1,11 @@
issue_267: {
options = { comparisons: true };
input: {
x = a % b / b * c * 2;
x = a % b * 2
}
expect: {
x = a % b / b * c * 2;
x = a % b * 2;
}
}

View File

@@ -0,0 +1,66 @@
issue_269_1: {
options = {unsafe: true};
input: {
f(
String(x),
Number(x),
Boolean(x),
String(),
Number(),
Boolean()
);
}
expect: {
f(
x + '', +x, !!x,
'', 0, false
);
}
}
issue_269_dangers: {
options = {unsafe: true};
input: {
f(
String(x, x),
Number(x, x),
Boolean(x, x)
);
}
expect: {
f(String(x, x), Number(x, x), Boolean(x, x));
}
}
issue_269_in_scope: {
options = {unsafe: true};
input: {
var String, Number, Boolean;
f(
String(x),
Number(x, x),
Boolean(x)
);
}
expect: {
var String, Number, Boolean;
f(String(x), Number(x, x), Boolean(x));
}
}
strings_concat: {
options = {unsafe: true};
input: {
f(
String(x + 'str'),
String('str' + x)
);
}
expect: {
f(
x + 'str',
'str' + x
);
}
}

View File

@@ -101,10 +101,12 @@ lift_sequences_1: {
lift_sequences_2: {
options = { sequences: true, evaluate: true };
input: {
q = 1 + (foo(), bar(), 5) + 7 * (5 / (3 - (a(), (QW=ER), c(), 2))) - (x(), y(), 5);
foo.x = (foo = {}, 10);
bar = (bar = {}, 10);
}
expect: {
foo(), bar(), a(), QW = ER, c(), x(), y(), q = 36
foo.x = (foo = {}, 10),
bar = {}, bar = 10;
}
}

View File

@@ -7,8 +7,15 @@ var assert = require("assert");
var sys = require("util");
var tests_dir = path.dirname(module.filename);
var failures = 0;
var failed_files = {};
run_compress_tests();
if (failures) {
sys.error("\n!!! Failed " + failures + " test cases.");
sys.error("!!! " + Object.keys(failed_files).join(", "));
process.exit(1);
}
/* -----[ utils ]----- */
@@ -83,6 +90,8 @@ function run_compress_tests() {
output: output,
expected: expect
});
failures++;
failed_files[file] = 1;
}
}
var tests = parse_test(path.resolve(dir, file));