Port back changes from Parse-js HEAD and merge changes back into non-unicdoe version.

This commit is contained in:
Jürg Lehni 2011-07-31 12:11:22 +01:00
parent 7f81184848
commit d3241f2540
3 changed files with 123 additions and 92 deletions

20
lib/parse-js-min.js vendored

File diff suppressed because one or more lines are too long

View file

@ -362,6 +362,7 @@ function tokenizer($TEXT) {
case "0" : return "\0";
case "x" : return String.fromCharCode(hex_bytes(2));
case "u" : return String.fromCharCode(hex_bytes(4));
case "\n": return "";
default : return ch;
}
};
@ -382,7 +383,24 @@ function tokenizer($TEXT) {
var quote = next(), ret = "";
for (;;) {
var ch = next(true);
if (ch == "\\") ch = read_escaped_char();
if (ch == "\\") {
// read OctalEscapeSequence (XXX: deprecated if "strict mode")
// https://github.com/mishoo/UglifyJS/issues/178
var octal_len = 0, first = null;
ch = read_while(function(ch){
if (ch >= "0" && ch <= "7") {
if (!first) {
first = ch;
return ++octal_len;
}
else if (first <= "3" && octal_len <= 2) return ++octal_len;
else if (first >= "4" && octal_len <= 1) return ++octal_len;
}
return false;
});
if (octal_len > 0) ch = String.fromCharCode(parseInt(ch, 8));
else ch = read_escaped_char();
}
else if (ch == quote) break;
ret += ch;
}
@ -1200,6 +1218,47 @@ function parse($TEXT, exigent_mode, embed_tokens) {
};
/* -----[ Utilities ]----- */
function curry(f) {
var args = slice(arguments, 1);
return function() { return f.apply(this, args.concat(slice(arguments))); };
};
function prog1(ret) {
if (ret instanceof Function)
ret = ret();
for (var i = 1, n = arguments.length; --n > 0; ++i)
arguments[i]();
return ret;
};
function array_to_hash(a) {
var ret = {};
for (var i = 0; i < a.length; ++i)
ret[a[i]] = true;
return ret;
};
function slice(a, start) {
return Array.prototype.slice.call(a, start || 0);
};
function characters(str) {
return str.split("");
};
function member(name, array) {
for (var i = array.length; --i >= 0;)
if (array[i] === name)
return true;
return false;
};
function HOP(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
/* -----[ helper for AST traversal ]----- */
function ast_walker() {
@ -1441,7 +1500,8 @@ function gen_code(ast, options) {
quote_keys : false,
space_colon : false,
beautify : false,
ascii_only : false
ascii_only : false,
inline_script: false
});
var beautify = !!options.beautify;
var indentation = 0,
@ -1449,7 +1509,10 @@ function gen_code(ast, options) {
space = beautify ? " " : "";
function encode_string(str) {
return make_string(str, options.ascii_only);
var ret = make_string(str, options.ascii_only);
if (options.inline_script)
ret = ret.replace(/<\x2fscript([>/\t\n\f\r ])/gi, "<\\/script$1");
return ret;
};
function make_name(name) {
@ -1705,6 +1768,10 @@ function gen_code(ast, options) {
!(rvalue[1] == operator && member(operator, [ "&&", "||", "*" ]))) {
right = "(" + right + ")";
}
else if (!beautify && options.inline_script && (operator == "<" || operator == "<<")
&& rvalue[0] == "regexp" && /^script/i.test(rvalue[1])) {
right = " " + right;
}
return add_spaces([ left, operator, right ]);
},
"unary-prefix": function(operator, expr) {
@ -1735,7 +1802,7 @@ function gen_code(ast, options) {
// body in p[1][3] and type ("get" / "set") in p[2].
return indent(make_function(p[0], p[1][2], p[1][3], p[2]));
}
var key = p[0], val = make(p[1]);
var key = p[0], val = parenthesize(p[1], "seq");
if (options.quote_keys) {
key = encode_string(key);
} else if ((typeof key == "number" || !beautify && +key + "" == key)
@ -1888,41 +1955,6 @@ function gen_code(ast, options) {
/* -----[ Utilities ]----- */
function curry(f) {
var args = slice(arguments, 1);
return function() { return f.apply(this, args.concat(slice(arguments))); };
};
function prog1(ret) {
if (ret instanceof Function)
ret = ret();
for (var i = 1, n = arguments.length; --n > 0; ++i)
arguments[i]();
return ret;
};
function array_to_hash(a) {
var ret = {};
for (var i = 0; i < a.length; ++i)
ret[a[i]] = true;
return ret;
};
function slice(a, start) {
return Array.prototype.slice.call(a, start || 0);
};
function characters(str) {
return str.split("");
};
function member(name, array) {
for (var i = array.length; --i >= 0;)
if (array[i] === name)
return true;
return false;
};
function repeat_string(str, i) {
return i < 1 ? "" : new Array(i + 1).join(str);
};
@ -1945,10 +1977,6 @@ function is_identifier(name) {
&& !HOP(KEYWORDS, name);
};
function HOP(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
function MAP(a, f, o) {
var ret = [];
for (var i = 0; i < a.length; ++i) {

View file

@ -342,6 +342,7 @@ function tokenizer($TEXT) {
case "0" : return "\0";
case "x" : return String.fromCharCode(hex_bytes(2));
case "u" : return String.fromCharCode(hex_bytes(4));
case "\n": return "";
default : return ch;
}
};
@ -1163,6 +1164,47 @@ function parse($TEXT, exigent_mode, embed_tokens) {
};
/* -----[ Utilities ]----- */
function curry(f) {
var args = slice(arguments, 1);
return function() { return f.apply(this, args.concat(slice(arguments))); };
};
function prog1(ret) {
if (ret instanceof Function)
ret = ret();
for (var i = 1, n = arguments.length; --n > 0; ++i)
arguments[i]();
return ret;
};
function array_to_hash(a) {
var ret = {};
for (var i = 0; i < a.length; ++i)
ret[a[i]] = true;
return ret;
};
function slice(a, start) {
return Array.prototype.slice.call(a, start || 0);
};
function characters(str) {
return str.split("");
};
function member(name, array) {
for (var i = array.length; --i >= 0;)
if (array[i] === name)
return true;
return false;
};
function HOP(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
/* -----[ helper for AST traversal ]----- */
function ast_walker() {
@ -1832,41 +1874,6 @@ function gen_code(ast, options) {
/* -----[ Utilities ]----- */
function curry(f) {
var args = slice(arguments, 1);
return function() { return f.apply(this, args.concat(slice(arguments))); };
};
function prog1(ret) {
if (ret instanceof Function)
ret = ret();
for (var i = 1, n = arguments.length; --n > 0; ++i)
arguments[i]();
return ret;
};
function array_to_hash(a) {
var ret = {};
for (var i = 0; i < a.length; ++i)
ret[a[i]] = true;
return ret;
};
function slice(a, start) {
return Array.prototype.slice.call(a, start || 0);
};
function characters(str) {
return str.split("");
};
function member(name, array) {
for (var i = array.length; --i >= 0;)
if (array[i] === name)
return true;
return false;
};
function repeat_string(str, i) {
return i < 1 ? "" : new Array(i + 1).join(str);
};
@ -1889,10 +1896,6 @@ function is_identifier(name) {
&& !HOP(KEYWORDS, name);
};
function HOP(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
};
function MAP(a, f, o) {
var ret = [];
for (var i = 0; i < a.length; ++i) {