mirror of
https://github.com/S2-/minifyfromhtml.git
synced 2025-08-03 12:20:04 +02:00
update minify
This commit is contained in:
140
node_modules/uglify-js/lib/parse.js
generated
vendored
140
node_modules/uglify-js/lib/parse.js
generated
vendored
@@ -133,14 +133,10 @@ function is_letter(code) {
|
||||
}
|
||||
|
||||
function is_surrogate_pair_head(code) {
|
||||
if (typeof code == "string")
|
||||
code = code.charCodeAt(0);
|
||||
return code >= 0xd800 && code <= 0xdbff;
|
||||
}
|
||||
|
||||
function is_surrogate_pair_tail(code) {
|
||||
if (typeof code == "string")
|
||||
code = code.charCodeAt(0);
|
||||
return code >= 0xdc00 && code <= 0xdfff;
|
||||
}
|
||||
|
||||
@@ -164,10 +160,6 @@ function is_unicode_connector_punctuation(ch) {
|
||||
return UNICODE.connector_punctuation.test(ch);
|
||||
}
|
||||
|
||||
function is_identifier(name) {
|
||||
return !RESERVED_WORDS[name] && /^[a-z_$][a-z0-9_$]*$/i.test(name);
|
||||
}
|
||||
|
||||
function is_identifier_start(code) {
|
||||
return code == 36 || code == 95 || is_letter(code);
|
||||
}
|
||||
@@ -238,6 +230,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
directives : {},
|
||||
directive_stack : []
|
||||
};
|
||||
var prev_was_dot = false;
|
||||
|
||||
function peek() {
|
||||
return S.text.charAt(S.pos);
|
||||
@@ -272,10 +265,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
function find_eol() {
|
||||
var text = S.text;
|
||||
for (var i = S.pos, n = S.text.length; i < n; ++i) {
|
||||
var ch = text[i];
|
||||
if (NEWLINE_CHARS[ch])
|
||||
return i;
|
||||
for (var i = S.pos; i < S.text.length; ++i) {
|
||||
if (NEWLINE_CHARS[text[i]]) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -292,16 +283,12 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
S.tokpos = S.pos;
|
||||
}
|
||||
|
||||
var prev_was_dot = false;
|
||||
function token(type, value, is_comment) {
|
||||
S.regex_allowed = ((type == "operator" && !UNARY_POSTFIX[value]) ||
|
||||
(type == "keyword" && KEYWORDS_BEFORE_EXPRESSION[value]) ||
|
||||
(type == "punc" && PUNC_BEFORE_EXPRESSION[value]));
|
||||
if (type == "punc" && value == ".") {
|
||||
prev_was_dot = true;
|
||||
} else if (!is_comment) {
|
||||
prev_was_dot = false;
|
||||
}
|
||||
S.regex_allowed = type == "operator" && !UNARY_POSTFIX[value]
|
||||
|| type == "keyword" && KEYWORDS_BEFORE_EXPRESSION[value]
|
||||
|| type == "punc" && PUNC_BEFORE_EXPRESSION[value];
|
||||
if (type == "punc" && value == ".") prev_was_dot = true;
|
||||
else if (!is_comment) prev_was_dot = false;
|
||||
var ret = {
|
||||
type : type,
|
||||
value : value,
|
||||
@@ -364,11 +351,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
parse_error("Legacy octal literals are not allowed in strict mode");
|
||||
}
|
||||
var valid = parse_js_number(num);
|
||||
if (!isNaN(valid)) {
|
||||
return token("num", valid);
|
||||
} else {
|
||||
parse_error("Invalid syntax: " + num);
|
||||
}
|
||||
if (!isNaN(valid)) return token("num", valid);
|
||||
parse_error("Invalid syntax: " + num);
|
||||
}
|
||||
|
||||
function read_escaped_char(in_string) {
|
||||
@@ -469,8 +453,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
if (ch == "\\") escaped = backslash = true, next();
|
||||
else if (is_identifier_char(ch)) name += next();
|
||||
else break;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (ch != "u") parse_error("Expecting UnicodeEscapeSequence -- uXXXX");
|
||||
ch = read_escaped_char();
|
||||
if (!is_identifier_char(ch)) parse_error("Unicode char: " + ch.charCodeAt(0) + " is not valid in identifier");
|
||||
@@ -510,7 +493,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
var regexp = new RegExp(source, mods);
|
||||
regexp.raw_source = source;
|
||||
return token("regexp", regexp);
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
parse_error(e.message);
|
||||
}
|
||||
});
|
||||
@@ -544,9 +527,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
function handle_dot() {
|
||||
next();
|
||||
return is_digit(peek().charCodeAt(0))
|
||||
? read_num(".")
|
||||
: token("punc", ".");
|
||||
return is_digit(peek().charCodeAt(0)) ? read_num(".") : token("punc", ".");
|
||||
}
|
||||
|
||||
function read_word() {
|
||||
@@ -562,7 +543,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
return function(x) {
|
||||
try {
|
||||
return cont(x);
|
||||
} catch(ex) {
|
||||
} catch (ex) {
|
||||
if (ex === EX_EOF) parse_error(eof_error);
|
||||
else throw ex;
|
||||
}
|
||||
@@ -598,11 +579,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
switch (code) {
|
||||
case 34: case 39: return read_string(ch);
|
||||
case 46: return handle_dot();
|
||||
case 47: {
|
||||
var tok = handle_slash();
|
||||
if (tok === next_token) continue;
|
||||
return tok;
|
||||
}
|
||||
case 47:
|
||||
var tok = handle_slash();
|
||||
if (tok === next_token) continue;
|
||||
return tok;
|
||||
}
|
||||
if (is_digit(code)) return read_num();
|
||||
if (PUNC_CHARS[ch]) return token("punc", next());
|
||||
@@ -620,12 +600,8 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
next_token.add_directive = function(directive) {
|
||||
S.directive_stack[S.directive_stack.length - 1].push(directive);
|
||||
|
||||
if (S.directives[directive] === undefined) {
|
||||
S.directives[directive] = 1;
|
||||
} else {
|
||||
S.directives[directive]++;
|
||||
}
|
||||
if (S.directives[directive]) S.directives[directive]++;
|
||||
else S.directives[directive] = 1;
|
||||
}
|
||||
|
||||
next_token.push_directives_stack = function() {
|
||||
@@ -633,13 +609,10 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
}
|
||||
|
||||
next_token.pop_directives_stack = function() {
|
||||
var directives = S.directive_stack[S.directive_stack.length - 1];
|
||||
|
||||
for (var i = 0; i < directives.length; i++) {
|
||||
var directives = S.directive_stack.pop();
|
||||
for (var i = directives.length; --i >= 0;) {
|
||||
S.directives[directives[i]]--;
|
||||
}
|
||||
|
||||
S.directive_stack.pop();
|
||||
}
|
||||
|
||||
next_token.has_directive = function(directive) {
|
||||
@@ -651,27 +624,17 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
||||
|
||||
/* -----[ Parser (constants) ]----- */
|
||||
|
||||
var UNARY_PREFIX = makePredicate([
|
||||
"typeof",
|
||||
"void",
|
||||
"delete",
|
||||
"--",
|
||||
"++",
|
||||
"!",
|
||||
"~",
|
||||
"-",
|
||||
"+"
|
||||
]);
|
||||
var UNARY_PREFIX = makePredicate("typeof void delete -- ++ ! ~ - +");
|
||||
|
||||
var UNARY_POSTFIX = makePredicate([ "--", "++" ]);
|
||||
var UNARY_POSTFIX = makePredicate("-- ++");
|
||||
|
||||
var ASSIGNMENT = makePredicate([ "=", "+=", "-=", "/=", "*=", "%=", ">>=", "<<=", ">>>=", "|=", "^=", "&=" ]);
|
||||
var ASSIGNMENT = makePredicate("= += -= /= *= %= >>= <<= >>>= |= ^= &=");
|
||||
|
||||
var PRECEDENCE = function(a, ret) {
|
||||
for (var i = 0; i < a.length; ++i) {
|
||||
var b = a[i];
|
||||
for (var j = 0; j < b.length; ++j) {
|
||||
ret[b[j]] = i + 1;
|
||||
for (var i = 0; i < a.length;) {
|
||||
var b = a[i++];
|
||||
for (var j = 0; j < b.length; j++) {
|
||||
ret[b[j]] = i;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@@ -688,7 +651,7 @@ var PRECEDENCE = function(a, ret) {
|
||||
["*", "/", "%"]
|
||||
], {});
|
||||
|
||||
var ATOMIC_START_TOKEN = makePredicate([ "atom", "num", "string", "regexp", "name" ]);
|
||||
var ATOMIC_START_TOKEN = makePredicate("atom num string regexp name");
|
||||
|
||||
/* -----[ Parser ]----- */
|
||||
|
||||
@@ -704,10 +667,9 @@ function parse($TEXT, options) {
|
||||
}, true);
|
||||
|
||||
var S = {
|
||||
input : (typeof $TEXT == "string"
|
||||
? tokenizer($TEXT, options.filename,
|
||||
options.html5_comments, options.shebang)
|
||||
: $TEXT),
|
||||
input : typeof $TEXT == "string"
|
||||
? tokenizer($TEXT, options.filename, options.html5_comments, options.shebang)
|
||||
: $TEXT,
|
||||
token : null,
|
||||
prev : null,
|
||||
peeked : null,
|
||||
@@ -763,15 +725,12 @@ function parse($TEXT, options) {
|
||||
}
|
||||
|
||||
function unexpected(token) {
|
||||
if (token == null)
|
||||
token = S.token;
|
||||
if (token == null) token = S.token;
|
||||
token_error(token, "Unexpected token: " + token_to_string(token.type, token.value));
|
||||
}
|
||||
|
||||
function expect_token(type, val) {
|
||||
if (is(type, val)) {
|
||||
return next();
|
||||
}
|
||||
if (is(type, val)) return next();
|
||||
token_error(S.token, "Unexpected token: " + token_to_string(S.token.type, S.token.value) + ", expected: " + token_to_string(type, val));
|
||||
}
|
||||
|
||||
@@ -824,20 +783,19 @@ function parse($TEXT, options) {
|
||||
handle_regexp();
|
||||
switch (S.token.type) {
|
||||
case "string":
|
||||
if (S.in_directives) {
|
||||
var token = peek();
|
||||
if (S.token.raw.indexOf("\\") == -1
|
||||
&& (is_token(token, "punc", ";")
|
||||
|| is_token(token, "punc", "}")
|
||||
|| has_newline_before(token)
|
||||
|| is_token(token, "eof"))) {
|
||||
S.input.add_directive(S.token.value);
|
||||
var dir = S.in_directives;
|
||||
var body = expression(true);
|
||||
if (dir) {
|
||||
if (body instanceof AST_String) {
|
||||
var value = body.start.raw.slice(1, -1);
|
||||
S.input.add_directive(value);
|
||||
body.value = value;
|
||||
} else {
|
||||
S.in_directives = false;
|
||||
S.in_directives = dir = false;
|
||||
}
|
||||
}
|
||||
var dir = S.in_directives, stat = simple_statement();
|
||||
return dir ? new AST_Directive(stat.body) : stat;
|
||||
semicolon();
|
||||
return dir ? new AST_Directive(body) : new AST_SimpleStatement({ body: body });
|
||||
case "num":
|
||||
case "regexp":
|
||||
case "operator":
|
||||
@@ -1002,8 +960,10 @@ function parse($TEXT, options) {
|
||||
return new AST_LabeledStatement({ body: stat, label: label });
|
||||
}
|
||||
|
||||
function simple_statement(tmp) {
|
||||
return new AST_SimpleStatement({ body: (tmp = expression(true), semicolon(), tmp) });
|
||||
function simple_statement() {
|
||||
var body = expression(true);
|
||||
semicolon();
|
||||
return new AST_SimpleStatement({ body: body });
|
||||
}
|
||||
|
||||
function break_cont(type) {
|
||||
@@ -1290,6 +1250,7 @@ function parse($TEXT, options) {
|
||||
var ex = expression(true);
|
||||
var len = start.comments_before.length;
|
||||
[].unshift.apply(ex.start.comments_before, start.comments_before);
|
||||
start.comments_before.length = 0;
|
||||
start.comments_before = ex.start.comments_before;
|
||||
start.comments_before_length = len;
|
||||
if (len == 0 && start.comments_before.length > 0) {
|
||||
@@ -1305,6 +1266,7 @@ function parse($TEXT, options) {
|
||||
var end = prev();
|
||||
end.comments_before = ex.end.comments_before;
|
||||
[].push.apply(ex.end.comments_after, end.comments_after);
|
||||
end.comments_after.length = 0;
|
||||
end.comments_after = ex.end.comments_after;
|
||||
ex.end = end;
|
||||
if (ex instanceof AST_Call) mark_pure(ex);
|
||||
|
Reference in New Issue
Block a user