This commit is contained in:
Andrey Taritsyn 2015-01-09 09:12:21 +00:00
commit ad59a2ec28
6 changed files with 47 additions and 44 deletions

View File

@ -153,7 +153,7 @@ if (ARGS.r) {
var OUTPUT_OPTIONS = { var OUTPUT_OPTIONS = {
beautify: BEAUTIFY ? true : false, beautify: BEAUTIFY ? true : false,
preamble: ARGS.preamble || null, preamble: ARGS.preamble || null
}; };
if (ARGS.screw_ie8) { if (ARGS.screw_ie8) {
@ -234,7 +234,7 @@ var SOURCES_CONTENT = {};
var SOURCE_MAP = ARGS.source_map ? UglifyJS.SourceMap({ var SOURCE_MAP = ARGS.source_map ? UglifyJS.SourceMap({
file: P_RELATIVE ? path.relative(path.dirname(ARGS.source_map), OUTPUT_FILE) : OUTPUT_FILE, file: P_RELATIVE ? path.relative(path.dirname(ARGS.source_map), OUTPUT_FILE) : OUTPUT_FILE,
root: ARGS.source_map_root, root: ARGS.source_map_root,
orig: ORIG_MAP, orig: ORIG_MAP
}) : null; }) : null;
OUTPUT_OPTIONS.source_map = SOURCE_MAP; OUTPUT_OPTIONS.source_map = SOURCE_MAP;
@ -287,7 +287,7 @@ async.eachLimit(files, 1, function (file, cb) {
filename : file, filename : file,
toplevel : TOPLEVEL, toplevel : TOPLEVEL,
expression : ARGS.expr, expression : ARGS.expr,
bare_returns : ARGS.bare_returns, bare_returns : ARGS.bare_returns
}); });
} catch(ex) { } catch(ex) {
if (ex instanceof UglifyJS.JS_Parse_Error) { if (ex instanceof UglifyJS.JS_Parse_Error) {

View File

@ -113,11 +113,11 @@ AST_Node.warn = function(txt, props) {
/* -----[ statements ]----- */ /* -----[ statements ]----- */
var AST_Statement = DEFNODE("Statement", null, { var AST_Statement = DEFNODE("Statement", null, {
$documentation: "Base class of all statements", $documentation: "Base class of all statements"
}); });
var AST_Debugger = DEFNODE("Debugger", null, { var AST_Debugger = DEFNODE("Debugger", null, {
$documentation: "Represents a debugger statement", $documentation: "Represents a debugger statement"
}, AST_Statement); }, AST_Statement);
var AST_Directive = DEFNODE("Directive", "value scope", { var AST_Directive = DEFNODE("Directive", "value scope", {
@ -125,7 +125,7 @@ var AST_Directive = DEFNODE("Directive", "value scope", {
$propdoc: { $propdoc: {
value: "[string] The value of this directive as a plain string (it's not an AST_String!)", value: "[string] The value of this directive as a plain string (it's not an AST_String!)",
scope: "[AST_Scope/S] The scope that this directive affects" scope: "[AST_Scope/S] The scope that this directive affects"
}, }
}, AST_Statement); }, AST_Statement);
var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", { var AST_SimpleStatement = DEFNODE("SimpleStatement", "body", {
@ -162,7 +162,7 @@ var AST_Block = DEFNODE("Block", "body", {
}, AST_Statement); }, AST_Statement);
var AST_BlockStatement = DEFNODE("BlockStatement", null, { var AST_BlockStatement = DEFNODE("BlockStatement", null, {
$documentation: "A block statement", $documentation: "A block statement"
}, AST_Block); }, AST_Block);
var AST_EmptyStatement = DEFNODE("EmptyStatement", null, { var AST_EmptyStatement = DEFNODE("EmptyStatement", null, {
@ -286,14 +286,14 @@ var AST_Scope = DEFNODE("Scope", "directives variables functions uses_with uses_
uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`", uses_eval: "[boolean/S] tells whether this scope contains a direct call to the global `eval`",
parent_scope: "[AST_Scope?/S] link to the parent scope", parent_scope: "[AST_Scope?/S] link to the parent scope",
enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes", enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
cname: "[integer/S] current index for mangling variables (used internally by the mangler)", cname: "[integer/S] current index for mangling variables (used internally by the mangler)"
}, }
}, AST_Block); }, AST_Block);
var AST_Toplevel = DEFNODE("Toplevel", "globals", { var AST_Toplevel = DEFNODE("Toplevel", "globals", {
$documentation: "The toplevel scope", $documentation: "The toplevel scope",
$propdoc: { $propdoc: {
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names", globals: "[Object/S] a map of name -> SymbolDef for all undeclared names"
}, },
wrap_enclose: function(arg_parameter_pairs) { wrap_enclose: function(arg_parameter_pairs) {
var self = this; var self = this;
@ -343,11 +343,11 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
body: new AST_Assign({ body: new AST_Assign({
left: new AST_Sub({ left: new AST_Sub({
expression: new AST_SymbolRef({ name: "exports" }), expression: new AST_SymbolRef({ name: "exports" }),
property: new AST_String({ value: sym.name }), property: new AST_String({ value: sym.name })
}), }),
operator: "=", operator: "=",
right: new AST_SymbolRef(sym), right: new AST_SymbolRef(sym)
}), })
})); }));
}); });
return MAP.splice(body); return MAP.splice(body);
@ -417,7 +417,7 @@ var AST_Throw = DEFNODE("Throw", null, {
var AST_LoopControl = DEFNODE("LoopControl", "label", { var AST_LoopControl = DEFNODE("LoopControl", "label", {
$documentation: "Base class for loop control statements (`break` and `continue`)", $documentation: "Base class for loop control statements (`break` and `continue`)",
$propdoc: { $propdoc: {
label: "[AST_LabelRef?] the label, or null if none", label: "[AST_LabelRef?] the label, or null if none"
}, },
_walk: function(visitor) { _walk: function(visitor) {
return visitor._visit(this, this.label && function(){ return visitor._visit(this, this.label && function(){
@ -467,11 +467,11 @@ var AST_Switch = DEFNODE("Switch", "expression", {
}, AST_Block); }, AST_Block);
var AST_SwitchBranch = DEFNODE("SwitchBranch", null, { var AST_SwitchBranch = DEFNODE("SwitchBranch", null, {
$documentation: "Base class for `switch` branches", $documentation: "Base class for `switch` branches"
}, AST_Block); }, AST_Block);
var AST_Default = DEFNODE("Default", null, { var AST_Default = DEFNODE("Default", null, {
$documentation: "A `default` switch branch", $documentation: "A `default` switch branch"
}, AST_SwitchBranch); }, AST_SwitchBranch);
var AST_Case = DEFNODE("Case", "expression", { var AST_Case = DEFNODE("Case", "expression", {
@ -720,7 +720,7 @@ var AST_Conditional = DEFNODE("Conditional", "condition consequent alternative",
}); });
var AST_Assign = DEFNODE("Assign", null, { var AST_Assign = DEFNODE("Assign", null, {
$documentation: "An assignment expression — `a = b + 5`", $documentation: "An assignment expression — `a = b + 5`"
}, AST_Binary); }, AST_Binary);
/* -----[ LITERALS ]----- */ /* -----[ LITERALS ]----- */
@ -767,15 +767,15 @@ var AST_ObjectProperty = DEFNODE("ObjectProperty", "key value", {
}); });
var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", null, { var AST_ObjectKeyVal = DEFNODE("ObjectKeyVal", null, {
$documentation: "A key: value object property", $documentation: "A key: value object property"
}, AST_ObjectProperty); }, AST_ObjectProperty);
var AST_ObjectSetter = DEFNODE("ObjectSetter", null, { var AST_ObjectSetter = DEFNODE("ObjectSetter", null, {
$documentation: "An object setter property", $documentation: "An object setter property"
}, AST_ObjectProperty); }, AST_ObjectProperty);
var AST_ObjectGetter = DEFNODE("ObjectGetter", null, { var AST_ObjectGetter = DEFNODE("ObjectGetter", null, {
$documentation: "An object getter property", $documentation: "An object getter property"
}, AST_ObjectProperty); }, AST_ObjectProperty);
var AST_Symbol = DEFNODE("Symbol", "scope name thedef", { var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
@ -784,7 +784,7 @@ var AST_Symbol = DEFNODE("Symbol", "scope name thedef", {
scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)", scope: "[AST_Scope/S] the current scope (not necessarily the definition scope)",
thedef: "[SymbolDef/S] the definition of this symbol" thedef: "[SymbolDef/S] the definition of this symbol"
}, },
$documentation: "Base class for all symbols", $documentation: "Base class for all symbols"
}); });
var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, { var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
@ -799,7 +799,7 @@ var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
}, AST_Symbol); }, AST_Symbol);
var AST_SymbolVar = DEFNODE("SymbolVar", null, { var AST_SymbolVar = DEFNODE("SymbolVar", null, {
$documentation: "Symbol defining a variable", $documentation: "Symbol defining a variable"
}, AST_SymbolDeclaration); }, AST_SymbolDeclaration);
var AST_SymbolConst = DEFNODE("SymbolConst", null, { var AST_SymbolConst = DEFNODE("SymbolConst", null, {
@ -807,19 +807,19 @@ var AST_SymbolConst = DEFNODE("SymbolConst", null, {
}, AST_SymbolDeclaration); }, AST_SymbolDeclaration);
var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, { var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, {
$documentation: "Symbol naming a function argument", $documentation: "Symbol naming a function argument"
}, AST_SymbolVar); }, AST_SymbolVar);
var AST_SymbolDefun = DEFNODE("SymbolDefun", null, { var AST_SymbolDefun = DEFNODE("SymbolDefun", null, {
$documentation: "Symbol defining a function", $documentation: "Symbol defining a function"
}, AST_SymbolDeclaration); }, AST_SymbolDeclaration);
var AST_SymbolLambda = DEFNODE("SymbolLambda", null, { var AST_SymbolLambda = DEFNODE("SymbolLambda", null, {
$documentation: "Symbol naming a function expression", $documentation: "Symbol naming a function expression"
}, AST_SymbolDeclaration); }, AST_SymbolDeclaration);
var AST_SymbolCatch = DEFNODE("SymbolCatch", null, { var AST_SymbolCatch = DEFNODE("SymbolCatch", null, {
$documentation: "Symbol naming the exception in catch", $documentation: "Symbol naming the exception in catch"
}, AST_SymbolDeclaration); }, AST_SymbolDeclaration);
var AST_Label = DEFNODE("Label", "references", { var AST_Label = DEFNODE("Label", "references", {
@ -834,15 +834,15 @@ var AST_Label = DEFNODE("Label", "references", {
}, AST_Symbol); }, AST_Symbol);
var AST_SymbolRef = DEFNODE("SymbolRef", null, { var AST_SymbolRef = DEFNODE("SymbolRef", null, {
$documentation: "Reference to some symbol (not definition/declaration)", $documentation: "Reference to some symbol (not definition/declaration)"
}, AST_Symbol); }, AST_Symbol);
var AST_LabelRef = DEFNODE("LabelRef", null, { var AST_LabelRef = DEFNODE("LabelRef", null, {
$documentation: "Reference to a label symbol", $documentation: "Reference to a label symbol"
}, AST_Symbol); }, AST_Symbol);
var AST_This = DEFNODE("This", null, { var AST_This = DEFNODE("This", null, {
$documentation: "The `this` symbol", $documentation: "The `this` symbol"
}, AST_Symbol); }, AST_Symbol);
var AST_Constant = DEFNODE("Constant", null, { var AST_Constant = DEFNODE("Constant", null, {
@ -874,7 +874,7 @@ var AST_RegExp = DEFNODE("RegExp", "value", {
}, AST_Constant); }, AST_Constant);
var AST_Atom = DEFNODE("Atom", null, { var AST_Atom = DEFNODE("Atom", null, {
$documentation: "Base class for atoms", $documentation: "Base class for atoms"
}, AST_Constant); }, AST_Constant);
var AST_Null = DEFNODE("Null", null, { var AST_Null = DEFNODE("Null", null, {
@ -903,7 +903,7 @@ var AST_Infinity = DEFNODE("Infinity", null, {
}, AST_Atom); }, AST_Atom);
var AST_Boolean = DEFNODE("Boolean", null, { var AST_Boolean = DEFNODE("Boolean", null, {
$documentation: "Base class for booleans", $documentation: "Base class for booleans"
}, AST_Atom); }, AST_Atom);
var AST_False = DEFNODE("False", null, { var AST_False = DEFNODE("False", null, {

View File

@ -1350,7 +1350,7 @@ merge(Compressor.prototype, {
self.condition = make_node(AST_Binary, self.condition, { self.condition = make_node(AST_Binary, self.condition, {
left: self.condition, left: self.condition,
operator: "&&", operator: "&&",
right: first.condition.negate(compressor), right: first.condition.negate(compressor)
}); });
} else { } else {
self.condition = first.condition.negate(compressor); self.condition = first.condition.negate(compressor);
@ -1363,7 +1363,7 @@ merge(Compressor.prototype, {
self.condition = make_node(AST_Binary, self.condition, { self.condition = make_node(AST_Binary, self.condition, {
left: self.condition, left: self.condition,
operator: "&&", operator: "&&",
right: first.condition, right: first.condition
}); });
} else { } else {
self.condition = first.condition; self.condition = first.condition;
@ -1820,7 +1820,7 @@ merge(Compressor.prototype, {
return make_node(AST_Binary, el[0], { return make_node(AST_Binary, el[0], {
operator : "+", operator : "+",
left : prev, left : prev,
right : el[0], right : el[0]
}); });
}, first).transform(compressor); }, first).transform(compressor);
} }
@ -2369,7 +2369,7 @@ merge(Compressor.prototype, {
value : self.value, value : self.value,
file : p.start.file, file : p.start.file,
line : p.start.line, line : p.start.line,
col : p.start.col, col : p.start.col
}); });
return make_node(AST_Number, self, { return make_node(AST_Number, self, {
value: +self.value value: +self.value

View File

@ -62,7 +62,7 @@ function OutputStream(options) {
comments : false, comments : false,
preserve_line : false, preserve_line : false,
screw_ie8 : false, screw_ie8 : false,
preamble : null, preamble : null
}, true); }, true);
var indentation = 0; var indentation = 0;
@ -187,12 +187,15 @@ function OutputStream(options) {
} }
might_need_space = false; might_need_space = false;
} }
var a = str.split(/\r?\n/), n = a.length - 1; var a = str.split(/\r?\n/), len = a.length;
current_line += n; if (len > 0) {
if (n == 0) { var n = len - 1;
current_col += a[n].length; current_line += n;
} else { if (n == 0) {
current_col = a[n].length; current_col += a[n].length;
} else {
current_col = a[n].length;
}
} }
current_pos += str.length; current_pos += str.length;
last = str; last = str;

View File

@ -617,7 +617,7 @@ function parse($TEXT, options) {
toplevel : null, toplevel : null,
expression : false, expression : false,
html5_comments : true, html5_comments : true,
bare_returns : false, bare_returns : false
}); });
var S = { var S = {

View File

@ -51,7 +51,7 @@ function SourceMap(options) {
orig : null, orig : null,
orig_line_diff : 0, orig_line_diff : 0,
dest_line_diff : 0, dest_line_diff : 0
}); });
var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig); var orig_map = options.orig && new MOZ_SourceMap.SourceMapConsumer(options.orig);
var generator; var generator;