feat: refactoring project

This commit is contained in:
Carlos
2024-11-23 14:56:07 -05:00
parent f0c2a50c18
commit 1c6db5818d
2351 changed files with 39323 additions and 60326 deletions

31
node_modules/terser/CHANGELOG.md generated vendored
View File

@@ -1,5 +1,36 @@
# Changelog
## v5.36.0
- Support import attributes `with` syntax
## v5.35.0
- Ensure parent directory exists when using --output on CLI (#1530)
## v5.34.1
- bump the rollup devDependency to disable CVE warnings (Terser was not affected)
## v5.34.0
- internal: stop assigning properties to objects they don't belong in
- internal: run compress tests in parallel
- `drop_console`: emit an empty function if the return value of `console.METHOD(...)` may be called.
## v5.33.0
- `reduce_vars` improved when dealing with hoisted function definitions (#1544)
## v5.32.0
- `import("module")` can now be input and output from ESTree AST (#1557)
- `BigInt` literals can now be input and output from ESTree AST (#1555)
- `typeof` an object or array (`typeof {}` and `typeof []`) can now be statically evaluated. (#1546)
## v5.31.6
- Retain side effects in a `case` when the expression is a sequence (comma) expression
## v5.31.5
- Revert v5.31.4, which created mysterious issues #1548, #1549

2
node_modules/terser/README.md generated vendored
View File

@@ -972,7 +972,7 @@ await minify(code, { mangle: { toplevel: true } }).code;
- `false` -- `obj["prop"]` is mangled.
- `true` -- `obj.prop` is mangled unless there is `obj["prop"]` elsewhere in the code.
- `nth_identifer` (default: an internal mangler that weights based on character
- `nth_identifier` (default: an internal mangler that weights based on character
frequency analysis) -- Pass an object with a `get(n)` function that converts an
ordinal into the nth most favored (usually shortest) identifier.
Optionally also provide `reset()`, `sort()`, and `consider(chars, delta)` to

View File

@@ -2871,8 +2871,11 @@ function parse($TEXT, options) {
return new AST_ClassStaticBlock({ start, body, end: prev() });
}
function maybe_import_assertion() {
if (is("name", "assert") && !has_newline_before(S.token)) {
function maybe_import_attributes() {
if (
(is("keyword", "with") || is("name", "assert"))
&& !has_newline_before(S.token)
) {
next();
return object_or_destructuring_();
}
@@ -2903,7 +2906,7 @@ function parse($TEXT, options) {
}
next();
const assert_clause = maybe_import_assertion();
const attributes = maybe_import_attributes();
return new AST_Import({
start,
@@ -2915,7 +2918,7 @@ function parse($TEXT, options) {
quote: mod_str.quote,
end: mod_str,
}),
assert_clause,
attributes,
end: S.token,
});
}
@@ -3048,7 +3051,7 @@ function parse($TEXT, options) {
}
next();
const assert_clause = maybe_import_assertion();
const attributes = maybe_import_attributes();
return new AST_Export({
start: start,
@@ -3061,7 +3064,7 @@ function parse($TEXT, options) {
end: mod_str,
}),
end: prev(),
assert_clause
attributes
});
} else {
return new AST_Export({
@@ -3107,7 +3110,7 @@ function parse($TEXT, options) {
exported_value: exported_value,
exported_definition: exported_definition,
end: prev(),
assert_clause: null
attributes: null
});
}
@@ -5097,13 +5100,13 @@ var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", function AST_N
var AST_Import = DEFNODE(
"Import",
"imported_name imported_names module_name assert_clause",
"imported_name imported_names module_name attributes",
function AST_Import(props) {
if (props) {
this.imported_name = props.imported_name;
this.imported_names = props.imported_names;
this.module_name = props.module_name;
this.assert_clause = props.assert_clause;
this.attributes = props.attributes;
this.start = props.start;
this.end = props.end;
}
@@ -5116,7 +5119,7 @@ var AST_Import = DEFNODE(
imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
imported_names: "[AST_NameMapping*] The names of non-default imported variables",
module_name: "[AST_String] String literal describing where this module came from",
assert_clause: "[AST_Object?] The import assertion"
attributes: "[AST_Object?] The import attributes (with {...})"
},
_walk: function(visitor) {
return visitor._visit(this, function() {
@@ -5155,7 +5158,7 @@ var AST_ImportMeta = DEFNODE("ImportMeta", null, function AST_ImportMeta(props)
var AST_Export = DEFNODE(
"Export",
"exported_definition exported_value is_default exported_names module_name assert_clause",
"exported_definition exported_value is_default exported_names module_name attributes",
function AST_Export(props) {
if (props) {
this.exported_definition = props.exported_definition;
@@ -5163,7 +5166,7 @@ var AST_Export = DEFNODE(
this.is_default = props.is_default;
this.exported_names = props.exported_names;
this.module_name = props.module_name;
this.assert_clause = props.assert_clause;
this.attributes = props.attributes;
this.start = props.start;
this.end = props.end;
}
@@ -5178,7 +5181,7 @@ var AST_Export = DEFNODE(
exported_names: "[AST_NameMapping*?] List of exported names",
module_name: "[AST_String?] Name of the file to load exports from",
is_default: "[Boolean] Whether this is the default exported value of this module",
assert_clause: "[AST_Object?] The import assertion"
attributes: "[AST_Object?] The import attributes"
},
_walk: function (visitor) {
return visitor._visit(this, function () {
@@ -7157,23 +7160,23 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
return body;
};
const assert_clause_from_moz = (assertions) => {
if (assertions && assertions.length > 0) {
function import_attributes_from_moz(attributes) {
if (attributes && attributes.length > 0) {
return new AST_Object({
start: my_start_token(assertions),
end: my_end_token(assertions),
properties: assertions.map((assertion_kv) =>
start: my_start_token(attributes),
end: my_end_token(attributes),
properties: attributes.map((attr) =>
new AST_ObjectKeyVal({
start: my_start_token(assertion_kv),
end: my_end_token(assertion_kv),
key: assertion_kv.key.name || assertion_kv.key.value,
value: from_moz(assertion_kv.value)
start: my_start_token(attr),
end: my_end_token(attr),
key: attr.key.name || attr.key.value,
value: from_moz(attr.value)
})
)
});
}
return null;
};
}
var MOZ_TO_ME = {
Program: function(M) {
@@ -7545,7 +7548,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
imported_name: imported_name,
imported_names : imported_names,
module_name : from_moz(M.source),
assert_clause: assert_clause_from_moz(M.assertions)
attributes: import_attributes_from_moz(M.attributes || M.assertions)
});
},
@@ -7571,6 +7574,23 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
});
},
ImportExpression: function(M) {
const args = [from_moz(M.source)];
if (M.options) {
args.push(from_moz(M.options));
}
return new AST_Call({
start: my_start_token(M),
end: my_end_token(M),
expression: from_moz({
type: "Identifier",
name: "import"
}),
optional: false,
args
});
},
ExportAllDeclaration: function(M) {
var foreign_name = M.exported == null ?
new AST_SymbolExportForeign({ name: "*" }) :
@@ -7585,7 +7605,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
})
],
module_name: from_moz(M.source),
assert_clause: assert_clause_from_moz(M.assertions)
attributes: import_attributes_from_moz(M.attributes || M.assertions)
});
},
@@ -7596,7 +7616,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
exported_definition: from_moz(M.declaration),
exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(from_moz) : null,
module_name: from_moz(M.source),
assert_clause: assert_clause_from_moz(M.assertions)
attributes: import_attributes_from_moz(M.attributes || M.assertions)
});
},
@@ -7638,6 +7658,11 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
args.value = { source, flags };
return new AST_RegExp(args);
}
const bi = typeof M.value === "bigint" ? M.value.toString() : M.bigint;
if (typeof bi === "string") {
args.value = bi;
return new AST_BigInt(args);
}
if (val === null) return new AST_Null(args);
switch (typeof val) {
case "string":
@@ -7705,14 +7730,6 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
});
},
BigIntLiteral(M) {
return new AST_BigInt({
start : my_start_token(M),
end : my_end_token(M),
value : M.value
});
},
EmptyStatement: function(M) {
return new AST_EmptyStatement({
start: my_start_token(M),
@@ -8185,6 +8202,15 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
};
});
def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
if (M.expression instanceof AST_SymbolRef && M.expression.name === "import") {
const [source, options] = M.args.map(to_moz);
return {
type: "ImportExpression",
source,
options
};
}
return {
type: "CallExpression",
callee: to_moz(M.expression),
@@ -8342,22 +8368,22 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
};
});
const assert_clause_to_moz = assert_clause => {
const assertions = [];
if (assert_clause) {
for (const { key, value } of assert_clause.properties) {
function import_attributes_to_moz(attribute) {
const import_attributes = [];
if (attribute) {
for (const { key, value } of attribute.properties) {
const key_moz = is_basic_identifier_string(key)
? { type: "Identifier", name: key }
: { type: "Literal", value: key, raw: JSON.stringify(key) };
assertions.push({
import_attributes.push({
type: "ImportAttribute",
key: key_moz,
value: to_moz(value)
});
}
}
return assertions;
};
return import_attributes;
}
def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
if (M.exported_names) {
@@ -8372,7 +8398,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
type: "ExportAllDeclaration",
source: to_moz(M.module_name),
exported: exported,
assertions: assert_clause_to_moz(M.assert_clause)
attributes: import_attributes_to_moz(M.attributes)
};
}
return {
@@ -8386,7 +8412,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
}),
declaration: to_moz(M.exported_definition),
source: to_moz(M.module_name),
assertions: assert_clause_to_moz(M.assert_clause)
attributes: import_attributes_to_moz(M.attributes)
};
}
return {
@@ -8424,7 +8450,7 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
type: "ImportDeclaration",
specifiers: specifiers,
source: to_moz(M.module_name),
assertions: assert_clause_to_moz(M.assert_clause)
attributes: import_attributes_to_moz(M.attributes)
};
});
@@ -8730,8 +8756,13 @@ def_transform(AST_PrefixedTemplateString, function(self, tw) {
});
def_to_moz(AST_BigInt, M => ({
type: "BigIntLiteral",
value: M.value
type: "Literal",
// value cannot be represented natively
// see: https://github.com/estree/estree/blob/master/es2020.md#bigintliteral
value: null,
// `M.value` is a string that may be a hex number representation.
// but "bigint" property should have only decimal digits
bigint: typeof BigInt === "function" ? BigInt(M.value).toString() : M.value,
}));
AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);
@@ -10567,9 +10598,9 @@ function OutputStream(options) {
output.space();
}
self.module_name.print(output);
if (self.assert_clause) {
output.print("assert");
self.assert_clause.print(output);
if (self.attributes) {
output.print("with");
self.attributes.print(output);
}
output.semicolon();
});
@@ -10663,9 +10694,9 @@ function OutputStream(options) {
output.space();
self.module_name.print(output);
}
if (self.assert_clause) {
output.print("assert");
self.assert_clause.print(output);
if (self.attributes) {
output.print("with");
self.attributes.print(output);
}
if (self.exported_value
&& !(self.exported_value instanceof AST_Defun ||
@@ -11651,7 +11682,7 @@ function redefined_catch_def(def) {
}
}
AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null, toplevel = this } = {}) {
AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = undefined, toplevel = this } = {}) {
options = defaults(options, {
cache: null,
ie8: false,
@@ -11975,7 +12006,7 @@ AST_Scope.DEFMETHOD("add_child_scope", function (scope) {
scope.parent_scope = this;
// Propagate to this.uses_arguments from arrow functions
if ((scope instanceof AST_Arrow) && !this.uses_arguments) {
if ((scope instanceof AST_Arrow) && (this instanceof AST_Lambda && !this.uses_arguments)) {
this.uses_arguments = walk(scope, node => {
if (
node instanceof AST_SymbolRef
@@ -13042,6 +13073,23 @@ function make_sequence(orig, expressions) {
});
}
function make_empty_function(self) {
return make_node(AST_Function, self, {
uses_arguments: false,
argnames: [],
body: [],
is_generator: false,
async: false,
variables: new Map(),
uses_with: false,
uses_eval: false,
parent_scope: null,
enclosed: [],
cname: 0,
block_scope: undefined,
});
}
function make_node_from_constant(val, orig) {
switch (typeof val) {
case "string":
@@ -13268,9 +13316,9 @@ function is_reachable(scope_node, defs) {
}
/** Check if a ref refers to the name of a function/class it's defined within */
function is_recursive_ref(compressor, def) {
function is_recursive_ref(tw, def) {
var node;
for (var i = 0; node = compressor.parent(i); i++) {
for (var i = 0; node = tw.parent(i); i++) {
if (node instanceof AST_Lambda || node instanceof AST_Class) {
var name = node.name;
if (name && name.definition() === def) {
@@ -13836,7 +13884,7 @@ function is_nullish(node, compressor) {
return any(this.definitions, compressor);
});
def_has_side_effects(AST_VarDef, function() {
return this.value;
return this.value != null;
});
def_has_side_effects(AST_TemplateSegment, return_false);
def_has_side_effects(AST_TemplateString, function(compressor) {
@@ -14395,6 +14443,54 @@ function is_modified(compressor, tw, node, value, level, immutable) {
}
}
/**
* Check if a node may be used by the expression it's in
* void (0, 1, {node}, 2) -> false
* console.log(0, {node}) -> true
*/
function is_used_in_expression(tw) {
for (let p = -1, node, parent; node = tw.parent(p), parent = tw.parent(p + 1); p++) {
if (parent instanceof AST_Sequence) {
const nth_expression = parent.expressions.indexOf(node);
if (nth_expression !== parent.expressions.length - 1) {
// Detect (0, x.noThis)() constructs
const grandparent = tw.parent(p + 2);
if (
parent.expressions.length > 2
|| parent.expressions.length === 1
|| !requires_sequence_to_maintain_binding(grandparent, parent, parent.expressions[1])
) {
return false;
}
return true;
} else {
continue;
}
}
if (parent instanceof AST_Unary) {
const op = parent.operator;
if (op === "void") {
return false;
}
if (op === "typeof" || op === "+" || op === "-" || op === "!" || op === "~") {
continue;
}
}
if (
parent instanceof AST_SimpleStatement
|| parent instanceof AST_LabeledStatement
) {
return false;
}
if (parent instanceof AST_Scope) {
return false;
}
return true;
}
return true;
}
/***********************************************************************
A JavaScript tokenizer / parser / beautifier / compressor.
@@ -14579,14 +14675,25 @@ def_eval(AST_Object, function (compressor, depth) {
var non_converting_unary = makePredicate("! typeof void");
def_eval(AST_UnaryPrefix, function (compressor, depth) {
var e = this.expression;
// Function would be evaluated to an array and so typeof would
// incorrectly return 'object'. Hence making is a special case.
if (compressor.option("typeofs")
&& this.operator == "typeof"
&& (e instanceof AST_Lambda
&& this.operator == "typeof") {
// Function would be evaluated to an array and so typeof would
// incorrectly return 'object'. Hence making is a special case.
if (e instanceof AST_Lambda
|| e instanceof AST_SymbolRef
&& e.fixed_value() instanceof AST_Lambda)) {
return typeof function () { };
&& e.fixed_value() instanceof AST_Lambda) {
return typeof function () { };
}
if (
(e instanceof AST_Object
|| e instanceof AST_Array
|| (e instanceof AST_SymbolRef
&& (e.fixed_value() instanceof AST_Object
|| e.fixed_value() instanceof AST_Array)))
&& !e.has_side_effects(compressor)
) {
return typeof {};
}
}
if (!non_converting_unary.has(this.operator))
depth++;
@@ -15638,45 +15745,6 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
}
});
/**
* Check if a node may be used by the expression it's in
* void (0, 1, {node}, 2) -> false
* console.log(0, {node}) -> true
*/
function is_used_in_expression(tw) {
for (let p = -1, node, parent; node = tw.parent(p), parent = tw.parent(p + 1); p++) {
if (parent instanceof AST_Sequence) {
const nth_expression = parent.expressions.indexOf(node);
if (nth_expression !== parent.expressions.length - 1) {
// Detect (0, x.noThis)() constructs
const grandparent = tw.parent(p + 2);
if (
parent.expressions.length > 2
|| parent.expressions.length === 1
|| !requires_sequence_to_maintain_binding(grandparent, parent, parent.expressions[1])
) {
return false;
}
return true;
} else {
continue;
}
}
if (parent instanceof AST_Unary) {
const op = parent.operator;
if (op === "void") {
return false;
}
if (op === "typeof" || op === "+" || op === "-" || op === "!" || op === "~") {
continue;
}
}
return true;
}
return true;
}
/***********************************************************************
A JavaScript tokenizer / parser / beautifier / compressor.
@@ -16113,28 +16181,50 @@ function mark_lambda(tw, descend, compressor) {
* // use defined_after
* }
*
* This function is called on the parent to handle this issue.
* Or even indirectly:
*
* B();
* var defined_after = true;
* function A() {
* // use defined_after
* }
* function B() {
* A();
* }
*
* Access a variable before declaration will either throw a ReferenceError
* (if the variable is declared with `let` or `const`),
* or get an `undefined` (if the variable is declared with `var`).
*
* If the variable is inlined into the function, the behavior will change.
*
* This function is called on the parent to disallow inlining of such variables,
*/
function handle_defined_after_hoist(parent) {
const defuns = [];
walk(parent, node => {
if (node === parent) return;
if (node instanceof AST_Defun) defuns.push(node);
if (node instanceof AST_Defun) {
defuns.push(node);
return true;
}
if (
node instanceof AST_Scope
|| node instanceof AST_SimpleStatement
) return true;
});
// `defun` id to array of `defun` it uses
const defun_dependencies_map = new Map();
// `defun` id to array of enclosing `def` that are used by the function
const dependencies_map = new Map();
// all symbol ids that will be tracked for read/write
const symbols_of_interest = new Set();
const defuns_of_interest = new Set();
const potential_conflicts = [];
for (const defun of defuns) {
const fname_def = defun.name.definition();
const found_self_ref_in_other_defuns = defuns.some(
d => d !== defun && d.enclosed.indexOf(fname_def) !== -1
);
const enclosing_defs = [];
for (const def of defun.enclosed) {
if (
@@ -16145,93 +16235,107 @@ function handle_defined_after_hoist(parent) {
continue;
}
// defun is hoisted, so always safe
symbols_of_interest.add(def.id);
// found a reference to another function
if (
def.assignments === 0
&& def.orig.length === 1
&& def.orig[0] instanceof AST_SymbolDefun
) {
defuns_of_interest.add(def.id);
symbols_of_interest.add(def.id);
defuns_of_interest.add(fname_def.id);
symbols_of_interest.add(fname_def.id);
if (!defun_dependencies_map.has(fname_def.id)) {
defun_dependencies_map.set(fname_def.id, []);
}
defun_dependencies_map.get(fname_def.id).push(def.id);
continue;
}
if (found_self_ref_in_other_defuns) {
def.fixed = false;
continue;
}
enclosing_defs.push(def);
}
// for the slower checks below this loop
potential_conflicts.push({ defun, def, fname_def });
symbols_of_interest.add(def.id);
if (enclosing_defs.length) {
dependencies_map.set(fname_def.id, enclosing_defs);
defuns_of_interest.add(fname_def.id);
symbols_of_interest.add(fname_def.id);
defuns_of_interest.add(defun);
}
}
// linearize all symbols, and locate defs that are read after the defun
if (potential_conflicts.length) {
// All "symbols of interest", that is, defuns or defs, that we found.
// These are placed in order so we can check which is after which.
const found_symbols = [];
// Indices of `found_symbols` which are writes
const found_symbol_writes = new Set();
// Defun ranges are recorded because we don't care if a function uses the def internally
const defun_ranges = new Map();
// No defuns use outside constants
if (!dependencies_map.size) {
return;
}
let tw;
parent.walk((tw = new TreeWalker((node, descend) => {
if (node instanceof AST_Defun && defuns_of_interest.has(node)) {
const start = found_symbols.length;
descend();
const end = found_symbols.length;
// Increment to count "symbols of interest" (defuns or defs) that we found.
// These are tracked in AST order so we can check which is after which.
let symbol_index = 1;
// Map a defun ID to its first read (a `symbol_index`)
const defun_first_read_map = new Map();
// Map a symbol ID to its last write (a `symbol_index`)
const symbol_last_write_map = new Map();
defun_ranges.set(node, { start, end });
return true;
}
// if we found a defun on the list, mark IN_DEFUN=id and descend
walk_parent(parent, (node, walk_info) => {
if (node instanceof AST_Symbol && node.thedef) {
const id = node.definition().id;
if (node instanceof AST_Symbol && node.thedef) {
const id = node.definition().id;
if (symbols_of_interest.has(id)) {
if (node instanceof AST_SymbolDeclaration || is_lhs(node, tw)) {
found_symbol_writes.add(found_symbols.length);
}
found_symbols.push(id);
symbol_index++;
// Track last-writes to symbols
if (symbols_of_interest.has(id)) {
if (node instanceof AST_SymbolDeclaration || is_lhs(node, walk_info.parent())) {
symbol_last_write_map.set(id, symbol_index);
}
}
})));
for (const { def, defun, fname_def } of potential_conflicts) {
const defun_range = defun_ranges.get(defun);
// find the index in `found_symbols`, with some special rules:
const find = (sym_id, starting_at = 0, must_be_write = false) => {
let index = starting_at;
for (;;) {
index = found_symbols.indexOf(sym_id, index);
if (index === -1) {
break;
} else if (index >= defun_range.start && index < defun_range.end) {
index = defun_range.end;
continue;
} else if (must_be_write && !found_symbol_writes.has(index)) {
index++;
continue;
} else {
break;
}
// Track first-reads of defuns (refined later)
if (defuns_of_interest.has(id)) {
if (!defun_first_read_map.has(id) && !is_recursive_ref(walk_info, id)) {
defun_first_read_map.set(id, symbol_index);
}
}
}
});
return index;
};
// Refine `defun_first_read_map` to be as high as possible
for (const [defun, defun_first_read] of defun_first_read_map) {
// Update all depdencies of `defun`
const queue = new Set(defun_dependencies_map.get(defun));
for (const enclosed_defun of queue) {
let enclosed_defun_first_read = defun_first_read_map.get(enclosed_defun);
if (enclosed_defun_first_read != null && enclosed_defun_first_read < defun_first_read) {
continue;
}
const read_defun_at = find(fname_def.id);
const wrote_def_at = find(def.id, read_defun_at + 1, true);
defun_first_read_map.set(enclosed_defun, defun_first_read);
const wrote_def_after_reading_defun = read_defun_at != -1 && wrote_def_at != -1 && wrote_def_at > read_defun_at;
for (const enclosed_enclosed_defun of defun_dependencies_map.get(enclosed_defun) || []) {
queue.add(enclosed_enclosed_defun);
}
}
}
if (wrote_def_after_reading_defun) {
// ensure write-then-read order, otherwise clear `fixed`
// This is safe because last-writes (found_symbol_writes) are assumed to be as late as possible, and first-reads (defun_first_read_map) are assumed to be as early as possible.
for (const [defun, defs] of dependencies_map) {
const defun_first_read = defun_first_read_map.get(defun);
if (defun_first_read === undefined) {
continue;
}
for (const def of defs) {
if (def.fixed === false) {
continue;
}
let def_last_write = symbol_last_write_map.get(def.id) || 0;
if (defun_first_read < def_last_write) {
def.fixed = false;
}
}
@@ -18865,9 +18969,8 @@ def_optimize(AST_Node, function(self) {
});
AST_Toplevel.DEFMETHOD("drop_console", function(options) {
var isArray = Array.isArray(options);
return this.transform(new TreeTransformer(function(self) {
const isArray = Array.isArray(options);
const tt = new TreeTransformer(function(self) {
if (self.TYPE !== "Call") {
return;
}
@@ -18878,18 +18981,35 @@ AST_Toplevel.DEFMETHOD("drop_console", function(options) {
return;
}
if (isArray && options.indexOf(exp.property) === -1) {
if (isArray && !options.includes(exp.property)) {
return;
}
var name = exp.expression;
var depth = 2;
while (name.expression) {
name = name.expression;
depth++;
}
if (is_undeclared_ref(name) && name.name == "console") {
return make_node(AST_Undefined, self);
if (
depth === 3
&& !["call", "apply"].includes(exp.property)
&& is_used_in_expression(tt)
) {
// a (used) call to Function.prototype methods (eg: console.log.bind(console))
// but not .call and .apply which would also return undefined.
exp.expression = make_empty_function(self);
set_flag(exp.expression, SQUEEZED);
self.args = [];
} else {
return make_node(AST_Undefined, self);
}
}
}));
});
return this.transform(tt);
});
AST_Node.DEFMETHOD("equivalent_to", function(node) {
@@ -19588,7 +19708,9 @@ def_optimize(AST_Switch, function(self, compressor) {
eliminate_branch(branch, body[body.length - 1]);
continue;
}
if (exp instanceof AST_Node) exp = branch.expression.tail_node().evaluate(compressor);
if (exp instanceof AST_Node && !exp.has_side_effects(compressor)) {
exp = branch.expression.tail_node().evaluate(compressor);
}
if (exp === value) {
exact_match = branch;
if (default_branch) {
@@ -19770,12 +19892,9 @@ def_optimize(AST_Switch, function(self, compressor) {
break DEFAULT;
}
let sideEffect = body.find(branch => {
return (
branch !== default_or_exact
&& branch.expression.has_side_effects(compressor)
);
});
let sideEffect = body.find(
branch => branch !== default_or_exact && branch.expression.has_side_effects(compressor)
);
// If no cases cause a side-effect, we can eliminate the switch entirely.
if (!sideEffect) {
return make_node(AST_BlockStatement, self, {
@@ -19883,9 +20002,10 @@ def_optimize(AST_Switch, function(self, compressor) {
right: branch.expression,
}),
body: consequent,
alternative: null
})
].concat(always)
alternative: null,
}),
always,
],
}).optimize(compressor);
}
return self;
@@ -19908,13 +20028,12 @@ def_optimize(AST_Switch, function(self, compressor) {
let pblock = make_node(AST_BlockStatement, prev, { body: pbody });
return bblock.equivalent_to(pblock);
}
function statement(expression) {
return make_node(AST_SimpleStatement, expression, {
body: expression
});
function statement(body) {
return make_node(AST_SimpleStatement, body, { body });
}
function has_nested_break(root) {
let has_break = false;
let tw = new TreeWalker(node => {
if (has_break) return true;
if (node instanceof AST_Lambda) return true;
@@ -20267,10 +20386,7 @@ def_optimize(AST_Call, function(self, compressor) {
&& is_undeclared_ref(exp)
&& exp.name == "Function") {
// new Function() => function(){}
if (self.args.length == 0) return make_node(AST_Function, self, {
argnames: [],
body: []
}).optimize(compressor);
if (self.args.length == 0) return make_empty_function(self).optimize(compressor);
if (self.args.every((x) => x instanceof AST_String)) {
// quite a corner-case, but we can handle it:
// https://github.com/mishoo/UglifyJS2/issues/203
@@ -22030,10 +22146,7 @@ def_optimize(AST_Dot, function(self, compressor) {
});
break;
case "Function":
self.expression = make_node(AST_Function, self.expression, {
argnames: [],
body: []
});
self.expression = make_empty_function(self.expression);
break;
case "Number":
self.expression = make_node(AST_Number, self.expression, {
@@ -31578,7 +31691,9 @@ function mangle_properties(ast, options, annotated_props = find_annotated_props(
} else if (node instanceof AST_ObjectProperty) {
// setter, getter, method or class field
if (!keep_quoted || !node.quote) {
node.key.name = mangle(node.key.name);
if (!node.computed_key()) {
node.key.name = mangle(node.key.name);
}
}
} else if (node instanceof AST_Dot) {
if (!keep_quoted || !node.quote) {
@@ -31955,7 +32070,7 @@ function* minify_sync_or_async(files, options, _fs_module) {
if (node.block_scope) {
node.block_scope.variables = undefined;
node.block_scope.enclosed = undefined;
node.parent_scope = undefined;
node.block_scope.parent_scope = undefined;
}
});
}
@@ -32348,6 +32463,7 @@ async function run_cli({ program, packageJson, fs, path }) {
return;
}
} else if (program.output) {
fs.mkdirSync(path.dirname(program.output), { recursive: true });
fs.writeFileSync(program.output, result.code);
if (options.sourceMap && options.sourceMap.url !== "inline" && result.map) {
fs.writeFileSync(program.output + ".map", result.map);

12
node_modules/terser/lib/ast.js generated vendored
View File

@@ -1481,13 +1481,13 @@ var AST_NameMapping = DEFNODE("NameMapping", "foreign_name name", function AST_N
var AST_Import = DEFNODE(
"Import",
"imported_name imported_names module_name assert_clause",
"imported_name imported_names module_name attributes",
function AST_Import(props) {
if (props) {
this.imported_name = props.imported_name;
this.imported_names = props.imported_names;
this.module_name = props.module_name;
this.assert_clause = props.assert_clause;
this.attributes = props.attributes;
this.start = props.start;
this.end = props.end;
}
@@ -1500,7 +1500,7 @@ var AST_Import = DEFNODE(
imported_name: "[AST_SymbolImport] The name of the variable holding the module's default export.",
imported_names: "[AST_NameMapping*] The names of non-default imported variables",
module_name: "[AST_String] String literal describing where this module came from",
assert_clause: "[AST_Object?] The import assertion"
attributes: "[AST_Object?] The import attributes (with {...})"
},
_walk: function(visitor) {
return visitor._visit(this, function() {
@@ -1539,7 +1539,7 @@ var AST_ImportMeta = DEFNODE("ImportMeta", null, function AST_ImportMeta(props)
var AST_Export = DEFNODE(
"Export",
"exported_definition exported_value is_default exported_names module_name assert_clause",
"exported_definition exported_value is_default exported_names module_name attributes",
function AST_Export(props) {
if (props) {
this.exported_definition = props.exported_definition;
@@ -1547,7 +1547,7 @@ var AST_Export = DEFNODE(
this.is_default = props.is_default;
this.exported_names = props.exported_names;
this.module_name = props.module_name;
this.assert_clause = props.assert_clause;
this.attributes = props.attributes;
this.start = props.start;
this.end = props.end;
}
@@ -1562,7 +1562,7 @@ var AST_Export = DEFNODE(
exported_names: "[AST_NameMapping*?] List of exported names",
module_name: "[AST_String?] Name of the file to load exports from",
is_default: "[Boolean] Whether this is the default exported value of this module",
assert_clause: "[AST_Object?] The import assertion"
attributes: "[AST_Object?] The import attributes"
},
_walk: function (visitor) {
return visitor._visit(this, function () {

1
node_modules/terser/lib/cli.js generated vendored
View File

@@ -307,6 +307,7 @@ export async function run_cli({ program, packageJson, fs, path }) {
return;
}
} else if (program.output) {
fs.mkdirSync(path.dirname(program.output), { recursive: true });
fs.writeFileSync(program.output, result.code);
if (options.sourceMap && options.sourceMap.url !== "inline" && result.map) {
fs.writeFileSync(program.output + ".map", result.map);

View File

@@ -107,6 +107,23 @@ export function make_sequence(orig, expressions) {
});
}
export function make_empty_function(self) {
return make_node(AST_Function, self, {
uses_arguments: false,
argnames: [],
body: [],
is_generator: false,
async: false,
variables: new Map(),
uses_with: false,
uses_eval: false,
parent_scope: null,
enclosed: [],
cname: 0,
block_scope: undefined,
});
}
export function make_node_from_constant(val, orig) {
switch (typeof val) {
case "string":
@@ -333,9 +350,9 @@ export function is_reachable(scope_node, defs) {
}
/** Check if a ref refers to the name of a function/class it's defined within */
export function is_recursive_ref(compressor, def) {
export function is_recursive_ref(tw, def) {
var node;
for (var i = 0; node = compressor.parent(i); i++) {
for (var i = 0; node = tw.parent(i); i++) {
if (node instanceof AST_Lambda || node instanceof AST_Class) {
var name = node.name;
if (name && name.definition() === def) {

View File

@@ -103,8 +103,8 @@ import {
is_empty,
is_ref_of,
can_be_evicted_from_block,
requires_sequence_to_maintain_binding,
} from "./common.js";
import { is_used_in_expression } from "./inference.js";
const r_keep_assign = /keep_assign/;
@@ -503,42 +503,3 @@ AST_Scope.DEFMETHOD("drop_unused", function(compressor) {
}
}
});
/**
* Check if a node may be used by the expression it's in
* void (0, 1, {node}, 2) -> false
* console.log(0, {node}) -> true
*/
function is_used_in_expression(tw) {
for (let p = -1, node, parent; node = tw.parent(p), parent = tw.parent(p + 1); p++) {
if (parent instanceof AST_Sequence) {
const nth_expression = parent.expressions.indexOf(node);
if (nth_expression !== parent.expressions.length - 1) {
// Detect (0, x.noThis)() constructs
const grandparent = tw.parent(p + 2);
if (
parent.expressions.length > 2
|| parent.expressions.length === 1
|| !requires_sequence_to_maintain_binding(grandparent, parent, parent.expressions[1])
) {
return false;
}
return true;
} else {
continue;
}
}
if (parent instanceof AST_Unary) {
const op = parent.operator;
if (op === "void") {
return false;
}
if (op === "typeof" || op === "+" || op === "-" || op === "!" || op === "~") {
continue;
}
}
return true;
}
return true;
}

View File

@@ -218,14 +218,25 @@ def_eval(AST_Object, function (compressor, depth) {
var non_converting_unary = makePredicate("! typeof void");
def_eval(AST_UnaryPrefix, function (compressor, depth) {
var e = this.expression;
// Function would be evaluated to an array and so typeof would
// incorrectly return 'object'. Hence making is a special case.
if (compressor.option("typeofs")
&& this.operator == "typeof"
&& (e instanceof AST_Lambda
&& this.operator == "typeof") {
// Function would be evaluated to an array and so typeof would
// incorrectly return 'object'. Hence making is a special case.
if (e instanceof AST_Lambda
|| e instanceof AST_SymbolRef
&& e.fixed_value() instanceof AST_Lambda)) {
return typeof function () { };
&& e.fixed_value() instanceof AST_Lambda) {
return typeof function () { };
}
if (
(e instanceof AST_Object
|| e instanceof AST_Array
|| (e instanceof AST_SymbolRef
&& (e.fixed_value() instanceof AST_Object
|| e.fixed_value() instanceof AST_Array)))
&& !e.has_side_effects(compressor)
) {
return typeof {};
}
}
if (!non_converting_unary.has(this.operator))
depth++;

View File

@@ -176,6 +176,7 @@ import {
is_undefined,
is_lhs,
aborts,
is_used_in_expression,
} from "./inference.js";
import {
SQUEEZED,
@@ -195,6 +196,7 @@ import {
make_sequence,
best_of,
best_of_expression,
make_empty_function,
make_node_from_constant,
merge_sequence,
get_simple_key,
@@ -510,9 +512,8 @@ def_optimize(AST_Node, function(self) {
});
AST_Toplevel.DEFMETHOD("drop_console", function(options) {
var isArray = Array.isArray(options);
return this.transform(new TreeTransformer(function(self) {
const isArray = Array.isArray(options);
const tt = new TreeTransformer(function(self) {
if (self.TYPE !== "Call") {
return;
}
@@ -523,18 +524,35 @@ AST_Toplevel.DEFMETHOD("drop_console", function(options) {
return;
}
if (isArray && options.indexOf(exp.property) === -1) {
if (isArray && !options.includes(exp.property)) {
return;
}
var name = exp.expression;
var depth = 2;
while (name.expression) {
name = name.expression;
depth++;
}
if (is_undeclared_ref(name) && name.name == "console") {
return make_node(AST_Undefined, self);
if (
depth === 3
&& !["call", "apply"].includes(exp.property)
&& is_used_in_expression(tt)
) {
// a (used) call to Function.prototype methods (eg: console.log.bind(console))
// but not .call and .apply which would also return undefined.
exp.expression = make_empty_function(self);
set_flag(exp.expression, SQUEEZED);
self.args = [];
} else {
return make_node(AST_Undefined, self);
}
}
}));
});
return this.transform(tt);
});
AST_Node.DEFMETHOD("equivalent_to", function(node) {
@@ -1233,7 +1251,9 @@ def_optimize(AST_Switch, function(self, compressor) {
eliminate_branch(branch, body[body.length - 1]);
continue;
}
if (exp instanceof AST_Node) exp = branch.expression.tail_node().evaluate(compressor);
if (exp instanceof AST_Node && !exp.has_side_effects(compressor)) {
exp = branch.expression.tail_node().evaluate(compressor);
}
if (exp === value) {
exact_match = branch;
if (default_branch) {
@@ -1415,12 +1435,9 @@ def_optimize(AST_Switch, function(self, compressor) {
break DEFAULT;
}
let sideEffect = body.find(branch => {
return (
branch !== default_or_exact
&& branch.expression.has_side_effects(compressor)
);
});
let sideEffect = body.find(
branch => branch !== default_or_exact && branch.expression.has_side_effects(compressor)
);
// If no cases cause a side-effect, we can eliminate the switch entirely.
if (!sideEffect) {
return make_node(AST_BlockStatement, self, {
@@ -1528,9 +1545,10 @@ def_optimize(AST_Switch, function(self, compressor) {
right: branch.expression,
}),
body: consequent,
alternative: null
})
].concat(always)
alternative: null,
}),
always,
],
}).optimize(compressor);
}
return self;
@@ -1553,13 +1571,12 @@ def_optimize(AST_Switch, function(self, compressor) {
let pblock = make_node(AST_BlockStatement, prev, { body: pbody });
return bblock.equivalent_to(pblock);
}
function statement(expression) {
return make_node(AST_SimpleStatement, expression, {
body: expression
});
function statement(body) {
return make_node(AST_SimpleStatement, body, { body });
}
function has_nested_break(root) {
let has_break = false;
let tw = new TreeWalker(node => {
if (has_break) return true;
if (node instanceof AST_Lambda) return true;
@@ -1912,10 +1929,7 @@ def_optimize(AST_Call, function(self, compressor) {
&& is_undeclared_ref(exp)
&& exp.name == "Function") {
// new Function() => function(){}
if (self.args.length == 0) return make_node(AST_Function, self, {
argnames: [],
body: []
}).optimize(compressor);
if (self.args.length == 0) return make_empty_function(self).optimize(compressor);
if (self.args.every((x) => x instanceof AST_String)) {
// quite a corner-case, but we can handle it:
// https://github.com/mishoo/UglifyJS2/issues/203
@@ -3675,10 +3689,7 @@ def_optimize(AST_Dot, function(self, compressor) {
});
break;
case "Function":
self.expression = make_node(AST_Function, self.expression, {
argnames: [],
body: []
});
self.expression = make_empty_function(self.expression);
break;
case "Number":
self.expression = make_node(AST_Number, self.expression, {

View File

@@ -121,7 +121,7 @@ import {
member,
has_annotation,
} from "../utils/index.js";
import { make_sequence, best_of_expression, read_property } from "./common.js";
import { make_sequence, best_of_expression, read_property, requires_sequence_to_maintain_binding } from "./common.js";
import { INLINED, UNDEFINED, has_flag } from "./compressor-flags.js";
import { pure_prop_access_globals, is_pure_native_fn, is_pure_native_method } from "./native-objects.js";
@@ -424,7 +424,7 @@ export function is_nullish(node, compressor) {
return any(this.definitions, compressor);
});
def_has_side_effects(AST_VarDef, function() {
return this.value;
return this.value != null;
});
def_has_side_effects(AST_TemplateSegment, return_false);
def_has_side_effects(AST_TemplateString, function(compressor) {
@@ -982,3 +982,51 @@ export function is_modified(compressor, tw, node, value, level, immutable) {
return !immutable && is_modified(compressor, tw, parent, prop, level + 1);
}
}
/**
* Check if a node may be used by the expression it's in
* void (0, 1, {node}, 2) -> false
* console.log(0, {node}) -> true
*/
export function is_used_in_expression(tw) {
for (let p = -1, node, parent; node = tw.parent(p), parent = tw.parent(p + 1); p++) {
if (parent instanceof AST_Sequence) {
const nth_expression = parent.expressions.indexOf(node);
if (nth_expression !== parent.expressions.length - 1) {
// Detect (0, x.noThis)() constructs
const grandparent = tw.parent(p + 2);
if (
parent.expressions.length > 2
|| parent.expressions.length === 1
|| !requires_sequence_to_maintain_binding(grandparent, parent, parent.expressions[1])
) {
return false;
}
return true;
} else {
continue;
}
}
if (parent instanceof AST_Unary) {
const op = parent.operator;
if (op === "void") {
return false;
}
if (op === "typeof" || op === "+" || op === "-" || op === "!" || op === "~") {
continue;
}
}
if (
parent instanceof AST_SimpleStatement
|| parent instanceof AST_LabeledStatement
) {
return false;
}
if (parent instanceof AST_Scope) {
return false;
}
return true;
}
return true;
}

View File

@@ -94,8 +94,7 @@ import {
walk,
walk_body,
TreeWalker,
walk_parent,
} from "../ast.js";
import { HOP, make_node, noop } from "../utils/index.js";
@@ -496,28 +495,50 @@ function mark_lambda(tw, descend, compressor) {
* // use defined_after
* }
*
* This function is called on the parent to handle this issue.
* Or even indirectly:
*
* B();
* var defined_after = true;
* function A() {
* // use defined_after
* }
* function B() {
* A();
* }
*
* Access a variable before declaration will either throw a ReferenceError
* (if the variable is declared with `let` or `const`),
* or get an `undefined` (if the variable is declared with `var`).
*
* If the variable is inlined into the function, the behavior will change.
*
* This function is called on the parent to disallow inlining of such variables,
*/
function handle_defined_after_hoist(parent) {
const defuns = [];
walk(parent, node => {
if (node === parent) return;
if (node instanceof AST_Defun) defuns.push(node);
if (node instanceof AST_Defun) {
defuns.push(node);
return true;
}
if (
node instanceof AST_Scope
|| node instanceof AST_SimpleStatement
) return true;
});
// `defun` id to array of `defun` it uses
const defun_dependencies_map = new Map();
// `defun` id to array of enclosing `def` that are used by the function
const dependencies_map = new Map();
// all symbol ids that will be tracked for read/write
const symbols_of_interest = new Set();
const defuns_of_interest = new Set();
const potential_conflicts = [];
for (const defun of defuns) {
const fname_def = defun.name.definition();
const found_self_ref_in_other_defuns = defuns.some(
d => d !== defun && d.enclosed.indexOf(fname_def) !== -1
);
const enclosing_defs = [];
for (const def of defun.enclosed) {
if (
@@ -528,93 +549,107 @@ function handle_defined_after_hoist(parent) {
continue;
}
// defun is hoisted, so always safe
symbols_of_interest.add(def.id);
// found a reference to another function
if (
def.assignments === 0
&& def.orig.length === 1
&& def.orig[0] instanceof AST_SymbolDefun
) {
defuns_of_interest.add(def.id);
symbols_of_interest.add(def.id);
defuns_of_interest.add(fname_def.id);
symbols_of_interest.add(fname_def.id);
if (!defun_dependencies_map.has(fname_def.id)) {
defun_dependencies_map.set(fname_def.id, []);
}
defun_dependencies_map.get(fname_def.id).push(def.id);
continue;
}
if (found_self_ref_in_other_defuns) {
def.fixed = false;
continue;
}
enclosing_defs.push(def);
}
// for the slower checks below this loop
potential_conflicts.push({ defun, def, fname_def });
symbols_of_interest.add(def.id);
if (enclosing_defs.length) {
dependencies_map.set(fname_def.id, enclosing_defs);
defuns_of_interest.add(fname_def.id);
symbols_of_interest.add(fname_def.id);
defuns_of_interest.add(defun);
}
}
// linearize all symbols, and locate defs that are read after the defun
if (potential_conflicts.length) {
// All "symbols of interest", that is, defuns or defs, that we found.
// These are placed in order so we can check which is after which.
const found_symbols = [];
// Indices of `found_symbols` which are writes
const found_symbol_writes = new Set();
// Defun ranges are recorded because we don't care if a function uses the def internally
const defun_ranges = new Map();
// No defuns use outside constants
if (!dependencies_map.size) {
return;
}
let tw;
parent.walk((tw = new TreeWalker((node, descend) => {
if (node instanceof AST_Defun && defuns_of_interest.has(node)) {
const start = found_symbols.length;
descend();
const end = found_symbols.length;
// Increment to count "symbols of interest" (defuns or defs) that we found.
// These are tracked in AST order so we can check which is after which.
let symbol_index = 1;
// Map a defun ID to its first read (a `symbol_index`)
const defun_first_read_map = new Map();
// Map a symbol ID to its last write (a `symbol_index`)
const symbol_last_write_map = new Map();
defun_ranges.set(node, { start, end });
return true;
}
// if we found a defun on the list, mark IN_DEFUN=id and descend
walk_parent(parent, (node, walk_info) => {
if (node instanceof AST_Symbol && node.thedef) {
const id = node.definition().id;
if (node instanceof AST_Symbol && node.thedef) {
const id = node.definition().id;
if (symbols_of_interest.has(id)) {
if (node instanceof AST_SymbolDeclaration || is_lhs(node, tw)) {
found_symbol_writes.add(found_symbols.length);
}
found_symbols.push(id);
symbol_index++;
// Track last-writes to symbols
if (symbols_of_interest.has(id)) {
if (node instanceof AST_SymbolDeclaration || is_lhs(node, walk_info.parent())) {
symbol_last_write_map.set(id, symbol_index);
}
}
})));
for (const { def, defun, fname_def } of potential_conflicts) {
const defun_range = defun_ranges.get(defun);
// find the index in `found_symbols`, with some special rules:
const find = (sym_id, starting_at = 0, must_be_write = false) => {
let index = starting_at;
for (;;) {
index = found_symbols.indexOf(sym_id, index);
if (index === -1) {
break;
} else if (index >= defun_range.start && index < defun_range.end) {
index = defun_range.end;
continue;
} else if (must_be_write && !found_symbol_writes.has(index)) {
index++;
continue;
} else {
break;
}
// Track first-reads of defuns (refined later)
if (defuns_of_interest.has(id)) {
if (!defun_first_read_map.has(id) && !is_recursive_ref(walk_info, id)) {
defun_first_read_map.set(id, symbol_index);
}
}
}
});
return index;
};
// Refine `defun_first_read_map` to be as high as possible
for (const [defun, defun_first_read] of defun_first_read_map) {
// Update all depdencies of `defun`
const queue = new Set(defun_dependencies_map.get(defun));
for (const enclosed_defun of queue) {
let enclosed_defun_first_read = defun_first_read_map.get(enclosed_defun);
if (enclosed_defun_first_read != null && enclosed_defun_first_read < defun_first_read) {
continue;
}
const read_defun_at = find(fname_def.id);
const wrote_def_at = find(def.id, read_defun_at + 1, true);
defun_first_read_map.set(enclosed_defun, defun_first_read);
const wrote_def_after_reading_defun = read_defun_at != -1 && wrote_def_at != -1 && wrote_def_at > read_defun_at;
for (const enclosed_enclosed_defun of defun_dependencies_map.get(enclosed_defun) || []) {
queue.add(enclosed_enclosed_defun);
}
}
}
if (wrote_def_after_reading_defun) {
// ensure write-then-read order, otherwise clear `fixed`
// This is safe because last-writes (found_symbol_writes) are assumed to be as late as possible, and first-reads (defun_first_read_map) are assumed to be as early as possible.
for (const [defun, defs] of dependencies_map) {
const defun_first_read = defun_first_read_map.get(defun);
if (defun_first_read === undefined) {
continue;
}
for (const def of defs) {
if (def.fixed === false) {
continue;
}
let def_last_write = symbol_last_write_map.get(def.id) || 0;
if (defun_first_read < def_last_write) {
def.fixed = false;
}
}

2
node_modules/terser/lib/minify.js generated vendored
View File

@@ -305,7 +305,7 @@ function* minify_sync_or_async(files, options, _fs_module) {
if (node.block_scope) {
node.block_scope.variables = undefined;
node.block_scope.enclosed = undefined;
node.parent_scope = undefined;
node.block_scope.parent_scope = undefined;
}
});
}

View File

@@ -181,23 +181,23 @@ import { is_basic_identifier_string } from "./parse.js";
return body;
};
const assert_clause_from_moz = (assertions) => {
if (assertions && assertions.length > 0) {
function import_attributes_from_moz(attributes) {
if (attributes && attributes.length > 0) {
return new AST_Object({
start: my_start_token(assertions),
end: my_end_token(assertions),
properties: assertions.map((assertion_kv) =>
start: my_start_token(attributes),
end: my_end_token(attributes),
properties: attributes.map((attr) =>
new AST_ObjectKeyVal({
start: my_start_token(assertion_kv),
end: my_end_token(assertion_kv),
key: assertion_kv.key.name || assertion_kv.key.value,
value: from_moz(assertion_kv.value)
start: my_start_token(attr),
end: my_end_token(attr),
key: attr.key.name || attr.key.value,
value: from_moz(attr.value)
})
)
});
}
return null;
};
}
var MOZ_TO_ME = {
Program: function(M) {
@@ -569,7 +569,7 @@ import { is_basic_identifier_string } from "./parse.js";
imported_name: imported_name,
imported_names : imported_names,
module_name : from_moz(M.source),
assert_clause: assert_clause_from_moz(M.assertions)
attributes: import_attributes_from_moz(M.attributes || M.assertions)
});
},
@@ -595,6 +595,23 @@ import { is_basic_identifier_string } from "./parse.js";
});
},
ImportExpression: function(M) {
const args = [from_moz(M.source)];
if (M.options) {
args.push(from_moz(M.options));
}
return new AST_Call({
start: my_start_token(M),
end: my_end_token(M),
expression: from_moz({
type: "Identifier",
name: "import"
}),
optional: false,
args
});
},
ExportAllDeclaration: function(M) {
var foreign_name = M.exported == null ?
new AST_SymbolExportForeign({ name: "*" }) :
@@ -609,7 +626,7 @@ import { is_basic_identifier_string } from "./parse.js";
})
],
module_name: from_moz(M.source),
assert_clause: assert_clause_from_moz(M.assertions)
attributes: import_attributes_from_moz(M.attributes || M.assertions)
});
},
@@ -620,7 +637,7 @@ import { is_basic_identifier_string } from "./parse.js";
exported_definition: from_moz(M.declaration),
exported_names: M.specifiers && M.specifiers.length ? M.specifiers.map(from_moz) : null,
module_name: from_moz(M.source),
assert_clause: assert_clause_from_moz(M.assertions)
attributes: import_attributes_from_moz(M.attributes || M.assertions)
});
},
@@ -662,6 +679,11 @@ import { is_basic_identifier_string } from "./parse.js";
args.value = { source, flags };
return new AST_RegExp(args);
}
const bi = typeof M.value === "bigint" ? M.value.toString() : M.bigint;
if (typeof bi === "string") {
args.value = bi;
return new AST_BigInt(args);
}
if (val === null) return new AST_Null(args);
switch (typeof val) {
case "string":
@@ -729,14 +751,6 @@ import { is_basic_identifier_string } from "./parse.js";
});
},
BigIntLiteral(M) {
return new AST_BigInt({
start : my_start_token(M),
end : my_end_token(M),
value : M.value
});
},
EmptyStatement: function(M) {
return new AST_EmptyStatement({
start: my_start_token(M),
@@ -1209,6 +1223,15 @@ import { is_basic_identifier_string } from "./parse.js";
};
});
def_to_moz(AST_Call, function To_Moz_CallExpression(M) {
if (M.expression instanceof AST_SymbolRef && M.expression.name === "import") {
const [source, options] = M.args.map(to_moz);
return {
type: "ImportExpression",
source,
options
};
}
return {
type: "CallExpression",
callee: to_moz(M.expression),
@@ -1366,22 +1389,22 @@ import { is_basic_identifier_string } from "./parse.js";
};
});
const assert_clause_to_moz = assert_clause => {
const assertions = [];
if (assert_clause) {
for (const { key, value } of assert_clause.properties) {
function import_attributes_to_moz(attribute) {
const import_attributes = [];
if (attribute) {
for (const { key, value } of attribute.properties) {
const key_moz = is_basic_identifier_string(key)
? { type: "Identifier", name: key }
: { type: "Literal", value: key, raw: JSON.stringify(key) };
assertions.push({
import_attributes.push({
type: "ImportAttribute",
key: key_moz,
value: to_moz(value)
});
}
}
return assertions;
};
return import_attributes;
}
def_to_moz(AST_Export, function To_Moz_ExportDeclaration(M) {
if (M.exported_names) {
@@ -1396,7 +1419,7 @@ import { is_basic_identifier_string } from "./parse.js";
type: "ExportAllDeclaration",
source: to_moz(M.module_name),
exported: exported,
assertions: assert_clause_to_moz(M.assert_clause)
attributes: import_attributes_to_moz(M.attributes)
};
}
return {
@@ -1410,7 +1433,7 @@ import { is_basic_identifier_string } from "./parse.js";
}),
declaration: to_moz(M.exported_definition),
source: to_moz(M.module_name),
assertions: assert_clause_to_moz(M.assert_clause)
attributes: import_attributes_to_moz(M.attributes)
};
}
return {
@@ -1448,7 +1471,7 @@ import { is_basic_identifier_string } from "./parse.js";
type: "ImportDeclaration",
specifiers: specifiers,
source: to_moz(M.module_name),
assertions: assert_clause_to_moz(M.assert_clause)
attributes: import_attributes_to_moz(M.attributes)
};
});
@@ -1754,8 +1777,13 @@ import { is_basic_identifier_string } from "./parse.js";
});
def_to_moz(AST_BigInt, M => ({
type: "BigIntLiteral",
value: M.value
type: "Literal",
// value cannot be represented natively
// see: https://github.com/estree/estree/blob/master/es2020.md#bigintliteral
value: null,
// `M.value` is a string that may be a hex number representation.
// but "bigint" property should have only decimal digits
bigint: typeof BigInt === "function" ? BigInt(M.value).toString() : M.value,
}));
AST_Boolean.DEFMETHOD("to_mozilla_ast", AST_Constant.prototype.to_mozilla_ast);

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

@@ -1792,9 +1792,9 @@ function OutputStream(options) {
output.space();
}
self.module_name.print(output);
if (self.assert_clause) {
output.print("assert");
self.assert_clause.print(output);
if (self.attributes) {
output.print("with");
self.attributes.print(output);
}
output.semicolon();
});
@@ -1888,9 +1888,9 @@ function OutputStream(options) {
output.space();
self.module_name.print(output);
}
if (self.assert_clause) {
output.print("assert");
self.assert_clause.print(output);
if (self.attributes) {
output.print("with");
self.attributes.print(output);
}
if (self.exported_value
&& !(self.exported_value instanceof AST_Defun ||

17
node_modules/terser/lib/parse.js generated vendored
View File

@@ -2726,8 +2726,11 @@ function parse($TEXT, options) {
return new AST_ClassStaticBlock({ start, body, end: prev() });
}
function maybe_import_assertion() {
if (is("name", "assert") && !has_newline_before(S.token)) {
function maybe_import_attributes() {
if (
(is("keyword", "with") || is("name", "assert"))
&& !has_newline_before(S.token)
) {
next();
return object_or_destructuring_();
}
@@ -2758,7 +2761,7 @@ function parse($TEXT, options) {
}
next();
const assert_clause = maybe_import_assertion();
const attributes = maybe_import_attributes();
return new AST_Import({
start,
@@ -2770,7 +2773,7 @@ function parse($TEXT, options) {
quote: mod_str.quote,
end: mod_str,
}),
assert_clause,
attributes,
end: S.token,
});
}
@@ -2903,7 +2906,7 @@ function parse($TEXT, options) {
}
next();
const assert_clause = maybe_import_assertion();
const attributes = maybe_import_attributes();
return new AST_Export({
start: start,
@@ -2916,7 +2919,7 @@ function parse($TEXT, options) {
end: mod_str,
}),
end: prev(),
assert_clause
attributes
});
} else {
return new AST_Export({
@@ -2962,7 +2965,7 @@ function parse($TEXT, options) {
exported_value: exported_value,
exported_definition: exported_definition,
end: prev(),
assert_clause: null
attributes: null
});
}

View File

@@ -326,7 +326,9 @@ function mangle_properties(ast, options, annotated_props = find_annotated_props(
} else if (node instanceof AST_ObjectProperty) {
// setter, getter, method or class field
if (!keep_quoted || !node.quote) {
node.key.name = mangle(node.key.name);
if (!node.computed_key()) {
node.key.name = mangle(node.key.name);
}
}
} else if (node instanceof AST_Dot) {
if (!keep_quoted || !node.quote) {

4
node_modules/terser/lib/scope.js generated vendored
View File

@@ -200,7 +200,7 @@ function redefined_catch_def(def) {
}
}
AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = null, toplevel = this } = {}) {
AST_Scope.DEFMETHOD("figure_out_scope", function(options, { parent_scope = undefined, toplevel = this } = {}) {
options = defaults(options, {
cache: null,
ie8: false,
@@ -524,7 +524,7 @@ AST_Scope.DEFMETHOD("add_child_scope", function (scope) {
scope.parent_scope = this;
// Propagate to this.uses_arguments from arrow functions
if ((scope instanceof AST_Arrow) && !this.uses_arguments) {
if ((scope instanceof AST_Arrow) && (this instanceof AST_Lambda && !this.uses_arguments)) {
this.uses_arguments = walk(scope, node => {
if (
node instanceof AST_SymbolRef

4
node_modules/terser/package.json generated vendored
View File

@@ -4,7 +4,7 @@
"homepage": "https://terser.org",
"author": "Mihai Bazon <mihai.bazon@gmail.com> (http://lisperator.net/)",
"license": "BSD-2-Clause",
"version": "5.31.5",
"version": "5.36.0",
"engines": {
"node": ">=10"
},
@@ -57,7 +57,7 @@
"esm": "^3.2.25",
"mocha": "^9.2.0",
"pre-commit": "^1.2.2",
"rollup": "^2.56.3",
"rollup": "^2.79.2",
"semver": "^7.5.1",
"source-map": "~0.8.0-beta.0"
},