1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-03 04:10:04 +02:00

update packages to latest version

This commit is contained in:
s2
2022-08-20 18:51:33 +02:00
parent 09663a35a5
commit 806ebf9a57
4513 changed files with 366205 additions and 92512 deletions

145
node_modules/terser/lib/output.js generated vendored
View File

@@ -159,7 +159,7 @@ import {
is_basic_identifier_string,
is_identifier_string,
PRECEDENCE,
RESERVED_WORDS,
ALL_RESERVED_WORDS,
} from "./parse.js";
const EXPECT_DIRECTIVE = /^$|[;{][\s\n]*$/;
@@ -172,10 +172,52 @@ function is_some_comments(comment) {
// multiline comment
return (
(comment.type === "comment2" || comment.type === "comment1")
&& /@preserve|@lic|@cc_on|^\**!/i.test(comment.value)
&& /@preserve|@copyright|@lic|@cc_on|^\**!/i.test(comment.value)
);
}
class Rope {
constructor() {
this.committed = "";
this.current = "";
}
append(str) {
this.current += str;
}
insertAt(char, index) {
const { committed, current } = this;
if (index < committed.length) {
this.committed = committed.slice(0, index) + char + committed.slice(index);
} else if (index === committed.length) {
this.committed += char;
} else {
index -= committed.length;
this.committed += current.slice(0, index) + char;
this.current = current.slice(index);
}
}
charAt(index) {
const { committed } = this;
if (index < committed.length) return committed[index];
return this.current[index - committed.length];
}
curLength() {
return this.current.length;
}
length() {
return this.committed.length + this.current.length;
}
toString() {
return this.committed + this.current;
}
}
function OutputStream(options) {
var readonly = !options;
@@ -205,6 +247,8 @@ function OutputStream(options) {
width : 80,
wrap_iife : false,
wrap_func_args : true,
_destroy_ast : false
}, true);
if (options.shorthand === undefined)
@@ -240,11 +284,11 @@ function OutputStream(options) {
var current_col = 0;
var current_line = 1;
var current_pos = 0;
var OUTPUT = "";
var OUTPUT = new Rope();
let printed_comments = new Set();
var to_utf8 = options.ascii_only ? function(str, identifier) {
if (options.ecma >= 2015 && !options.safari10) {
var to_utf8 = options.ascii_only ? function(str, identifier = false, regexp = false) {
if (options.ecma >= 2015 && !options.safari10 && !regexp) {
str = str.replace(/[\ud800-\udbff][\udc00-\udfff]/g, function(ch) {
var code = get_full_char_code(ch, 0).toString(16);
return "\\u{" + code + "}";
@@ -349,11 +393,17 @@ function OutputStream(options) {
var do_add_mapping = mappings ? function() {
mappings.forEach(function(mapping) {
try {
let { name, token } = mapping;
if (token.type == "name" || token.type === "privatename") {
name = token.value;
} else if (name instanceof AST_Symbol) {
name = token.type === "string" ? token.value : name.name;
}
options.source_map.add(
mapping.token.file,
mapping.line, mapping.col,
mapping.token.line, mapping.token.col,
!mapping.name && mapping.token.type == "name" ? mapping.token.value : mapping.name
is_basic_identifier_string(name) ? name : undefined
);
} catch(ex) {
// Ignore bad mapping
@@ -365,19 +415,18 @@ function OutputStream(options) {
var ensure_line_len = options.max_line_len ? function() {
if (current_col > options.max_line_len) {
if (might_add_newline) {
var left = OUTPUT.slice(0, might_add_newline);
var right = OUTPUT.slice(might_add_newline);
OUTPUT.insertAt("\n", might_add_newline);
const curLength = OUTPUT.curLength();
if (mappings) {
var delta = right.length - current_col;
var delta = curLength - current_col;
mappings.forEach(function(mapping) {
mapping.line++;
mapping.col += delta;
});
}
OUTPUT = left + "\n" + right;
current_line++;
current_pos++;
current_col = right.length;
current_col = curLength;
}
}
if (might_add_newline) {
@@ -411,13 +460,13 @@ function OutputStream(options) {
if (prev === ":" && ch === "}" || (!ch || !";}".includes(ch)) && prev !== ";") {
if (options.semicolons || requireSemicolonChars.has(ch)) {
OUTPUT += ";";
OUTPUT.append(";");
current_col++;
current_pos++;
} else {
ensure_line_len();
if (current_col > 0) {
OUTPUT += "\n";
OUTPUT.append("\n");
current_pos++;
current_line++;
current_col = 0;
@@ -441,7 +490,7 @@ function OutputStream(options) {
|| (ch == "/" && ch == prev)
|| ((ch == "+" || ch == "-") && ch == last)
) {
OUTPUT += " ";
OUTPUT.append(" ");
current_col++;
current_pos++;
}
@@ -459,7 +508,7 @@ function OutputStream(options) {
if (!might_add_newline) do_add_mapping();
}
OUTPUT += str;
OUTPUT.append(str);
has_parens = str[str.length - 1] == "(";
current_pos += str.length;
var a = str.split(/\r?\n/), n = a.length - 1;
@@ -499,15 +548,15 @@ function OutputStream(options) {
var newline = options.beautify ? function() {
if (newline_insert < 0) return print("\n");
if (OUTPUT[newline_insert] != "\n") {
OUTPUT = OUTPUT.slice(0, newline_insert) + "\n" + OUTPUT.slice(newline_insert);
if (OUTPUT.charAt(newline_insert) != "\n") {
OUTPUT.insertAt("\n", newline_insert);
current_pos++;
current_line++;
}
newline_insert++;
} : options.max_line_len ? function() {
ensure_line_len();
might_add_newline = OUTPUT.length;
might_add_newline = OUTPUT.length();
} : noop;
var semicolon = options.beautify ? function() {
@@ -573,13 +622,14 @@ function OutputStream(options) {
if (might_add_newline) {
ensure_line_len();
}
return OUTPUT;
return OUTPUT.toString();
}
function has_nlb() {
let n = OUTPUT.length - 1;
const output = OUTPUT.toString();
let n = output.length - 1;
while (n >= 0) {
const code = OUTPUT.charCodeAt(n);
const code = output.charCodeAt(n);
if (code === CODE_LINE_BREAK) {
return true;
}
@@ -716,7 +766,7 @@ function OutputStream(options) {
!/comment[134]/.test(c.type)
))) return;
printed_comments.add(comments);
var insert = OUTPUT.length;
var insert = OUTPUT.length();
comments.filter(comment_filter, node).forEach(function(c, i) {
if (printed_comments.has(c)) return;
printed_comments.add(c);
@@ -745,9 +795,21 @@ function OutputStream(options) {
need_space = true;
}
});
if (OUTPUT.length > insert) newline_insert = insert;
if (OUTPUT.length() > insert) newline_insert = insert;
}
/**
* When output.option("_destroy_ast") is enabled, destroy the function.
* Call this after printing it.
*/
const gc_scope =
options["_destroy_ast"]
? function gc_scope(scope) {
scope.body.length = 0;
scope.argnames.length = 0;
}
: noop;
var stack = [];
return {
get : get,
@@ -775,7 +837,7 @@ function OutputStream(options) {
var encoded = encode_string(str, quote);
if (escape_directive === true && !encoded.includes("\\")) {
// Insert semicolons to break directive prologue
if (!EXPECT_DIRECTIVE.test(OUTPUT)) {
if (!EXPECT_DIRECTIVE.test(OUTPUT.toString())) {
force_semicolon();
}
force_semicolon();
@@ -794,6 +856,7 @@ function OutputStream(options) {
with_square : with_square,
add_mapping : add_mapping,
option : function(opt) { return options[opt]; },
gc_scope,
printed_comments: printed_comments,
prepend_comments: readonly ? noop : prepend_comments,
append_comments : readonly || comment_filter === return_false ? noop : append_comments,
@@ -1050,7 +1113,8 @@ function OutputStream(options) {
var p = output.parent();
if (this.args.length === 0
&& (p instanceof AST_PropAccess // (new Date).getTime(), (new Date)["getTime"]()
|| p instanceof AST_Call && p.expression === this)) // (new foo)(bar)
|| p instanceof AST_Call && p.expression === this
|| p instanceof AST_PrefixedTemplateString && p.prefix === this)) // (new foo)(bar)
return true;
});
@@ -1183,12 +1247,14 @@ function OutputStream(options) {
output.with_indent(output.next_indent(), function() {
output.append_comments(self, true);
});
output.add_mapping(self.end);
output.print("}");
}
function print_braced(self, output, allow_directives) {
if (self.body.length > 0) {
output.with_block(function() {
display_body(self.body, false, output, allow_directives);
output.add_mapping(self.end);
});
} else print_braced_empty(self, output);
}
@@ -1309,6 +1375,7 @@ function OutputStream(options) {
});
DEFPRINT(AST_Lambda, function(self, output) {
self._do_print(output);
output.gc_scope(self);
});
DEFPRINT(AST_PrefixedTemplateString, function(self, output) {
@@ -1388,6 +1455,7 @@ function OutputStream(options) {
print_braced(self, output);
}
if (needs_parens) { output.print(")"); }
output.gc_scope(self);
});
/* -----[ exits ]----- */
@@ -1631,6 +1699,10 @@ function OutputStream(options) {
output.space();
}
self.module_name.print(output);
if (self.assert_clause) {
output.print("assert");
self.assert_clause.print(output);
}
output.semicolon();
});
DEFPRINT(AST_ImportMeta, function(self, output) {
@@ -1696,6 +1768,10 @@ function OutputStream(options) {
output.space();
self.module_name.print(output);
}
if (self.assert_clause) {
output.print("assert");
self.assert_clause.print(output);
}
if (self.exported_value
&& !(self.exported_value instanceof AST_Defun ||
self.exported_value instanceof AST_Function ||
@@ -1713,7 +1789,11 @@ function OutputStream(options) {
// https://github.com/mishoo/UglifyJS2/issues/60
if (noin) {
parens = walk(node, node => {
if (node instanceof AST_Scope) return true;
// Don't go into scopes -- except arrow functions:
// https://github.com/terser/terser/issues/1019#issuecomment-877642607
if (node instanceof AST_Scope && !(node instanceof AST_Arrow)) {
return true;
}
if (node instanceof AST_Binary && node.operator == "in") {
return walk_abort; // makes walk() return true
}
@@ -1783,7 +1863,7 @@ function OutputStream(options) {
var expr = self.expression;
expr.print(output);
var prop = self.property;
var print_computed = RESERVED_WORDS.has(prop)
var print_computed = ALL_RESERVED_WORDS.has(prop)
? output.option("ie8")
: !is_identifier_string(
prop,
@@ -1816,6 +1896,7 @@ function OutputStream(options) {
if (self.optional) output.print("?");
output.print(".#");
output.add_mapping(self.end);
output.print_name(prop);
});
DEFPRINT(AST_Sub, function(self, output) {
@@ -1964,7 +2045,7 @@ function OutputStream(options) {
}
return output.print(make_num(key));
}
var print_string = RESERVED_WORDS.has(key)
var print_string = ALL_RESERVED_WORDS.has(key)
? output.option("ie8")
: (
output.option("ecma") < 2015 || output.option("safari10")
@@ -1991,7 +2072,7 @@ function OutputStream(options) {
output.option("ecma") >= 2015 || output.option("safari10")
) &&
get_name(self.value) === self.key &&
!RESERVED_WORDS.has(self.key)
!ALL_RESERVED_WORDS.has(self.key)
) {
print_property_name(self.key, self.quote, output);
@@ -2152,7 +2233,7 @@ function OutputStream(options) {
flags = flags ? sort_regexp_flags(flags) : "";
source = source.replace(r_slash_script, slash_script_replace);
output.print(output.to_utf8(`/${source}/${flags}`));
output.print(output.to_utf8(`/${source}/${flags}`, false, true));
const parent = output.parent();
if (
@@ -2269,8 +2350,10 @@ function OutputStream(options) {
DEFMAP([
AST_ObjectGetter,
AST_ObjectSetter,
AST_PrivateGetter,
AST_PrivateSetter,
], function(output) {
output.add_mapping(this.start, this.key.name);
output.add_mapping(this.key.end, this.key.name);
});
DEFMAP([ AST_ObjectProperty ], function(output) {