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

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;
}