Compare commits

...

12 Commits

Author SHA1 Message Date
Mihai Bazon
15a148ff6d v2.4.8 2013-12-18 12:10:43 +02:00
Mihai Bazon
428e19fed2 Add option to adjust the src/target line in the source map 2013-12-18 12:10:02 +02:00
Mihai Bazon
f65e55dff4 minor 2013-12-16 20:37:09 +02:00
Mihai Bazon
b634018618 Merge pull request #371 from colorhook/master
bugfix #242
2013-12-16 00:21:07 -08:00
colorhook
fa3300f314 bugfix #242 2013-12-16 15:53:43 +08:00
Mihai Bazon
bd0886a2c0 semicolons 2013-12-10 20:24:27 +02:00
Mihai Bazon
248f304f02 Merge pull request #245 from ForbesLindesay/patch-1
Make `DefaultsError` a real `Error` object
2013-12-10 10:23:29 -08:00
Mihai Bazon
dc5f70eab5 Add drop_console option to the compressor 2013-12-10 19:44:41 +02:00
Mihai Bazon
df8c5623af minor 2013-12-10 19:39:03 +02:00
Mihai Bazon
a790c09c91 v2.4.7 2013-12-09 12:09:31 +02:00
Mihai Bazon
8f35a363d9 AST_Catch shouldn't really inherit from AST_Scope. Fix #363
I hereby acknowledge that figure_out_scope has become a mess.
2013-12-05 13:30:29 +02:00
Forbes Lindesay
dfa395f6ff Make DefaultsError a real Error object 2013-07-22 01:44:03 +01:00
8 changed files with 90 additions and 11 deletions

View File

@@ -249,6 +249,9 @@ to set `true`; it's effectively a shortcut for `foo=true`).
statement would get discarded. The current implementation adds some
overhead (compression will be slower).
- `drop_console` -- default `false`. Pass `true` to discard calls to
`console.*` functions.
### The `unsafe` option
It enables some transformations that *might* break code logic in certain

View File

@@ -509,7 +509,7 @@ var AST_Catch = DEFNODE("Catch", "argname", {
walk_body(this, visitor);
});
}
}, AST_Scope);
}, AST_Block);
var AST_Finally = DEFNODE("Finally", null, {
$documentation: "A `finally` node; only makes sense as part of a `try` statement"

View File

@@ -70,6 +70,7 @@ function Compressor(options, false_by_default) {
pure_funcs : null,
negate_iife : !false_by_default,
screw_ie8 : false,
drop_console : false,
warnings : true,
global_defs : {}
@@ -1773,6 +1774,14 @@ merge(Compressor.prototype, {
return make_node(AST_Undefined, self).transform(compressor);
}
}
if (compressor.option("drop_console")) {
if (self.expression instanceof AST_PropAccess &&
self.expression.expression instanceof AST_SymbolRef &&
self.expression.expression.name == "console" &&
self.expression.expression.undeclared()) {
return make_node(AST_Undefined, self).transform(compressor);
}
}
return self.evaluate(compressor)[0];
});
@@ -1811,9 +1820,15 @@ merge(Compressor.prototype, {
}
if (compressor.option("cascade")) {
if (self.car instanceof AST_Assign
&& !self.car.left.has_side_effects(compressor)
&& self.car.left.equivalent_to(self.cdr)) {
return self.car;
&& !self.car.left.has_side_effects(compressor)) {
if (self.car.left.equivalent_to(self.cdr)) {
return self.car;
}
if (self.cdr instanceof AST_Call
&& self.cdr.expression.equivalent_to(self.car.left)) {
self.cdr.expression = self.car;
return self.cdr;
}
}
if (!self.car.has_side_effects(compressor)
&& !self.cdr.has_side_effects(compressor)

View File

@@ -82,14 +82,20 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
var defun = null;
var nesting = 0;
var tw = new TreeWalker(function(node, descend){
if (options.screw_ie8 && node instanceof AST_Catch) {
var save_scope = scope;
scope = new AST_Scope(node);
scope.init_scope_vars(nesting);
scope.parent_scope = save_scope;
descend();
scope = save_scope;
return true;
}
if (node instanceof AST_Scope) {
node.init_scope_vars(nesting);
var save_scope = node.parent_scope = scope;
var save_defun = defun;
if (!(node instanceof AST_Catch)) {
defun = node;
}
scope = node;
defun = scope = node;
++nesting; descend(); --nesting;
scope = save_scope;
defun = save_defun;
@@ -240,6 +246,11 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
out: while (true) {
var m = base54(++this.cname);
if (!is_identifier(m)) continue; // skip over "do"
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not
// shadow a name excepted from mangling.
if (options.except.indexOf(m) >= 0) continue;
// we must ensure that the mangled name does not shadow a name
// from some parent scope that is referenced in this or in
// inner scopes.

View File

@@ -49,6 +49,9 @@ function SourceMap(options) {
file : null,
root : null,
orig : null,
orig_line_diff : 0,
dest_line_diff : 0,
});
var generator = new MOZ_SourceMap.SourceMapGenerator({
file : options.file,
@@ -67,8 +70,8 @@ function SourceMap(options) {
name = info.name;
}
generator.addMapping({
generated : { line: gen_line, column: gen_col },
original : { line: orig_line, column: orig_col },
generated : { line: gen_line + options.dest_line_diff, column: gen_col },
original : { line: orig_line + options.orig_line_diff, column: orig_col },
source : source,
name : name
});

View File

@@ -82,9 +82,12 @@ function repeat_string(str, i) {
};
function DefaultsError(msg, defs) {
Error.call(this, msg);
this.msg = msg;
this.defs = defs;
};
DefaultsError.prototype = Object.create(Error.prototype);
DefaultsError.prototype.constructor = DefaultsError;
DefaultsError.croak = function(msg, defs) {
throw new DefaultsError(msg, defs);

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.6",
"version": "2.4.8",
"engines": { "node" : ">=0.4.0" },
"maintainers": [{
"name": "Mihai Bazon",

View File

@@ -119,3 +119,47 @@ unused_keep_setter_arg: {
}
}
}
unused_var_in_catch: {
options = { unused: true };
input: {
function foo() {
try {
foo();
} catch(ex) {
var x = 10;
}
}
}
expect: {
function foo() {
try {
foo();
} catch(ex) {}
}
}
}
used_var_in_catch: {
options = { unused: true };
input: {
function foo() {
try {
foo();
} catch(ex) {
var x = 10;
}
return x;
}
}
expect: {
function foo() {
try {
foo();
} catch(ex) {
var x = 10;
}
return x;
}
}
}