use directories for structure
This commit is contained in:
132
node_modules/uglify-js/lib/output.js
generated
vendored
132
node_modules/uglify-js/lib/output.js
generated
vendored
@@ -1,7 +1,7 @@
|
||||
/***********************************************************************
|
||||
|
||||
A JavaScript tokenizer / parser / beautifier / compressor.
|
||||
https://github.com/mishoo/UglifyJS2
|
||||
https://github.com/mishoo/UglifyJS
|
||||
|
||||
-------------------------------- (C) ---------------------------------
|
||||
|
||||
@@ -43,8 +43,6 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
var EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
|
||||
|
||||
function is_some_comments(comment) {
|
||||
// multiline comment
|
||||
return comment.type == "comment2" && /@preserve|@license|@cc_on/i.test(comment.value);
|
||||
@@ -121,15 +119,20 @@ function OutputStream(options) {
|
||||
});
|
||||
} : function(str) {
|
||||
var s = "";
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
if (is_surrogate_pair_head(str[i]) && !is_surrogate_pair_tail(str[i + 1])
|
||||
|| is_surrogate_pair_tail(str[i]) && !is_surrogate_pair_head(str[i - 1])) {
|
||||
s += "\\u" + str.charCodeAt(i).toString(16);
|
||||
} else {
|
||||
s += str[i];
|
||||
for (var i = 0, j = 0; i < str.length; i++) {
|
||||
var code = str.charCodeAt(i);
|
||||
if (is_surrogate_pair_head(code)) {
|
||||
if (is_surrogate_pair_tail(str.charCodeAt(i + 1))) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
} else if (!is_surrogate_pair_tail(code)) {
|
||||
continue;
|
||||
}
|
||||
s += str.slice(j, i) + "\\u" + code.toString(16);
|
||||
j = i + 1;
|
||||
}
|
||||
return s;
|
||||
return j == 0 ? str : s + str.slice(j);
|
||||
};
|
||||
|
||||
function make_string(str, quote) {
|
||||
@@ -378,7 +381,7 @@ function OutputStream(options) {
|
||||
};
|
||||
|
||||
function force_semicolon() {
|
||||
might_need_semicolon = false;
|
||||
if (might_need_semicolon) print(";");
|
||||
print(";");
|
||||
}
|
||||
|
||||
@@ -585,17 +588,7 @@ function OutputStream(options) {
|
||||
force_semicolon : force_semicolon,
|
||||
to_utf8 : to_utf8,
|
||||
print_name : function(name) { print(make_name(name)) },
|
||||
print_string : function(str, quote, escape_directive) {
|
||||
var encoded = encode_string(str, quote);
|
||||
if (escape_directive === true && encoded.indexOf("\\") === -1) {
|
||||
// Insert semicolons to break directive prologue
|
||||
if (!EXPECT_DIRECTIVE.test(OUTPUT)) {
|
||||
force_semicolon();
|
||||
}
|
||||
force_semicolon();
|
||||
}
|
||||
print(encoded);
|
||||
},
|
||||
print_string : function(str, quote) { print(encode_string(str, quote)) },
|
||||
next_indent : next_indent,
|
||||
with_indent : with_indent,
|
||||
with_block : with_block,
|
||||
@@ -633,17 +626,10 @@ function OutputStream(options) {
|
||||
nodetype.DEFMETHOD("_codegen", generator);
|
||||
}
|
||||
|
||||
var in_directive = false;
|
||||
var active_scope = null;
|
||||
var use_asm = null;
|
||||
var use_asm = false;
|
||||
|
||||
AST_Node.DEFMETHOD("print", function(stream, force_parens) {
|
||||
var self = this, generator = self._codegen;
|
||||
if (self instanceof AST_Scope) {
|
||||
active_scope = self;
|
||||
} else if (!use_asm && self instanceof AST_Directive && self.value == "use asm") {
|
||||
use_asm = active_scope;
|
||||
}
|
||||
function doit() {
|
||||
stream.prepend_comments(self);
|
||||
self.add_source_map(stream);
|
||||
@@ -657,9 +643,6 @@ function OutputStream(options) {
|
||||
doit();
|
||||
}
|
||||
stream.pop_node();
|
||||
if (self === use_asm) {
|
||||
use_asm = null;
|
||||
}
|
||||
});
|
||||
AST_Node.DEFMETHOD("_print", AST_Node.prototype.print);
|
||||
|
||||
@@ -799,7 +782,9 @@ function OutputStream(options) {
|
||||
PARENS(AST_Number, function(output) {
|
||||
var p = output.parent();
|
||||
if (p instanceof AST_PropAccess && p.expression === this) {
|
||||
var value = this.getValue();
|
||||
var value = this.value;
|
||||
// https://github.com/mishoo/UglifyJS/issues/115
|
||||
// https://github.com/mishoo/UglifyJS/pull/1009
|
||||
if (value < 0 || /^0/.test(make_num(value))) {
|
||||
return true;
|
||||
}
|
||||
@@ -828,7 +813,18 @@ function OutputStream(options) {
|
||||
/* -----[ PRINTERS ]----- */
|
||||
|
||||
DEFPRINT(AST_Directive, function(self, output) {
|
||||
output.print_string(self.value, self.quote);
|
||||
var quote = self.quote;
|
||||
var value = self.value;
|
||||
switch (output.option("quote_style")) {
|
||||
case 0:
|
||||
case 2:
|
||||
if (value.indexOf('"') == -1) quote = '"';
|
||||
break;
|
||||
case 1:
|
||||
if (value.indexOf("'") == -1) quote = "'";
|
||||
break;
|
||||
}
|
||||
output.print(quote + value + quote);
|
||||
output.semicolon();
|
||||
});
|
||||
DEFPRINT(AST_Debugger, function(self, output) {
|
||||
@@ -840,30 +836,27 @@ function OutputStream(options) {
|
||||
|
||||
function display_body(body, is_toplevel, output, allow_directives) {
|
||||
var last = body.length - 1;
|
||||
in_directive = allow_directives;
|
||||
var in_directive = allow_directives;
|
||||
var was_asm = use_asm;
|
||||
body.forEach(function(stmt, i) {
|
||||
if (in_directive === true && !(stmt instanceof AST_Directive ||
|
||||
stmt instanceof AST_EmptyStatement ||
|
||||
(stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String)
|
||||
)) {
|
||||
in_directive = false;
|
||||
}
|
||||
if (!(stmt instanceof AST_EmptyStatement)) {
|
||||
output.indent();
|
||||
stmt.print(output);
|
||||
if (!(i == last && is_toplevel)) {
|
||||
output.newline();
|
||||
if (is_toplevel) output.newline();
|
||||
if (in_directive) {
|
||||
if (stmt instanceof AST_Directive) {
|
||||
if (stmt.value == "use asm") use_asm = true;
|
||||
} else if (!(stmt instanceof AST_EmptyStatement)) {
|
||||
if (stmt instanceof AST_SimpleStatement && stmt.body instanceof AST_String) {
|
||||
output.force_semicolon();
|
||||
}
|
||||
in_directive = false;
|
||||
}
|
||||
}
|
||||
if (in_directive === true &&
|
||||
stmt instanceof AST_SimpleStatement &&
|
||||
stmt.body instanceof AST_String
|
||||
) {
|
||||
in_directive = false;
|
||||
}
|
||||
if (stmt instanceof AST_EmptyStatement) return;
|
||||
output.indent();
|
||||
stmt.print(output);
|
||||
if (i == last && is_toplevel) return;
|
||||
output.newline();
|
||||
if (is_toplevel) output.newline();
|
||||
});
|
||||
in_directive = false;
|
||||
use_asm = was_asm;
|
||||
}
|
||||
|
||||
AST_StatementWithBody.DEFMETHOD("_do_print_body", function(output) {
|
||||
@@ -1156,7 +1149,7 @@ function OutputStream(options) {
|
||||
function parenthesize_for_noin(node, output, noin) {
|
||||
var parens = false;
|
||||
// need to take some precautions here:
|
||||
// https://github.com/mishoo/UglifyJS2/issues/60
|
||||
// https://github.com/mishoo/UglifyJS/issues/60
|
||||
if (noin) node.walk(new TreeWalker(function(node) {
|
||||
if (parens || node instanceof AST_Scope) return true;
|
||||
if (node instanceof AST_Binary && node.operator == "in") {
|
||||
@@ -1221,7 +1214,7 @@ function OutputStream(options) {
|
||||
output.print_string(prop);
|
||||
output.print("]");
|
||||
} else {
|
||||
if (expr instanceof AST_Number && expr.getValue() >= 0) {
|
||||
if (expr instanceof AST_Number && expr.value >= 0) {
|
||||
if (!/[xa-f.)]/i.test(output.last())) {
|
||||
output.print(".");
|
||||
}
|
||||
@@ -1345,27 +1338,34 @@ function OutputStream(options) {
|
||||
output.print("this");
|
||||
});
|
||||
DEFPRINT(AST_Constant, function(self, output) {
|
||||
output.print(self.getValue());
|
||||
output.print(self.value);
|
||||
});
|
||||
DEFPRINT(AST_String, function(self, output) {
|
||||
output.print_string(self.getValue(), self.quote, in_directive);
|
||||
output.print_string(self.value, self.quote);
|
||||
});
|
||||
DEFPRINT(AST_Number, function(self, output) {
|
||||
if (use_asm && self.start && self.start.raw != null) {
|
||||
output.print(self.start.raw);
|
||||
} else {
|
||||
output.print(make_num(self.getValue()));
|
||||
output.print(make_num(self.value));
|
||||
}
|
||||
});
|
||||
|
||||
DEFPRINT(AST_RegExp, function(self, output) {
|
||||
var regexp = self.getValue();
|
||||
var regexp = self.value;
|
||||
var str = regexp.toString();
|
||||
var end = str.lastIndexOf("/");
|
||||
if (regexp.raw_source) {
|
||||
str = "/" + regexp.raw_source + str.slice(str.lastIndexOf("/"));
|
||||
str = "/" + regexp.raw_source + str.slice(end);
|
||||
} else if (end == 1) {
|
||||
str = "/(?:)" + str.slice(end);
|
||||
} else if (str.indexOf("/", 1) < end) {
|
||||
str = "/" + str.slice(1, end).replace(/\\\\|[^/]?\//g, function(match) {
|
||||
return match[0] == "\\" ? match : match.slice(0, -1) + "\\/";
|
||||
}) + str.slice(end);
|
||||
}
|
||||
output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(seq) {
|
||||
switch (seq[1]) {
|
||||
output.print(output.to_utf8(str).replace(/\\(?:\0(?![0-9])|[^\0])/g, function(match) {
|
||||
switch (match[1]) {
|
||||
case "\n": return "\\n";
|
||||
case "\r": return "\\r";
|
||||
case "\t": return "\t";
|
||||
@@ -1375,7 +1375,7 @@ function OutputStream(options) {
|
||||
case "\x0B": return "\v";
|
||||
case "\u2028": return "\\u2028";
|
||||
case "\u2029": return "\\u2029";
|
||||
default: return seq;
|
||||
default: return match;
|
||||
}
|
||||
}).replace(/[\n\r\u2028\u2029]/g, function(c) {
|
||||
switch (c) {
|
||||
@@ -1470,7 +1470,6 @@ function OutputStream(options) {
|
||||
AST_Node,
|
||||
// since the label symbol will mark it
|
||||
AST_LabeledStatement,
|
||||
AST_Toplevel,
|
||||
], noop);
|
||||
|
||||
// XXX: I'm not exactly sure if we need it for all of these nodes,
|
||||
@@ -1482,7 +1481,6 @@ function OutputStream(options) {
|
||||
AST_Constant,
|
||||
AST_Debugger,
|
||||
AST_Definitions,
|
||||
AST_Directive,
|
||||
AST_Finally,
|
||||
AST_Jump,
|
||||
AST_Lambda,
|
||||
|
Reference in New Issue
Block a user