GeezerVison is showing github.com (truncated) — github.com From ac9d4f3df15e8be7609d40fc480673466c678535 Mon Sep 17 00:00:00 2001
From: alexander-akait < [email protected]>
Date: Mon, 9 Nov 2026 08:50:12 +0000
Subject: [PATCH] refactor(javascript): read the minifier's syntax tree through
the path
The path keeps fast properties as a class instance and holds the tree it
reads, so a read through it costs less than calling the tree.
---
.../082-javascript-minify-path-reads.md | 5 +
lib/javascript/syntax-parser.js | 145 +-
lib/javascript/syntax-printer.js | 3594 ++++++++---------
types.d.ts | 543 +--
4 files changed, 1936 insertions(+), 2351 deletions(-)
create mode 100644 .changeset/082-javascript-minify-path-reads.md
diff --git a/.changeset/082-javascript-minify-path-reads.md b/.changeset/082-javascript-minify-path-reads.md
new file mode 100644
index 00000000000..c346e46b2e3
--- /dev/null
+++ b/.changeset/082-javascript-minify-path-reads.md
@@ -0,0 +1,5 @@
+---
+"webpack": patch
+---
+
+Speed up the JavaScript minifier, which now reads its tree through the path.
diff --git a/lib/javascript/syntax-parser.js b/lib/javascript/syntax-parser.js
index 8087488a597..682f54fd2aa 100644
--- a/lib/javascript/syntax-parser.js
+++ b/lib/javascript/syntax-parser.js
@@ -20785,6 +20785,9 @@ class ColumnarSyntaxTree {
}
}
+// What `A` reads while no tree is walked, so its reads keep one receiver map.
+const EMPTY_TREE = new ColumnarSyntaxTree();
+
/**
* Adds a regular expression's `regex` and a bigint's `bigint`, which ESTree
* spells out beside a literal's value and the tree reads off it.
@@ -20922,6 +20925,7 @@ const fromEstreeObject = (program, input) => {
throw error;
}
walkTree = tree;
+ A._tree = tree;
walkInput = input;
walkLineStarts = null;
return node;
@@ -21287,6 +21291,8 @@ const parserGoal = (sourceType) => ({
// the node a visitor is at, and the nodes enclosing it, innermost last.
/** @type {SyntaxTree | null} */
let walkTree = null;
+// Whether a parse wrote `walkTree` and so releases it; one a caller keeps is not.
+let walkOwned = false;
let walkInput = "";
let walkNode = 0;
let walkIndex = 0;
@@ -21475,19 +21481,28 @@ const walkNodeTree = (tree, node, index, visits) => {
}
};
+// WHY: a class keeps the path's getters on the prototype, so `A` itself keeps
+// fast properties; an object literal holding a getter falls into dictionary
+// mode, which makes every read through it a lookup.
/**
* The path every visitor of a JavaScript `SourceProcessor` run receives, its
* reads defaulting to the node the walk is at.
*/
-const A = {
- /** @type {unknown} the run's state, set by `SourceProcessor` for the length of a run */
- state: undefined,
+class JavascriptSyntaxPath {
+ constructor() {
+ /** @type {unknown} the run's state, set by `SourceProcessor` for the length of a run */
+ this.state = undefined;
+ /** @type {SyntaxTree} the tree the walk reads, an empty one while there is none */
+ this._tree = EMPTY_TREE;
+ }
+
/**
* @returns {number} the current node, valid during a visitor callback
*/
get node() {
return walkNode;
- },
+ }
+
/**
* @returns {number | null} the enclosing node, null at the program
*/
@@ -21495,23 +21510,27 @@ const A = {
return walkParents.length === 0
? null
: walkParents[walkParents.length - 1];
- },
+ }
+
/**
* @returns {number} the current node's index among its parent's children
*/
get index() {
return walkIndex;
- },
+ }
+
/** Stops the walk descending into the current node (enter only). */
skipChildren() {
walkSkipped = true;
- },
+ }
+
/** Stops the walk: no visitor fires after the current one returns. */
stop() {
if (walkStopped) return;
walkStopped = true;
walkHalted = getHaltVisitors().haltVisitors(walkVisitors);
- },
+ }
+
/**
* @param {number} level how many levels further out than the parent
* @returns {number} a node enclosing the current one, 0 past the program
@@ -21519,7 +21538,8 @@ const A = {
ancestor(level) {
const at = walkParents.length - 1 - level;
return at >= 0 ? walkParents[at] : 0;
- },
+ }
+
/**
* @param {number} type a `NodeType`
* @returns {boolean} whether a node enclosing the current one has that type
@@ -21530,35 +21550,40 @@ const A = {
if (tree.type(walkParents[i]) === type) return true;
}
return false;
- },
+ }
+
/**
* @param {number=} n node
* @returns {number} its `NodeType`
*/
type(n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).type(n);
- },
+ return this._tree._types[n];
+ }
+
/**
* @param {number=} n node
* @returns {[number, number]} where it starts and ends in the input
*/
range(n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).range(n);
- },
+ return this._tree.range(n);
+ }
+
/**
* @param {number=} n node
* @returns {number} where it starts in the input
*/
start(n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).start(n);
- },
+ return this._tree._starts[n];
+ }
+
/**
* @param {number=} n node
* @returns {number} where it ends in the input
*/
end(n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).end(n);
- },
+ return this._tree._ends[n];
+ }
+
/**
* Every JavaScript line terminator ends a line, as a parse error's position counts them.
* @param {number=} n node
@@ -21574,7 +21599,8 @@ const A = {
positionAt(walkLineStarts, tree.end(n))
);
return [start.line, start.column, end.line, end.column];
- },
+ }
+
/**
* @param {number=} n node, or the start offset when `end` is given
* @param {number=} end end offset, to read the input between two offsets
@@ -21585,28 +21611,32 @@ const A = {
const tree = /** @type {SyntaxTree} */ (walkTree);
const node = n === undefined ? walkNode : n;
return walkInput.slice(tree.start(node), tree.end(node));
- },
+ }
+
/**
* @param {number=} n node
* @returns {string} an identifier's name, "" for any other node
*/
name(n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).name(n);
- },
+ return this._tree.name(n);
+ }
+
/**
* @param {number=} n node
* @returns {TreeValue | undefined} a literal's or template element's value, "" for any other node
*/
value(n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).value(n);
- },
+ return this._tree.value(n);
+ }
+
/**
* @param {number=} n node
* @returns {number} how many children it has
*/
childCount(n = walkNode) {
return childrenOf(/** @type {SyntaxTree} */ (walkTree), n).length;
- },
+ }
+
/**
* @param {number} i the child's index
* @param {number=} n node
@@ -21615,22 +21645,25 @@ const A = {
child(i, n = walkNode) {
const children = childrenOf(/** @type {SyntaxTree} */ (walkTree), n);
return i < children.length ? children[i] : 0;
- },
+ }
+
/**
* @param {number=} n node
* @returns {number[]} its children in source order, as a new array
*/
children(n = walkNode) {
return childrenOf(/** @type {SyntaxTree} */ (walkTree), n);
- },
+ }
+
/**
* @param {number} field a `Field`
* @param {number=} n node
* @returns {number} how many nodes the field holds, at most one for a single node
*/
fieldCount(field, n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).fieldCount(field, n);
- },
+ return this._tree.fieldCount(field, n);
+ }
+
/**
* @param {number} i the item's index
* @param {number} field a `Field`
@@ -21638,8 +21671,9 @@ const A = {
* @returns {number} the field's `i`-th node, `0` past the end or for a hole
*/
field(i, field, n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).field(i, field, n);
- },
+ return this._tree.field(i, field, n);
+ }
+
/**
* @param {number} field a `Field` holding a list
* @param {string} name the name looked for
@@ -21654,15 +21688,17 @@ const A = {
if (item !== 0 && tree.name(item) === name) return item;
}
return 0;
- },
+ }
+
/**
* @param {number} flag a `Flag`
* @param {number=} n node
* @returns {boolean} whether it is set
*/
flag(flag, n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).flag(flag, n);
- },
+ return (this._tree._flags[n] & flag) !== 0;
+ }
+
/**
* A JavaScript node keeps no positions beyond its own.
* @param {number} part a `Part`
@@ -21671,7 +21707,8 @@ const A = {
*/
rangeOf(part, n = walkNode) {
return null;
- },
+ }
+
/**
* @param {number} part a `Part`
* @param {number=} n node
@@ -21679,7 +21716,8 @@ const A = {
*/
startOf(part, n = walkNode) {
return -1;
- },
+ }
+
/**
* @param {number} part a `Part`
* @param {number=} n node
@@ -21687,16 +21725,19 @@ const A = {
*/
endOf(part, n = walkNode) {
return -1;
- },
+ }
+
/**
* @param {number} part a `Part`
* @param {number=} n node
* @returns {string | null} the part's text, null where the node has none
*/
textOf(part, n = walkNode) {
- return /** @type {SyntaxTree} */ (walkTree).textOf(part, n);
+ return this._tree.textOf(part, n);
}
-};
+}
+
+const A = new JavascriptSyntaxPath();
/* eslint-disable jsdoc/require-template -- `A` below is the accessor const, not a type parameter */
/**
@@ -21985,6 +22026,8 @@ const parseIntoTree = (Parser, input, pos, options) => {
throw error;
}
walkTree = tree;
+ A._tree = tree;
+ walkOwned = true;
walkInput = input;
walkLineStarts = null;
return program;
@@ -22005,6 +22048,8 @@ const parsedTree = () => walkTree;
const takeParsedTree = () => {
const tree = walkTree;
walkTree = null;
+ A._tree = EMPTY_TREE;
+ walkOwned = false;
walkInput = "";
walkLineStarts = null;
return tree;
@@ -22016,12 +22061,29 @@ const takeParsedTree = () => {
*/
const releaseParsedTree = () => {
if (walkTree === null) return;
- walkTree.release();
+ if (walkOwned) walkTree.release();
+ walkOwned = false;
walkTree = null;
+ A._tree = EMPTY_TREE;
walkInput = "";
walkLineStarts = null;
};
+/**
+ * Points `A` at a tree its caller keeps and releases, as the minifier keeps
+ * one through a run; the next parse replaces it without releasing it.
+ * @param {SyntaxTree} tree the tree
+ * @param {string} input the source it was parsed from
+ * @returns {void}
+ */
+const readParsedTree = (tree, input) => {
+ releaseParsedTree();
+ walkTree = tree;
+ A._tree = tree;
+ walkInput = input;
+ walkLineStarts = null;
+};
+
/**
* The JavaScript `SourceProcessor` grammar: parse the input into a
* `SyntaxTree`, then walk it from the program, firing `enter` and `exit` in
@@ -22101,6 +22163,7 @@ const walkSyntaxTree = (tree, program, input, visitors, writer, inlined) => {
}
releaseParsedTree();
walkTree = tree;
+ A._tree = tree;
walkInput = input;
walking = true;
walkVisitors = visitors;
@@ -22122,6 +22185,7 @@ const walkSyntaxTree = (tree, program, input, visitors, writer, inlined) => {
if (walkHalted !== null) getHaltVisitors().resumeVisitors(walkHalted);
walking = false;
walkTree = null;
+ A._tree = EMPTY_TREE;
walkInput = "";
walkNode = 0;
walkParents.length = 0;
@@ -22204,6 +22268,7 @@ module.exports.parse = parse;
module.exports.parseProgram = parseProgram;
module.exports.parsedTree = parsedTree;
module.exports.takeParsedTree = takeParsedTree;
+module.exports.readParsedTree = readParsedTree;
module.exports.positionAt = positionAt;
module.exports.releaseParserCaches = releaseParserCaches;
module.exports.toEstreeObject = toEstreeObject;
diff --git a/lib/javascript/syntax-printer.js b/lib/javascript/syntax-printer.js
index 80993468353..b525371232e 100644
--- a/lib/javascript/syntax-printer.js
+++ b/lib/javascript/syntax-printer.js
@@ -2383,6 +2383,8 @@ const createPropertyMangler = (base54) => {
* @returns {PrinterModules["prepareNodePrint"]} what reads the source
*/
const createPrepareNodePrint = (parseModule, base54, treeMangler) => {
+ const { A } = require("./syntax-parser");
+
const propertyNames = createPropertyMangler(base54);
/**
@@ -2574,7 +2576,7 @@ const createPrepareNodePrint = (parseModule, base54, treeMangler) => {
if (kept === 1) {
// Past every comment, the source's end is a token too.
leadingToken = /** @type {number} */ (
- tokenAt(tree.start(program), false)
+ tokenAt(A.start(program), false)
);
}
return null;
@@ -2943,11 +2945,13 @@ const PARSE_FUNCTION_BODY = Symbol("a source read as a function body");
*/
const installParseTree = (parse) => {
const {
+ A,
Field,
NodeType,
buildLineStarts,
parseProgram,
positionAt,
+ readParsedTree,
takeParsedTree,
tokTypes
} = require("./syntax-parser");
@@ -3639,9 +3643,11 @@ const installParseTree = (parse) => {
(written, tokenAt, ownTable) => {
program = written;
tree = /** @type {SyntaxTree} */ (takeParsedTree());
- const count = tree.fieldCount(Field.body, program);
+ // `A` reads this tree through the run, which keeps and releases it
+ readParsedTree(tree, text);
+ const count = A.fieldCount(Field.body, program);
for (let i = 0; i < count && !module; i++) {
- const type = tree.type(tree.field(i, Field.body, program));
+ const type = A.type(A.field(i, Field.body, program));
module =
type === NodeType.ImportDeclaration ||
type === NodeType.ExportNamedDeclaration ||
@@ -4350,7 +4356,7 @@ const MARK_INFINITY = 2;
* @returns {TreeMangler} what reads the tree
*/
const createTreeMangler = (parse, scopeMangler) => {
- const { Field, Flag, NodeType, Part } = require("./syntax-parser");
+ const { A, Field, Flag, NodeType, Part } = require("./syntax-parser");
const { NODE_FIELDS } = require("./data");
const fieldsByName = /** @type {Record } */ (Field);
@@ -4447,7 +4453,7 @@ const createTreeMangler = (parse, scopeMangler) => {
* @returns {void}
*/
const readChild = (node, binding) => {
- if (tree.type(node) === NodeType.ParenthesizedExpression) {
+ if (A.type(node) === NodeType.ParenthesizedExpression) {
readParenthesized(node);
} else {
read(node, binding);
@@ -4460,14 +4466,14 @@ const createTreeMangler = (parse, scopeMangler) => {
* @returns {void}
*/
const read = (node, binding) => {
- const type = tree.type(node);
+ const type = A.type(node);
let printedType = type;
- starts[node] = tokenAt(tree.start(node), false);
- ends[node] = tokenAt(tree.end(node), true);
+ starts[node] = tokenAt(A.start(node), false);
+ ends[node] = tokenAt(A.end(node), true);
switch (type) {
case NodeType.SequenceExpression:
// terser reads a sequence's end off `peek()`, past the token after it.
- ends[node] = tokenAt(tree.end(node), true, 2);
+ ends[node] = tokenAt(A.end(node), true, 2);
break;
case NodeType.ArrowFunctionExpression:
ends[node] = 0;
@@ -4475,29 +4481,25 @@ const createTreeMangler = (parse, scopeMangler) => {
case NodeType.Property: {
// terser's parser opens a computed property at its `[`, but a
// binding pattern's at its key, as its conversion does.
- const key = tree.field(0, Field.key, node);
- const opensAt =
- !binding && tree.flag(Flag.computed, node) ? node : key;
- starts[node] = tokenAt(tree.start(opensAt), false);
- ends[node] = tokenAt(
- tree.end(tree.field(0, Field.value, node)),
- true
- );
+ const key = A.field(0, Field.key, node);
+ const opensAt = !binding && A.flag(Flag.computed, node) ? node : key;
+ starts[node] = tokenAt(A.start(opensAt), false);
+ ends[node] = tokenAt(A.end(A.field(0, Field.value, node)), true);
if (binding) marks[node] = MARK_BINDING_PROPERTY;
break;
}
case NodeType.FunctionDeclaration:
- if (tree.field(0, Field.id, node) === 0) {
+ if (A.field(0, Field.id, node) === 0) {
printedType = NodeType.FunctionExpression;
}
break;
case NodeType.ClassDeclaration:
- if (tree.field(0, Field.id, node) === 0) {
+ if (A.field(0, Field.id, node) === 0) {
printedType = NodeType.ClassExpression;
}
break;
case NodeType.Literal:
- if (tree.value(node) === Infinity) {
+ if (A.value(node) === Infinity) {
printedType = NodeType.Identifier;
marks[node] = MARK_INFINITY;
}
@@ -4512,9 +4514,9 @@ const createTreeMangler = (parse, scopeMangler) => {
for (let f = 0; f < fields.length; f++) {
const field = fields[f];
const childBinding = bindsIn(type, field, binding);
- const count = tree.fieldCount(field, node);
+ const count = A.fieldCount(field, node);
for (let i = 0; i < count; i++) {
- const child = tree.field(i, field, node);
+ const child = A.field(i, field, node);
if (child !== 0) readChild(child, childBinding);
}
}
@@ -4525,20 +4527,20 @@ const createTreeMangler = (parse, scopeMangler) => {
* @returns {number} the expression it holds, past any other parentheses
*/
const readParenthesized = (paren) => {
- const inner = tree.field(0, Field.expression, paren);
+ const inner = A.field(0, Field.expression, paren);
let expression = inner;
- if (tree.type(inner) === NodeType.ParenthesizedExpression) {
+ if (A.type(inner) === NodeType.ParenthesizedExpression) {
expression = readParenthesized(inner);
} else {
read(inner, false);
// terser reads a sequence's end off `peek()` once the parenthesis
// holding it is read, so it ends two tokens past the close.
- if (tree.type(inner) === NodeType.SequenceExpression) {
- ends[inner] = tokenAt(tree.end(paren), true, 2);
+ if (A.type(inner) === NodeType.SequenceExpression) {
+ ends[inner] = tokenAt(A.end(paren), true, 2);
}
}
- const open = tokenAt(tree.start(paren), false);
- const close = tokenAt(tree.end(paren), true);
+ const open = tokenAt(A.start(paren), false);
+ const close = tokenAt(A.end(paren), true);
if (open !== 0 && close !== 0) {
bindParenthesisComments(
table,
@@ -4557,11 +4559,6 @@ const createTreeMangler = (parse, scopeMangler) => {
return { starts, ends, types, marks, first: table.base };
};
- // The tree being mangled, which the walks naming its private names read.
- let tree = /** @type {SyntaxTree} */ (
- /** @type {SyntaxTree | null} */ (null)
- );
-
/**
* The private names a class declares, read off the tree being mangled.
* @param {number} node a class
@@ -4570,18 +4567,18 @@ const createTreeMangler = (parse, scopeMangler) => {
const privateNamesDeclaredIn = (node) => {
/** @type {string[]} */
const names = [];
- const body = tree.field(0, Field.body, node);
- const count = tree.fieldCount(Field.body, body);
+ const body = A.field(0, Field.body, node);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- const member = tree.field(i, Field.body, body);
- const type = tree.type(member);
- const key = tree.field(0, Field.key, member);
+ const member = A.field(i, Field.body, body);
+ const type = A.type(member);
+ const key = A.field(0, Field.key, member);
if (
(type === NodeType.PropertyDefinition ||
type === NodeType.MethodDefinition) &&
- tree.type(key) === NodeType.PrivateIdentifier
+ A.type(key) === NodeType.PrivateIdentifier
) {
- names.push(tree.name(key));
+ names.push(A.name(key));
}
}
return names;
@@ -4595,24 +4592,24 @@ const createTreeMangler = (parse, scopeMangler) => {
* @returns {void}
*/
const renamePrivateNames = (node, state) => {
- const type = tree.type(node);
+ const type = A.type(node);
/** @type {number} */
let renamed = 0;
if (
type === NodeType.MethodDefinition ||
type === NodeType.PropertyDefinition
) {
- renamed = tree.field(0, Field.key, node);
+ renamed = A.field(0, Field.key, node);
} else if (type === NodeType.MemberExpression) {
- renamed = tree.field(0, Field.property, node);
+ renamed = A.field(0, Field.property, node);
} else if (
type === NodeType.BinaryExpression &&
- tree.textOf(Part.operator, node) === "in"
+ A.textOf(Part.operator, node) === "in"
) {
- renamed = tree.field(0, Field.left, node);
+ renamed = A.field(0, Field.left, node);
}
- if (renamed !== 0 && tree.type(renamed) === NodeType.PrivateIdentifier) {
- const name = tree.name(renamed);
+ if (renamed !== 0 && A.type(renamed) === NodeType.PrivateIdentifier) {
+ const name = A.name(renamed);
const { kept, names } = state;
if ((kept === null || !kept.has(name)) && !names.has(name)) {
let mangled = state.identifiers.get(++state.counter);
@@ -4627,9 +4624,9 @@ const createTreeMangler = (parse, scopeMangler) => {
const fields =
type === NodeType.SwitchCase ? SWITCH_CASE_WALK : CHILD_FIELDS[type];
for (let f = 0; f < fields.length; f++) {
- const count = tree.fieldCount(fields[f], node);
+ const count = A.fieldCount(fields[f], node);
for (let i = 0; i < count; i++) {
- const child = tree.field(i, fields[f], node);
+ const child = A.field(i, fields[f], node);
if (child !== 0) renamePrivateNames(child, state);
}
}
@@ -4734,31 +4731,24 @@ const createTreeMangler = (parse, scopeMangler) => {
readsGone
);
if (!mayNamePrivate) return names;
- tree = parsed.tree;
- try {
- const kept = scopeMangler.privateNamesReadByEval(
- analysis,
- /** @type {(node: number) => string[]} */ (
- /** @type {(node: number) => string[]} */ (privateNamesDeclaredIn)
- )
- );
- // A private method's `name` is its private name, which `keepFnames`
- // keeps as it keeps the other functions' names.
- if (analysis.namesPrivate && options.keepFnames !== true) {
- /** @type {PrivateNames} */
- const state = {
- identifiers: options.nthIdentifier,
- counter: -1,
- names: new Map(),
- kept
- };
- renamePrivateNames(parsed.program, state);
- names.privateNames = state.names;
- }
- } finally {
- tree = /** @type {SyntaxTree} */ (
- /** @type {SyntaxTree | null} */ (null)
- );
+ const kept = scopeMangler.privateNamesReadByEval(
+ analysis,
+ /** @type {(node: number) => string[]} */ (
+ /** @type {(node: number) => string[]} */ (privateNamesDeclaredIn)
+ )
+ );
+ // A private method's `name` is its private name, which `keepFnames`
+ // keeps as it keeps the other functions' names.
+ if (analysis.namesPrivate && options.keepFnames !== true) {
+ /** @type {PrivateNames} */
+ const state = {
+ identifiers: options.nthIdentifier,
+ counter: -1,
+ names: new Map(),
+ kept
+ };
+ renamePrivateNames(parsed.program, state);
+ names.privateNames = state.names;
}
return names;
};
@@ -5910,7 +5900,7 @@ const checkFormatOptions = (given) => {
* @returns {(path: JavascriptPath, writer: JavascriptPrintContext) => string} the printer
*/
const createNodePrinter = (modules) => {
- const { Field, Flag, NodeType, Part } = require("./syntax-parser");
+ const { A, Field, Flag, NodeType, Part } = require("./syntax-parser");
const {
PURE_ANNOTATION,
convertedKind,
@@ -6443,18 +6433,18 @@ const createNodePrinter = (modules) => {
*/
const typeOf = (node) => {
if (node < 0) return NodeType.ObjectExpression;
- const type = tree.type(node);
+ const type = A.type(node);
switch (type) {
case NodeType.FunctionDeclaration:
- return tree.field(0, Field.id, node) === 0
+ return A.field(0, Field.id, node) === 0
? NodeType.FunctionExpression
: type;
case NodeType.ClassDeclaration:
- return tree.field(0, Field.id, node) === 0
+ return A.field(0, Field.id, node) === 0
? NodeType.ClassExpression
: type;
case NodeType.Literal:
- return tree.value(node) === Infinity ? NodeType.Identifier : type;
+ return A.value(node) === Infinity ? NodeType.Identifier : type;
case NodeType.ImportAttribute:
return NodeType.Property;
default:
@@ -6467,8 +6457,8 @@ const createNodePrinter = (modules) => {
* @returns {number} the node parentheses around it hold, which terser's tree has instead
*/
const unwrap = (node) => {
- while (node !== 0 && tree.type(node) === NodeType.ParenthesizedExpression) {
- node = tree.field(0, Field.expression, node);
+ while (node !== 0 && A.type(node) === NodeType.ParenthesizedExpression) {
+ node = A.field(0, Field.expression, node);
}
return node;
};
@@ -6478,7 +6468,7 @@ const createNodePrinter = (modules) => {
* @param {number} node a node
* @returns {number} the node the field holds, past parentheses, 0 for none
*/
- const childOf = (field, node) => unwrap(tree.field(0, field, node));
+ const childOf = (field, node) => unwrap(A.field(0, field, node));
/**
* @param {number} i the item's index
@@ -6486,14 +6476,14 @@ const createNodePrinter = (modules) => {
* @param {number} node a node
* @returns {number} the list's `i`-th node, past parentheses, 0 for a hole
*/
- const itemOf = (i, field, node) => unwrap(tree.field(i, field, node));
+ const itemOf = (i, field, node) => unwrap(A.field(i, field, node));
/**
* @param {number} node a node
* @returns {string} an identifier's name, a literal `Infinity`'s too
*/
const nameOf = (node) => {
- if (tree.type(node) === NodeType.Literal) return "Infinity";
+ if (A.type(node) === NodeType.Literal) return "Infinity";
const definition = mangledNames === null ? null : mangledNames[node];
if (substituted.size !== 0 && definition) {
const passed = substituted.get(definition);
@@ -6501,7 +6491,7 @@ const createNodePrinter = (modules) => {
}
return definition
? definition.mangledName || definition.name
- : tree.name(node);
+ : A.name(node);
};
/**
@@ -6509,7 +6499,7 @@ const createNodePrinter = (modules) => {
* @returns {string} the name it prints, as mangling renamed it
*/
const privateNameOf = (node) => {
- const name = tree.name(node);
+ const name = A.name(node);
const renamed = privateNames === null ? undefined : privateNames.get(name);
return renamed === undefined ? name : renamed;
};
@@ -6519,9 +6509,7 @@ const createNodePrinter = (modules) => {
* @returns {string} the name terser holds for it
*/
const keyName = (key) =>
- tree.type(key) === NodeType.Literal
- ? String(tree.value(key))
- : tree.name(key);
+ A.type(key) === NodeType.Literal ? String(A.value(key)) : A.name(key);
/**
* @param {number} member a property, method or class field, its key neither computed nor private
@@ -6532,10 +6520,10 @@ const createNodePrinter = (modules) => {
const name = keyName(key);
if (
renamedProperties === null ||
- tree.type(member) === NodeType.ImportAttribute ||
+ A.type(member) === NodeType.ImportAttribute ||
(renamedProperties.keepQuoted &&
- tree.type(key) === NodeType.Literal &&
- typeof tree.value(key) === "string")
+ A.type(key) === NodeType.Literal &&
+ typeof A.value(key) === "string")
) {
return name;
}
@@ -6546,17 +6534,14 @@ const createNodePrinter = (modules) => {
* @param {number} node a string literal
* @returns {string} the quote it was written with
*/
- const quoteOf = (node) =>
- /** @type {string} */ (tree.textOf(Part.raw, node))[0];
+ const quoteOf = (node) => /** @type {string} */ (A.textOf(Part.raw, node))[0];
/**
* @param {number} node an import's or export's name, a literal where quoted
* @returns {string} the name
*/
const moduleName = (node) =>
- tree.type(node) === NodeType.Literal
- ? String(tree.value(node))
- : tree.name(node);
+ A.type(node) === NodeType.Literal ? String(A.value(node)) : A.name(node);
/**
* @param {number} node a binary-like node, as `isBinary` finds one
@@ -6565,7 +6550,7 @@ const createNodePrinter = (modules) => {
const operatorOf = (node) =>
typeOf(node) === NodeType.AssignmentPattern
? "="
- : /** @type {string} */ (tree.textOf(Part.operator, node));
+ : /** @type {string} */ (A.textOf(Part.operator, node));
/**
* @param {number} type a node's type
@@ -6629,7 +6614,7 @@ const createNodePrinter = (modules) => {
*/
const isPrivateIn = (node) =>
typeOf(node) === NodeType.BinaryExpression &&
- tree.type(tree.field(0, Field.left, node)) === NodeType.PrivateIdentifier;
+ A.type(A.field(0, Field.left, node)) === NodeType.PrivateIdentifier;
/**
* @param {number} node a node
@@ -6653,7 +6638,7 @@ const createNodePrinter = (modules) => {
const type = typeOf(node);
return (
type === NodeType.UnaryExpression ||
- (type === NodeType.UpdateExpression && tree.flag(Flag.prefix, node))
+ (type === NodeType.UpdateExpression && A.flag(Flag.prefix, node))
);
};
@@ -6662,7 +6647,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it is terser's `UnaryPostfix`
*/
const isUnaryPostfix = (node) =>
- typeOf(node) === NodeType.UpdateExpression && !tree.flag(Flag.prefix, node);
+ typeOf(node) === NodeType.UpdateExpression && !A.flag(Flag.prefix, node);
/**
* @param {number} node a node
@@ -6670,15 +6655,14 @@ const createNodePrinter = (modules) => {
*/
const isDotOrSub = (node) =>
typeOf(node) === NodeType.MemberExpression &&
- tree.type(tree.field(0, Field.property, node)) !==
- NodeType.PrivateIdentifier;
+ A.type(A.field(0, Field.property, node)) !== NodeType.PrivateIdentifier;
/**
* @param {number} node a node
* @returns {boolean} whether it is a number literal
*/
const isNumber = (node) =>
- typeOf(node) === NodeType.Literal && typeof tree.value(node) === "number";
+ typeOf(node) === NodeType.Literal && typeof A.value(node) === "number";
/**
* @param {number} node a statement
@@ -6686,7 +6670,7 @@ const createNodePrinter = (modules) => {
*/
const isDirective = (node) =>
typeOf(node) === NodeType.ExpressionStatement &&
- tree.textOf(Part.directive, node) !== null;
+ A.textOf(Part.directive, node) !== null;
/**
* @param {number} node a statement
@@ -6695,14 +6679,14 @@ const createNodePrinter = (modules) => {
const isStringStatement = (node) => {
if (
typeOf(node) !== NodeType.ExpressionStatement ||
- tree.textOf(Part.directive, node) !== null
+ A.textOf(Part.directive, node) !== null
) {
return false;
}
const expression = childOf(Field.expression, node);
return (
typeOf(expression) === NodeType.Literal &&
- typeof tree.value(expression) === "string"
+ typeof A.value(expression) === "string"
);
};
@@ -6711,12 +6695,12 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it exports a value, not a named declaration
*/
const exportsValue = (node) => {
- const declaration = tree.field(0, Field.declaration, node);
- const type = tree.type(declaration);
+ const declaration = A.field(0, Field.declaration, node);
+ const type = A.type(declaration);
return (
(type !== NodeType.FunctionDeclaration &&
type !== NodeType.ClassDeclaration) ||
- tree.field(0, Field.id, declaration) === 0
+ A.field(0, Field.id, declaration) === 0
);
};
@@ -6726,7 +6710,7 @@ const createNodePrinter = (modules) => {
* @returns {number} where the node is among the arguments, -1 for nowhere
*/
const argumentIndex = (node, argument) => {
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
if (itemOf(i, Field.arguments, node) === argument) return i;
}
@@ -6738,8 +6722,8 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it is a key and its value, not a method or accessor
*/
const isKeyValue = (node) =>
- tree.type(node) === NodeType.ImportAttribute ||
- (tree.textOf(Part.kind, node) === "init" && !tree.flag(Flag.method, node));
+ A.type(node) === NodeType.ImportAttribute ||
+ (A.textOf(Part.kind, node) === "init" && !A.flag(Flag.method, node));
/**
* @param {number} node a property
@@ -6749,7 +6733,7 @@ const createNodePrinter = (modules) => {
let child = node;
for (let level = 0; ; level++) {
const parent = ancestorOf(level);
- switch (tree.type(parent)) {
+ switch (A.type(parent)) {
// A property is never a default's value, which is an expression.
case NodeType.ObjectPattern:
case NodeType.ArrayPattern:
@@ -6760,11 +6744,11 @@ const createNodePrinter = (modules) => {
case NodeType.FunctionDeclaration:
case NodeType.FunctionExpression:
case NodeType.ArrowFunctionExpression:
- return tree.field(0, Field.body, parent) !== child;
+ return A.field(0, Field.body, parent) !== child;
case NodeType.VariableDeclarator:
- return tree.field(0, Field.id, parent) === child;
+ return A.field(0, Field.id, parent) === child;
case NodeType.CatchClause:
- return tree.field(0, Field.param, parent) === child;
+ return A.field(0, Field.param, parent) === child;
default:
return false;
}
@@ -6778,16 +6762,13 @@ const createNodePrinter = (modules) => {
* @returns {string | undefined} the quote, "" for none
*/
const keyQuoteOf = (member) => {
- if (tree.type(member) === NodeType.ImportAttribute) return undefined;
- if (tree.flag(Flag.computed, member)) return "";
- const key = tree.field(0, Field.key, member);
- if (
- tree.type(key) !== NodeType.Literal ||
- typeof tree.value(key) !== "string"
- ) {
+ if (A.type(member) === NodeType.ImportAttribute) return undefined;
+ if (A.flag(Flag.computed, member)) return "";
+ const key = A.field(0, Field.key, member);
+ if (A.type(key) !== NodeType.Literal || typeof A.value(key) !== "string") {
return "";
}
- return tree.type(member) === NodeType.Property && bindsDeclared(member)
+ return A.type(member) === NodeType.Property && bindsDeclared(member)
? '"'
: quoteOf(key);
};
@@ -6801,13 +6782,13 @@ const createNodePrinter = (modules) => {
* @returns {boolean} true when it is passed over
*/
const isPassedOver = (node, parent, grandparent) => {
- switch (tree.type(node)) {
+ switch (A.type(node)) {
case NodeType.ParenthesizedExpression:
case NodeType.ImportDefaultSpecifier:
case NodeType.ClassBody:
return true;
case NodeType.BlockStatement: {
- const type = tree.type(parent);
+ const type = A.type(parent);
return (
type === NodeType.FunctionDeclaration ||
type === NodeType.FunctionExpression ||
@@ -6816,7 +6797,7 @@ const createNodePrinter = (modules) => {
);
}
case NodeType.ReturnStatement:
- return tree.type(grandparent) === NodeType.ArrowFunctionExpression
+ return A.type(grandparent) === NodeType.ArrowFunctionExpression
? soleStatement(parent) === node || sequenceReturn(parent) === node
: reducing.size !== 0 &&
reducing.get(grandparent) === childOf(Field.argument, node);
@@ -6831,17 +6812,16 @@ const createNodePrinter = (modules) => {
);
}
case NodeType.FunctionExpression: {
- const type = tree.type(parent);
+ const type = A.type(parent);
return (
(type === NodeType.MethodDefinition ||
(type === NodeType.Property && !isKeyValue(parent))) &&
- tree.field(0, Field.value, parent) === node
+ A.field(0, Field.value, parent) === node
);
}
case NodeType.AssignmentPattern:
return (
- tree.type(parent) === NodeType.Property &&
- printsShorthandDefault(parent)
+ A.type(parent) === NodeType.Property && printsShorthandDefault(parent)
);
default:
return false;
@@ -6853,7 +6833,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it prints as `{ a = b }`
*/
const printsShorthandDefault = (node) => {
- if (tree.flag(Flag.computed, node) || !output.option("shorthand")) {
+ if (A.flag(Flag.computed, node) || !output.option("shorthand")) {
return false;
}
const left = childOf(Field.left, childOf(Field.value, node));
@@ -6880,13 +6860,13 @@ const createNodePrinter = (modules) => {
parentsFound === 0 ? current : printedParents[parentsFound - 1];
parentsRead++;
if (
- MAY_PASS_OVER[tree.type(node)] === 1 &&
+ MAY_PASS_OVER[A.type(node)] === 1 &&
isPassedOver(node, parent, ancestorOf(parentsRead + 1))
) {
continue;
}
// An import's attributes print as the object terser holds them in.
- if (child > 0 && tree.type(child) === NodeType.ImportAttribute) {
+ if (child > 0 && A.type(child) === NodeType.ImportAttribute) {
printedParents[parentsFound++] = -node;
}
printedParents[parentsFound++] = node;
@@ -6939,7 +6919,7 @@ const createNodePrinter = (modules) => {
if (
!negatesCalls ||
output.option("wrapIife") ||
- tree.textOf(Part.directive, statement) !== null ||
+ A.textOf(Part.directive, statement) !== null ||
// What prints in the statement after it is not this one's start.
(statement < foundSize && dropped[statement] === 1)
) {
@@ -6952,7 +6932,7 @@ const createNodePrinter = (modules) => {
}
if (
typeOf(call) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, call) ||
+ A.flag(Flag.optional, call) ||
hasEdgeComments(call)
) {
return false;
@@ -7042,7 +7022,7 @@ const createNodePrinter = (modules) => {
*/
const opensUnreadTemplate = (node, part) => {
if (unreadTemplates.size === 0 || !unreadTemplates.has(node)) return false;
- const expressions = tree.fieldCount(Field.expressions, node);
+ const expressions = A.fieldCount(Field.expressions, node);
for (let i = 0; i < expressions; i++) {
const expression = itemOf(i, Field.expressions, node);
if (!printsUnreadPart(expression, node)) continue;
@@ -7217,10 +7197,10 @@ const createNodePrinter = (modules) => {
return (
exportsValue(node) &&
((type === NodeType.FunctionExpression &&
- tree.type(declaration) === NodeType.FunctionExpression) ||
+ A.type(declaration) === NodeType.FunctionExpression) ||
(type === NodeType.ClassExpression &&
- tree.field(0, Field.id, declaration) !== 0 &&
- !dropsName(tree.field(0, Field.id, declaration), keepsClassNames)))
+ A.field(0, Field.id, declaration) !== 0 &&
+ !dropsName(A.field(0, Field.id, declaration), keepsClassNames)))
);
};
@@ -7264,8 +7244,8 @@ const createNodePrinter = (modules) => {
!printedBareName(tag)) ||
isUnaryType(type) ||
(type === NodeType.MemberExpression &&
- !tree.flag(Flag.computed, tag) &&
- tree.type(tree.field(0, Field.property, tag)) === NodeType.Identifier &&
+ !A.flag(Flag.computed, tag) &&
+ A.type(A.field(0, Field.property, tag)) === NodeType.Identifier &&
typeOf(childOf(Field.object, tag)) === NodeType.ObjectExpression)
);
};
@@ -7303,11 +7283,11 @@ const createNodePrinter = (modules) => {
const findNode = (node, test) => {
const found = test(node);
if (found !== undefined) return found;
- const fields = CHILD_FIELDS[tree.type(node)];
+ const fields = CHILD_FIELDS[A.type(node)];
for (let f = 0; f < fields.length; f++) {
- const count = tree.fieldCount(fields[f], node);
+ const count = A.fieldCount(fields[f], node);
for (let i = 0; i < count; i++) {
- const child = tree.field(i, fields[f], node);
+ const child = A.field(i, fields[f], node);
if (child !== 0 && findNode(child, test)) return true;
}
}
@@ -7342,7 +7322,7 @@ const createNodePrinter = (modules) => {
}
if (
type === NodeType.BinaryExpression &&
- tree.textOf(Part.operator, node) === "in"
+ A.textOf(Part.operator, node) === "in"
) {
return true;
}
@@ -7375,7 +7355,7 @@ const createNodePrinter = (modules) => {
return leftIsObject(childOf(Field.test, node));
case NodeType.UpdateExpression:
return (
- !tree.flag(Flag.prefix, node) &&
+ !A.flag(Flag.prefix, node) &&
leftIsObject(childOf(Field.argument, node))
);
case NodeType.Identifier: {
@@ -7502,7 +7482,7 @@ const createNodePrinter = (modules) => {
return true;
}
if (typeOf(node) !== NodeType.AssignmentExpression) return false;
- const leftType = typeOf(tree.field(0, Field.left, node));
+ const leftType = typeOf(A.field(0, Field.left, node));
if (leftType === NodeType.ObjectPattern) return true;
return (
leftType === NodeType.ArrayPattern &&
@@ -7521,7 +7501,7 @@ const createNodePrinter = (modules) => {
const parent = parentAt(level);
if (isCalledOrAccessed(node, parent)) return true;
if (!isBinary(parent) || operatorOf(parent) !== "**") return false;
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
return (
isUnaryPrefix(node) &&
childOf(Field.left, parent) === node &&
@@ -7589,7 +7569,7 @@ const createNodePrinter = (modules) => {
!compresses ||
hasEdgeComments(node) ||
// Printing without the name it ends in, its assignment is its last value.
- readsAssigned(node, tree.fieldCount(Field.expressions, node))
+ readsAssigned(node, A.fieldCount(Field.expressions, node))
) {
return false;
}
@@ -7661,20 +7641,20 @@ const createNodePrinter = (modules) => {
*/
const endsInName = (node) => {
const last = itemOf(
- tree.fieldCount(Field.expressions, node) - 1,
+ A.fieldCount(Field.expressions, node) - 1,
Field.expressions,
node
);
const name =
typeOf(last) === NodeType.MemberExpression &&
- !tree.flag(Flag.computed, last) &&
- !tree.flag(Flag.optional, last)
+ !A.flag(Flag.computed, last) &&
+ !A.flag(Flag.optional, last)
? childOf(Field.object, last)
: last;
// A name a value collapsed into prints as that value.
return (
typeOf(name) === NodeType.Identifier &&
- tree.type(name) === NodeType.Identifier &&
+ A.type(name) === NodeType.Identifier &&
(collapsed.size === 0 || !collapsed.has(name))
);
};
@@ -7689,11 +7669,11 @@ const createNodePrinter = (modules) => {
const nodeType = typeOf(node);
if (MAY_PARENTHESIZE[nodeType] === 0) return false;
if (nodeType === NodeType.Identifier) {
- if (tree.type(node) !== NodeType.Identifier) return false;
+ if (A.type(node) !== NodeType.Identifier) return false;
// Only `let` and `async` are asked, spelled in 3 or 5 characters or escaped.
- const length = tree.end(node) - tree.start(node);
+ const length = A.end(node) - A.start(node);
if (length !== 3 && length !== 5 && length < 8) return false;
- const name = tree.name(node);
+ const name = A.name(node);
if (name !== "let" && name !== "async") return false;
}
const parent = parentAt(level);
@@ -7729,7 +7709,7 @@ const createNodePrinter = (modules) => {
return (
isCalledOrAccessed(node, parent) ||
(isBinary(parent) &&
- tree.textOf(Part.operator, parent) === "**" &&
+ A.textOf(Part.operator, parent) === "**" &&
childOf(Field.left, parent) === node) ||
Boolean(output.option("safari10") && isUnaryPrefix(parent))
);
@@ -7740,7 +7720,7 @@ const createNodePrinter = (modules) => {
if (level === 0 && printsBareUnreadPart(node, parent)) return false;
if (
level === 0 &&
- tree.fieldCount(Field.expressions, node) === 2 &&
+ A.fieldCount(Field.expressions, node) === 2 &&
dropsAssignedRead(
node,
compresses && dropsSideEffectFree ? keptItems(node) : null,
@@ -7907,7 +7887,7 @@ const createNodePrinter = (modules) => {
isCalledOrAccessed(node, parent) &&
!(
compresses &&
- tree.flag(Flag.optional, parent) &&
+ A.flag(Flag.optional, parent) &&
(typeOf(parent) === NodeType.MemberExpression ||
typeOf(parent) === NodeType.CallExpression)
)
@@ -7985,12 +7965,12 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const value = /** @type {number} */ (tree.value(node));
+ const value = /** @type {number} */ (A.value(node));
return value < 0 || makeNum(value).startsWith("0");
}
case NodeType.Identifier: {
// Only `let` and `async` reach here, as the test above leaves them.
- const name = tree.name(node);
+ const name = A.name(node);
let child = node;
let head = 0;
for (let i = level; ; i++) {
@@ -8008,7 +7988,7 @@ const createNodePrinter = (modules) => {
childOf(Field.left, head) === child
) {
return (
- name === "let" || (child === node && !tree.flag(Flag.await, head))
+ name === "let" || (child === node && !A.flag(Flag.await, head))
);
}
return (
@@ -8020,8 +8000,8 @@ const createNodePrinter = (modules) => {
(headType === NodeType.ForInStatement &&
childOf(Field.left, head) === child)) &&
typeOf(parent) === NodeType.MemberExpression &&
- tree.flag(Flag.computed, parent) &&
- !tree.flag(Flag.optional, parent)
+ A.flag(Flag.computed, parent) &&
+ !A.flag(Flag.optional, parent)
);
}
default:
@@ -8048,8 +8028,8 @@ const createNodePrinter = (modules) => {
// Only these put parentheses around what they hold whatever it is.
const holder = level === 0 ? ancestorOf(0) : 0;
const held =
- holder !== 0 && tree.type(holder) !== NodeType.ParenthesizedExpression
- ? tree.type(holder)
+ holder !== 0 && A.type(holder) !== NodeType.ParenthesizedExpression
+ ? A.type(holder)
: typeOf(parentAt(level));
if (
held !== NodeType.TaggedTemplateExpression &&
@@ -8086,7 +8066,7 @@ const createNodePrinter = (modules) => {
*/
const printNode = (child, wrap) => {
// A name is never wrapped: only a named function or class is.
- if (inlinesNames && tree.type(child) === NodeType.Identifier) {
+ if (inlinesNames && A.type(child) === NodeType.Identifier) {
const parens = needsParens(child, -1);
if (parens) output.print("(");
output.printName(nameOf(child));
@@ -8195,7 +8175,7 @@ const createNodePrinter = (modules) => {
printPiece(text, heads[child], tails[child]);
} else if (
!wrap &&
- tree.type(current) !== NodeType.Program &&
+ A.type(current) !== NodeType.Program &&
output.text.length === (currentParens ? 1 : 0)
) {
// Nothing is printed before them yet, which decides how they print.
@@ -8312,7 +8292,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} true for a name, a literal or an empty statement
*/
const takesLaterComments = (node) => {
- const type = tree.type(node);
+ const type = A.type(node);
return (
type === NodeType.Identifier ||
type === NodeType.Literal ||
@@ -8331,7 +8311,7 @@ const createNodePrinter = (modules) => {
const commentsBefore = (child) => {
// Most nodes have no comments before them, which nothing takes then;
// a keyword takes those on its value's leftmost edge.
- const type = tree.type(child);
+ const type = A.type(child);
const takes =
hasComments(/** @type {TreeTokens} */ (commentTokens).starts[child], 1) ||
type === NodeType.ReturnStatement ||
@@ -8442,7 +8422,7 @@ const createNodePrinter = (modules) => {
case NodeType.YieldExpression:
return childOf(Field.argument, parent);
case NodeType.UpdateExpression:
- return tree.flag(Flag.prefix, parent)
+ return A.flag(Flag.prefix, parent)
? undefined
: childOf(Field.argument, parent);
case NodeType.BinaryExpression:
@@ -8529,12 +8509,12 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const body = tree.field(0, Field.body, fn);
- const count = tree.fieldCount(Field.body, body);
+ const body = A.field(0, Field.body, fn);
+ const count = A.fieldCount(Field.body, body);
const argument = childOf(Field.argument, alternate);
return (
count !== 0 &&
- tree.field(count - 1, Field.body, body) === node &&
+ A.field(count - 1, Field.body, body) === node &&
(argument === 0 || returnsNothing(argument))
);
};
@@ -8546,7 +8526,7 @@ const createNodePrinter = (modules) => {
const printsInBraces = (fn) =>
(bracedBodies.size !== 0 && bracedBodies.has(fn)) ||
bindsInBody(fn) ||
- opensWithString(tree.field(0, Field.body, fn));
+ opensWithString(A.field(0, Field.body, fn));
/**
* @param {number} fn the function a program only calls, or one printing as a block
@@ -8559,7 +8539,7 @@ const createNodePrinter = (modules) => {
: (bareBodies.size === 0 || !bareBodies.has(fn)) && printsInBraces(fn);
if (block) output.print("{");
const at = output.text.length;
- displayBody(tree.field(0, Field.body, fn));
+ displayBody(A.field(0, Field.body, fn));
if (!block) {
if (listedExpression) bareExpressionBodies.add(fn);
return;
@@ -8580,7 +8560,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const displayBody = (owner) => {
- const count = tree.fieldCount(Field.body, owner);
+ const count = A.fieldCount(Field.body, owner);
// The kind of the declaration printed last, which the next of its kind
// continues, terser's `join_vars`.
/** @type {string | null} */
@@ -8611,7 +8591,7 @@ const createNodePrinter = (modules) => {
const bareVars = firstVar === 0 ? [] : laterBareVars(owner, firstVar);
let expressionsOnly = true;
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, owner);
+ const statement = A.field(i, Field.body, owner);
if (
printsNothing(statement) ||
(i === count - 1 && compresses && endsFunction(statement, owner)) ||
@@ -8759,7 +8739,7 @@ const createNodePrinter = (modules) => {
node = /** @type {number} */ (collapsed.get(node));
break;
}
- return tree.name(node) === "let" || isMovedRead(node);
+ return A.name(node) === "let" || isMovedRead(node);
case NodeType.LogicalExpression: {
// A known left side leaving the right prints that alone.
const kept = compresses ? knownLeftKept(node) : 0;
@@ -8800,7 +8780,7 @@ const createNodePrinter = (modules) => {
node = childOf(Field.expression, node);
break;
case NodeType.UpdateExpression:
- if (tree.flag(Flag.prefix, node)) return false;
+ if (A.flag(Flag.prefix, node)) return false;
node = childOf(Field.argument, node);
break;
default:
@@ -8821,7 +8801,7 @@ const createNodePrinter = (modules) => {
typeOf(node) === NodeType.ObjectPattern
? Field.properties
: Field.elements;
- const count = tree.fieldCount(field, node);
+ const count = A.fieldCount(field, node);
for (let i = 0; i < count; i++) {
const element = itemOf(i, field, node);
if (
@@ -8863,12 +8843,12 @@ const createNodePrinter = (modules) => {
* @returns {string} its keyword
*/
const kindOf = (node, exported) => {
- const kind = /** @type {string} */ (tree.textOf(Part.kind, node));
+ const kind = /** @type {string} */ (A.textOf(Part.kind, node));
if (kind !== "const" || !compresses || exported) return kind;
- const count = tree.fieldCount(Field.declarations, node);
+ const count = A.fieldCount(Field.declarations, node);
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, node);
- if (!bindsUnwritten(tree.field(0, Field.id, declarator))) return kind;
+ const declarator = A.field(i, Field.declarations, node);
+ if (!bindsUnwritten(A.field(0, Field.id, declarator))) return kind;
}
return "let";
};
@@ -8878,9 +8858,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether a declarator going but keeping its value prints it as a statement of its own
*/
const printsApart = (statement) => {
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, statement);
+ const declarator = A.field(i, Field.declarations, statement);
if (dropped[declarator] === 1 && keepsEffect[declarator] === 1) {
return true;
}
@@ -8970,7 +8950,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it may print as one with the one before it
*/
const joinsExpression = (statement, printed = statement) =>
- tree.textOf(Part.directive, statement) === null &&
+ A.textOf(Part.directive, statement) === null &&
// A string where directives may be prints a `;` first, ending a `return`.
!isStringStatement(statement) &&
/** @type {JavascriptPrintContext} */ (writer)
@@ -9014,18 +8994,18 @@ const createNodePrinter = (modules) => {
* @returns {number} the `return`, or 0 where none follows them or printing in it takes a space more and saves no braces
*/
const joinedReturn = (owner, from, first, opensArrow, opensBody = false) => {
- const count = tree.fieldCount(Field.body, owner);
+ const count = A.fieldCount(Field.body, owner);
if (opensArrow) {
// Joining the arrow's whole body, it would print as `=>(a,b)` reprinted.
let end = count - 1;
- while (end >= from && printsNothing(tree.field(end, Field.body, owner))) {
+ while (end >= from && printsNothing(A.field(end, Field.body, owner))) {
end--;
}
if (end >= from) {
const joined = joinedReturn(owner, from, first, false);
// A `return t?x:` the `return` after it ends ends the body too.
if (
- joined === tree.field(end, Field.body, owner) ||
+ joined === A.field(end, Field.body, owner) ||
typeOf(joined) === NodeType.IfStatement
) {
return 0;
@@ -9033,7 +9013,7 @@ const createNodePrinter = (modules) => {
}
}
for (let i = from; i < count; i++) {
- const statement = tree.field(i, Field.body, owner);
+ const statement = A.field(i, Field.body, owner);
if (printsNothing(statement)) continue;
if (joinableKind(statement) === "expression") continue;
if (
@@ -9061,7 +9041,7 @@ const createNodePrinter = (modules) => {
) {
if (!opensBody) return 0;
for (let j = i + 1; j < count; j++) {
- if (!printsNothing(tree.field(j, Field.body, owner))) return 0;
+ if (!printsNothing(A.field(j, Field.body, owner))) return 0;
}
}
return statement;
@@ -9206,12 +9186,12 @@ const createNodePrinter = (modules) => {
* @returns {number} its first statement printing as a `var`, 0 for none
*/
const firstPrintedVar = (owner) => {
- const count = tree.fieldCount(Field.body, owner);
+ const count = A.fieldCount(Field.body, owner);
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, owner);
+ const statement = A.field(i, Field.body, owner);
if (
typeOf(statement) === NodeType.VariableDeclaration &&
- tree.textOf(Part.kind, statement) === "var" &&
+ A.textOf(Part.kind, statement) === "var" &&
!printsNothing(statement) &&
!printsApart(statement) &&
/** @type {JavascriptPrintContext} */ (writer)
@@ -9232,14 +9212,14 @@ const createNodePrinter = (modules) => {
const laterBareVars = (owner, first) => {
/** @type {number[]} */
const bare = [];
- const count = tree.fieldCount(Field.body, owner);
+ const count = A.fieldCount(Field.body, owner);
let i = 0;
- while (tree.field(i, Field.body, owner) !== first) i++;
+ while (A.field(i, Field.body, owner) !== first) i++;
for (i++; i < count; i++) {
- const statement = tree.field(i, Field.body, owner);
+ const statement = A.field(i, Field.body, owner);
if (
typeOf(statement) !== NodeType.VariableDeclaration ||
- tree.textOf(Part.kind, statement) !== "var" ||
+ A.textOf(Part.kind, statement) !== "var" ||
holdsComments(statement) ||
printsNothing(statement) ||
!(
@@ -9252,13 +9232,13 @@ const createNodePrinter = (modules) => {
}
let names = true;
for (
- let j = tree.fieldCount(Field.declarations, statement) - 1;
+ let j = A.fieldCount(Field.declarations, statement) - 1;
j >= 0;
j--
) {
- const declarator = tree.field(j, Field.declarations, statement);
+ const declarator = A.field(j, Field.declarations, statement);
if (
- typeOf(tree.field(0, Field.id, declarator)) !== NodeType.Identifier ||
+ typeOf(A.field(0, Field.id, declarator)) !== NodeType.Identifier ||
(childOf(Field.init, declarator) !== 0 &&
!(deadInits.size !== 0 && deadInits.has(declarator)))
) {
@@ -9278,7 +9258,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printBraced = (owner, body) => {
- if (tree.fieldCount(Field.body, body) === 0) {
+ if (A.fieldCount(Field.body, body) === 0) {
printBracedEmpty(owner);
return;
}
@@ -9298,11 +9278,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether each one is an empty statement
*/
const listsOnlyEmpty = (body) => {
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- if (
- tree.type(tree.field(i, Field.body, body)) !== NodeType.EmptyStatement
- ) {
+ if (A.type(A.field(i, Field.body, body)) !== NodeType.EmptyStatement) {
return false;
}
}
@@ -9407,7 +9385,7 @@ const createNodePrinter = (modules) => {
return false;
case NodeType.BinaryExpression:
return !(
- tree.textOf(Part.operator, parent) === "**" &&
+ A.textOf(Part.operator, parent) === "**" &&
childOf(Field.left, parent) === node
);
default:
@@ -9451,7 +9429,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it is that global: one no scope declares and no `with` or `eval` may
*/
const isGlobalUndefined = (node, name = "undefined") => {
- if (tree.name(node) !== name || mangledNames === null) return false;
+ if (A.name(node) !== name || mangledNames === null) return false;
const definition = mangledNames[node];
return (
isMinifierVariable(definition) &&
@@ -9479,7 +9457,7 @@ const createNodePrinter = (modules) => {
case NodeType.Property:
return (
// Without shorthands its value prints after the key, as any other.
- (!tree.flag(Flag.shorthand, parent) || !output.option("shorthand")) &&
+ (!A.flag(Flag.shorthand, parent) || !output.option("shorthand")) &&
typeOf(parentAt(1)) === NodeType.ObjectExpression &&
childOf(Field.value, parent) === node
);
@@ -9506,7 +9484,7 @@ const createNodePrinter = (modules) => {
}
const definition = mangledNames[node];
return (
- constructedWhenCalled.has(tree.name(node)) &&
+ constructedWhenCalled.has(A.name(node)) &&
isMinifierVariable(definition) &&
definition.undeclared &&
!definition.written &&
@@ -9525,7 +9503,7 @@ const createNodePrinter = (modules) => {
const callee = childOf(Field.callee, node);
return (
readsBuiltInConstructor(callee) &&
- (tree.name(callee) !== "RegExp" || patternIsPrimitive(node))
+ (A.name(callee) !== "RegExp" || patternIsPrimitive(node))
);
};
@@ -9666,16 +9644,16 @@ const createNodePrinter = (modules) => {
const isUnreadImport = (specifier) =>
dropsUnused &&
!hasEdgeComments(specifier) &&
- isUnusedBinding(tree.field(0, Field.local, specifier));
+ isUnusedBinding(A.field(0, Field.local, specifier));
/**
* @param {number} node an import declaration
* @returns {boolean} whether it binds no name anything reads, loading its module only
*/
const importsNothingRead = (node) => {
- const count = tree.fieldCount(Field.specifiers, node);
+ const count = A.fieldCount(Field.specifiers, node);
for (let i = 0; i < count; i++) {
- if (!isUnreadImport(tree.field(i, Field.specifiers, node))) return false;
+ if (!isUnreadImport(A.field(i, Field.specifiers, node))) return false;
}
return true;
};
@@ -9722,7 +9700,7 @@ const createNodePrinter = (modules) => {
if (evaluateConstant(node) !== undefined) return true;
if (typeOf(node) === NodeType.LogicalExpression) {
// A left side deciding it never runs the right.
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
const truth = knownTruth(childOf(Field.left, node));
if (
(operator === "&&" && truth === false) ||
@@ -9768,7 +9746,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it is a constructor every edition defines, whose `instanceof` reads only its `prototype`, and nothing writes either
*/
const answersInstanceof = (node) => {
- const name = tree.name(node);
+ const name = A.name(node);
return (
ORDINARY_CONSTRUCTORS.includes(name) &&
isGlobalUndefined(node, name) &&
@@ -9784,12 +9762,12 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it reads a member of a built-in prototype `builtInOwnerOf` names, which no write the program makes replaces
*/
const readsPrototypeMember = (node) => {
- if (tree.flag(Flag.computed, node)) return false;
+ if (A.flag(Flag.computed, node)) return false;
const owner = builtInOwnerOf(childOf(Field.object, node));
return (
owner !== undefined &&
owner.endsWith(".prototype") &&
- !writesBuiltIn(`${owner}.${tree.name(childOf(Field.property, node))}`)
+ !writesBuiltIn(`${owner}.${A.name(childOf(Field.property, node))}`)
);
};
@@ -9809,9 +9787,9 @@ const createNodePrinter = (modules) => {
}
if (typeOf(node) === NodeType.ObjectExpression) return true;
// A hole joins what the prototypes hold at its index.
- const count = tree.fieldCount(Field.elements, node);
+ const count = A.fieldCount(Field.elements, node);
for (let i = 0; i < count; i++) {
- if (tree.field(i, Field.elements, node) === 0) return false;
+ if (A.field(i, Field.elements, node) === 0) return false;
}
return (
!writesBuiltIn("Array.prototype.toString") &&
@@ -9833,16 +9811,16 @@ const createNodePrinter = (modules) => {
case NodeType.ArrayExpression: {
if (intoObject) return false;
// A hole reads what the prototypes hold at its index.
- const count = tree.fieldCount(Field.elements, argument);
+ const count = A.fieldCount(Field.elements, argument);
for (let i = 0; i < count; i++) {
- if (tree.field(i, Field.elements, argument) === 0) return true;
+ if (A.field(i, Field.elements, argument) === 0) return true;
}
return writesBuiltIn("Array.prototype.*");
}
case NodeType.TemplateLiteral:
return !intoObject && writesBuiltIn("String.prototype.*");
case NodeType.Literal: {
- const value = tree.value(argument);
+ const value = A.value(argument);
if (typeof value === "string") {
return !intoObject && writesBuiltIn("String.prototype.*");
}
@@ -9855,12 +9833,12 @@ const createNodePrinter = (modules) => {
return !intoObject;
case NodeType.ObjectExpression: {
if (!intoObject) return true;
- const count = tree.fieldCount(Field.properties, argument);
+ const count = A.fieldCount(Field.properties, argument);
for (let i = 0; i < count; i++) {
- const property = tree.field(i, Field.properties, argument);
+ const property = A.field(i, Field.properties, argument);
if (
typeOf(property) === NodeType.Property &&
- tree.textOf(Part.kind, property) === "get"
+ A.textOf(Part.kind, property) === "get"
) {
return true;
}
@@ -9951,7 +9929,7 @@ const createNodePrinter = (modules) => {
const readsPlainGlobal = (node) =>
!answersWith &&
!probedReads.has(node) &&
- /** @type {Set} */ (readGlobals).has(tree.name(node));
+ /** @type {Set} */ (readGlobals).has(A.name(node));
/**
* @param {number} node a name
@@ -9963,7 +9941,7 @@ const createNodePrinter = (modules) => {
isMinifierVariable(definition) &&
definition.undeclared &&
readsPlainGlobal(node) &&
- tree.name(node) !== "undefined"
+ A.name(node) !== "undefined"
);
};
@@ -9976,10 +9954,10 @@ const createNodePrinter = (modules) => {
case NodeType.TemplateLiteral:
return true;
case NodeType.Literal:
- return typeof tree.value(node) === "string";
+ return typeof A.value(node) === "string";
case NodeType.BinaryExpression:
return (
- tree.textOf(Part.operator, node) === "+" &&
+ A.textOf(Part.operator, node) === "+" &&
joinsStrings(childOf(Field.left, node)) &&
joinsStrings(childOf(Field.right, node))
);
@@ -9993,20 +9971,20 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it passes no pattern, or one a literal or an operator makes, which is no object
*/
const patternIsPrimitive = (node) => {
- if (tree.fieldCount(Field.arguments, node) === 0) return true;
- const pattern = tree.field(0, Field.arguments, node);
+ if (A.fieldCount(Field.arguments, node) === 0) return true;
+ const pattern = A.field(0, Field.arguments, node);
switch (typeOf(pattern)) {
case NodeType.Literal: {
// A regular expression literal is an object, whatever it reads as.
- const value = tree.value(pattern);
+ const value = A.value(pattern);
if (typeof value === "object" && value !== null) return false;
- const raw = tree.textOf(Part.raw, pattern);
+ const raw = A.textOf(Part.raw, pattern);
return raw === null || raw.charCodeAt(0) !== 47;
}
case NodeType.TemplateLiteral:
return true;
case NodeType.UnaryExpression:
- return tree.textOf(Part.operator, pattern) !== "delete";
+ return A.textOf(Part.operator, pattern) !== "delete";
// Every binary operator answers a primitive; one of constants or
// strings alone prints as one string, the case the rest take.
case NodeType.BinaryExpression:
@@ -10035,14 +10013,14 @@ const createNodePrinter = (modules) => {
const callee = childOf(Field.callee, node);
if (
typeOf(callee) !== NodeType.Identifier ||
- tree.name(callee) !== "RegExp" ||
+ A.name(callee) !== "RegExp" ||
mangledNames === null ||
- tree.flag(Flag.optional, node)
+ A.flag(Flag.optional, node)
) {
return false;
}
const definition = mangledNames[callee];
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
if (
!isMinifierVariable(definition) ||
!definition.undeclared ||
@@ -10054,7 +10032,7 @@ const createNodePrinter = (modules) => {
}
// Nothing passed makes `/(?:)/`.
if (count === 0) return true;
- const first = unwrap(tree.field(0, Field.arguments, node));
+ const first = unwrap(A.field(0, Field.arguments, node));
// A regular expression passed gives its source, and its flags where
// none are, read by the native accessors no write replaces; before
// ECMAScript 2015 flags beside one throw.
@@ -10070,7 +10048,7 @@ const createNodePrinter = (modules) => {
literal !== undefined ? literal.source : argumentValue(first);
const flags =
count === 2
- ? argumentValue(tree.field(1, Field.arguments, node))
+ ? argumentValue(A.field(1, Field.arguments, node))
: literal !== undefined
? literal.flags
: "";
@@ -10103,7 +10081,7 @@ const createNodePrinter = (modules) => {
while (typeOf(root) === NodeType.MemberExpression) {
root = childOf(Field.object, root);
}
- return isGlobalUndefined(root, tree.name(root)) ? value : undefined;
+ return isGlobalUndefined(root, A.name(root)) ? value : undefined;
};
/**
@@ -10131,11 +10109,11 @@ const createNodePrinter = (modules) => {
*/
const dottedNameOf = (node) => {
const type = typeOf(node);
- if (type === NodeType.Identifier) return tree.name(node);
+ if (type === NodeType.Identifier) return A.name(node);
if (
type !== NodeType.MemberExpression ||
- tree.flag(Flag.computed, node) ||
- tree.flag(Flag.optional, node)
+ A.flag(Flag.computed, node) ||
+ A.flag(Flag.optional, node)
) {
return "";
}
@@ -10143,7 +10121,7 @@ const createNodePrinter = (modules) => {
const property = childOf(Field.property, node);
return object === "" || typeOf(property) !== NodeType.Identifier
? ""
- : `${object}.${tree.name(property)}`;
+ : `${object}.${A.name(property)}`;
};
/**
@@ -10157,18 +10135,18 @@ const createNodePrinter = (modules) => {
let callee = childOf(Field.callee, node);
if (
typeOf(callee) !== NodeType.MemberExpression ||
- tree.flag(Flag.computed, callee)
+ A.flag(Flag.computed, callee)
) {
return false;
}
// `console.log.call(…)` and `.apply(…)` call the method too.
- const method = tree.name(childOf(Field.property, callee));
+ const method = A.name(childOf(Field.property, callee));
if (
(method === "call" || method === "apply") &&
typeOf(childOf(Field.object, callee)) === NodeType.MemberExpression
) {
callee = childOf(Field.object, callee);
- if (tree.flag(Flag.computed, callee)) return false;
+ if (A.flag(Flag.computed, callee)) return false;
}
const object = childOf(Field.object, callee);
const property = childOf(Field.property, callee);
@@ -10176,7 +10154,7 @@ const createNodePrinter = (modules) => {
typeOf(object) === NodeType.Identifier &&
isGlobalUndefined(object, "console") &&
typeOf(property) === NodeType.Identifier &&
- (droppedConsole === true || droppedConsole.has(tree.name(property)))
+ (droppedConsole === true || droppedConsole.has(A.name(property)))
);
};
@@ -10190,12 +10168,12 @@ const createNodePrinter = (modules) => {
node = unwrap(node);
switch (typeOf(node)) {
case NodeType.Literal:
- return typeof tree.value(node) !== "bigint";
+ return typeof A.value(node) !== "bigint";
case NodeType.FunctionExpression:
case NodeType.ArrowFunctionExpression:
return true;
case NodeType.ArrayExpression: {
- const count = tree.fieldCount(Field.elements, node);
+ const count = A.fieldCount(Field.elements, node);
for (let i = 0; i < count; i++) {
const element = itemOf(i, Field.elements, node);
if (element !== 0 && !convertsNatively(element)) return false;
@@ -10205,7 +10183,7 @@ const createNodePrinter = (modules) => {
case NodeType.ObjectExpression: {
// A key conversion reads, a new prototype or an accessor, as `Error`'s
// `cause`, runs its code.
- const count = tree.fieldCount(Field.properties, node);
+ const count = A.fieldCount(Field.properties, node);
for (let i = 0; i < count; i++) {
const property = itemOf(i, Field.properties, node);
if (typeOf(property) === NodeType.SpreadElement) {
@@ -10214,8 +10192,8 @@ const createNodePrinter = (modules) => {
}
if (
typeOf(property) !== NodeType.Property ||
- tree.flag(Flag.computed, property) ||
- tree.textOf(Part.kind, property) !== "init"
+ A.flag(Flag.computed, property) ||
+ A.textOf(Part.kind, property) !== "init"
) {
return false;
}
@@ -10232,7 +10210,7 @@ const createNodePrinter = (modules) => {
if (
typeOf(callee) === NodeType.MemberExpression &&
typeOf(childOf(Field.object, callee)) === NodeType.Identifier &&
- tree.name(childOf(Field.object, callee)) === "Math" &&
+ A.name(childOf(Field.object, callee)) === "Math" &&
callsPureBuiltIn(node)
) {
return true;
@@ -10254,10 +10232,10 @@ const createNodePrinter = (modules) => {
if (typeOf(argument) !== NodeType.ArrayExpression) {
return (
typeOf(argument) === NodeType.Literal &&
- typeof tree.value(argument) === "string"
+ typeof A.value(argument) === "string"
);
}
- const count = tree.fieldCount(Field.elements, argument);
+ const count = A.fieldCount(Field.elements, argument);
for (let i = 0; i < count; i++) {
const element = itemOf(i, Field.elements, argument);
if (element === 0 || !convertsNatively(element)) return false;
@@ -10278,7 +10256,7 @@ const createNodePrinter = (modules) => {
case NodeType.ObjectExpression:
return convertsNatively(argument);
case NodeType.Literal:
- return typeof tree.value(argument) === "string";
+ return typeof A.value(argument) === "string";
default:
return false;
}
@@ -10307,7 +10285,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} true where the arguments make it throw nothing
*/
const takesArgumentsQuietly = (builtin, node) => {
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
if (count === 0) return true;
const first = unwrap(itemOf(0, Field.arguments, node));
const value = evaluateConstant(first);
@@ -10345,7 +10323,7 @@ const createNodePrinter = (modules) => {
if (!tables.NATIVE_ARG1_IS_ITERABLE.includes(builtin)) return true;
// `null` or `undefined` makes an empty collection.
if (
- (typeOf(first) === NodeType.Literal && tree.value(first) === null) ||
+ (typeOf(first) === NodeType.Literal && A.value(first) === null) ||
isUndefinedValue(first)
) {
return true;
@@ -10362,7 +10340,7 @@ const createNodePrinter = (modules) => {
}
if (builtin === "Set") return true;
// A map takes entries, a weak collection objects to key by.
- const elements = tree.fieldCount(Field.elements, first);
+ const elements = A.fieldCount(Field.elements, first);
for (let i = 0; i < elements; i++) {
const element = itemOf(i, Field.elements, first);
const entry = builtin === "WeakSet" ? element : 0;
@@ -10375,7 +10353,7 @@ const createNodePrinter = (modules) => {
const key =
builtin === "WeakSet"
? entry
- : tree.fieldCount(Field.elements, element) === 0
+ : A.fieldCount(Field.elements, element) === 0
? 0
: itemOf(0, Field.elements, element);
const type = key === 0 ? 0 : typeOf(key);
@@ -10398,7 +10376,7 @@ const createNodePrinter = (modules) => {
const isNonNullishPrimitive = (node) => {
if (
typeOf(node) === NodeType.Literal &&
- typeof tree.value(node) === "bigint"
+ typeof A.value(node) === "bigint"
) {
return true;
}
@@ -10419,7 +10397,7 @@ const createNodePrinter = (modules) => {
node = unwrap(node);
if (
typeOf(node) === NodeType.Literal &&
- typeof tree.value(node) === "bigint"
+ typeof A.value(node) === "bigint"
) {
return true;
}
@@ -10442,8 +10420,8 @@ const createNodePrinter = (modules) => {
*/
const isNullLiteral = (node) =>
typeOf(node) === NodeType.Literal &&
- tree.value(node) === null &&
- tree.textOf(Part.raw, node) === "null";
+ A.value(node) === null &&
+ A.textOf(Part.raw, node) === "null";
/**
* What `unsafe` adds to `Object`'s statics throws only on what is no
@@ -10485,12 +10463,12 @@ const createNodePrinter = (modules) => {
* @returns {boolean} true where it runs nothing but making its value
*/
const callsPureBuiltIn = (node) => {
- if (!compresses || tree.flag(Flag.optional, node)) return false;
+ if (!compresses || A.flag(Flag.optional, node)) return false;
const callee = childOf(Field.callee, node);
let builtin;
let method = "";
if (typeOf(callee) === NodeType.Identifier) {
- builtin = tree.name(callee);
+ builtin = A.name(callee);
if (!isGlobalUndefined(callee, builtin)) return false;
} else {
// `a["b"]` names the method `a.b` does.
@@ -10498,7 +10476,7 @@ const createNodePrinter = (modules) => {
if (method === "") return false;
const object = childOf(Field.object, callee);
if (typeOf(object) !== NodeType.Identifier) return false;
- builtin = tree.name(object);
+ builtin = A.name(object);
if (!isGlobalUndefined(object, builtin)) return false;
}
// `Object` makes an object of its first argument and `Boolean` reads its
@@ -10537,7 +10515,7 @@ const createNodePrinter = (modules) => {
];
}
const [functions, statics, objectStatics] = pureNatives;
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
if (method === "" && builtin === "BigInt") {
return (
functions.has(builtin) &&
@@ -10557,7 +10535,7 @@ const createNodePrinter = (modules) => {
}
if (
typeOf(unwrap(argument)) === NodeType.Literal &&
- typeof tree.value(unwrap(argument)) === "bigint" &&
+ typeof A.value(unwrap(argument)) === "bigint" &&
takesBigIntQuietly(builtin, method, i)
) {
continue;
@@ -10678,7 +10656,7 @@ const createNodePrinter = (modules) => {
if (sideEffectFree.size !== 0 && callsSideEffectFree(node)) return true;
const tables = output.tokenTables;
const table = /** @type {TokenTable} */ (tables.last);
- const start = tree.start(node);
+ const start = A.start(node);
for (const comment of tables.members(
tables.commentsOf(commentTokens.starts[node], false)
)) {
@@ -10720,7 +10698,7 @@ const createNodePrinter = (modules) => {
set !== undefined &&
(set === 0 ||
((setFirst[set] !== 0 || exportedDeclarators.has(set)) &&
- tree.start(node) >= tree.end(set)))
+ A.start(node) >= A.end(set)))
);
};
@@ -10731,7 +10709,7 @@ const createNodePrinter = (modules) => {
const annotatedSideEffectFree = (node) => {
const tables = output.tokenTables;
const table = /** @type {TokenTable} */ (tables.last);
- const start = tree.start(node);
+ const start = A.start(node);
for (const comment of tables.members(
tables.commentsOf(
/** @type {TreeTokens} */ (commentTokens).starts[node],
@@ -10759,17 +10737,17 @@ const createNodePrinter = (modules) => {
if (typeOf(declaration) === NodeType.FunctionDeclaration) {
if (!annotated && !annotatedSideEffectFree(declaration)) return;
sideEffectFree.set(declaration, 0);
- const id = tree.field(0, Field.id, declaration);
+ const id = A.field(0, Field.id, declaration);
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[id];
if (isMinifierVariable(definition)) sideEffectFree.set(definition, 0);
return;
}
if (typeOf(declaration) !== NodeType.VariableDeclaration) return;
const marked = annotated || annotatedSideEffectFree(declaration);
- const count = tree.fieldCount(Field.declarations, declaration);
+ const count = A.fieldCount(Field.declarations, declaration);
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, declaration);
- const id = tree.field(0, Field.id, declarator);
+ const declarator = A.field(i, Field.declarations, declaration);
+ const id = A.field(0, Field.id, declarator);
const init = childOf(Field.init, declarator);
if (
typeOf(id) !== NodeType.Identifier ||
@@ -10805,12 +10783,12 @@ const createNodePrinter = (modules) => {
break;
case NodeType.ExportNamedDeclaration:
case NodeType.ExportDefaultDeclaration: {
- const declaration = tree.field(0, Field.declaration, node);
+ const declaration = A.field(0, Field.declaration, node);
if (typeOf(declaration) === NodeType.VariableDeclaration) {
- const count = tree.fieldCount(Field.declarations, declaration);
+ const count = A.fieldCount(Field.declarations, declaration);
for (let i = 0; i < count; i++) {
exportedDeclarators.add(
- tree.field(i, Field.declarations, declaration)
+ A.field(i, Field.declarations, declaration)
);
}
}
@@ -10841,9 +10819,9 @@ const createNodePrinter = (modules) => {
if (type !== NodeType.VariableDeclaration) {
return dropped[statement] === 1;
}
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, statement);
+ const declarator = A.field(i, Field.declarations, statement);
if (dropped[declarator] !== 1 || keepsOwnEffect(declarator)) {
return false;
}
@@ -10863,10 +10841,10 @@ const createNodePrinter = (modules) => {
* @returns {number} how many values it prints as statements of their own where its declarators all go, as its generator prints them; -1 where it prints one
*/
const printedValues = (statement) => {
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
let printed = 0;
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, statement);
+ const declarator = A.field(i, Field.declarations, statement);
if (
dropped[declarator] !== 1 ||
!(keepsEffect[declarator] === 1 || printed > 0 || i < count - 1)
@@ -10894,12 +10872,11 @@ const createNodePrinter = (modules) => {
}
const left =
typeOf(heritage) === NodeType.LogicalExpression &&
- tree.textOf(Part.operator, heritage) === "&&"
+ A.textOf(Part.operator, heritage) === "&&"
? childOf(Field.left, heritage)
: heritage;
return (
- typeOf(left) === NodeType.Literal &&
- tree.textOf(Part.raw, left) === "null"
+ typeOf(left) === NodeType.Literal && A.textOf(Part.raw, left) === "null"
);
};
@@ -10910,11 +10887,11 @@ const createNodePrinter = (modules) => {
const dropsNow = (candidate) => {
const type = typeOf(candidate);
if (type === NodeType.FunctionDeclaration) {
- return isUnusedBinding(tree.field(0, Field.id, candidate));
+ return isUnusedBinding(A.field(0, Field.id, candidate));
}
if (type === NodeType.ClassDeclaration) {
return (
- isUnusedBinding(tree.field(0, Field.id, candidate)) &&
+ isUnusedBinding(A.field(0, Field.id, candidate)) &&
isPureValue(candidate)
);
}
@@ -11283,7 +11260,7 @@ const createNodePrinter = (modules) => {
case NodeType.ClassExpression:
return true;
case NodeType.Literal:
- return (tree.textOf(Part.raw, node) || "").charCodeAt(0) === 47;
+ return (A.textOf(Part.raw, node) || "").charCodeAt(0) === 47;
default:
return false;
}
@@ -11301,7 +11278,7 @@ const createNodePrinter = (modules) => {
* @returns {RegExp | undefined} the expression as this engine compiles it, undefined where it rejects it
*/
const compiledRegExp = (node) => {
- const raw = /** @type {string} */ (tree.textOf(Part.raw, node));
+ const raw = /** @type {string} */ (A.textOf(Part.raw, node));
const end = raw.lastIndexOf("/");
try {
return new RegExp(raw.slice(1, end), raw.slice(end + 1));
@@ -11335,7 +11312,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
if (!isLiteralTree(itemOf(i, Field.arguments, node))) return false;
}
@@ -11390,7 +11367,7 @@ const createNodePrinter = (modules) => {
node = unwrap(node);
if (isRegExpLiteral(node)) return regExpText(node);
if (typeOf(node) === NodeType.Literal) {
- const literal = tree.value(node);
+ const literal = A.value(node);
return typeof literal === "bigint" ? literal : undefined;
}
if (
@@ -11405,7 +11382,7 @@ const createNodePrinter = (modules) => {
) {
return undefined;
}
- const count = tree.fieldCount(Field.elements, node);
+ const count = A.fieldCount(Field.elements, node);
let text = "";
for (let i = 0; i < count; i++) {
if (i > 0) text += ",";
@@ -11468,7 +11445,7 @@ const createNodePrinter = (modules) => {
const evaluateConstant = (node) => {
switch (typeOf(node)) {
case NodeType.Literal: {
- const value = tree.value(node);
+ const value = A.value(node);
// A regular expression this engine rejects holds `null` too.
return typeof value === "string" ||
typeof value === "number" ||
@@ -11487,7 +11464,7 @@ const createNodePrinter = (modules) => {
// The global `NaN` and `Infinity` nothing shadows, which no script
// may set, as terser's `evaluate` reads them.
if (!keepsGlobalNames) {
- const name = tree.name(node);
+ const name = A.name(node);
if (name === "NaN" && isGlobalUndefined(node, name)) {
return Number.NaN;
}
@@ -11512,12 +11489,12 @@ const createNodePrinter = (modules) => {
}
case NodeType.TemplateLiteral: {
// A tagged template is not walked into: its tag reads the parts.
- const count = tree.fieldCount(Field.quasis, node);
+ const count = A.fieldCount(Field.quasis, node);
let text = "";
for (let i = 0; i < count; i++) {
// Untagged, every part has its cooked text.
text += /** @type {{ raw: string, cooked: string }} */ (
- tree.value(tree.field(i, Field.quasis, node))
+ A.value(A.field(i, Field.quasis, node))
).cooked;
if (i < count - 1) {
const expression = itemOf(i, Field.expressions, node);
@@ -11530,7 +11507,7 @@ const createNodePrinter = (modules) => {
: typeOf(expression) === NodeType.Literal
? isRegExpLiteral(expression)
? regExpText(expression)
- : tree.value(expression)
+ : A.value(expression)
: joinedArrayOf(expression);
if (
value === undefined &&
@@ -11546,14 +11523,14 @@ const createNodePrinter = (modules) => {
}
case NodeType.UnaryExpression: {
const argument = childOf(Field.argument, node);
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (operator === "delete") {
// What is no reference deletes nothing, which is `true`.
const type = typeOf(argument);
if (type === NodeType.Identifier) {
// The global object's own `undefined`, `NaN` and `Infinity`
// are not configurable.
- const name = tree.name(argument);
+ const name = A.name(argument);
return (name === "undefined" ||
name === "NaN" ||
name === "Infinity") &&
@@ -11638,9 +11615,7 @@ const createNodePrinter = (modules) => {
}
}
case NodeType.BinaryExpression: {
- const operator = /** @type {string} */ (
- tree.textOf(Part.operator, node)
- );
+ const operator = /** @type {string} */ (A.textOf(Part.operator, node));
if (operator === "+") {
const leftNode = childOf(Field.left, node);
const rightNode = childOf(Field.right, node);
@@ -11690,7 +11665,7 @@ const createNodePrinter = (modules) => {
case NodeType.LogicalExpression: {
const left = evaluateConstant(childOf(Field.left, node));
if (left === undefined) return undefined;
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (
operator === "&&" ? !left : operator === "||" ? left : left !== null
) {
@@ -11729,14 +11704,14 @@ const createNodePrinter = (modules) => {
// And of `{a: 1}.a` or `{a: {b: 1}}.a.b`.
if (value !== 0) return evaluateConstant(value);
if (
- !tree.flag(Flag.computed, node) ||
- tree.flag(Flag.optional, node) ||
+ !A.flag(Flag.computed, node) ||
+ A.flag(Flag.optional, node) ||
typeOf(array) !== NodeType.ArrayExpression
) {
return undefined;
}
const index = evaluateConstant(childOf(Field.property, node));
- const count = tree.fieldCount(Field.elements, array);
+ const count = A.fieldCount(Field.elements, array);
if (typeof index !== "number" || !(index >= 0 && index < count)) {
return undefined;
}
@@ -11757,7 +11732,7 @@ const createNodePrinter = (modules) => {
}
case NodeType.SequenceExpression: {
// terser's `evaluate` of `(a, 1)`, where the others run nothing.
- const last = tree.fieldCount(Field.expressions, node) - 1;
+ const last = A.fieldCount(Field.expressions, node) - 1;
for (let i = 0; i < last; i++) {
if (!isPureValue(itemOf(i, Field.expressions, node))) {
return undefined;
@@ -11776,7 +11751,7 @@ const createNodePrinter = (modules) => {
? value
: joinedOf(node);
}
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
const argument = itemOf(i, Field.arguments, node);
if (
@@ -11812,7 +11787,7 @@ const createNodePrinter = (modules) => {
// A declaration of the function's body runs before what follows it there.
return (
setFirst[declarator] === 1 ||
- (setFirst[declarator] === 2 && tree.start(read) >= tree.end(declarator))
+ (setFirst[declarator] === 2 && A.start(read) >= A.end(declarator))
);
};
@@ -11861,7 +11836,7 @@ const createNodePrinter = (modules) => {
addedLiteral(node) !== undefined && addsToString(left)
? context.get(left).length + 1 + printedLength(joinedLiterals(node))
: context.get(left).length +
- /** @type {string} */ (tree.textOf(Part.operator, node)).length +
+ /** @type {string} */ (A.textOf(Part.operator, node)).length +
context.get(right).length;
return !hasEdgeComments(left) &&
!hasEdgeComments(right) &&
@@ -11917,7 +11892,7 @@ const createNodePrinter = (modules) => {
if (typeOf(node) !== NodeType.BinaryExpression || isPrivateIn(node)) {
return false;
}
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (operator === "in" || operator === "instanceof") return false;
const folded = binaryFolded(node);
return (
@@ -11938,7 +11913,7 @@ const createNodePrinter = (modules) => {
!dropsDeadCode ||
(parentType !== NodeType.BinaryExpression &&
parentType !== NodeType.LogicalExpression) ||
- tree.textOf(Part.operator, parent) === "**"
+ A.textOf(Part.operator, parent) === "**"
) {
return false;
}
@@ -11950,7 +11925,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const value = tree.value(kept);
+ const value = A.value(kept);
return (
typeof value === "string" ||
typeof value === "boolean" ||
@@ -12049,7 +12024,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const value = tree.value(kept);
+ const value = A.value(kept);
return (
typeof value === "string" ||
(typeof value === "number" &&
@@ -12059,7 +12034,7 @@ const createNodePrinter = (modules) => {
if (typeOf(node) !== NodeType.BinaryExpression || isPrivateIn(node)) {
return false;
}
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
const parent = parentAt(0);
const parentType = typeOf(parent);
if (operator === "in" || operator === "instanceof") return false;
@@ -12087,7 +12062,7 @@ const createNodePrinter = (modules) => {
if (
(parentType !== NodeType.BinaryExpression &&
parentType !== NodeType.LogicalExpression) ||
- tree.textOf(Part.operator, parent) === "**" ||
+ A.textOf(Part.operator, parent) === "**" ||
// The run of a string's `+` prints its left alone.
(addedLiteral(parent) !== undefined &&
childOf(Field.left, parent) === node &&
@@ -12203,11 +12178,11 @@ const createNodePrinter = (modules) => {
// The name reads the global anywhere no `with`, `eval` or binding takes it.
nanReadsGlobal = 1;
for (let node = 0; node < foundSize; node++) {
- const type = tree.type(node);
+ const type = A.type(node);
if (
type === NodeType.WithStatement ||
(type === NodeType.Identifier &&
- (tree.name(node) === "eval" ||
+ (A.name(node) === "eval" ||
(nameOf(node) === "NaN" && !isGlobalUndefined(node, "NaN"))))
) {
nanReadsGlobal = 2;
@@ -12272,15 +12247,15 @@ const createNodePrinter = (modules) => {
}
const body = childOf(Field.body, fn);
if (typeOf(body) !== NodeType.BlockStatement) return;
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
if (count === 0) return;
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, body);
+ const statement = A.field(i, Field.body, body);
if (readsCalledFunction(fn, statement)) return;
if (typeOf(statement) === NodeType.ExpressionStatement) {
// Printed where the call is, it may open a statement.
if (
- tree.textOf(Part.directive, statement) !== null ||
+ A.textOf(Part.directive, statement) !== null ||
opensAmbiguously(childOf(Field.expression, statement))
) {
return;
@@ -12298,19 +12273,19 @@ const createNodePrinter = (modules) => {
if (i !== 0 || typeOf(statement) !== NodeType.IfStatement) return;
// Only the first leaves early, for what its test reads truthy.
const test = childOf(Field.test, statement);
- let exit = tree.field(0, Field.consequent, statement);
+ let exit = A.field(0, Field.consequent, statement);
if (
typeOf(exit) === NodeType.BlockStatement &&
- tree.fieldCount(Field.body, exit) === 1
+ A.fieldCount(Field.body, exit) === 1
) {
- exit = tree.field(0, Field.body, exit);
+ exit = A.field(0, Field.body, exit);
}
const value =
typeOf(exit) === NodeType.ReturnStatement
? childOf(Field.argument, exit)
: -1;
if (
- tree.field(0, Field.alternate, statement) !== 0 ||
+ A.field(0, Field.alternate, statement) !== 0 ||
value === -1 ||
(value !== 0 && !isPureValue(value)) ||
opensAmbiguously(test)
@@ -12321,9 +12296,9 @@ const createNodePrinter = (modules) => {
if (reducedCalls.has(call)) undoReduced(fn, call);
unreadBodies.add(fn);
for (let i = 0; i < count; i++) {
- unreadStatements.add(tree.field(i, Field.body, body));
+ unreadStatements.add(A.field(i, Field.body, body));
}
- const last = tree.field(count - 1, Field.body, body);
+ const last = A.field(count - 1, Field.body, body);
const value =
typeOf(last) === NodeType.ReturnStatement
? childOf(Field.argument, last)
@@ -12332,9 +12307,9 @@ const createNodePrinter = (modules) => {
unreadValues.add(value);
noteUnreadValue(value);
}
- const params = tree.fieldCount(Field.params, fn);
+ const params = A.fieldCount(Field.params, fn);
for (let i = 0; i < params; i++) {
- const param = tree.field(i, Field.params, fn);
+ const param = A.field(i, Field.params, fn);
const argument = itemOf(i, Field.arguments, call);
if (inlinesArgument(param, argument)) continue;
substituted.set(
@@ -12349,7 +12324,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it is named, the name maybe read, which may call it again
*/
const readsFunctionName = (fn) => {
- const id = tree.field(0, Field.id, fn);
+ const id = A.field(0, Field.id, fn);
if (id === 0) return false;
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[id];
return !isMinifierVariable(definition) || definition.referenceCount !== 0;
@@ -12376,14 +12351,14 @@ const createNodePrinter = (modules) => {
(type !== NodeType.FunctionExpression &&
type !== NodeType.FunctionDeclaration &&
type !== NodeType.ArrowFunctionExpression) ||
- tree.flag(Flag.optional, call) ||
+ A.flag(Flag.optional, call) ||
(type !== NodeType.ArrowFunctionExpression &&
((moved === undefined && readsFunctionName(fn)) || readsArguments(fn)))
) {
return;
}
- const params = tree.fieldCount(Field.params, fn);
- const args = tree.fieldCount(Field.arguments, call);
+ const params = A.fieldCount(Field.params, fn);
+ const args = A.fieldCount(Field.arguments, call);
for (let i = 0; i < params; i++) {
if (typeOf(itemOf(i, Field.params, fn)) !== NodeType.Identifier) return;
}
@@ -12455,14 +12430,14 @@ const createNodePrinter = (modules) => {
const body = childOf(Field.body, fn);
const read = onceReadIn(body, definition);
if (read === 0) return;
- const start = tree.start(read);
+ const start = A.start(read);
// A loop would make a new value each time round where one was read.
const looped = findNode(body, (inner) =>
FUNCTION_TYPES[typeOf(inner)] === 1
? false
: LOOP_TYPES[typeOf(inner)] === 1 &&
- tree.start(inner) <= start &&
- tree.end(inner) >= tree.end(read)
+ A.start(inner) <= start &&
+ A.end(inner) >= A.end(read)
? true
: undefined
);
@@ -12480,23 +12455,23 @@ const createNodePrinter = (modules) => {
case NodeType.UnaryExpression:
return typeOf(childOf(Field.argument, node)) === NodeType.Literal;
case NodeType.ArrayExpression: {
- const count = tree.fieldCount(Field.elements, node);
+ const count = A.fieldCount(Field.elements, node);
for (let i = 0; i < count; i++) {
- const element = tree.field(i, Field.elements, node);
+ const element = A.field(i, Field.elements, node);
if (element !== 0 && !isLiteralTree(element)) return false;
}
return true;
}
case NodeType.ObjectExpression: {
- const count = tree.fieldCount(Field.properties, node);
+ const count = A.fieldCount(Field.properties, node);
for (let i = 0; i < count; i++) {
- const property = tree.field(i, Field.properties, node);
+ const property = A.field(i, Field.properties, node);
if (
typeOf(property) !== NodeType.Property ||
- tree.textOf(Part.kind, property) !== "init" ||
- tree.flag(Flag.method, property) ||
- tree.flag(Flag.computed, property) ||
- tree.flag(Flag.shorthand, property) ||
+ A.textOf(Part.kind, property) !== "init" ||
+ A.flag(Flag.method, property) ||
+ A.flag(Flag.computed, property) ||
+ A.flag(Flag.shorthand, property) ||
!isLiteralTree(childOf(Field.value, property))
) {
return false;
@@ -12516,7 +12491,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const noteConstant = (declarator) => {
- const id = tree.field(0, Field.id, declarator);
+ const id = A.field(0, Field.id, declarator);
const init = childOf(Field.init, declarator);
if (typeOf(id) !== NodeType.Identifier || init === 0) return;
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[id];
@@ -12583,7 +12558,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether each element is a literal, or one under a unary operator, of a value printing like a name
*/
const holdsConstants = (array) => {
- const count = tree.fieldCount(Field.elements, array);
+ const count = A.fieldCount(Field.elements, array);
if (count === 0 || holdsComments(array)) return false;
for (let i = 0; i < count; i++) {
const element = itemOf(i, Field.elements, array);
@@ -12607,15 +12582,15 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether each property is a plain key, a name or string other than `__proto__`, set to a value `holdsConstants` takes
*/
const holdsConstantProperties = (object) => {
- const count = tree.fieldCount(Field.properties, object);
+ const count = A.fieldCount(Field.properties, object);
if (count === 0 || holdsComments(object)) return false;
for (let i = 0; i < count; i++) {
- const property = tree.field(i, Field.properties, object);
+ const property = A.field(i, Field.properties, object);
if (
typeOf(property) !== NodeType.Property ||
- tree.textOf(Part.kind, property) !== "init" ||
- tree.flag(Flag.method, property) ||
- tree.flag(Flag.computed, property) ||
+ A.textOf(Part.kind, property) !== "init" ||
+ A.flag(Flag.method, property) ||
+ A.flag(Flag.computed, property) ||
keyOf(property) === undefined
) {
return false;
@@ -12644,10 +12619,9 @@ const createNodePrinter = (modules) => {
const key = childOf(Field.key, property);
const name =
typeOf(key) === NodeType.Identifier
- ? tree.name(key)
- : typeOf(key) === NodeType.Literal &&
- typeof tree.value(key) === "string"
- ? /** @type {string} */ (tree.value(key))
+ ? A.name(key)
+ : typeOf(key) === NodeType.Literal && typeof A.value(key) === "string"
+ ? /** @type {string} */ (A.value(key))
: undefined;
return name === "__proto__" ? undefined : name;
};
@@ -12659,30 +12633,30 @@ const createNodePrinter = (modules) => {
*/
const constantItemOf = (member, literal) => {
const property = childOf(Field.property, member);
- const computed = tree.flag(Flag.computed, member);
+ const computed = A.flag(Flag.computed, member);
if (typeOf(literal) === NodeType.ArrayExpression) {
const index =
- typeOf(property) === NodeType.Literal ? tree.value(property) : null;
+ typeOf(property) === NodeType.Literal ? A.value(property) : null;
return computed &&
typeof index === "number" &&
Number.isInteger(index) &&
index >= 0 &&
- index < tree.fieldCount(Field.elements, literal)
+ index < A.fieldCount(Field.elements, literal)
? itemOf(index, Field.elements, literal)
: 0;
}
const key = computed
? typeOf(property) === NodeType.Literal &&
- typeof tree.value(property) === "string"
- ? tree.value(property)
+ typeof A.value(property) === "string"
+ ? A.value(property)
: undefined
: typeOf(property) === NodeType.Identifier
- ? tree.name(property)
+ ? A.name(property)
: undefined;
if (key === undefined) return 0;
// The last property of a key is the one the literal keeps.
- for (let i = tree.fieldCount(Field.properties, literal) - 1; i >= 0; i--) {
- const item = tree.field(i, Field.properties, literal);
+ for (let i = A.fieldCount(Field.properties, literal) - 1; i >= 0; i--) {
+ const item = A.field(i, Field.properties, literal);
if (keyOf(item) === key) return childOf(Field.value, item);
}
return 0;
@@ -12706,7 +12680,7 @@ const createNodePrinter = (modules) => {
const item = constantItemOf(member, array);
if (
item === 0 ||
- tree.flag(Flag.optional, member) ||
+ A.flag(Flag.optional, member) ||
!isSetBefore(definition, object)
) {
return;
@@ -12733,15 +12707,14 @@ const createNodePrinter = (modules) => {
if (childOf(Field.callee, parent) === member) return;
break;
case NodeType.UnaryExpression:
- if (tree.textOf(Part.operator, parent) === "delete") return;
+ if (A.textOf(Part.operator, parent) === "delete") return;
break;
}
const value = /** @type {string | number | boolean | null} */ (
evaluateConstant(item)
);
const reads = indexReads.get(definition);
- const longer =
- printedLength(value) - (tree.end(member) - tree.start(member));
+ const longer = printedLength(value) - (A.end(member) - A.start(member));
if (reads === undefined) {
indexReads.set(definition, [1, longer]);
} else {
@@ -12798,7 +12771,7 @@ const createNodePrinter = (modules) => {
const parentType = typeOf(parent);
if (
parentType === NodeType.VariableDeclarator &&
- tree.field(0, Field.id, parent) === node
+ A.field(0, Field.id, parent) === node
) {
return;
}
@@ -12808,10 +12781,10 @@ const createNodePrinter = (modules) => {
parentType === NodeType.ExpressionStatement ||
parentType === NodeType.ExportSpecifier ||
(parentType === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, parent) === "delete");
+ A.textOf(Part.operator, parent) === "delete");
const asObject =
parentType === NodeType.MemberExpression &&
- tree.field(0, Field.object, parent) === node;
+ A.field(0, Field.object, parent) === node;
if (readEarly && constant !== undefined) {
// Run before its declaration, the read throws: it prints the name.
deadZoneReads.add(node);
@@ -12891,9 +12864,9 @@ const createNodePrinter = (modules) => {
reads[0] === definition.referenceCount &&
!readInDeadZone.has(definition) &&
reads[1] <=
- tree.name(tree.field(0, Field.id, declarator)).length +
- tree.end(array) -
- tree.start(array)
+ A.name(A.field(0, Field.id, declarator)).length +
+ A.end(array) -
+ A.start(array)
) {
inlinedArrays.add(definition);
droppedReads.set(definition, reads[0]);
@@ -12919,8 +12892,8 @@ const createNodePrinter = (modules) => {
const id =
typeOf(declarator) === NodeType.Identifier
? declarator
- : tree.field(0, Field.id, declarator);
- const name = tree.name(id).length;
+ : A.field(0, Field.id, declarator);
+ const name = A.name(id).length;
const value = printedLength(
/** @type {string | number | boolean | null} */ (
constantValues.get(definition)
@@ -12947,9 +12920,9 @@ const createNodePrinter = (modules) => {
const definition = unreadParams[i];
const param = /** @type {number} */ (inlined.get(definition));
const fn = /** @type {MinifierScope} */ (definition.scope).node;
- const count = tree.fieldCount(Field.params, fn);
+ const count = A.fieldCount(Field.params, fn);
for (let j = 0; j < count; j++) {
- if (dropped[tree.field(j, Field.params, fn)] !== 1) {
+ if (dropped[A.field(j, Field.params, fn)] !== 1) {
dropped[param] = 0;
inlined.delete(definition);
break;
@@ -13038,8 +13011,8 @@ const createNodePrinter = (modules) => {
return arrowReturned(parent) !== read || opensAmbiguously(value);
case NodeType.BinaryExpression:
case NodeType.LogicalExpression: {
- const operator = tree.textOf(Part.operator, value);
- const parentOperator = tree.textOf(Part.operator, parent);
+ const operator = A.textOf(Part.operator, value);
+ const parentOperator = A.textOf(Part.operator, parent);
// `??` mixed with `||` or `&&` is a syntax error without parentheses.
if (
(operator === "??" &&
@@ -13059,7 +13032,7 @@ const createNodePrinter = (modules) => {
}
case NodeType.MemberExpression:
return !(
- tree.flag(Flag.computed, parent) &&
+ A.flag(Flag.computed, parent) &&
childOf(Field.property, parent) === read
);
default:
@@ -13100,8 +13073,7 @@ const createNodePrinter = (modules) => {
return (
childOf(Field.value, parent) !== read &&
!(
- tree.flag(Flag.computed, parent) &&
- childOf(Field.key, parent) === read
+ A.flag(Flag.computed, parent) && childOf(Field.key, parent) === read
)
);
case NodeType.AssignmentExpression:
@@ -13112,7 +13084,7 @@ const createNodePrinter = (modules) => {
return childOf(Field.test, parent) === read && !printsTestAlone(parent);
case NodeType.MemberExpression:
return !(
- tree.flag(Flag.computed, parent) &&
+ A.flag(Flag.computed, parent) &&
childOf(Field.property, parent) === read
);
// What an arrow returns; one opening with `{` the callers check.
@@ -13156,7 +13128,7 @@ const createNodePrinter = (modules) => {
case NodeType.BinaryExpression:
return (
!update &&
- tree.textOf(Part.operator, parent) === "**" &&
+ A.textOf(Part.operator, parent) === "**" &&
childOf(Field.left, parent) === read
);
default:
@@ -13225,7 +13197,7 @@ const createNodePrinter = (modules) => {
readsReference(shown, node) &&
(type !== NodeType.Identifier ||
isUnaryType(typeOf(parentAt(0))) ||
- tree.name(shown) === "eval")
+ A.name(shown) === "eval")
) {
output.print("(0,");
printPiece(
@@ -13284,7 +13256,7 @@ const createNodePrinter = (modules) => {
type === NodeType.AwaitExpression ||
(type === NodeType.NewExpression &&
!asCall &&
- tree.fieldCount(Field.arguments, shown) === 0)) &&
+ A.fieldCount(Field.arguments, shown) === 0)) &&
!unaryNeedsParensAt(node, type === NodeType.UpdateExpression)) ||
((type === NodeType.ObjectExpression ||
type === NodeType.ClassExpression ||
@@ -13309,7 +13281,7 @@ const createNodePrinter = (modules) => {
asCall ||
// With arguments, a `new` is no callee's `new` without them.
(type === NodeType.NewExpression &&
- tree.fieldCount(Field.arguments, shown) > 0)) &&
+ A.fieldCount(Field.arguments, shown) > 0)) &&
!(opensAmbiguously(shown) && firstInStatement(node, 0, true)))
);
// What `new` constructs reads a call at its head as its own arguments.
@@ -13426,10 +13398,10 @@ const createNodePrinter = (modules) => {
const readsArguments = (fn) => {
let found = argumentsReaders.get(fn);
if (found === undefined) {
- found = findNode(tree.field(0, Field.body, fn), (node) => {
- switch (tree.type(node)) {
+ found = findNode(A.field(0, Field.body, fn), (node) => {
+ switch (A.type(node)) {
case NodeType.Identifier:
- return tree.name(node) === "arguments" ? true : undefined;
+ return A.name(node) === "arguments" ? true : undefined;
case NodeType.FunctionExpression:
case NodeType.FunctionDeclaration:
return false;
@@ -13453,13 +13425,13 @@ const createNodePrinter = (modules) => {
/** @type {number[] | undefined} */
let prefix;
if (typeOf(value) === NodeType.BlockStatement) {
- const count = tree.fieldCount(Field.body, value);
+ const count = A.fieldCount(Field.body, value);
if (count === 0) return 0;
if (count > 1) {
prefix = prefixExpressions(fn, value, count - 1, false);
if (prefix === undefined) return 0;
}
- const statement = tree.field(count - 1, Field.body, value);
+ const statement = A.field(count - 1, Field.body, value);
// A `return` printing as a statement prints no value to return.
if (
typeOf(statement) !== NodeType.ReturnStatement ||
@@ -13486,11 +13458,11 @@ const createNodePrinter = (modules) => {
/** @type {number[]} */
const prefix = [];
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, body);
+ const statement = A.field(i, Field.body, body);
if (skipsUnprinted && printsNothing(statement)) continue;
if (
typeOf(statement) !== NodeType.ExpressionStatement ||
- tree.textOf(Part.directive, statement) !== null ||
+ A.textOf(Part.directive, statement) !== null ||
hasEdgeComments(statement) ||
readsCalledFunction(fn, statement)
) {
@@ -13574,10 +13546,10 @@ const createNodePrinter = (modules) => {
}
// One `return`, what prints after it nothing, what prints before it
// expression statements.
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
let at = -1;
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, body);
+ const statement = A.field(i, Field.body, body);
if (typeOf(statement) === NodeType.ReturnStatement) {
// A `return` printing as a statement prints no value to return.
if (voidTails.size !== 0 && voidTails.has(statement)) return 0;
@@ -13587,9 +13559,9 @@ const createNodePrinter = (modules) => {
}
if (at === -1) return 0;
for (let i = at + 1; i < count; i++) {
- if (!printsNothing(tree.field(i, Field.body, body))) return 0;
+ if (!printsNothing(A.field(i, Field.body, body))) return 0;
}
- const value = childOf(Field.argument, tree.field(at, Field.body, body));
+ const value = childOf(Field.argument, A.field(at, Field.body, body));
const prefix = prefixExpressions(fn, body, at, true);
if (
value === 0 ||
@@ -13611,17 +13583,17 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it reads a name the function declares, other than a parameter, and prints it as that name, not the value folded there
*/
const readsOwnName = (fn, node, own = node) => {
- const start = tree.start(fn);
- const end = tree.end(fn);
- const ownStart = tree.start(own);
- const ownEnd = tree.end(own);
+ const start = A.start(fn);
+ const end = A.end(fn);
+ const ownStart = A.start(own);
+ const ownEnd = A.end(own);
return findNode(node, (inner) => {
- if (tree.type(inner) !== NodeType.Identifier) return undefined;
+ if (A.type(inner) !== NodeType.Identifier) return undefined;
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[inner];
if (!isMinifierVariable(definition) || definition.undeclared) {
return undefined;
}
- const declaredAt = tree.start(
+ const declaredAt = A.start(
/** @type {MinifierScope} */ (definition.scope).node
);
if (
@@ -13643,19 +13615,19 @@ const createNodePrinter = (modules) => {
// The one read of a function moved there prints the function.
const moved = movedCallOf(inner);
if (moved !== 0) {
- const params = tree.fieldCount(Field.params, moved);
+ const params = A.fieldCount(Field.params, moved);
for (let i = 0; i < params; i++) {
- if (readsOwnName(fn, tree.field(i, Field.params, moved), moved)) {
+ if (readsOwnName(fn, A.field(i, Field.params, moved), moved)) {
return true;
}
}
- return readsOwnName(fn, tree.field(0, Field.body, moved), moved)
+ return readsOwnName(fn, A.field(0, Field.body, moved), moved)
? true
: undefined;
}
- const params = tree.fieldCount(Field.params, fn);
+ const params = A.fieldCount(Field.params, fn);
for (let i = 0; i < params; i++) {
- const param = tree.field(i, Field.params, fn);
+ const param = A.field(i, Field.params, fn);
if (
/** @type {TreeDefinition[]} */ (mangledNames)[param] === definition
) {
@@ -13686,12 +13658,12 @@ const createNodePrinter = (modules) => {
return !hasEdgeComments(node);
case NodeType.FunctionExpression:
case NodeType.ArrowFunctionExpression: {
- const body = tree.field(0, Field.body, node);
+ const body = A.field(0, Field.body, node);
return (
- tree.field(0, Field.id, node) === 0 &&
- tree.fieldCount(Field.params, node) === 0 &&
+ A.field(0, Field.id, node) === 0 &&
+ A.fieldCount(Field.params, node) === 0 &&
typeOf(body) === NodeType.BlockStatement &&
- tree.fieldCount(Field.body, body) === 0 &&
+ A.fieldCount(Field.body, body) === 0 &&
!holdsComments(node)
);
}
@@ -13706,20 +13678,20 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it runs at once, neither async nor a generator nor holding comments, each parameter a name never written passed one set before the call, a constant its reads print, or passed nothing and read nowhere, and each argument past them a literal or an empty function
*/
const passesFixedNames = (fn, call) => {
- const count = tree.fieldCount(Field.params, fn);
- const passed = tree.fieldCount(Field.arguments, call);
+ const count = A.fieldCount(Field.params, fn);
+ const passed = A.fieldCount(Field.arguments, call);
for (let i = count; i < passed; i++) {
- if (!isEmptyValue(tree.field(i, Field.arguments, call))) return false;
+ if (!isEmptyValue(A.field(i, Field.arguments, call))) return false;
}
if (
- tree.flag(Flag.async, fn) ||
- tree.flag(Flag.generator, fn) ||
+ A.flag(Flag.async, fn) ||
+ A.flag(Flag.generator, fn) ||
holdsComments(fn)
) {
return false;
}
for (let i = 0; i < count; i++) {
- const param = tree.field(i, Field.params, fn);
+ const param = A.field(i, Field.params, fn);
if (i >= passed) {
// A parameter passed nothing that nothing reads.
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[
@@ -13745,7 +13717,7 @@ const createNodePrinter = (modules) => {
/** @type {MinifierVariable} */ (
/** @type {TreeDefinition[]} */ (mangledNames)[argument]
),
- tree.start(call)
+ A.start(call)
)
) {
return false;
@@ -13762,9 +13734,9 @@ const createNodePrinter = (modules) => {
const readsCalledFunction = (fn, value) => {
// A parameter printing the constant passed for it prints no name to hide.
let count = 0;
- const params = tree.fieldCount(Field.params, fn);
+ const params = A.fieldCount(Field.params, fn);
for (let i = 0; i < params; i++) {
- const param = tree.field(i, Field.params, fn);
+ const param = A.field(i, Field.params, fn);
if (
constantArguments.size === 0 ||
dropped[param] !== 1 ||
@@ -13773,22 +13745,22 @@ const createNodePrinter = (modules) => {
count++;
}
}
- const id = tree.field(0, Field.id, fn);
- const name = id === 0 ? "" : tree.name(id);
+ const id = A.field(0, Field.id, fn);
+ const name = id === 0 ? "" : A.name(id);
/**
* @param {number} node a name
* @returns {boolean} whether it spells the function's name where it reads a binding: a key or member name binds nothing
*/
const spellsOwnName = (node) =>
name !== "" &&
- tree.name(node) === name &&
+ A.name(node) === name &&
(mangledNames === null || mangledNames[node] !== null);
/**
* @param {number} node a node of the value
* @returns {boolean | undefined} true where it reads the function itself, undefined to look inside
*/
const readsFunction = (node) => {
- switch (tree.type(node)) {
+ switch (A.type(node)) {
case NodeType.ThisExpression:
case NodeType.Super:
case NodeType.MetaProperty:
@@ -13798,10 +13770,10 @@ const createNodePrinter = (modules) => {
// the value read as `eval` calls none; `await` or `yield` is a name
// only outside an async function or generator the call may sit in.
return (
- tree.name(node) === "arguments" ||
- (tree.name(node) === "eval" && node !== value) ||
- tree.name(node) === "await" ||
- tree.name(node) === "yield" ||
+ A.name(node) === "arguments" ||
+ (A.name(node) === "eval" && node !== value) ||
+ A.name(node) === "await" ||
+ A.name(node) === "yield" ||
spellsOwnName(node)
);
case NodeType.ArrowFunctionExpression:
@@ -13820,8 +13792,8 @@ const createNodePrinter = (modules) => {
count !== 0 ||
(name !== "" &&
findNode(node, (inner) =>
- tree.type(inner) === NodeType.Identifier &&
- (spellsOwnName(inner) || tree.name(inner) === "eval")
+ A.type(inner) === NodeType.Identifier &&
+ (spellsOwnName(inner) || A.name(inner) === "eval")
? true
: undefined
))
@@ -13844,11 +13816,11 @@ const createNodePrinter = (modules) => {
const heritage = childOf(Field.superClass, node);
if (heritage !== 0 && findNode(heritage, test)) return true;
const body = childOf(Field.body, node);
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- const member = tree.field(i, Field.body, body);
+ const member = A.field(i, Field.body, body);
if (
- tree.flag(Flag.computed, member) &&
+ A.flag(Flag.computed, member) &&
findNode(childOf(Field.key, member), test)
) {
return true;
@@ -13881,9 +13853,9 @@ const createNodePrinter = (modules) => {
const noteReduced = (fn, call, value) => {
reducing.set(fn, value);
reducedCalls.set(call, fn);
- const count = tree.fieldCount(Field.params, fn);
+ const count = A.fieldCount(Field.params, fn);
for (let i = 0; i < count; i++) {
- const param = tree.field(i, Field.params, fn);
+ const param = A.field(i, Field.params, fn);
const argument = itemOf(i, Field.arguments, call);
if (inlinesArgument(param, argument)) continue;
substituted.set(
@@ -13903,11 +13875,11 @@ const createNodePrinter = (modules) => {
reducing.delete(fn);
if (reducedPrefixes.size !== 0) reducedPrefixes.delete(fn);
reducedCalls.delete(call);
- const count = tree.fieldCount(Field.params, fn);
+ const count = A.fieldCount(Field.params, fn);
for (let i = 0; i < count; i++) {
substituted.delete(
/** @type {TreeDefinition[]} */ (mangledNames)[
- tree.field(i, Field.params, fn)
+ A.field(i, Field.params, fn)
]
);
}
@@ -13919,13 +13891,13 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether each name it passes prints as itself, not what it is read as, which its parameter prints, or goes as a constant inlined there
*/
const passesPrintedNames = (call, fn) => {
- const count = tree.fieldCount(Field.arguments, call);
- const params = tree.fieldCount(Field.params, fn);
+ const count = A.fieldCount(Field.arguments, call);
+ const params = A.fieldCount(Field.params, fn);
for (let i = 0; i < count; i++) {
const argument = itemOf(i, Field.arguments, call);
if (
i < params &&
- inlinesArgument(tree.field(i, Field.params, fn), argument)
+ inlinesArgument(A.field(i, Field.params, fn), argument)
) {
continue;
}
@@ -13946,7 +13918,7 @@ const createNodePrinter = (modules) => {
*/
const passesNothing = (call) =>
typeOf(call) === NodeType.CallExpression &&
- !tree.flag(Flag.optional, call) &&
+ !A.flag(Flag.optional, call) &&
!holdsComments(call);
/**
@@ -13984,23 +13956,23 @@ const createNodePrinter = (modules) => {
const labeledExitOf = (statement) => {
if (
typeOf(statement) !== NodeType.IfStatement ||
- tree.field(0, Field.alternate, statement) !== 0 ||
+ A.field(0, Field.alternate, statement) !== 0 ||
hasEdgeComments(statement)
) {
return 0;
}
- let body = tree.field(0, Field.consequent, statement);
+ let body = A.field(0, Field.consequent, statement);
if (
typeOf(body) === NodeType.BlockStatement &&
- tree.fieldCount(Field.body, body) === 1 &&
+ A.fieldCount(Field.body, body) === 1 &&
!holdsComments(body)
) {
- body = tree.field(0, Field.body, body);
+ body = A.field(0, Field.body, body);
}
const type = typeOf(body);
return (type === NodeType.BreakStatement ||
type === NodeType.ContinueStatement) &&
- tree.field(0, Field.label, body) !== 0 &&
+ A.field(0, Field.label, body) !== 0 &&
!hasEdgeComments(body)
? body
: 0;
@@ -14013,28 +13985,27 @@ const createNodePrinter = (modules) => {
const bareExitOf = (statement) => {
if (
typeOf(statement) !== NodeType.IfStatement ||
- tree.field(0, Field.alternate, statement) !== 0 ||
+ A.field(0, Field.alternate, statement) !== 0 ||
hasEdgeComments(statement)
) {
return 0;
}
- let body = tree.field(0, Field.consequent, statement);
+ let body = A.field(0, Field.consequent, statement);
if (
typeOf(body) === NodeType.BlockStatement &&
- tree.fieldCount(Field.body, body) === 1 &&
+ A.fieldCount(Field.body, body) === 1 &&
!holdsComments(body)
) {
- body = tree.field(0, Field.body, body);
+ body = A.field(0, Field.body, body);
}
switch (typeOf(body)) {
case NodeType.BreakStatement:
case NodeType.ContinueStatement:
- return tree.field(0, Field.label, body) === 0 && !hasEdgeComments(body)
+ return A.field(0, Field.label, body) === 0 && !hasEdgeComments(body)
? body
: 0;
case NodeType.ReturnStatement:
- return tree.field(0, Field.argument, body) === 0 &&
- !hasEdgeComments(body)
+ return A.field(0, Field.argument, body) === 0 && !hasEdgeComments(body)
? body
: 0;
default:
@@ -14056,8 +14027,8 @@ const createNodePrinter = (modules) => {
return (
other !== 0 &&
typeOf(other) === typeOf(labeled) &&
- tree.name(tree.field(0, Field.label, other)) ===
- tree.name(tree.field(0, Field.label, labeled))
+ A.name(A.field(0, Field.label, other)) ===
+ A.name(A.field(0, Field.label, labeled))
);
}
const value = returnedValueOf(statement);
@@ -14077,21 +14048,21 @@ const createNodePrinter = (modules) => {
const returnedValueOf = (statement, exit = NodeType.ReturnStatement) => {
if (
typeOf(statement) !== NodeType.IfStatement ||
- tree.field(0, Field.alternate, statement) !== 0 ||
+ A.field(0, Field.alternate, statement) !== 0 ||
hasEdgeComments(statement)
) {
return 0;
}
- let body = tree.field(0, Field.consequent, statement);
+ let body = A.field(0, Field.consequent, statement);
if (
typeOf(body) === NodeType.BlockStatement &&
- tree.fieldCount(Field.body, body) === 1 &&
+ A.fieldCount(Field.body, body) === 1 &&
!holdsComments(body)
) {
- body = tree.field(0, Field.body, body);
+ body = A.field(0, Field.body, body);
}
return typeOf(body) === exit && !holdsComments(body)
- ? tree.field(0, Field.argument, body)
+ ? A.field(0, Field.argument, body)
: 0;
};
@@ -14104,20 +14075,20 @@ const createNodePrinter = (modules) => {
const type = typeOf(node);
if (other === 0 || typeOf(other) !== type) return false;
for (const flag of FLAG_BITS) {
- if (tree.flag(flag, node) !== tree.flag(flag, other)) return false;
+ if (A.flag(flag, node) !== A.flag(flag, other)) return false;
}
if (
- tree.textOf(Part.operator, node) !== tree.textOf(Part.operator, other) ||
- tree.textOf(Part.kind, node) !== tree.textOf(Part.kind, other)
+ A.textOf(Part.operator, node) !== A.textOf(Part.operator, other) ||
+ A.textOf(Part.kind, node) !== A.textOf(Part.kind, other)
) {
return false;
}
- if (type === NodeType.Property && !tree.flag(Flag.computed, node)) {
+ if (type === NodeType.Property && !A.flag(Flag.computed, node)) {
// A key quoted or not prints alike, where quotes go.
- const key = tree.field(0, Field.key, node);
- const otherKey = tree.field(0, Field.key, other);
- const value = tree.field(0, Field.value, node);
- const otherValue = tree.field(0, Field.value, other);
+ const key = A.field(0, Field.key, node);
+ const otherKey = A.field(0, Field.key, other);
+ const value = A.field(0, Field.value, node);
+ const otherValue = A.field(0, Field.value, other);
return (
!hasEdgeComments(key) &&
!hasEdgeComments(otherKey) &&
@@ -14132,30 +14103,30 @@ const createNodePrinter = (modules) => {
switch (type) {
case NodeType.Identifier:
return (
- tree.name(node) === tree.name(other) &&
+ A.name(node) === A.name(other) &&
(mangledNames === null || mangledNames[node] === mangledNames[other])
);
case NodeType.PrivateIdentifier:
- return tree.name(node) === tree.name(other);
+ return A.name(node) === A.name(other);
case NodeType.Literal:
return (
- tree.textOf(Part.raw, node) === tree.textOf(Part.raw, other) ||
- (typeof tree.value(node) !== "object" &&
- tree.value(node) === tree.value(other))
+ A.textOf(Part.raw, node) === A.textOf(Part.raw, other) ||
+ (typeof A.value(node) !== "object" &&
+ A.value(node) === A.value(other))
);
case NodeType.TemplateElement:
return (
- /** @type {{ raw: string }} */ (tree.value(node)).raw ===
- /** @type {{ raw: string }} */ (tree.value(other)).raw
+ /** @type {{ raw: string }} */ (A.value(node)).raw ===
+ /** @type {{ raw: string }} */ (A.value(other)).raw
);
default: {
- const fields = CHILD_FIELDS[tree.type(node)];
+ const fields = CHILD_FIELDS[A.type(node)];
for (let f = 0; f < fields.length; f++) {
- const count = tree.fieldCount(fields[f], node);
- if (tree.fieldCount(fields[f], other) !== count) return false;
+ const count = A.fieldCount(fields[f], node);
+ if (A.fieldCount(fields[f], other) !== count) return false;
for (let i = 0; i < count; i++) {
- const child = tree.field(i, fields[f], node);
- const otherChild = tree.field(i, fields[f], other);
+ const child = A.field(i, fields[f], node);
+ const otherChild = A.field(i, fields[f], other);
if (
child === 0
? otherChild !== 0
@@ -14236,7 +14207,7 @@ const createNodePrinter = (modules) => {
case NodeType.ChainExpression:
return true;
case NodeType.Identifier:
- return tree.name(node) === "eval";
+ return A.name(node) === "eval";
default:
return false;
}
@@ -14263,7 +14234,7 @@ const createNodePrinter = (modules) => {
case NodeType.TaggedTemplateExpression:
return true;
case NodeType.CallExpression:
- return !tree.flag(Flag.optional, parent);
+ return !A.flag(Flag.optional, parent);
case NodeType.NewExpression:
return childOf(Field.callee, parent) !== node;
case NodeType.VariableDeclarator:
@@ -14274,7 +14245,7 @@ const createNodePrinter = (modules) => {
return childOf(Field.value, parent) === node;
// `deletesValue` prints what it takes as a value, then `!0`.
case NodeType.UnaryExpression:
- return tree.textOf(Part.operator, parent) === "delete";
+ return A.textOf(Part.operator, parent) === "delete";
default:
return false;
}
@@ -14292,7 +14263,7 @@ const createNodePrinter = (modules) => {
const name = childOf(Field.left, assignment);
const valueType = typeOf(childOf(Field.right, assignment));
if (
- tree.textOf(Part.operator, assignment) !== "=" ||
+ A.textOf(Part.operator, assignment) !== "=" ||
typeOf(name) !== NodeType.Identifier ||
hasEdgeComments(name) ||
countedWrites.has(name) ||
@@ -14317,7 +14288,7 @@ const createNodePrinter = (modules) => {
definition.kind === DECLARES_CLASS ||
definition.kind === DECLARES_DEF_CLASS ||
definition.kind === DECLARES_LAMBDA ||
- !writesSet(definition, tree.start(statement || assignment)) ||
+ !writesSet(definition, A.start(statement || assignment)) ||
// `arguments` reads what a parameter is set to, in sloppy code.
(definition.kind === DECLARES_FUNARG &&
readsArguments(functionOf(definition)))
@@ -14343,27 +14314,27 @@ const createNodePrinter = (modules) => {
if (
(type === NodeType.ConditionalExpression ||
(type === NodeType.LogicalExpression &&
- tree.textOf(Part.operator, node) !== "??")) &&
+ A.textOf(Part.operator, node) !== "??")) &&
!hasEdgeComments(node)
) {
noteUnreadOperand(node);
return;
} else if (type === NodeType.SequenceExpression) {
- const count = tree.fieldCount(Field.expressions, node);
+ const count = A.fieldCount(Field.expressions, node);
for (let i = 0; i < count - 1; i++) {
noteUnreadTemplate(itemOf(i, Field.expressions, node));
}
node = itemOf(count - 1, Field.expressions, node);
} else if (
type === NodeType.UnaryExpression &&
- (tree.textOf(Part.operator, node) === "void" ||
- tree.textOf(Part.operator, node) === "!") &&
+ (A.textOf(Part.operator, node) === "void" ||
+ A.textOf(Part.operator, node) === "!") &&
!hasEdgeComments(node)
) {
node = childOf(Field.argument, node);
} else if (
type === NodeType.BinaryExpression &&
- tree.textOf(Part.operator, node) === "+" &&
+ A.textOf(Part.operator, node) === "+" &&
!hasEdgeComments(node) &&
givesString(childOf(Field.left, node))
) {
@@ -14373,7 +14344,7 @@ const createNodePrinter = (modules) => {
node = childOf(Field.left, node);
if (
typeOf(right) !== NodeType.Literal ||
- typeof tree.value(right) !== "string"
+ typeof A.value(right) !== "string"
) {
noteStringOnly(node);
return;
@@ -14393,7 +14364,7 @@ const createNodePrinter = (modules) => {
const noteUnreadTemplate = (node) => {
if (
typeOf(node) === NodeType.TemplateLiteral &&
- tree.fieldCount(Field.expressions, node) !== 0 &&
+ A.fieldCount(Field.expressions, node) !== 0 &&
!holdsComments(node)
) {
unreadTemplates.add(node);
@@ -14411,7 +14382,7 @@ const createNodePrinter = (modules) => {
stringOnlyValues.add(node);
if (
typeOf(node) !== NodeType.BinaryExpression ||
- tree.textOf(Part.operator, node) !== "+" ||
+ A.textOf(Part.operator, node) !== "+" ||
hasEdgeComments(node) ||
!givesString(childOf(Field.left, node))
) {
@@ -14436,11 +14407,11 @@ const createNodePrinter = (modules) => {
node = childOf(Field.alternate, node);
} else if (
type === NodeType.LogicalExpression &&
- tree.textOf(Part.operator, node) !== "??"
+ A.textOf(Part.operator, node) !== "??"
) {
// What `||` runs last nobody reads either; right of `&&`, what
// prints with the other operator would bind looser than it.
- const or = tree.textOf(Part.operator, node) === "||";
+ const or = A.textOf(Part.operator, node) === "||";
node = childOf(Field.right, node);
if (or && typeOf(node) === NodeType.LogicalExpression) {
unreadValues.add(node);
@@ -14465,17 +14436,17 @@ const createNodePrinter = (modules) => {
const makesClass = (statement, definition, count = -1) => {
const names = /** @type {TreeDefinition[]} */ (mangledNames);
if (typeOf(statement) === NodeType.ExportNamedDeclaration) {
- statement = tree.field(0, Field.declaration, statement);
+ statement = A.field(0, Field.declaration, statement);
}
const type = statement === 0 ? 0 : typeOf(statement);
if (type === NodeType.ClassDeclaration) {
- return names[tree.field(0, Field.id, statement)] === definition;
+ return names[A.field(0, Field.id, statement)] === definition;
}
if (type !== NodeType.VariableDeclaration) return false;
- if (count === -1) count = tree.fieldCount(Field.declarations, statement);
+ if (count === -1) count = A.fieldCount(Field.declarations, statement);
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, statement);
- if (names[tree.field(0, Field.id, declarator)] === definition) {
+ const declarator = A.field(i, Field.declarations, statement);
+ if (names[A.field(0, Field.id, declarator)] === definition) {
return (
typeOf(childOf(Field.init, declarator)) === NodeType.ClassExpression
);
@@ -14501,7 +14472,7 @@ const createNodePrinter = (modules) => {
];
if (!isMinifierVariable(definition) || definition.written) return;
for (let i = 0; i <= index; i++) {
- const statement = tree.field(i, Field.body, list);
+ const statement = A.field(i, Field.body, list);
if (
i < index
? makesClass(statement, definition)
@@ -14519,7 +14490,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const noteBareVar = (declarator) => {
- const id = tree.field(0, Field.id, declarator);
+ const id = A.field(0, Field.id, declarator);
if (typeOf(id) !== NodeType.Identifier || childOf(Field.init, declarator)) {
return;
}
@@ -14533,12 +14504,12 @@ const createNodePrinter = (modules) => {
*/
const declaresNamesOnly = (declaration) => {
for (
- let i = tree.fieldCount(Field.declarations, declaration) - 1;
+ let i = A.fieldCount(Field.declarations, declaration) - 1;
i >= 0;
i--
) {
- const declarator = tree.field(i, Field.declarations, declaration);
- if (typeOf(tree.field(0, Field.id, declarator)) !== NodeType.Identifier) {
+ const declarator = A.field(i, Field.declarations, declaration);
+ if (typeOf(A.field(0, Field.id, declarator)) !== NodeType.Identifier) {
return false;
}
}
@@ -14563,7 +14534,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const noteGuardRead = (node, parent) => {
- const operator = tree.textOf(Part.operator, parent);
+ const operator = A.textOf(Part.operator, parent);
if (
childOf(Field.left, parent) !== node ||
(operator !== "||" && operator !== "??")
@@ -14587,9 +14558,9 @@ const createNodePrinter = (modules) => {
const right = childOf(Field.right, parent);
if (
typeOf(right) === NodeType.AssignmentExpression &&
- tree.textOf(Part.operator, right) === "=" &&
+ A.textOf(Part.operator, right) === "=" &&
/** @type {TreeDefinition[]} */ (mangledNames)[
- tree.field(0, Field.left, right)
+ A.field(0, Field.left, right)
] === definition
) {
guardReads.push(node, definition);
@@ -14597,17 +14568,17 @@ const createNodePrinter = (modules) => {
return;
}
if (typeOf(onceStatement) !== NodeType.VariableDeclaration) return;
- const count = tree.fieldCount(Field.declarations, onceStatement);
+ const count = A.fieldCount(Field.declarations, onceStatement);
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, onceStatement);
+ const declarator = A.field(i, Field.declarations, onceStatement);
const init = childOf(Field.init, declarator);
if (
init !== 0 &&
/** @type {TreeDefinition[]} */ (mangledNames)[
- tree.field(0, Field.id, declarator)
+ A.field(0, Field.id, declarator)
] === definition &&
- tree.start(node) >= tree.start(init) &&
- tree.end(node) <= tree.end(init)
+ A.start(node) >= A.start(init) &&
+ A.end(node) <= A.end(init)
) {
foldUnsetRead(node);
return;
@@ -14626,12 +14597,9 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
for (let i = 0; i < count; i++) {
- const id = childOf(
- Field.id,
- tree.field(i, Field.declarations, statement)
- );
+ const id = childOf(Field.id, A.field(i, Field.declarations, statement));
const definition =
typeOf(id) === NodeType.Identifier ? mangledNames[id] : null;
if (!isMinifierVariable(definition) || definition.referenceCount !== 0) {
@@ -14669,9 +14637,9 @@ const createNodePrinter = (modules) => {
// An `if`'s branch, no list's statement, goes as one does; one beside
// a `break` or `continue` a loop's test takes in stays its body.
if (typeOf(parent) === NodeType.IfStatement) {
- const other = tree.field(
+ const other = A.field(
0,
- tree.field(0, Field.consequent, parent) === node
+ A.field(0, Field.consequent, parent) === node
? Field.alternate
: Field.consequent,
parent
@@ -14689,7 +14657,7 @@ const createNodePrinter = (modules) => {
// A loop's declarators are set once, each before the next.
const init = childOf(Field.init, node);
if (typeOf(init) === NodeType.VariableDeclaration) {
- if (tree.fieldCount(Field.declarations, init) > 1) {
+ if (A.fieldCount(Field.declarations, init) > 1) {
collapseInto(init, 0);
}
// What the loop's test, update and body set, it set before.
@@ -14698,11 +14666,11 @@ const createNodePrinter = (modules) => {
}
if (type === NodeType.SwitchCase) {
// A case's statements run in order once it is entered.
- const count = tree.fieldCount(Field.consequent, node);
+ const count = A.fieldCount(Field.consequent, node);
// Whether a statement before always leaves, terser's `dead_code`.
let exited = false;
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.consequent, node);
+ const statement = A.field(i, Field.consequent, node);
if (exited && neverReached(statement)) {
dropped[statement] = 1;
findNode(statement, discountRead);
@@ -14714,12 +14682,12 @@ const createNodePrinter = (modules) => {
if (declaresLexically(statement)) {
if (!namesNothingNamed(statement)) continue;
} else if (i + 1 < count) {
- collapseInto(statement, tree.field(i + 1, Field.consequent, node));
+ collapseInto(statement, A.field(i + 1, Field.consequent, node));
}
if (typeOf(statement) !== NodeType.VariableDeclaration) continue;
- const declarations = tree.fieldCount(Field.declarations, statement);
+ const declarations = A.fieldCount(Field.declarations, statement);
for (let j = 0; j < declarations; j++) {
- const declarator = tree.field(j, Field.declarations, statement);
+ const declarator = A.field(j, Field.declarations, statement);
if (!hasEdgeComments(declarator)) {
candidates.push(declarator);
keepsEffect[declarator] = 2;
@@ -14739,14 +14707,14 @@ const createNodePrinter = (modules) => {
let quiet = scopesVars;
// Whether a statement before always leaves the list, terser's `dead_code`.
let exited = false;
- const count = tree.fieldCount(Field.body, node);
+ const count = A.fieldCount(Field.body, node);
if (scopesVars && type !== NodeType.StaticBlock) noteDirectives(node);
// The modules imported so far: a later bare import of one loads nothing.
/** @type {Set | undefined} */
const imported =
type === NodeType.Program && dropsUnused ? new Set() : undefined;
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, node);
+ const statement = A.field(i, Field.body, node);
if (exited && neverReached(statement)) {
dropped[statement] = 1;
findNode(statement, discountRead);
@@ -14755,14 +14723,14 @@ const createNodePrinter = (modules) => {
if (
exited &&
typeOf(statement) === NodeType.VariableDeclaration &&
- tree.textOf(Part.kind, statement) === "var" &&
+ A.textOf(Part.kind, statement) === "var" &&
!holdsComments(statement) &&
declaresNamesOnly(statement)
) {
// terser's `dead_code`: the `var` declares its names, setting none.
- const declarations = tree.fieldCount(Field.declarations, statement);
+ const declarations = A.fieldCount(Field.declarations, statement);
for (let j = 0; j < declarations; j++) {
- const declarator = tree.field(j, Field.declarations, statement);
+ const declarator = A.field(j, Field.declarations, statement);
const init = childOf(Field.init, declarator);
if (init !== 0) {
deadInits.add(declarator);
@@ -14777,7 +14745,7 @@ const createNodePrinter = (modules) => {
// Each declarator is set before the next, where those fold.
noteInitialized(statement);
if (i + 1 < count) {
- const next = tree.field(i + 1, Field.body, node);
+ const next = A.field(i + 1, Field.body, node);
collapseInto(statement, next);
collapseFreshLater(node, i);
// Declarations whose values all fold into the next statement run
@@ -14785,17 +14753,17 @@ const createNodePrinter = (modules) => {
for (
let j = i;
j > 0 &&
- foldsWhole(tree.field(j, Field.body, node)) &&
- typeOf(tree.field(j - 1, Field.body, node)) ===
+ foldsWhole(A.field(j, Field.body, node)) &&
+ typeOf(A.field(j - 1, Field.body, node)) ===
NodeType.VariableDeclaration;
j--
) {
- collapseInto(tree.field(j - 1, Field.body, node), next);
+ collapseInto(A.field(j - 1, Field.body, node), next);
}
if (sameExit(statement, next)) exitPairs.push(statement, next);
if (
typeOf(statement) === NodeType.IfStatement &&
- tree.field(0, Field.alternate, statement) === 0 &&
+ A.field(0, Field.alternate, statement) === 0 &&
(typeOf(next) === NodeType.ReturnStatement ||
typeOf(next) === NodeType.ThrowStatement ||
typeOf(next) === NodeType.IfStatement)
@@ -14806,9 +14774,9 @@ const createNodePrinter = (modules) => {
}
const statementType = typeOf(statement);
if (statementType === NodeType.VariableDeclaration) {
- const declarations = tree.fieldCount(Field.declarations, statement);
+ const declarations = A.fieldCount(Field.declarations, statement);
for (let j = 0; j < declarations; j++) {
- const declarator = tree.field(j, Field.declarations, statement);
+ const declarator = A.field(j, Field.declarations, statement);
if (scopesVars) {
setFirst[declarator] = quiet ? 1 : 2;
noteBareVar(declarator);
@@ -14847,7 +14815,7 @@ const createNodePrinter = (modules) => {
} else if (
statementType === NodeType.BlockStatement &&
dropsDeadCode &&
- tree.fieldCount(Field.body, statement) === 0 &&
+ A.fieldCount(Field.body, statement) === 0 &&
!holdsComments(statement)
) {
// An empty block runs nothing.
@@ -14858,7 +14826,7 @@ const createNodePrinter = (modules) => {
i === count - 1 &&
LOOP_TYPES[typeOf(parent)] === 1 &&
childOf(Field.body, parent) === node &&
- tree.field(0, Field.label, statement) === 0 &&
+ A.field(0, Field.label, statement) === 0 &&
!hasEdgeComments(statement)
) {
// A loop's body ending goes on to the next pass as its `continue` does.
@@ -14869,22 +14837,21 @@ const createNodePrinter = (modules) => {
} else if (
statementType === NodeType.TryStatement &&
dropsDeadCode &&
- tree.fieldCount(Field.body, tree.field(0, Field.block, statement)) ===
- 0 &&
+ A.fieldCount(Field.body, A.field(0, Field.block, statement)) === 0 &&
!holdsComments(statement) &&
- (tree.field(0, Field.handler, statement) === 0 ||
- !findNode(tree.field(0, Field.handler, statement), findHoisted))
+ (A.field(0, Field.handler, statement) === 0 ||
+ !findNode(A.field(0, Field.handler, statement), findHoisted))
) {
dropEmptyTry(statement);
} else if (
imported !== undefined &&
statementType === NodeType.ImportDeclaration
) {
- const source = tree.value(tree.field(0, Field.source, statement));
+ const source = A.value(A.field(0, Field.source, statement));
if (
typeof source === "string" &&
- tree.fieldCount(Field.attributes, statement) === 0 &&
- !tree.textOf(Part.phase, statement)
+ A.fieldCount(Field.attributes, statement) === 0 &&
+ !A.textOf(Part.phase, statement)
) {
if (
imported.has(source) &&
@@ -14906,7 +14873,7 @@ const createNodePrinter = (modules) => {
i === count - 2 &&
(FUNCTION_TYPES[typeOf(parent)] === 1 ||
LOOP_TYPES[typeOf(parent)] === 1) &&
- tree.field(0, Field.body, parent) === node
+ A.field(0, Field.body, parent) === node
) {
exitElseCandidates.push(statement, node, parent);
}
@@ -14939,7 +14906,7 @@ const createNodePrinter = (modules) => {
findNode(childOf(Field.test, statement), discountRead);
const update = childOf(Field.update, statement);
if (update !== 0) findNode(update, discountRead);
- findNode(tree.field(0, Field.body, statement), discountRead);
+ findNode(A.field(0, Field.body, statement), discountRead);
}
// A `return` ending a function's body of a call returning nothing.
if (
@@ -14947,8 +14914,8 @@ const createNodePrinter = (modules) => {
i === count - 1 &&
typeOf(node) === NodeType.BlockStatement &&
FUNCTION_TYPES[typeOf(parent)] === 1 &&
- !tree.flag(Flag.async, parent) &&
- !tree.flag(Flag.generator, parent)
+ !A.flag(Flag.async, parent) &&
+ !A.flag(Flag.generator, parent)
) {
blockCandidates.push(statement, parent);
}
@@ -14962,7 +14929,7 @@ const createNodePrinter = (modules) => {
if (
(statementType === NodeType.ExpressionStatement ||
(statementType === NodeType.VariableDeclaration &&
- tree.fieldCount(Field.declarations, statement) === 1)) &&
+ A.fieldCount(Field.declarations, statement) === 1)) &&
(typeOf(node) === NodeType.Program ||
(typeOf(node) === NodeType.BlockStatement &&
FUNCTION_TYPES[typeOf(parent)] === 1))
@@ -14988,7 +14955,7 @@ const createNodePrinter = (modules) => {
}
} else if (
type === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, node) === "delete" &&
+ A.textOf(Part.operator, node) === "delete" &&
// One `deletesValue` folds prints a dropped write's value then `!0`.
(!compresses || hasEdgeComments(node))
) {
@@ -14999,7 +14966,7 @@ const createNodePrinter = (modules) => {
if (
isMinifierVariable(definition) &&
(definition.declarations & ~READ_ANY_TIME) !== 0 &&
- readsSet(definition, tree.start(node))
+ readsSet(definition, A.start(node))
) {
settledReads.add(node);
}
@@ -15009,7 +14976,7 @@ const createNodePrinter = (modules) => {
) {
noteGuardRead(node, parent);
}
- if (tree.name(node) === "Object") noteObjectUse(node, parent);
+ if (A.name(node) === "Object") noteObjectUse(node, parent);
if (probingTry !== 0) probedReads.add(node);
if (moveReads.has(node)) moveReaders.set(node, readingFunction);
if (
@@ -15050,15 +15017,15 @@ const createNodePrinter = (modules) => {
const argument = childOf(Field.argument, node);
if (
argument !== 0 &&
- tree.flag(Flag.async, readingFunction) &&
- tree.flag(Flag.generator, readingFunction)
+ A.flag(Flag.async, readingFunction) &&
+ A.flag(Flag.generator, readingFunction)
) {
awaitedReturns.add(argument);
}
} else if (
(type === NodeType.FunctionExpression ||
type === NodeType.ClassExpression) &&
- tree.field(0, Field.id, node) !== 0
+ A.field(0, Field.id, node) !== 0
) {
namedExpressions.push(node);
}
@@ -15071,9 +15038,9 @@ const createNodePrinter = (modules) => {
tailHolders.push(node);
if (
type === NodeType.LabeledStatement &&
- LOOP_TYPES[typeOf(tree.field(0, Field.body, node))] === 1
+ LOOP_TYPES[typeOf(A.field(0, Field.body, node))] === 1
) {
- labeledParents.set(tree.field(0, Field.body, node), node);
+ labeledParents.set(A.field(0, Field.body, node), node);
}
}
const outerFunction = readingFunction;
@@ -15110,7 +15077,7 @@ const createNodePrinter = (modules) => {
type === NodeType.ClassDeclaration ||
type === NodeType.ClassExpression
) {
- inDerivedClass = tree.field(0, Field.superClass, node) !== 0;
+ inDerivedClass = A.field(0, Field.superClass, node) !== 0;
} else if (
type === NodeType.StaticBlock ||
type === NodeType.PropertyDefinition ||
@@ -15121,7 +15088,7 @@ const createNodePrinter = (modules) => {
thisThrows =
inDerivedClass &&
typeOf(parent) === NodeType.MethodDefinition &&
- tree.textOf(Part.kind, parent) === "constructor";
+ A.textOf(Part.kind, parent) === "constructor";
}
const outerOnce = onceStatement;
if (
@@ -15129,7 +15096,7 @@ const createNodePrinter = (modules) => {
type === NodeType.VariableDeclaration) &&
(parent === readingFunction ||
(FUNCTION_TYPES[typeOf(readingFunction)] === 1 &&
- tree.field(0, Field.body, readingFunction) === parent))
+ A.field(0, Field.body, readingFunction) === parent))
) {
onceStatement = node;
} else if (
@@ -15141,7 +15108,7 @@ const createNodePrinter = (modules) => {
}
if (type === NodeType.FunctionDeclaration) {
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[
- tree.field(0, Field.id, node)
+ A.field(0, Field.id, node)
];
// A name not a variable is never looked up.
declaredFunctions.set(/** @type {MinifierVariable} */ (definition), node);
@@ -15152,16 +15119,16 @@ const createNodePrinter = (modules) => {
functionStack.push(node);
if (FUNCTION_TYPES[type] === 1) probingTry = 0;
}
- const fields = CHILD_FIELDS[tree.type(node)];
+ const fields = CHILD_FIELDS[A.type(node)];
const holder = parenthesesHolder;
if (type === NodeType.ParenthesizedExpression) parenthesesHolder = parent;
for (let f = 0; f < fields.length; f++) {
const probes =
type === NodeType.TryStatement && fields[f] === Field.block;
if (probes) probingTry++;
- const count = tree.fieldCount(fields[f], node);
+ const count = A.fieldCount(fields[f], node);
for (let i = 0; i < count; i++) {
- const child = tree.field(i, fields[f], node);
+ const child = A.field(i, fields[f], node);
if (child === 0) continue;
collectDroppable(child, node, candidates);
// Past a constructor's `super()`, its `this` is set.
@@ -15193,10 +15160,10 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const noteDirectives = (body) => {
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, body);
- const directive = tree.textOf(Part.directive, statement);
+ const statement = A.field(i, Field.body, body);
+ const directive = A.textOf(Part.directive, statement);
if (directive === null) return;
if (directive !== "use strict") continue;
if (!walkStrict) {
@@ -15224,10 +15191,10 @@ const createNodePrinter = (modules) => {
if (childOf(Field.callee, parent) === node) return;
break;
case NodeType.UnaryExpression:
- if (tree.textOf(Part.operator, parent) === "typeof") return;
+ if (A.textOf(Part.operator, parent) === "typeof") return;
break;
case NodeType.BinaryExpression:
- if (tree.textOf(Part.operator, parent) === "instanceof") return;
+ if (A.textOf(Part.operator, parent) === "instanceof") return;
break;
}
if (isGlobalUndefined(node, "Object")) objectWrites = true;
@@ -15245,7 +15212,7 @@ const createNodePrinter = (modules) => {
if (
objectWrites === true ||
typeOf(object) !== NodeType.Identifier ||
- tree.name(object) !== "Object"
+ A.name(object) !== "Object"
) {
return;
}
@@ -15265,17 +15232,17 @@ const createNodePrinter = (modules) => {
if (childOf(Field.value, parent) !== member) return;
break;
case NodeType.UnaryExpression:
- if (tree.textOf(Part.operator, parent) !== "delete") return;
+ if (A.textOf(Part.operator, parent) !== "delete") return;
break;
default:
return;
}
if (!isGlobalUndefined(object, "Object")) return;
const property = childOf(Field.property, member);
- const key = !tree.flag(Flag.computed, member)
- ? tree.name(property)
+ const key = !A.flag(Flag.computed, member)
+ ? A.name(property)
: typeOf(property) === NodeType.Literal
- ? tree.value(property)
+ ? A.value(property)
: undefined;
if (typeof key === "string") {
objectWrites.add(key);
@@ -15294,30 +15261,30 @@ const createNodePrinter = (modules) => {
const type = typeOf(statement);
if (type === NodeType.ClassDeclaration) {
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[
- tree.field(0, Field.id, statement)
+ A.field(0, Field.id, statement)
];
if (isMinifierVariable(definition)) {
- setNames.set(definition, tree.end(statement));
+ setNames.set(definition, A.end(statement));
}
return;
}
if (
type !== NodeType.VariableDeclaration ||
- tree.textOf(Part.kind, statement) === "var"
+ A.textOf(Part.kind, statement) === "var"
) {
return;
}
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, statement);
- const id = tree.field(0, Field.id, declarator);
+ const declarator = A.field(i, Field.declarations, statement);
+ const id = A.field(0, Field.id, declarator);
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[id];
if (
typeOf(id) === NodeType.Identifier &&
isMinifierVariable(definition)
) {
// Set once its declarator ran, the declarators after it read it set.
- setNames.set(definition, tree.end(declarator));
+ setNames.set(definition, A.end(declarator));
}
}
};
@@ -15350,7 +15317,7 @@ const createNodePrinter = (modules) => {
return (
nested !== 0 &&
typeOf(nested) !== NodeType.FunctionDeclaration &&
- tree.start(nested) >= end
+ A.start(nested) >= end
);
};
@@ -15359,7 +15326,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it is `using` or `await using`, which disposes of its values
*/
const disposes = (statement) => {
- const kind = tree.textOf(Part.kind, statement);
+ const kind = A.textOf(Part.kind, statement);
return kind === "using" || kind === "await using";
};
@@ -15396,14 +15363,14 @@ const createNodePrinter = (modules) => {
*/
const collapseInto = (statement, next) => {
if (hasEdgeComments(statement) || hasEdgeComments(next)) return;
- collapsingFrom = tree.start(statement);
+ collapsingFrom = A.start(statement);
const type = typeOf(statement);
if (type === NodeType.ExpressionStatement) {
- if (tree.textOf(Part.directive, statement) !== null) return;
+ if (A.textOf(Part.directive, statement) !== null) return;
const assignment = childOf(Field.expression, statement);
if (
typeOf(assignment) !== NodeType.AssignmentExpression ||
- tree.textOf(Part.operator, assignment) !== "="
+ A.textOf(Part.operator, assignment) !== "="
) {
return;
}
@@ -15445,7 +15412,7 @@ const createNodePrinter = (modules) => {
(definition.kind === DECLARES_VAR ||
definition.kind === DECLARES_LET ||
definition.kind === DECLARES_FUNARG) &&
- writesSet(definition, tree.start(statement)) &&
+ writesSet(definition, A.start(statement)) &&
isUnusedBinding(target) &&
!opensAmbiguously(value) &&
typeOf(value) !== NodeType.Identifier &&
@@ -15468,12 +15435,12 @@ const createNodePrinter = (modules) => {
// Each declarator folds into the next value after it, of a declarator
// or of `next`: one without a value evaluates nothing. Where every
// value after it folded, it may fold into `next` past their reads.
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
let holder = next;
let evaluated = firstRead(next);
let intoNext = true;
for (let i = count - 1; i >= 0; i--) {
- const declarator = tree.field(i, Field.declarations, statement);
+ const declarator = A.field(i, Field.declarations, statement);
const folded =
aliasesRead[declarator] === 3 ||
collapseDeclarator(declarator, holder, evaluated) ||
@@ -15495,9 +15462,9 @@ const createNodePrinter = (modules) => {
*/
const foldsWhole = (statement) => {
if (typeOf(statement) !== NodeType.VariableDeclaration) return false;
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
for (let i = 0; i < count; i++) {
- if (aliasesRead[tree.field(i, Field.declarations, statement)] !== 3) {
+ if (aliasesRead[A.field(i, Field.declarations, statement)] !== 3) {
return false;
}
}
@@ -15511,22 +15478,22 @@ const createNodePrinter = (modules) => {
const isFreshConstant = (node) => {
switch (typeOf(node)) {
case NodeType.ArrayExpression: {
- const count = tree.fieldCount(Field.elements, node);
+ const count = A.fieldCount(Field.elements, node);
for (let i = 0; i < count; i++) {
- const element = tree.field(i, Field.elements, node);
+ const element = A.field(i, Field.elements, node);
if (element !== 0 && !isConstantPart(element)) return false;
}
return true;
}
case NodeType.ObjectExpression: {
- const count = tree.fieldCount(Field.properties, node);
+ const count = A.fieldCount(Field.properties, node);
for (let i = 0; i < count; i++) {
- const property = tree.field(i, Field.properties, node);
+ const property = A.field(i, Field.properties, node);
if (
typeOf(property) !== NodeType.Property ||
- tree.textOf(Part.kind, property) !== "init" ||
- tree.flag(Flag.method, property) ||
- tree.flag(Flag.computed, property) ||
+ A.textOf(Part.kind, property) !== "init" ||
+ A.flag(Flag.method, property) ||
+ A.flag(Flag.computed, property) ||
!isConstantPart(childOf(Field.value, property))
) {
return false;
@@ -15585,7 +15552,7 @@ const createNodePrinter = (modules) => {
found = hasEdgeComments(inner) ? 0 : inner;
return true;
case NodeType.UnaryExpression:
- return tree.textOf(Part.operator, inner) === "delete" &&
+ return A.textOf(Part.operator, inner) === "delete" &&
typeOf(childOf(Field.argument, inner)) === NodeType.Identifier
? false
: undefined;
@@ -15609,7 +15576,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const collapseFreshLater = (list, index) => {
- const statement = tree.field(index, Field.body, list);
+ const statement = A.field(index, Field.body, list);
if (
typeOf(statement) !== NodeType.VariableDeclaration ||
disposes(statement) ||
@@ -15617,12 +15584,12 @@ const createNodePrinter = (modules) => {
) {
return;
}
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
for (let i = 0; i < count; i++) {
collapseFreshDeclarator(
list,
index,
- tree.field(i, Field.declarations, statement)
+ A.field(i, Field.declarations, statement)
);
}
};
@@ -15635,7 +15602,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const collapseFreshDeclarator = (list, index, declarator) => {
- const id = tree.field(0, Field.id, declarator);
+ const id = A.field(0, Field.id, declarator);
const init = childOf(Field.init, declarator);
if (
aliasesRead[declarator] === 3 ||
@@ -15659,7 +15626,7 @@ const createNodePrinter = (modules) => {
) {
return;
}
- collapsingFrom = tree.start(declarator);
+ collapsingFrom = A.start(declarator);
if (!isFreshConstant(init) || !isPureValue(init)) return;
// The names it reads, which nothing between may declare again.
/** @type {Map} */
@@ -15690,7 +15657,7 @@ const createNodePrinter = (modules) => {
if (type === NodeType.Identifier) {
const read = names[inner];
if (read === definition) {
- if (hasEdgeComments(inner) || tree.start(inner) < zoneEnd) {
+ if (hasEdgeComments(inner) || A.start(inner) < zoneEnd) {
blocked = true;
} else {
found = inner;
@@ -15701,7 +15668,7 @@ const createNodePrinter = (modules) => {
if (
isMinifierVariable(read) &&
reads.size !== 0 &&
- tree.start(inner) >= zoneEnd &&
+ A.start(inner) >= zoneEnd &&
reads.has(read.name) &&
reads.get(read.name) !== read
) {
@@ -15728,15 +15695,15 @@ const createNodePrinter = (modules) => {
// `export{c}` lists names, which take no value.
type === NodeType.ExportSpecifier ||
(type === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, inner) === "delete")
+ A.textOf(Part.operator, inner) === "delete")
) {
- zoneEnd = Math.max(zoneEnd, tree.end(inner));
+ zoneEnd = Math.max(zoneEnd, A.end(inner));
}
return undefined;
};
- const count = tree.fieldCount(Field.body, list);
+ const count = A.fieldCount(Field.body, list);
for (let i = index + 1; i < count; i++) {
- if (findNode(tree.field(i, Field.body, list), findLaterRead)) break;
+ if (findNode(A.field(i, Field.body, list), findLaterRead)) break;
}
if (found === 0 || blocked) return;
collapsed.set(found, init);
@@ -15753,7 +15720,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it folds
*/
const collapseDeclarator = (declarator, holder, evaluated) => {
- const id = tree.field(0, Field.id, declarator);
+ const id = A.field(0, Field.id, declarator);
const init = childOf(Field.init, declarator);
if (
!dropsUnused ||
@@ -15778,7 +15745,7 @@ const createNodePrinter = (modules) => {
return false;
}
// The declarators before it are set by then.
- collapsingFrom = tree.start(declarator);
+ collapsingFrom = A.start(declarator);
collapsingValue = init;
argumentsChecked = 0;
collapsingPure = isPureValue(init);
@@ -15807,7 +15774,7 @@ const createNodePrinter = (modules) => {
*/
const holdsCollapsed = (next) => {
if (typeOf(next) !== NodeType.VariableDeclaration) return;
- keepsValue.add(tree.field(0, Field.declarations, next));
+ keepsValue.add(A.field(0, Field.declarations, next));
};
/**
@@ -15910,11 +15877,11 @@ const createNodePrinter = (modules) => {
case NodeType.MemberExpression:
if (!isArgumentsMember(node)) return undefined;
return (
- tree.flag(Flag.computed, node) &&
+ A.flag(Flag.computed, node) &&
findNode(childOf(Field.property, node), writesArguments)
);
case NodeType.Identifier:
- return tree.name(node) === "arguments" || undefined;
+ return A.name(node) === "arguments" || undefined;
}
};
@@ -15923,7 +15890,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean | undefined} true for the name `arguments`
*/
const namesArguments = (node) =>
- (typeOf(node) === NodeType.Identifier && tree.name(node) === "arguments") ||
+ (typeOf(node) === NodeType.Identifier && A.name(node) === "arguments") ||
undefined;
/**
@@ -15949,7 +15916,7 @@ const createNodePrinter = (modules) => {
: 0;
return target !== 0 &&
typeOf(target) === NodeType.Identifier &&
- tree.name(target) === name
+ A.name(target) === name
? true
: undefined;
};
@@ -15991,7 +15958,7 @@ const createNodePrinter = (modules) => {
const isStableTarget = (node, definition) =>
typeOf(node) === NodeType.MemberExpression &&
isStable(childOf(Field.object, node), definition) &&
- (!tree.flag(Flag.computed, node) ||
+ (!A.flag(Flag.computed, node) ||
isStable(childOf(Field.property, node), definition));
/**
@@ -16013,7 +15980,7 @@ const createNodePrinter = (modules) => {
* @returns {number} its first item that is not stable, 0 where a spread comes first or none is
*/
const firstUnstable = (field, node, definition) => {
- const count = tree.fieldCount(field, node);
+ const count = A.fieldCount(field, node);
for (let i = 0; i < count; i++) {
const item = itemOf(i, field, node);
// A hole evaluates nothing.
@@ -16038,20 +16005,20 @@ const createNodePrinter = (modules) => {
* @returns {number} the first property value that is not stable, 0 where a computed key, spread, method or shorthand comes first, or none is
*/
const firstUnstableValue = (node, definition) => {
- const count = tree.fieldCount(Field.properties, node);
+ const count = A.fieldCount(Field.properties, node);
for (let i = 0; i < count; i++) {
const property = itemOf(i, Field.properties, node);
if (
typeOf(property) !== NodeType.Property ||
- tree.flag(Flag.computed, property) ||
- tree.textOf(Part.kind, property) !== "init"
+ A.flag(Flag.computed, property) ||
+ A.textOf(Part.kind, property) !== "init"
) {
return 0;
}
const value = childOf(Field.value, property);
if (isStable(value, definition)) continue;
// A shorthand's value prints as its key.
- return tree.flag(Flag.shorthand, property) ? 0 : value;
+ return A.flag(Flag.shorthand, property) ? 0 : value;
}
return 0;
};
@@ -16074,10 +16041,7 @@ const createNodePrinter = (modules) => {
return childOf(Field.discriminant, statement);
case NodeType.VariableDeclaration:
if (disposes(statement)) return 0;
- return childOf(
- Field.init,
- tree.field(0, Field.declarations, statement)
- );
+ return childOf(Field.init, A.field(0, Field.declarations, statement));
case NodeType.ForStatement: {
const init = childOf(Field.init, statement);
return typeOf(init) === NodeType.VariableDeclaration
@@ -16113,18 +16077,14 @@ const createNodePrinter = (modules) => {
// A `var` set in a `for … in` head is set before what it goes over.
if (
type !== NodeType.ForStatement &&
- childOf(Field.init, tree.field(0, Field.declarations, head)) !== 0
+ childOf(Field.init, A.field(0, Field.declarations, head)) !== 0
) {
return false;
}
- if (tree.textOf(Part.kind, head) === "var") return true;
- const count = tree.fieldCount(Field.declarations, head);
+ if (A.textOf(Part.kind, head) === "var") return true;
+ const count = A.fieldCount(Field.declarations, head);
for (let i = 0; i < count; i++) {
- const id = tree.field(
- 0,
- Field.id,
- tree.field(i, Field.declarations, head)
- );
+ const id = A.field(0, Field.id, A.field(i, Field.declarations, head));
if (typeOf(id) !== NodeType.Identifier) return false;
}
// The head's names may mangle as a local the value reads, which they hide.
@@ -16166,7 +16126,7 @@ const createNodePrinter = (modules) => {
// a member's object and key are evaluated before it.
const left = childOf(Field.left, node);
if (
- tree.textOf(Part.operator, node) !== "=" ||
+ A.textOf(Part.operator, node) !== "=" ||
(typeOf(left) === NodeType.Identifier
? names[left] === definition
: !isStableTarget(left, definition))
@@ -16181,10 +16141,7 @@ const createNodePrinter = (modules) => {
break;
case NodeType.CallExpression: {
const callee = childOf(Field.callee, node);
- if (
- tree.flag(Flag.optional, node) ||
- !readsSame(callee, definition)
- ) {
+ if (A.flag(Flag.optional, node) || !readsSame(callee, definition)) {
node = callee;
break;
}
@@ -16214,15 +16171,15 @@ const createNodePrinter = (modules) => {
case NodeType.MemberExpression: {
const object = childOf(Field.object, node);
node =
- tree.flag(Flag.computed, node) &&
- !tree.flag(Flag.optional, node) &&
+ A.flag(Flag.computed, node) &&
+ !A.flag(Flag.optional, node) &&
isStable(object, definition)
? childOf(Field.property, node)
: object;
break;
}
case NodeType.UnaryExpression:
- if (tree.textOf(Part.operator, node) === "delete") return 0;
+ if (A.textOf(Part.operator, node) === "delete") return 0;
node = childOf(Field.argument, node);
break;
case NodeType.AwaitExpression:
@@ -16250,7 +16207,7 @@ const createNodePrinter = (modules) => {
node = readsSame(tag, definition)
? firstUnstable(
Field.expressions,
- tree.field(0, Field.quasi, node),
+ A.field(0, Field.quasi, node),
definition
)
: tag;
@@ -16281,15 +16238,15 @@ const createNodePrinter = (modules) => {
case NodeType.ContinueStatement:
return true;
case NodeType.BlockStatement: {
- const count = tree.fieldCount(Field.body, statement);
+ const count = A.fieldCount(Field.body, statement);
for (let i = 0; i < count; i++) {
- if (exitsAlways(tree.field(i, Field.body, statement))) return true;
+ if (exitsAlways(A.field(i, Field.body, statement))) return true;
}
return false;
}
case NodeType.IfStatement: {
- const consequent = tree.field(0, Field.consequent, statement);
- const alternate = tree.field(0, Field.alternate, statement);
+ const consequent = A.field(0, Field.consequent, statement);
+ const alternate = A.field(0, Field.alternate, statement);
const test = childOf(Field.test, statement);
const value = evaluateConstant(test);
if (value !== undefined && isPureTest(test)) {
@@ -16302,10 +16259,10 @@ const createNodePrinter = (modules) => {
}
case NodeType.TryStatement: {
// A `finally` running normally leaves as its block or `catch` did.
- const handler = tree.field(0, Field.handler, statement);
+ const handler = A.field(0, Field.handler, statement);
return (
- exitsAlways(tree.field(0, Field.block, statement)) &&
- (handler === 0 || exitsAlways(tree.field(0, Field.body, handler)))
+ exitsAlways(A.field(0, Field.block, statement)) &&
+ (handler === 0 || exitsAlways(A.field(0, Field.body, handler)))
);
}
default:
@@ -16336,7 +16293,7 @@ const createNodePrinter = (modules) => {
let loop = statement;
while (typeOf(loop) === NodeType.LabeledStatement) {
if (hasEdgeComments(loop)) return false;
- loop = tree.field(0, Field.body, loop);
+ loop = A.field(0, Field.body, loop);
}
const type = typeOf(loop);
return (
@@ -16360,7 +16317,7 @@ const createNodePrinter = (modules) => {
return (
((value !== undefined && !value) || isUndefinedValue(test)) &&
isPureTest(test) &&
- !findNode(tree.field(0, Field.body, statement), findHoisted)
+ !findNode(A.field(0, Field.body, statement), findHoisted)
);
};
@@ -16376,7 +16333,7 @@ const createNodePrinter = (modules) => {
init !== 0 &&
!hasEdgeComments(init) &&
(typeOf(init) !== NodeType.VariableDeclaration ||
- tree.textOf(Part.kind, init) === "var") &&
+ A.textOf(Part.kind, init) === "var") &&
// An `in` keeps the parentheses a loop's head gives it.
!findNode(init, findIn) &&
neverLoops(statement)
@@ -16392,7 +16349,7 @@ const createNodePrinter = (modules) => {
const neverRuns = (statement) => {
if (
!dropsDeadCode ||
- tree.field(0, Field.alternate, statement) !== 0 ||
+ A.field(0, Field.alternate, statement) !== 0 ||
holdsComments(statement)
) {
return false;
@@ -16402,7 +16359,7 @@ const createNodePrinter = (modules) => {
return (
((value !== undefined && !value) || isUndefinedValue(test)) &&
isPureTest(test) &&
- !findNode(tree.field(0, Field.consequent, statement), findHoisted)
+ !findNode(A.field(0, Field.consequent, statement), findHoisted)
);
};
@@ -16419,15 +16376,15 @@ const createNodePrinter = (modules) => {
*/
const bound = (target) => {
findNode(target, (inner) => {
- switch (tree.type(inner)) {
+ switch (A.type(inner)) {
case NodeType.Identifier:
names.push(inner);
return false;
case NodeType.AssignmentPattern:
- bound(tree.field(0, Field.left, inner));
+ bound(A.field(0, Field.left, inner));
return false;
case NodeType.Property:
- bound(tree.field(0, Field.value, inner));
+ bound(A.field(0, Field.value, inner));
return false;
case NodeType.MemberExpression:
return false;
@@ -16440,11 +16397,9 @@ const createNodePrinter = (modules) => {
const result = findHoisted(inner);
if (result !== true) return result;
if (typeOf(inner) === NodeType.FunctionDeclaration) return true;
- const count = tree.fieldCount(Field.declarations, inner);
+ const count = A.fieldCount(Field.declarations, inner);
for (let i = 0; i < count; i++) {
- bound(
- tree.field(0, Field.id, tree.field(i, Field.declarations, inner))
- );
+ bound(A.field(0, Field.id, A.field(i, Field.declarations, inner)));
}
return false;
});
@@ -16458,8 +16413,8 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it printed so, not where the `catch` declares a function or a name its parameter takes
*/
const dropEmptyTry = (statement) => {
- const handler = tree.field(0, Field.handler, statement);
- const finalizer = tree.field(0, Field.finalizer, statement);
+ const handler = A.field(0, Field.handler, statement);
+ const finalizer = A.field(0, Field.finalizer, statement);
const names = handler === 0 ? undefined : caughtVarNames(handler);
if (names === null) return false;
if (
@@ -16488,16 +16443,16 @@ const createNodePrinter = (modules) => {
* @returns {number[] | null | undefined} the names it declares with `var`, as `deadVarNames` gives them; null too where its parameter is a pattern or one of the names
*/
const caughtVarNames = (handler) => {
- const body = tree.field(0, Field.body, handler);
+ const body = A.field(0, Field.body, handler);
if (!findNode(body, findHoisted)) return undefined;
- const param = tree.field(0, Field.param, handler);
+ const param = A.field(0, Field.param, handler);
// A `var` naming the parameter sets that, declaring it outside.
if (param !== 0 && typeOf(param) !== NodeType.Identifier) return null;
const declared = param === 0 ? undefined : varNamesOf(body);
if (declared === null) return null;
if (declared !== undefined) {
for (const name of declared) {
- if (tree.name(name) === tree.name(param)) return null;
+ if (A.name(name) === A.name(param)) return null;
}
}
return deadVarNames(body);
@@ -16594,7 +16549,7 @@ const createNodePrinter = (modules) => {
/** @type {Map} */
const reads = new Map();
findNode(gone, (inner) => {
- if (tree.type(inner) === NodeType.Identifier) {
+ if (A.type(inner) === NodeType.Identifier) {
const definition = names[inner];
reads.set(definition, (reads.get(definition) || 0) + 1);
}
@@ -16624,9 +16579,9 @@ const createNodePrinter = (modules) => {
const leavesBranch = (statement) => {
const type = typeOf(statement);
if (type !== NodeType.BlockStatement) return EXIT_TYPES[type] === 1;
- const count = tree.fieldCount(Field.body, statement);
+ const count = A.fieldCount(Field.body, statement);
for (let i = 0; i < count; i++) {
- if (EXIT_TYPES[typeOf(tree.field(i, Field.body, statement))] === 1) {
+ if (EXIT_TYPES[typeOf(A.field(i, Field.body, statement))] === 1) {
return true;
}
}
@@ -16642,14 +16597,14 @@ const createNodePrinter = (modules) => {
*/
const nextToIf = (statement, list) => {
if (list === 0) return false;
- const count = tree.fieldCount(Field.body, list);
+ const count = A.fieldCount(Field.body, list);
let i = 0;
- while (tree.field(i, Field.body, list) !== statement) i++;
+ while (A.field(i, Field.body, list) !== statement) i++;
return (
(i > 0 &&
- typeOf(tree.field(i - 1, Field.body, list)) === NodeType.IfStatement) ||
+ typeOf(A.field(i - 1, Field.body, list)) === NodeType.IfStatement) ||
(i + 1 < count &&
- typeOf(tree.field(i + 1, Field.body, list)) === NodeType.IfStatement)
+ typeOf(A.field(i + 1, Field.body, list)) === NodeType.IfStatement)
);
};
@@ -16682,8 +16637,8 @@ const createNodePrinter = (modules) => {
}
const truth = knownTruth(test);
if (truth === undefined) return;
- const consequent = tree.field(0, Field.consequent, statement);
- const alternate = tree.field(0, Field.alternate, statement);
+ const consequent = A.field(0, Field.consequent, statement);
+ const alternate = A.field(0, Field.alternate, statement);
const [kept, gone] = truth
? [consequent, alternate]
: [alternate, consequent];
@@ -16700,8 +16655,8 @@ const createNodePrinter = (modules) => {
if (kept !== 0) {
const branch =
typeOf(kept) === NodeType.BlockStatement &&
- tree.fieldCount(Field.body, kept) === 1
- ? tree.field(0, Field.body, kept)
+ A.fieldCount(Field.body, kept) === 1
+ ? A.field(0, Field.body, kept)
: kept;
if (
typeOf(branch) !== NodeType.ExpressionStatement ||
@@ -16726,7 +16681,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const noteTestedBranch = (statement, test) => {
- const consequent = tree.field(0, Field.consequent, statement);
+ const consequent = A.field(0, Field.consequent, statement);
const alternate = elseOf(statement);
if (
!compresses ||
@@ -16772,8 +16727,8 @@ const createNodePrinter = (modules) => {
}
return;
}
- const consequent = tree.field(0, Field.consequent, statement);
- const alternate = tree.field(0, Field.alternate, statement);
+ const consequent = A.field(0, Field.consequent, statement);
+ const alternate = A.field(0, Field.alternate, statement);
const gone = value ? alternate : consequent;
if (gone !== 0 && holdsComments(gone)) return;
const hoisted = gone === 0 ? undefined : deadVarNames(gone);
@@ -16827,7 +16782,7 @@ const createNodePrinter = (modules) => {
const findSwitchBreak = (node) => {
switch (typeOf(node)) {
case NodeType.BreakStatement:
- return tree.field(0, Field.label, node) === 0 ? true : undefined;
+ return A.field(0, Field.label, node) === 0 ? true : undefined;
case NodeType.ForStatement:
case NodeType.ForInStatement:
case NodeType.ForOfStatement:
@@ -16863,7 +16818,7 @@ const createNodePrinter = (modules) => {
typeOf(discriminant) === NodeType.SequenceExpression
) {
const last = itemOf(
- tree.fieldCount(Field.expressions, discriminant) - 1,
+ A.fieldCount(Field.expressions, discriminant) - 1,
Field.expressions,
discriminant
);
@@ -16874,11 +16829,11 @@ const createNodePrinter = (modules) => {
noteConvergingSwitch(node, parent);
return;
}
- const count = tree.fieldCount(Field.cases, node);
+ const count = A.fieldCount(Field.cases, node);
let start = -1;
let fallback = -1;
for (let i = 0; i < count && start === -1; i++) {
- const test = childOf(Field.test, tree.field(i, Field.cases, node));
+ const test = childOf(Field.test, A.field(i, Field.cases, node));
if (test === 0) {
fallback = i;
continue;
@@ -16895,14 +16850,14 @@ const createNodePrinter = (modules) => {
const gone = tests ? [] : [discriminant];
let ended = start === -1;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.cases, node);
+ const item = A.field(i, Field.cases, node);
// A case prints nothing of its own, its comments included.
if (hasEdgeComments(item)) return;
const test = childOf(Field.test, item);
if (test !== 0) gone.push(test);
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
for (let j = 0; j < statements; j++) {
- const statement = tree.field(j, Field.consequent, item);
+ const statement = A.field(j, Field.consequent, item);
if (i < start || ended) {
gone.push(statement);
} else if (breaksSwitch(statement)) {
@@ -16931,7 +16886,7 @@ const createNodePrinter = (modules) => {
if (
holdsComments(part) ||
(type === NodeType.VariableDeclaration &&
- tree.textOf(Part.kind, part) !== "var") ||
+ A.textOf(Part.kind, part) !== "var") ||
type === NodeType.ClassDeclaration
) {
return;
@@ -16985,10 +16940,10 @@ const createNodePrinter = (modules) => {
if (!dropsDeadCode || hasEdgeComments(node)) return;
const value = evaluateConstant(childOf(Field.discriminant, node));
if (value === undefined) return;
- const count = tree.fieldCount(Field.cases, node);
+ const count = A.fieldCount(Field.cases, node);
let match = 0;
while (match < count) {
- const test = childOf(Field.test, tree.field(match, Field.cases, node));
+ const test = childOf(Field.test, A.field(match, Field.cases, node));
if (test !== 0 && evaluateConstant(test) === value) break;
match++;
}
@@ -16996,7 +16951,7 @@ const createNodePrinter = (modules) => {
const unlabeled = [];
let labeled = false;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.cases, node);
+ const item = A.field(i, Field.cases, node);
const test = childOf(Field.test, item);
// A `default` is jumped to where no case matches; a case before the
// match, where its test may match or runs something.
@@ -17018,14 +16973,14 @@ const createNodePrinter = (modules) => {
let reached = false;
let opened = false;
for (let i = 0, next = 0; i < count; i++) {
- const item = tree.field(i, Field.cases, node);
+ const item = A.field(i, Field.cases, node);
const printsUnlabeled = unlabeled[next] === item;
if (printsUnlabeled) next++;
else reached = opened = true;
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
let kept = false;
for (let j = 0; j < statements; j++) {
- const statement = tree.field(j, Field.consequent, item);
+ const statement = A.field(j, Field.consequent, item);
if (!reached) {
if (dropped[statement] !== 1 && neverReached(statement)) {
dropped[statement] = 1;
@@ -17055,13 +17010,13 @@ const createNodePrinter = (modules) => {
const breaksSwitch = (statement) => {
if (
typeOf(statement) === NodeType.BlockStatement &&
- tree.fieldCount(Field.body, statement) === 1
+ A.fieldCount(Field.body, statement) === 1
) {
- statement = tree.field(0, Field.body, statement);
+ statement = A.field(0, Field.body, statement);
}
return (
typeOf(statement) === NodeType.BreakStatement &&
- tree.field(0, Field.label, statement) === 0
+ A.field(0, Field.label, statement) === 0
);
};
@@ -17073,7 +17028,7 @@ const createNodePrinter = (modules) => {
for (const statement of kept) {
if (
typeOf(statement) !== NodeType.ExpressionStatement ||
- tree.textOf(Part.directive, statement) !== null ||
+ A.textOf(Part.directive, statement) !== null ||
hasEdgeComments(statement) ||
// A string alone prints apart, past a `;`.
typeof evaluateConstant(childOf(Field.expression, statement)) ===
@@ -17112,7 +17067,7 @@ const createNodePrinter = (modules) => {
return 0;
}
if (printedCases(node) !== 1) return 0;
- const item = tree.field(0, Field.cases, node);
+ const item = A.field(0, Field.cases, node);
const test = childOf(Field.test, item);
if (
test === 0 ||
@@ -17124,10 +17079,10 @@ const createNodePrinter = (modules) => {
) {
return 0;
}
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
let printed = 0;
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.consequent, item);
+ const statement = A.field(i, Field.consequent, item);
if (i === statements - 1 && isPlainBreak(statement)) break;
// A `break` leaving the `switch` has no `switch` to leave in an `if`,
// and the case test reads names its body declares, as an `if` test not.
@@ -17154,7 +17109,7 @@ const createNodePrinter = (modules) => {
return item !== 0 ? item : switchAsIfElse(node);
}
return parentType === NodeType.IfStatement &&
- tree.field(0, Field.alternate, parent) === 0
+ A.field(0, Field.alternate, parent) === 0
? switchAsIf(node)
: 0;
};
@@ -17192,8 +17147,8 @@ const createNodePrinter = (modules) => {
printedCases(node) === 2 &&
printsAboveEquality(childOf(Field.discriminant, node))
) {
- const first = tree.field(0, Field.cases, node);
- const second = tree.field(1, Field.cases, node);
+ const first = A.field(0, Field.cases, node);
+ const second = A.field(1, Field.cases, node);
const item = childOf(Field.test, first) === 0 ? second : first;
const other = item === first ? second : first;
const test = childOf(Field.test, item);
@@ -17225,9 +17180,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether its statements run as an `if`'s body: no `break` of the `switch` but one ending them, and no name declared in the block
*/
const runsAsBody = (item) => {
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.consequent, item);
+ const statement = A.field(i, Field.consequent, item);
if (i === statements - 1 && isPlainBreak(statement)) break;
if (findNode(statement, findSwitchBreak) || keepsLexicalName(statement)) {
return false;
@@ -17241,9 +17196,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether any of its statements prints, but a `break` ending them
*/
const runsCaseStatements = (item) => {
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.consequent, item);
+ const statement = A.field(i, Field.consequent, item);
if (i === statements - 1 && isPlainBreak(statement)) break;
if (!printedNothing(statement)) return true;
}
@@ -17255,9 +17210,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether each of its statements prints nothing, so it falls into the next
*/
const casePrintsNothing = (item) => {
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
for (let i = 0; i < statements; i++) {
- if (!statementPrintsNothing(tree.field(i, Field.consequent, item))) {
+ if (!statementPrintsNothing(A.field(i, Field.consequent, item))) {
return false;
}
}
@@ -17279,9 +17234,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether each of its statements prints nothing, but a `break` ending them
*/
const caseRunsNothing = (item) => {
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.consequent, item);
+ const statement = A.field(i, Field.consequent, item);
if (i === statements - 1 && isPlainBreak(statement)) break;
if (!statementPrintsNothing(statement)) return false;
}
@@ -17293,10 +17248,10 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether a `break` ends its statements
*/
const endsInBreak = (item) => {
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
return (
statements !== 0 &&
- isPlainBreak(tree.field(statements - 1, Field.consequent, item))
+ isPlainBreak(A.field(statements - 1, Field.consequent, item))
);
};
@@ -17308,21 +17263,21 @@ const createNodePrinter = (modules) => {
*/
const printSwitchAsIf = (node, item) => {
const context = /** @type {JavascriptPrintContext} */ (writer);
- const count = tree.fieldCount(Field.cases, node);
+ const count = A.fieldCount(Field.cases, node);
const other =
printedCases(node) < 2
? 0
- : tree.field(
- tree.field(0, Field.cases, node) === item ? 1 : 0,
+ : A.field(
+ A.field(0, Field.cases, node) === item ? 1 : 0,
Field.cases,
node
);
// With the `default` first falling into the case, it runs where the test
// fails, as it does after a case running nothing; one running nothing goes.
- const breaks = other !== 0 && endsInBreak(tree.field(0, Field.cases, node));
+ const breaks = other !== 0 && endsInBreak(A.field(0, Field.cases, node));
const negates =
other !== 0 &&
- ((tree.field(0, Field.cases, node) === other && !breaks) ||
+ ((A.field(0, Field.cases, node) === other && !breaks) ||
(breaks && !runsCaseStatements(item)));
const alone =
other !== 0 && !negates && breaks && !runsCaseStatements(other);
@@ -17351,7 +17306,7 @@ const createNodePrinter = (modules) => {
printCaseStatements(other);
}
for (let i = count - 1; i >= 0; i--) {
- context.consume(tree.field(i, Field.cases, node));
+ context.consume(A.field(i, Field.cases, node));
}
};
@@ -17361,9 +17316,9 @@ const createNodePrinter = (modules) => {
*/
const soleStatementOf = (block) => {
let sole = 0;
- const count = tree.fieldCount(Field.body, block);
+ const count = A.fieldCount(Field.body, block);
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, block);
+ const statement = A.field(i, Field.body, block);
if (printsNothing(statement)) continue;
if (sole !== 0 || declaresLexically(statement)) return block;
sole = statement;
@@ -17379,11 +17334,11 @@ const createNodePrinter = (modules) => {
*/
const printCaseBody = (item, beforeElse) => {
const context = /** @type {JavascriptPrintContext} */ (writer);
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
let only = 0;
let printed = 0;
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.consequent, item);
+ const statement = A.field(i, Field.consequent, item);
if (i === statements - 1 && isPlainBreak(statement)) break;
if (!printedNothing(statement)) {
only = statement;
@@ -17403,7 +17358,7 @@ const createNodePrinter = (modules) => {
output.space();
let first = true;
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.consequent, item);
+ const statement = A.field(i, Field.consequent, item);
if (
printedNothing(statement) ||
(i === statements - 1 && isPlainBreak(statement))
@@ -17440,7 +17395,7 @@ const createNodePrinter = (modules) => {
type === NodeType.WhileStatement) &&
!beforeElse) ||
(type === NodeType.VariableDeclaration &&
- tree.textOf(Part.kind, shown) === "var" &&
+ A.textOf(Part.kind, shown) === "var" &&
printsWholeVar(shown)) ||
(type === NodeType.ExpressionStatement &&
typeof evaluateConstant(childOf(Field.expression, shown)) !==
@@ -17459,10 +17414,10 @@ const createNodePrinter = (modules) => {
*/
const joinsCaseStatements = (item) => {
if (!compresses) return false;
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
let first = true;
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.consequent, item);
+ const statement = A.field(i, Field.consequent, item);
if (
printedNothing(statement) ||
(i === statements - 1 && isPlainBreak(statement))
@@ -17488,9 +17443,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it prints as itself, no declarator of it going
*/
const printsWholeVar = (statement) => {
- const count = tree.fieldCount(Field.declarations, statement);
+ const count = A.fieldCount(Field.declarations, statement);
for (let i = 0; i < count; i++) {
- if (dropped[tree.field(i, Field.declarations, statement)] === 1) {
+ if (dropped[A.field(i, Field.declarations, statement)] === 1) {
return false;
}
}
@@ -17504,9 +17459,9 @@ const createNodePrinter = (modules) => {
*/
const printCaseStatements = (item) => {
const context = /** @type {JavascriptPrintContext} */ (writer);
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.consequent, item);
+ const statement = A.field(i, Field.consequent, item);
if (
printedNothing(statement) ||
(i === statements - 1 && isPlainBreak(statement))
@@ -17523,9 +17478,9 @@ const createNodePrinter = (modules) => {
* @returns {number} how many of its cases print: those before the run of cases ending it that run nothing, a test that runs nothing and no statement but a `break`, unless a `default` before that run would catch their values
*/
const printedCases = (node) => {
- let count = tree.fieldCount(Field.cases, node);
+ let count = A.fieldCount(Field.cases, node);
for (; count > 0; count--) {
- const item = tree.field(count - 1, Field.cases, node);
+ const item = A.field(count - 1, Field.cases, node);
const test = childOf(Field.test, item);
const unlabeled = unlabeledCases.size !== 0 && unlabeledCases.has(item);
if (
@@ -17536,12 +17491,12 @@ const createNodePrinter = (modules) => {
break;
}
}
- const all = tree.fieldCount(Field.cases, node);
+ const all = A.fieldCount(Field.cases, node);
if (count === all) return count;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.cases, node);
+ const item = A.field(i, Field.cases, node);
if (
- tree.field(0, Field.test, item) === 0 &&
+ A.field(0, Field.test, item) === 0 &&
!(unlabeledCases.size !== 0 && unlabeledCases.has(item))
) {
return all;
@@ -17559,11 +17514,11 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const noteConvergingSwitch = (node, parent) => {
- const count = tree.fieldCount(Field.cases, node);
+ const count = A.fieldCount(Field.cases, node);
let fallback = false;
// Decided before anything is built: most `switch`es stop here.
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.cases, node);
+ const item = A.field(i, Field.cases, node);
const test = childOf(Field.test, item);
if (
hasEdgeComments(item) ||
@@ -17576,24 +17531,24 @@ const createNodePrinter = (modules) => {
if (test === 0) fallback = true;
}
// A comment on what it tests stays, as the known-value fold keeps it.
- if (!fallback || holdsComments(tree.field(0, Field.discriminant, node))) {
+ if (!fallback || holdsComments(A.field(0, Field.discriminant, node))) {
return;
}
/** @type {number[]} */
const gone = [];
for (let i = 0; i < count; i++) {
- const test = childOf(Field.test, tree.field(i, Field.cases, node));
+ const test = childOf(Field.test, A.field(i, Field.cases, node));
if (test !== 0) gone.push(test);
}
- const last = tree.field(count - 1, Field.cases, node);
+ const last = A.field(count - 1, Field.cases, node);
/** @type {Set} */
const kept = new Set();
/** @type {number[]} */
const hoisted = [];
let ended = false;
- const statements = tree.fieldCount(Field.consequent, last);
+ const statements = A.fieldCount(Field.consequent, last);
for (let j = 0; j < statements; j++) {
- const statement = tree.field(j, Field.consequent, last);
+ const statement = A.field(j, Field.consequent, last);
if (ended) {
gone.push(statement);
} else if (isPlainBreak(statement)) {
@@ -17639,19 +17594,15 @@ const createNodePrinter = (modules) => {
const declaresVarOnly = (statement) => {
if (
typeOf(statement) !== NodeType.VariableDeclaration ||
- tree.textOf(Part.kind, statement) !== "var" ||
+ A.textOf(Part.kind, statement) !== "var" ||
holdsComments(statement)
) {
return false;
}
- for (
- let i = tree.fieldCount(Field.declarations, statement) - 1;
- i >= 0;
- i--
- ) {
- const declarator = tree.field(i, Field.declarations, statement);
+ for (let i = A.fieldCount(Field.declarations, statement) - 1; i >= 0; i--) {
+ const declarator = A.field(i, Field.declarations, statement);
if (
- typeOf(tree.field(0, Field.id, declarator)) !== NodeType.Identifier ||
+ typeOf(A.field(0, Field.id, declarator)) !== NodeType.Identifier ||
childOf(Field.init, declarator) !== 0
) {
return false;
@@ -17709,14 +17660,14 @@ const createNodePrinter = (modules) => {
} else {
context.consume(discriminant);
}
- const count = tree.fieldCount(Field.cases, node);
+ const count = A.fieldCount(Field.cases, node);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.cases, node);
- const test = tree.field(0, Field.test, item);
+ const item = A.field(i, Field.cases, node);
+ const test = A.field(0, Field.test, item);
if (test !== 0) context.consume(test);
- const statements = tree.fieldCount(Field.consequent, item);
+ const statements = A.fieldCount(Field.consequent, item);
for (let j = 0; j < statements; j++) {
- const statement = tree.field(j, Field.consequent, item);
+ const statement = A.field(j, Field.consequent, item);
if (
!kept.has(statement) ||
context.get(statement).length === 0 ||
@@ -17756,7 +17707,7 @@ const createNodePrinter = (modules) => {
const type = typeOf(statement);
if (
(type === NodeType.VariableDeclaration &&
- tree.textOf(Part.kind, statement) !== "var") ||
+ A.textOf(Part.kind, statement) !== "var") ||
type === NodeType.ClassDeclaration ||
type === NodeType.FunctionDeclaration
) {
@@ -17806,7 +17757,7 @@ const createNodePrinter = (modules) => {
if (type === NodeType.LogicalExpression) {
const left = childOf(Field.left, node);
const value = evaluateConstant(left);
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (
value !== undefined &&
(operator === "&&"
@@ -17865,7 +17816,7 @@ const createNodePrinter = (modules) => {
const readsInfinity = (node) => {
if (typeOf(node) === NodeType.Identifier) {
return (
- tree.type(node) === NodeType.Literal ||
+ A.type(node) === NodeType.Literal ||
(!keepsGlobalNames &&
!keepsInfinity &&
isGlobalUndefined(node, "Infinity"))
@@ -17873,19 +17824,19 @@ const createNodePrinter = (modules) => {
}
if (
typeOf(node) !== NodeType.MemberExpression ||
- tree.flag(Flag.computed, node) ||
- tree.flag(Flag.optional, node)
+ A.flag(Flag.computed, node) ||
+ A.flag(Flag.optional, node)
) {
return false;
}
const object = childOf(Field.object, node);
- const property = tree.field(0, Field.property, node);
+ const property = A.field(0, Field.property, node);
return (
typeOf(object) === NodeType.Identifier &&
isGlobalUndefined(object, "Number") &&
typeOf(property) === NodeType.Identifier &&
- (tree.name(property) === "POSITIVE_INFINITY" ||
- tree.name(property) === "NEGATIVE_INFINITY")
+ (A.name(property) === "POSITIVE_INFINITY" ||
+ A.name(property) === "NEGATIVE_INFINITY")
);
};
@@ -17909,7 +17860,7 @@ const createNodePrinter = (modules) => {
const type = typeOf(shown);
const parent = parentAt(0);
return (
- (type === NodeType.Literal && typeof tree.value(kept) !== "number") ||
+ (type === NodeType.Literal && typeof A.value(kept) !== "number") ||
type === NodeType.TemplateLiteral ||
type === NodeType.ArrayExpression ||
// A unary operation stands bare where another operator may, a `!`
@@ -17944,7 +17895,7 @@ const createNodePrinter = (modules) => {
const printsAsInfinity = (node) =>
isGlobalUndefined(node, "Infinity")
? !keepsGlobalNames && !keepsInfinity
- : tree.type(node) === NodeType.Literal;
+ : A.type(node) === NodeType.Literal;
/**
* @param {number} node an assignment
@@ -17973,7 +17924,7 @@ const createNodePrinter = (modules) => {
case NodeType.TemplateLiteral:
return true;
case NodeType.Literal: {
- const literal = tree.value(value);
+ const literal = A.value(value);
// `2.x` and `2()` read otherwise than the number.
return (
typeof literal === "string" ||
@@ -17995,7 +17946,7 @@ const createNodePrinter = (modules) => {
}
const kept = foldedOperand(node);
if (typeOf(kept) !== NodeType.AssignmentExpression) return 0;
- const left = typeOf(tree.field(0, Field.left, kept));
+ const left = typeOf(A.field(0, Field.left, kept));
return left === NodeType.ObjectPattern || left === NodeType.ArrayPattern
? 0
: kept;
@@ -18089,7 +18040,7 @@ const createNodePrinter = (modules) => {
const pickedOperand = (node, printing = false) => {
const left = childOf(Field.left, node);
const right = childOf(Field.right, node);
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (operator === "??") {
// What is never `null` or `undefined` leaves `??` nothing to run.
if (
@@ -18141,9 +18092,9 @@ const createNodePrinter = (modules) => {
const printsFolded = (node, kept) => {
if (kept === 0) return false;
const context = /** @type {JavascriptPrintContext} */ (writer);
- const fields = CHILD_FIELDS[tree.type(node)];
+ const fields = CHILD_FIELDS[A.type(node)];
for (let f = 0; f < fields.length; f++) {
- const child = tree.field(0, fields[f], node);
+ const child = A.field(0, fields[f], node);
if (child !== kept) context.consume(child);
}
if (
@@ -18259,7 +18210,7 @@ const createNodePrinter = (modules) => {
if (currentParens) return true;
const leftType =
keptType === NodeType.AssignmentExpression
- ? typeOf(tree.field(0, Field.left, kept))
+ ? typeOf(A.field(0, Field.left, kept))
: 0;
// An object pattern's assignment takes them anywhere.
if (leftType === NodeType.ObjectPattern) return false;
@@ -18297,8 +18248,8 @@ const createNodePrinter = (modules) => {
case NodeType.ReturnStatement: {
const text = /** @type {JavascriptPrintContext} */ (writer).get(kept);
return (
- tree.field(0, Field.left, parent) !== node &&
- tree.field(0, Field.id, parent) !== node &&
+ A.field(0, Field.left, parent) !== node &&
+ A.field(0, Field.id, parent) !== node &&
!text.includes(",") &&
!HOLDS_IN_TEXT.test(text)
);
@@ -18338,7 +18289,7 @@ const createNodePrinter = (modules) => {
const readsDeclared = (node) => {
while (typeOf(node) === NodeType.SequenceExpression) {
node = itemOf(
- tree.fieldCount(Field.expressions, node) - 1,
+ A.fieldCount(Field.expressions, node) - 1,
Field.expressions,
node
);
@@ -18375,7 +18326,7 @@ const createNodePrinter = (modules) => {
if (pickedBranch(parent) !== child) return 0;
break;
case NodeType.UnaryExpression: {
- const operator = tree.textOf(Part.operator, parent);
+ const operator = A.textOf(Part.operator, parent);
if (operator !== "delete" && operator !== "typeof") return 0;
// A declared name reads alike bare under `typeof`.
if (operator === "typeof" && readsDeclared(node)) return 0;
@@ -18408,7 +18359,7 @@ const createNodePrinter = (modules) => {
const runsNothing = (statement) =>
dropsSideEffectFree &&
dropped[statement] === 0 &&
- tree.textOf(Part.directive, statement) === null &&
+ A.textOf(Part.directive, statement) === null &&
!holdsComments(statement) &&
isPureValue(childOf(Field.expression, statement));
@@ -18421,7 +18372,7 @@ const createNodePrinter = (modules) => {
case NodeType.FunctionDeclaration:
return true;
case NodeType.VariableDeclaration:
- if (tree.textOf(Part.kind, node) === "var") return true;
+ if (A.textOf(Part.kind, node) === "var") return true;
return undefined;
case NodeType.FunctionExpression:
case NodeType.ArrowFunctionExpression:
@@ -18463,7 +18414,7 @@ const createNodePrinter = (modules) => {
*/
const discountRead = (node) => {
if (
- tree.type(node) !== NodeType.Identifier ||
+ A.type(node) !== NodeType.Identifier ||
countedWrites.has(node) ||
discounted[node] === 1
) {
@@ -18629,9 +18580,9 @@ const createNodePrinter = (modules) => {
if (typeOf(declaration) !== NodeType.VariableDeclaration) {
return dropped[declaration] === 1;
}
- const count = tree.fieldCount(Field.declarations, declaration);
+ const count = A.fieldCount(Field.declarations, declaration);
for (let i = 0; i < count; i++) {
- if (dropped[tree.field(i, Field.declarations, declaration)] !== 1) {
+ if (dropped[A.field(i, Field.declarations, declaration)] !== 1) {
return false;
}
}
@@ -18646,18 +18597,18 @@ const createNodePrinter = (modules) => {
*/
const noteReexports = (program) => {
if (!dropsUnused || mangledNames === null || beautifies) return;
- const count = tree.fieldCount(Field.body, program);
+ const count = A.fieldCount(Field.body, program);
/** @type {Map} */
const listed = new Map();
/** @type {number[]} */
const imports = [];
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, program);
+ const statement = A.field(i, Field.body, program);
const type = typeOf(statement);
if (type === NodeType.ImportDeclaration) {
if (
- tree.fieldCount(Field.specifiers, statement) !== 0 &&
- !tree.textOf(Part.phase, statement) &&
+ A.fieldCount(Field.specifiers, statement) !== 0 &&
+ !A.textOf(Part.phase, statement) &&
!holdsComments(statement)
) {
imports.push(statement);
@@ -18666,20 +18617,20 @@ const createNodePrinter = (modules) => {
}
if (
type !== NodeType.ExportNamedDeclaration ||
- tree.field(0, Field.declaration, statement) !== 0 ||
- tree.field(0, Field.source, statement) !== 0 ||
+ A.field(0, Field.declaration, statement) !== 0 ||
+ A.field(0, Field.source, statement) !== 0 ||
holdsComments(statement)
) {
continue;
}
- const specifiers = tree.fieldCount(Field.specifiers, statement);
+ const specifiers = A.fieldCount(Field.specifiers, statement);
if (specifiers !== 0) {
if (exportLists.length !== 0) joinedLists.add(statement);
exportLists.push(statement);
}
for (let j = 0; j < specifiers; j++) {
- const specifier = tree.field(j, Field.specifiers, statement);
- const definition = mangledNames[tree.field(0, Field.local, specifier)];
+ const specifier = A.field(j, Field.specifiers, statement);
+ const definition = mangledNames[A.field(0, Field.local, specifier)];
if (!isMinifierVariable(definition)) continue;
const list = listed.get(definition);
if (list === undefined) listed.set(definition, [specifier]);
@@ -18692,20 +18643,20 @@ const createNodePrinter = (modules) => {
/** @type {Map} */
const sources = new Map();
for (const statement of imports) {
- const specifiers = tree.fieldCount(Field.specifiers, statement);
+ const specifiers = A.fieldCount(Field.specifiers, statement);
let moves = true;
// A name nothing reads goes, the module loading all the same.
let unread = 0;
for (let j = 0; j < specifiers; j++) {
- if (isUnreadImport(tree.field(j, Field.specifiers, statement))) {
+ if (isUnreadImport(A.field(j, Field.specifiers, statement))) {
unread++;
}
}
if (unread === specifiers) continue;
for (let j = 0; moves && j < specifiers; j++) {
- const specifier = tree.field(j, Field.specifiers, statement);
+ const specifier = A.field(j, Field.specifiers, statement);
if (isUnreadImport(specifier)) continue;
- const definition = mangledNames[tree.field(0, Field.local, specifier)];
+ const definition = mangledNames[A.field(0, Field.local, specifier)];
const list = isMinifierVariable(definition)
? listed.get(definition)
: undefined;
@@ -18730,16 +18681,16 @@ const createNodePrinter = (modules) => {
}
if (!moves) continue;
reexportedImports.add(statement);
- if (tree.fieldCount(Field.attributes, statement) === 0) {
- const source = tree.value(tree.field(0, Field.source, statement));
+ if (A.fieldCount(Field.attributes, statement) === 0) {
+ const source = A.value(A.field(0, Field.source, statement));
const first = sources.get(/** @type {string} */ (source));
if (first === undefined) {
sources.set(/** @type {string} */ (source), statement);
reexportsAlike.set(statement, []);
} else if (
- typeOf(tree.field(0, Field.specifiers, statement)) !==
+ typeOf(A.field(0, Field.specifiers, statement)) !==
NodeType.ImportNamespaceSpecifier &&
- typeOf(tree.field(0, Field.specifiers, first)) !==
+ typeOf(A.field(0, Field.specifiers, first)) !==
NodeType.ImportNamespaceSpecifier
) {
/** @type {number[]} */ (reexportsAlike.get(first)).push(statement);
@@ -18747,12 +18698,12 @@ const createNodePrinter = (modules) => {
}
}
for (let j = 0; j < specifiers; j++) {
- const specifier = tree.field(j, Field.specifiers, statement);
+ const specifier = A.field(j, Field.specifiers, statement);
if (isUnreadImport(specifier)) continue;
const list = /** @type {number[]} */ (
listed.get(
/** @type {MinifierVariable} */ (
- mangledNames[tree.field(0, Field.local, specifier)]
+ mangledNames[A.field(0, Field.local, specifier)]
)
)
);
@@ -18768,22 +18719,22 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printReexport = (node) => {
- const count = tree.fieldCount(Field.specifiers, node);
+ const count = A.fieldCount(Field.specifiers, node);
if (mergedReexports.has(node)) {
// The first loading its module prints its names.
for (let i = 0; i < count; i++) {
- skipNode(tree.field(i, Field.specifiers, node));
+ skipNode(A.field(i, Field.specifiers, node));
}
return;
}
output.print("export");
- const first = tree.field(0, Field.specifiers, node);
+ const first = A.field(0, Field.specifiers, node);
if (typeOf(first) === NodeType.ImportNamespaceSpecifier) {
skipNode(first);
output.print("*as");
output.space();
printForeignName(
- tree.field(
+ A.field(
0,
Field.exported,
/** @type {number[]} */ (reexportsOf.get(first))[0]
@@ -18795,7 +18746,7 @@ const createNodePrinter = (modules) => {
output.print("{");
let listed = 0;
for (let i = 0; i < count; i++) {
- skipNode(tree.field(i, Field.specifiers, node));
+ skipNode(A.field(i, Field.specifiers, node));
}
const alike = reexportsAlike.get(node);
for (const owner of alike === undefined || alike.length === 0
@@ -18815,20 +18766,20 @@ const createNodePrinter = (modules) => {
* @returns {number} how many it printed then
*/
const printReexportNames = (node, listed) => {
- const count = tree.fieldCount(Field.specifiers, node);
+ const count = A.fieldCount(Field.specifiers, node);
for (let i = 0; i < count; i++) {
- const specifier = tree.field(i, Field.specifiers, node);
+ const specifier = A.field(i, Field.specifiers, node);
const foreign =
typeOf(specifier) === NodeType.ImportDefaultSpecifier
? 0
- : tree.field(0, Field.imported, specifier);
+ : A.field(0, Field.imported, specifier);
const name = foreign === 0 ? "default" : moduleName(foreign);
const exports = reexportsOf.get(specifier);
// A name nothing reads exports nothing.
if (exports === undefined) continue;
for (const exported of exports) {
if (listed++) output.print(",");
- const as = tree.field(0, Field.exported, exported);
+ const as = A.field(0, Field.exported, exported);
if (foreign === 0) output.print("default");
else printForeignName(foreign);
if (moduleName(as) !== name) {
@@ -18866,7 +18817,7 @@ const createNodePrinter = (modules) => {
const takeIn = (node, parent) => {
const type = typeOf(node);
if (type === NodeType.Literal) {
- const value = tree.value(node);
+ const value = A.value(node);
if (typeof value !== "string" || !takesBacktick(node, parent)) {
return true;
}
@@ -18875,17 +18826,17 @@ const createNodePrinter = (modules) => {
}
if (
type === NodeType.ExpressionStatement &&
- tree.textOf(Part.directive, node) !== null
+ A.textOf(Part.directive, node) !== null
) {
return false;
}
// A template printing as written spells the program's strings too.
if (type === NodeType.TemplateLiteral) strings++;
- const fields = CHILD_FIELDS[tree.type(node)];
+ const fields = CHILD_FIELDS[A.type(node)];
for (let f = 0; f < fields.length; f++) {
- const count = tree.fieldCount(fields[f], node);
+ const count = A.fieldCount(fields[f], node);
for (let i = 0; i < count; i++) {
- const child = tree.field(i, fields[f], node);
+ const child = A.field(i, fields[f], node);
if (child !== 0 && !takeIn(child, node)) return false;
}
}
@@ -18904,7 +18855,7 @@ const createNodePrinter = (modules) => {
*/
const takesBacktick = (node, parent) => {
// An attribute reads as terser's `Property`, but its value is a string.
- if (parent > 0 && tree.type(parent) === NodeType.ImportAttribute) {
+ if (parent > 0 && A.type(parent) === NodeType.ImportAttribute) {
return false;
}
switch (typeOf(parent)) {
@@ -18920,8 +18871,7 @@ const createNodePrinter = (modules) => {
case NodeType.MethodDefinition:
case NodeType.PropertyDefinition:
return (
- childOf(Field.key, parent) !== node ||
- tree.flag(Flag.computed, parent)
+ childOf(Field.key, parent) !== node || A.flag(Flag.computed, parent)
);
case NodeType.CallExpression:
case NodeType.NewExpression: {
@@ -18930,12 +18880,12 @@ const createNodePrinter = (modules) => {
return !(
childOf(Field.callee, parent) !== node &&
((typeOf(callee) === NodeType.Identifier &&
- tree.name(callee) === "require") ||
+ A.name(callee) === "require") ||
(typeOf(callee) === NodeType.MemberExpression &&
- !tree.flag(Flag.computed, callee) &&
+ !A.flag(Flag.computed, callee) &&
typeOf(childOf(Field.object, callee)) === NodeType.Identifier &&
- tree.name(childOf(Field.object, callee)) === "Object" &&
- tree.name(childOf(Field.property, callee)) === "defineProperty"))
+ A.name(childOf(Field.object, callee)) === "Object" &&
+ A.name(childOf(Field.property, callee)) === "defineProperty"))
);
}
default:
@@ -18976,8 +18926,8 @@ const createNodePrinter = (modules) => {
* @returns {number} what its one statement calls, 0 where it holds another statement
*/
const programCallee = (program) => {
- if (tree.fieldCount(Field.body, program) !== 1) return 0;
- const statement = tree.field(0, Field.body, program);
+ if (A.fieldCount(Field.body, program) !== 1) return 0;
+ const statement = A.field(0, Field.body, program);
if (typeOf(statement) !== NodeType.ExpressionStatement) return 0;
const call = childOf(Field.expression, statement);
return typeOf(call) === NodeType.CallExpression
@@ -18993,8 +18943,8 @@ const createNodePrinter = (modules) => {
* @returns {number} the function, 0 for none
*/
const functionOnlyCalled = (program) => {
- if (keepsWrapper || tree.fieldCount(Field.body, program) !== 1) return 0;
- const fn = calledInPlace(tree.field(0, Field.body, program), false);
+ if (keepsWrapper || A.fieldCount(Field.body, program) !== 1) return 0;
+ const fn = calledInPlace(A.field(0, Field.body, program), false);
if (fn === 0) return 0;
unwrapsInBlock = bindsInBody(fn);
return fn;
@@ -19007,12 +18957,12 @@ const createNodePrinter = (modules) => {
*/
const passesOnlyInlined = (call, fn) => {
if (constantArguments.size === 0) return false;
- const count = tree.fieldCount(Field.params, fn);
- if (count !== tree.fieldCount(Field.arguments, call)) return false;
+ const count = A.fieldCount(Field.params, fn);
+ if (count !== A.fieldCount(Field.arguments, call)) return false;
for (let i = 0; i < count; i++) {
if (
!inlinesArgument(
- tree.field(i, Field.params, fn),
+ A.field(i, Field.params, fn),
itemOf(i, Field.arguments, call)
)
) {
@@ -19029,11 +18979,11 @@ const createNodePrinter = (modules) => {
const printedValueOf = (statement) => {
if (
typeOf(statement) !== NodeType.VariableDeclaration ||
- tree.fieldCount(Field.declarations, statement) !== 1
+ A.fieldCount(Field.declarations, statement) !== 1
) {
return 0;
}
- const declarator = tree.field(0, Field.declarations, statement);
+ const declarator = A.field(0, Field.declarations, statement);
return dropped[declarator] === 1 &&
keepsEffect[declarator] === 1 &&
!hasEdgeComments(declarator)
@@ -19057,7 +19007,7 @@ const createNodePrinter = (modules) => {
);
const operator =
typeOf(expression) === NodeType.UnaryExpression
- ? tree.textOf(Part.operator, expression)
+ ? A.textOf(Part.operator, expression)
: null;
// A `!` changes what a `return` gives; only `void` keeps it `undefined`.
return (operator === "void" ||
@@ -19126,14 +19076,14 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether its statements declare a `let`, `const` or class that stays
*/
const bindsInBody = (fn) => {
- const body = tree.field(0, Field.body, fn);
- const count = tree.fieldCount(Field.body, body);
+ const body = A.field(0, Field.body, fn);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
const type = typeOf(item);
if (
((type === NodeType.VariableDeclaration &&
- tree.textOf(Part.kind, item) !== "var") ||
+ A.textOf(Part.kind, item) !== "var") ||
type === NodeType.ClassDeclaration) &&
!bindsNothing(item)
) {
@@ -19149,12 +19099,12 @@ const createNodePrinter = (modules) => {
*/
const hoistsName = (declaration) => {
if (hoistedDefinitions.size === 0) return false;
- const count = tree.fieldCount(Field.declarations, declaration);
+ const count = A.fieldCount(Field.declarations, declaration);
for (let i = 0; i < count; i++) {
- const id = tree.field(
+ const id = A.field(
0,
Field.id,
- tree.field(i, Field.declarations, declaration)
+ A.field(i, Field.declarations, declaration)
);
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[id];
if (
@@ -19180,10 +19130,7 @@ const createNodePrinter = (modules) => {
const children = at.childScopes;
for (let i = 0; i < children.length; i++) {
const child = /** @type {MinifierScope} */ (children[i]);
- if (
- tree.start(child.node) <= position &&
- position < tree.end(child.node)
- ) {
+ if (A.start(child.node) <= position && position < A.end(child.node)) {
at = child;
found = true;
break;
@@ -19210,10 +19157,10 @@ const createNodePrinter = (modules) => {
const definitions = [];
for (let i = 0; i < placedVars.length; i++) {
const declaration = placedVars[i];
- const count = tree.fieldCount(Field.declarations, declaration);
+ const count = A.fieldCount(Field.declarations, declaration);
for (let j = 0; j < count; j++) {
- const declarator = tree.field(j, Field.declarations, declaration);
- const id = tree.field(0, Field.id, declarator);
+ const declarator = A.field(j, Field.declarations, declaration);
+ const id = A.field(0, Field.id, declarator);
const definition =
typeOf(id) === NodeType.Identifier ? mangledNames[id] : undefined;
if (
@@ -19239,7 +19186,7 @@ const createNodePrinter = (modules) => {
// A function moved to its call is seen from the call's scopes there.
const first =
typeOf(childOf(Field.callee, call)) === NodeType.Identifier
- ? scopeAt(own, tree.start(call))
+ ? scopeAt(own, A.start(call))
: /** @type {MinifierScope} */ (own.upper);
const around = /** @type {MinifierScope} */ (first.variableScope);
if (
@@ -19326,7 +19273,7 @@ const createNodePrinter = (modules) => {
: callOfStatement(statement);
if (
typeOf(call) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, call) ||
+ A.flag(Flag.optional, call) ||
hasEdgeComments(call)
) {
return 0;
@@ -19342,9 +19289,9 @@ const createNodePrinter = (modules) => {
// A declaration's one read is this call: its body reads not its name,
// nor, nested, may an expression's.
(type !== NodeType.FunctionDeclaration &&
- (nested ? readsFunctionName(fn) : tree.field(0, Field.id, fn) !== 0)) ||
- tree.flag(Flag.async, fn) ||
- tree.flag(Flag.generator, fn) ||
+ (nested ? readsFunctionName(fn) : A.field(0, Field.id, fn) !== 0)) ||
+ A.flag(Flag.async, fn) ||
+ A.flag(Flag.generator, fn) ||
hasEdgeComments(fn)
) {
return 0;
@@ -19353,15 +19300,15 @@ const createNodePrinter = (modules) => {
// which nothing in the body may then hide.
let substitutes = false;
if (
- tree.fieldCount(Field.params, fn) !== 0 ||
- tree.fieldCount(Field.arguments, call) !== 0
+ A.fieldCount(Field.params, fn) !== 0 ||
+ A.fieldCount(Field.arguments, call) !== 0
) {
if (!nested) return 0;
if (!passesOnlyInlined(call, fn)) {
// WHY: a body of more statements renamed so no longer repeats
// the text a helper prints as elsewhere, which deflate codes in less.
if (
- tree.fieldCount(Field.body, tree.field(0, Field.body, fn)) > 2 ||
+ A.fieldCount(Field.body, A.field(0, Field.body, fn)) > 2 ||
!passesFixedNames(fn, call) ||
!passesPrintedNames(call, fn)
) {
@@ -19370,23 +19317,23 @@ const createNodePrinter = (modules) => {
substitutes = true;
}
}
- const body = tree.field(0, Field.body, fn);
+ const body = A.field(0, Field.body, fn);
if (typeOf(body) !== NodeType.BlockStatement || hasEdgeComments(body)) {
return 0;
}
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (
typeOf(item) === NodeType.ExpressionStatement &&
- tree.textOf(Part.directive, item) !== null
+ A.textOf(Part.directive, item) !== null
) {
return 0;
}
}
const arrow = type === NodeType.ArrowFunctionExpression;
// Nothing reading the call, the `return` ending the body prints what it runs.
- const last = count === 0 ? 0 : tree.field(count - 1, Field.body, body);
+ const last = count === 0 ? 0 : A.field(count - 1, Field.body, body);
const tail =
nested &&
typeOf(statement) !== NodeType.ReturnStatement &&
@@ -19395,7 +19342,7 @@ const createNodePrinter = (modules) => {
? last
: 0;
const reads = findNode(body, (node) => {
- switch (tree.type(node)) {
+ switch (A.type(node)) {
case NodeType.FunctionExpression:
case NodeType.ArrowFunctionExpression:
case NodeType.ClassExpression:
@@ -19412,7 +19359,7 @@ const createNodePrinter = (modules) => {
// A `var` binds in the scope around the block, where it may,
// even one a dropped statement prints its name for.
if (bindsNothing(node) && !hoistsName(node)) return undefined;
- if (tree.textOf(Part.kind, node) !== "var") {
+ if (A.textOf(Part.kind, node) !== "var") {
return substitutes || undefined;
}
if (!nested) return true;
@@ -19421,10 +19368,9 @@ const createNodePrinter = (modules) => {
case NodeType.LabeledStatement:
return nested || undefined;
case NodeType.Identifier:
- return tree.name(node) === "eval" ||
- (!arrow && tree.name(node) === "arguments") ||
- (nested &&
- (tree.name(node) === "await" || tree.name(node) === "yield"))
+ return A.name(node) === "eval" ||
+ (!arrow && A.name(node) === "arguments") ||
+ (nested && (A.name(node) === "await" || A.name(node) === "yield"))
? true
: undefined;
case NodeType.ThisExpression:
@@ -19477,11 +19423,11 @@ const createNodePrinter = (modules) => {
}
// A parameter passed a name prints that name.
const passed = Math.min(
- tree.fieldCount(Field.params, fn),
- tree.fieldCount(Field.arguments, call)
+ A.fieldCount(Field.params, fn),
+ A.fieldCount(Field.arguments, call)
);
for (let i = 0; i < passed; i++) {
- const param = tree.field(i, Field.params, fn);
+ const param = A.field(i, Field.params, fn);
const argument = itemOf(i, Field.arguments, call);
if (inlinesArgument(param, argument)) continue;
substituted.set(
@@ -19500,9 +19446,9 @@ const createNodePrinter = (modules) => {
noteUnreadValue(value);
}
}
- const body = tree.field(0, Field.body, fn);
- if (tree.fieldCount(Field.body, body) === 1) {
- const type = typeOf(tree.field(0, Field.body, body));
+ const body = A.field(0, Field.body, fn);
+ if (A.fieldCount(Field.body, body) === 1) {
+ const type = typeOf(A.field(0, Field.body, body));
if (
type !== NodeType.VariableDeclaration &&
type !== NodeType.ClassDeclaration
@@ -19519,7 +19465,7 @@ const createNodePrinter = (modules) => {
*/
const heldByReads = (candidate) => {
const type = typeOf(candidate);
- const id = tree.field(0, Field.id, candidate);
+ const id = A.field(0, Field.id, candidate);
if (!mayGoUnread(id)) return 0;
if (type === NodeType.FunctionDeclaration) return id;
if (type === NodeType.ClassDeclaration) {
@@ -19579,10 +19525,7 @@ const createNodePrinter = (modules) => {
}
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[node];
const declaring = held.get(definition);
- if (
- declaring === undefined ||
- tree.field(0, Field.id, declaring) === node
- ) {
+ if (declaring === undefined || A.field(0, Field.id, declaring) === node) {
return;
}
reads.push(definition);
@@ -19636,14 +19579,11 @@ const createNodePrinter = (modules) => {
*/
const earlyPrintStart = (read) => {
for (const [outerRead, outer] of earlyDefuns) {
- if (
- tree.start(read) > tree.start(outer) &&
- tree.end(read) <= tree.end(outer)
- ) {
+ if (A.start(read) > A.start(outer) && A.end(read) <= A.end(outer)) {
return earlyPrintStart(outerRead);
}
}
- return tree.start(read);
+ return A.start(read);
};
/**
@@ -19672,13 +19612,13 @@ const createNodePrinter = (modules) => {
const fn = declaredFunctions.get(definition);
// `arguments` reads each argument passed, a parameter or not.
if (fn === undefined || readsArguments(fn)) continue;
- const params = tree.fieldCount(Field.params, fn);
+ const params = A.fieldCount(Field.params, fn);
// A rest reads every argument from its own on, and a default may read
// `arguments`, which `readsArguments` looks for in the body alone.
if (!plainParameters(fn, params)) continue;
// A spread may pass none, moving every argument after it down.
if (spreadsArgument(call)) continue;
- for (let i = tree.fieldCount(Field.arguments, call) - 1; i >= 0; i--) {
+ for (let i = A.fieldCount(Field.arguments, call) - 1; i >= 0; i--) {
const argument = itemOf(i, Field.arguments, call);
if (trimmedArguments.has(argument)) continue;
// A comment anywhere in it may be one that prints, as a license.
@@ -19742,7 +19682,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it passes a spread
*/
const spreadsArgument = (call) => {
- const count = tree.fieldCount(Field.arguments, call);
+ const count = A.fieldCount(Field.arguments, call);
for (let i = 0; i < count; i++) {
if (typeOf(itemOf(i, Field.arguments, call)) === NodeType.SpreadElement) {
return true;
@@ -19833,7 +19773,7 @@ const createNodePrinter = (modules) => {
if (
declarator === undefined ||
moveReaders.get(read) !== functionOf(definition) ||
- tree.start(read) < tree.end(declarator)
+ A.start(read) < A.end(declarator)
) {
readsNested.add(definition);
}
@@ -19868,11 +19808,11 @@ const createNodePrinter = (modules) => {
) {
continue;
}
- const count = tree.fieldCount(Field.body, list);
+ const count = A.fieldCount(Field.body, list);
let j = 0;
- while (tree.field(j, Field.body, list) !== statement) j++;
+ while (A.field(j, Field.body, list) !== statement) j++;
for (j++; j < count; j++) {
- const next = tree.field(j, Field.body, list);
+ const next = A.field(j, Field.body, list);
if (dropped[next] !== 1 && neverReached(next)) {
dropped[next] = 1;
findNode(next, discountRead);
@@ -19895,7 +19835,7 @@ const createNodePrinter = (modules) => {
(typeOf(parent) === NodeType.BlockStatement ||
typeOf(parent) === NodeType.Program ||
(typeOf(parent) === NodeType.IfStatement &&
- tree.field(0, Field.alternate, parent) === 0)) &&
+ A.field(0, Field.alternate, parent) === 0)) &&
!foldedSwitches.has(statement) &&
!holdsComments(statement) &&
printedCases(statement) === 0 &&
@@ -19915,7 +19855,7 @@ const createNodePrinter = (modules) => {
LISTS_STATEMENTS[typeOf(laterLoops[i + 1])] === 1 &&
!holdsComments(statement) &&
(typeOf(statement) === NodeType.WhileStatement ||
- tree.field(0, Field.init, statement) === 0) &&
+ A.field(0, Field.init, statement) === 0) &&
(test === 0 || isPureValue(test))
) {
dropped[statement] = 1;
@@ -19989,10 +19929,10 @@ const createNodePrinter = (modules) => {
statement !== 0 &&
dropped[statement] === 0 &&
!emptyTries.has(statement) &&
- listsNothing(tree.field(0, Field.block, statement)) &&
+ listsNothing(A.field(0, Field.block, statement)) &&
!holdsComments(statement) &&
// A function a read prints may yet come back to the block.
- !findNode(tree.field(0, Field.block, statement), findHoisted)
+ !findNode(A.field(0, Field.block, statement), findHoisted)
) {
if (dropEmptyTry(statement)) changed = true;
else laterTries[i] = 0;
@@ -20071,7 +20011,7 @@ const createNodePrinter = (modules) => {
? moves[i]
: childOf(Field.init, moves[i]);
if (fn === moves[i]) {
- if (tree.start(moves[i + 1]) < tree.start(fn)) {
+ if (A.start(moves[i + 1]) < A.start(fn)) {
// The walk is past the first node printed, too late to print it first.
if (moves[i + 1] === firstPrinted) {
dropped[fn] = 0;
@@ -20109,9 +20049,9 @@ const createNodePrinter = (modules) => {
const inner = moves[i + 1];
readsLater =
dropped[moves[i]] === 1 &&
- tree.start(inner) > tree.start(defun) &&
- tree.end(inner) <= tree.end(defun) &&
- tree.end(moves[i]) > printedFrom &&
+ A.start(inner) > A.start(defun) &&
+ A.end(inner) <= A.end(defun) &&
+ A.end(moves[i]) > printedFrom &&
!earlyDefuns.has(inner);
}
if (!readsLater) continue;
@@ -20222,7 +20162,7 @@ const createNodePrinter = (modules) => {
const candidate = candidates[i];
if (dropped[candidate] !== 1 && aliasesRead[candidate] !== 3) continue;
const definition = /** @type {TreeDefinition[]} */ (mangledNames)[
- tree.field(0, Field.id, candidate)
+ A.field(0, Field.id, candidate)
];
if (
isMinifierVariable(definition) &&
@@ -20235,7 +20175,7 @@ const createNodePrinter = (modules) => {
}
for (let i = 0; i < namedExpressions.length; i++) {
const node = namedExpressions[i];
- const id = tree.field(0, Field.id, node);
+ const id = A.field(0, Field.id, node);
if (
dropsName(
id,
@@ -20261,10 +20201,10 @@ const createNodePrinter = (modules) => {
// or, as a `wrap` or `enclose` wrapper, stays.
const only = keepsWrapper ? programCallee(program) : unwrappedFunction;
if (only !== 0 && unreadBodies.delete(only)) {
- const body = tree.field(0, Field.body, only);
- const count = tree.fieldCount(Field.body, body);
+ const body = A.field(0, Field.body, only);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- unreadStatements.delete(tree.field(i, Field.body, body));
+ unreadStatements.delete(A.field(i, Field.body, body));
}
}
};
@@ -20278,9 +20218,9 @@ const createNodePrinter = (modules) => {
return false;
}
let printed = 0;
- const count = tree.fieldCount(Field.body, node);
+ const count = A.fieldCount(Field.body, node);
for (let i = 0; i < count && printed < 2; i++) {
- if (!printsNothing(tree.field(i, Field.body, node))) printed++;
+ if (!printsNothing(A.field(i, Field.body, node))) printed++;
}
return printed > 1;
};
@@ -20295,7 +20235,7 @@ const createNodePrinter = (modules) => {
compresses &&
dropsDeadCode &&
!holdsComments(node) &&
- !findNode(tree.field(0, Field.body, node), findLoopExit) &&
+ !findNode(A.field(0, Field.body, node), findLoopExit) &&
evaluateConstant(childOf(Field.test, node))
);
@@ -20320,9 +20260,9 @@ const createNodePrinter = (modules) => {
}
let statement = 0;
let empty = 0;
- const count = tree.fieldCount(Field.body, block);
+ const count = A.fieldCount(Field.body, block);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, block);
+ const item = A.field(i, Field.body, block);
if (printsNothing(item)) {
// `;` is shorter than the `{}` of a block printing nothing.
if (empty === 0 && typeOf(item) === NodeType.EmptyStatement) {
@@ -20366,15 +20306,14 @@ const createNodePrinter = (modules) => {
type === NodeType.VariableDeclaration
? // One printing a value alone prints as that statement.
printedValues(statement) !== 1 &&
- (tree.textOf(Part.kind, statement) !== "var" ||
- printsApart(statement))
+ (A.textOf(Part.kind, statement) !== "var" || printsApart(statement))
: type === NodeType.FunctionDeclaration ||
type === NodeType.ClassDeclaration
) {
return 0;
}
return typeOf(parent) === NodeType.IfStatement &&
- tree.field(0, Field.consequent, parent) === block &&
+ A.field(0, Field.consequent, parent) === block &&
elseOf(parent) !== 0 &&
endsInOpenIf(statement)
? 0
@@ -20395,7 +20334,7 @@ const createNodePrinter = (modules) => {
}
return (
typeOf(exit) === NodeType.ContinueStatement &&
- tree.field(0, Field.label, exit) === 0
+ A.field(0, Field.label, exit) === 0
);
};
@@ -20406,8 +20345,8 @@ const createNodePrinter = (modules) => {
*/
const restAfter = (body, node) => {
let rest = 0;
- for (let i = tree.fieldCount(Field.body, body) - 1; i >= 0; i--) {
- const statement = tree.field(i, Field.body, body);
+ for (let i = A.fieldCount(Field.body, body) - 1; i >= 0; i--) {
+ const statement = A.field(i, Field.body, body);
if (statement === node) break;
if (printsNothing(statement)) continue;
if (rest !== 0) return 0;
@@ -20425,7 +20364,7 @@ const createNodePrinter = (modules) => {
*/
const dropTailExits = (holder) => {
const type = typeOf(holder);
- const body = tree.field(0, Field.body, holder);
+ const body = A.field(0, Field.body, holder);
if (FUNCTION_TYPES[type] === 1) {
if (
typeOf(body) !== NodeType.BlockStatement ||
@@ -20462,8 +20401,8 @@ const createNodePrinter = (modules) => {
const dropTailExit = (statement, holder, kind) => {
switch (typeOf(statement)) {
case NodeType.BlockStatement: {
- for (let i = tree.fieldCount(Field.body, statement) - 1; i >= 0; i--) {
- const item = tree.field(i, Field.body, statement);
+ for (let i = A.fieldCount(Field.body, statement) - 1; i >= 0; i--) {
+ const item = A.field(i, Field.body, statement);
if (printsNothing(item)) continue;
dropTailExit(item, holder, kind);
// Gone, it leaves the statement before it last.
@@ -20476,7 +20415,7 @@ const createNodePrinter = (modules) => {
if (mergedExits[statement] !== 0) {
// The last of a run leaving alike takes the run's exit with it.
if ((mergedExits[statement] & 1) === 0) {
- const exit = tree.field(0, Field.consequent, statement);
+ const exit = A.field(0, Field.consequent, statement);
dropTailExit(exit, holder, kind);
if (
typeOf(exit) === NodeType.BlockStatement
@@ -20488,22 +20427,22 @@ const createNodePrinter = (modules) => {
}
return;
}
- dropTailExit(tree.field(0, Field.consequent, statement), holder, kind);
- const alternate = tree.field(0, Field.alternate, statement);
+ dropTailExit(A.field(0, Field.consequent, statement), holder, kind);
+ const alternate = A.field(0, Field.alternate, statement);
if (alternate !== 0) dropTailExit(alternate, holder, kind);
dropKeptNothing(statement);
return;
}
case NodeType.LabeledStatement:
- dropTailExit(tree.field(0, Field.body, statement), holder, kind);
+ dropTailExit(A.field(0, Field.body, statement), holder, kind);
return;
// Its last case's statements run last, falling out of it.
case NodeType.SwitchStatement: {
- const count = tree.fieldCount(Field.cases, statement);
+ const count = A.fieldCount(Field.cases, statement);
if (count === 0) return;
- const item = tree.field(count - 1, Field.cases, statement);
- for (let i = tree.fieldCount(Field.consequent, item) - 1; i >= 0; i--) {
- const inner = tree.field(i, Field.consequent, item);
+ const item = A.field(count - 1, Field.cases, statement);
+ for (let i = A.fieldCount(Field.consequent, item) - 1; i >= 0; i--) {
+ const inner = A.field(i, Field.consequent, item);
if (printsNothing(inner)) continue;
dropTailExit(inner, holder, kind);
if (!printsNothing(inner)) return;
@@ -20512,13 +20451,13 @@ const createNodePrinter = (modules) => {
}
// A `finally` runs past an exit the `try` ends in, its own the last word.
case NodeType.TryStatement: {
- const block = tree.field(0, Field.block, statement);
+ const block = A.field(0, Field.block, statement);
dropTailExit(block, holder, kind);
- const handler = tree.field(0, Field.handler, statement);
+ const handler = A.field(0, Field.handler, statement);
if (handler !== 0) {
- dropTailExit(tree.field(0, Field.body, handler), holder, kind);
+ dropTailExit(A.field(0, Field.body, handler), holder, kind);
}
- const finalizer = tree.field(0, Field.finalizer, statement);
+ const finalizer = A.field(0, Field.finalizer, statement);
if (
dropsDeadCode &&
finalizer !== 0 &&
@@ -20544,7 +20483,7 @@ const createNodePrinter = (modules) => {
const label =
typeOf(statement) === NodeType.ReturnStatement
? 0
- : tree.field(0, Field.label, statement);
+ : A.field(0, Field.label, statement);
let leaves = false;
switch (typeOf(statement)) {
case NodeType.ReturnStatement: {
@@ -20578,7 +20517,7 @@ const createNodePrinter = (modules) => {
const parent = parentAt(level);
const type = typeOf(parent);
if (type === NodeType.IfStatement) {
- if (tree.field(0, Field.consequent, parent) === child) {
+ if (A.field(0, Field.consequent, parent) === child) {
return elseOf(parent) !== 0;
}
} else if (
@@ -20589,7 +20528,7 @@ const createNodePrinter = (modules) => {
} else if (
HOLDS_BODY[type] !== 1 ||
printsAsDo(parent) ||
- tree.field(0, Field.body, parent) !== child
+ A.field(0, Field.body, parent) !== child
) {
return false;
}
@@ -20617,11 +20556,11 @@ const createNodePrinter = (modules) => {
}
let last = 0;
for (
- let i = tree.fieldCount(Field.body, body) - 1;
+ let i = A.fieldCount(Field.body, body) - 1;
i >= 0 && last === 0;
i--
) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (!printsNothing(item)) last = item;
}
if (
@@ -20662,19 +20601,19 @@ const createNodePrinter = (modules) => {
if (hasEdgeComments(argument)) return false;
switch (typeOf(argument)) {
case NodeType.UnaryExpression:
- return tree.textOf(Part.operator, argument) === "void";
+ return A.textOf(Part.operator, argument) === "void";
case NodeType.CallExpression: {
const callee = childOf(Field.callee, argument);
const type = typeOf(callee);
if (
(type !== NodeType.FunctionExpression &&
type !== NodeType.ArrowFunctionExpression) ||
- tree.flag(Flag.async, callee) ||
- tree.flag(Flag.generator, callee)
+ A.flag(Flag.async, callee) ||
+ A.flag(Flag.generator, callee)
) {
return false;
}
- const body = tree.field(0, Field.body, callee);
+ const body = A.field(0, Field.body, callee);
// An arrow's value is what it returns; a function inside returns its own.
return (
typeOf(body) === NodeType.BlockStatement &&
@@ -20690,7 +20629,7 @@ const createNodePrinter = (modules) => {
case NodeType.SequenceExpression:
return isUndefinedValue(
itemOf(
- tree.fieldCount(Field.expressions, argument) - 1,
+ A.fieldCount(Field.expressions, argument) - 1,
Field.expressions,
argument
)
@@ -20712,15 +20651,15 @@ const createNodePrinter = (modules) => {
if (type !== NodeType.ForStatement && type !== NodeType.WhileStatement) {
return;
}
- const body = tree.field(0, Field.body, loop);
+ const body = A.field(0, Field.body, loop);
let first = body;
if (typeOf(body) === NodeType.BlockStatement) {
// Its test would read past a name the block scopes.
if (scopesLexically(body)) return;
first = 0;
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count && first === 0; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (!printsNothing(item)) first = item;
}
}
@@ -20733,7 +20672,7 @@ const createNodePrinter = (modules) => {
) {
return;
}
- const consequent = tree.field(0, Field.consequent, first);
+ const consequent = A.field(0, Field.consequent, first);
const alternate = elseOf(first);
let rest = 0;
if (!isBareBreak(unwrappedBranch(consequent, first))) {
@@ -20765,7 +20704,7 @@ const createNodePrinter = (modules) => {
*/
const isBareBreak = (statement) =>
typeOf(statement) === NodeType.BreakStatement &&
- tree.field(0, Field.label, statement) === 0 &&
+ A.field(0, Field.label, statement) === 0 &&
!hasEdgeComments(statement);
/**
@@ -20782,7 +20721,7 @@ const createNodePrinter = (modules) => {
output.print("&&");
}
if (
- !isBareBreak(unwrappedBranch(tree.field(0, Field.consequent, exit), exit))
+ !isBareBreak(unwrappedBranch(A.field(0, Field.consequent, exit), exit))
) {
// `if(x)y;else break` loops while `x`.
printNode(negated, test !== 0 && !joinsLogical(negated, "&&", false));
@@ -20804,7 +20743,7 @@ const createNodePrinter = (modules) => {
*/
const namesLabel = (label, holder) =>
typeOf(holder) === NodeType.LabeledStatement &&
- tree.name(tree.field(0, Field.label, holder)) === tree.name(label);
+ A.name(A.field(0, Field.label, holder)) === A.name(label);
/**
* terser's `if_return` with a body: `if(t){x();return}y` ending a function
@@ -20815,7 +20754,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const noteExitElse = (node, body, holder) => {
- const block = tree.field(0, Field.consequent, node);
+ const block = A.field(0, Field.consequent, node);
if (
!dropsDeadCode ||
dropped[node] === 1 ||
@@ -20828,13 +20767,13 @@ const createNodePrinter = (modules) => {
) {
return;
}
- const count = tree.fieldCount(Field.body, block);
- const exit = tree.field(count - 1, Field.body, block);
+ const count = A.fieldCount(Field.body, block);
+ const exit = A.field(count - 1, Field.body, block);
if (count < 2 || !leavesBody(exit, holder)) return;
// Only expressions print before the `else`, none an `if` it would take.
let runs = 0;
for (let i = 0; i < count - 1; i++) {
- const statement = tree.field(i, Field.body, block);
+ const statement = A.field(i, Field.body, block);
if (
typeOf(statement) !== NodeType.ExpressionStatement ||
!printsOneStatement(statement, 0)
@@ -20863,7 +20802,7 @@ const createNodePrinter = (modules) => {
runs === 1 &&
typeOf(rest) === NodeType.ExpressionStatement &&
dropped[rest] !== 1 &&
- tree.textOf(Part.directive, rest) === null &&
+ A.textOf(Part.directive, rest) === null &&
!holdsComments(rest) &&
!hasEdgeComments(childOf(Field.test, node)) &&
LOOP_TYPES[typeOf(holder)] === 1
@@ -20883,7 +20822,7 @@ const createNodePrinter = (modules) => {
holder = parentAt(1);
if (
LOOP_TYPES[typeOf(holder)] !== 1 ||
- tree.field(0, Field.body, holder) !== parentAt(0)
+ A.field(0, Field.body, holder) !== parentAt(0)
) {
return 0;
}
@@ -20895,9 +20834,9 @@ const createNodePrinter = (modules) => {
) {
return 0;
}
- const exit = unwrappedBranch(tree.field(0, Field.consequent, node), node);
+ const exit = unwrappedBranch(A.field(0, Field.consequent, node), node);
if (!leavesBody(exit, holder)) return 0;
- const body = tree.field(0, Field.body, holder);
+ const body = A.field(0, Field.body, holder);
const rest = restAfter(body, node);
return rest !== 0 &&
!hasEdgeComments(rest) &&
@@ -20911,8 +20850,8 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it lists a declaration printing, which no statement's body may be bare
*/
const listsDeclaration = (block) => {
- for (let i = tree.fieldCount(Field.body, block) - 1; i >= 0; i--) {
- let statement = tree.field(i, Field.body, block);
+ for (let i = A.fieldCount(Field.body, block) - 1; i >= 0; i--) {
+ let statement = A.field(i, Field.body, block);
// An `if` joined to its loop's test prints as the branch it keeps.
const rest =
breakElses.size === 0 ? undefined : breakElses.get(statement);
@@ -20922,7 +20861,7 @@ const createNodePrinter = (modules) => {
(type === NodeType.FunctionDeclaration ||
type === NodeType.ClassDeclaration ||
(type === NodeType.VariableDeclaration &&
- tree.textOf(Part.kind, statement) !== "var")) &&
+ A.textOf(Part.kind, statement) !== "var")) &&
!printsNothing(statement)
) {
return true;
@@ -20942,13 +20881,13 @@ const createNodePrinter = (modules) => {
holder = parentAt(1);
if (
LOOP_TYPES[typeOf(holder)] !== 1 ||
- tree.field(0, Field.body, holder) !== parentAt(0)
+ A.field(0, Field.body, holder) !== parentAt(0)
) {
return false;
}
body = parentAt(0);
} else {
- body = tree.field(0, Field.body, holder);
+ body = A.field(0, Field.body, holder);
}
if (
elseOf(node) !== 0 ||
@@ -20956,7 +20895,7 @@ const createNodePrinter = (modules) => {
(node < foundSize && mergedExits[node] !== 0) ||
!negatesCheaply(childOf(Field.test, node)) ||
!leavesBody(
- unwrappedBranch(tree.field(0, Field.consequent, node), node),
+ unwrappedBranch(A.field(0, Field.consequent, node), node),
holder
)
) {
@@ -20964,8 +20903,8 @@ const createNodePrinter = (modules) => {
}
let printing = 0;
let last = 0;
- for (let i = tree.fieldCount(Field.body, body) - 1; i >= 0; i--) {
- const statement = tree.field(i, Field.body, body);
+ for (let i = A.fieldCount(Field.body, body) - 1; i >= 0; i--) {
+ const statement = A.field(i, Field.body, body);
if (statement === node) break;
if (printsNothing(statement)) continue;
const type = typeOf(statement);
@@ -20973,7 +20912,7 @@ const createNodePrinter = (modules) => {
type === NodeType.FunctionDeclaration ||
type === NodeType.ClassDeclaration ||
(type === NodeType.VariableDeclaration &&
- tree.textOf(Part.kind, statement) !== "var")
+ A.textOf(Part.kind, statement) !== "var")
) {
return false;
}
@@ -21000,7 +20939,7 @@ const createNodePrinter = (modules) => {
NEGATES_BARE[type] === 1 ||
(type === NodeType.BinaryExpression &&
EQUALITIES.includes(
- /** @type {string} */ (tree.textOf(Part.operator, shown))
+ /** @type {string} */ (A.textOf(Part.operator, shown))
))
);
};
@@ -21031,7 +20970,7 @@ const createNodePrinter = (modules) => {
if (
typeOf(holder) !== NodeType.IfStatement ||
elseOf(holder) !== 0 ||
- tree.field(0, Field.consequent, holder) !==
+ A.field(0, Field.consequent, holder) !==
(parent === holder ? node : parent) ||
(parent !== holder && unwrappedStatement(parent, holder) !== node) ||
hasEdgeComments(node) ||
@@ -21089,7 +21028,7 @@ const createNodePrinter = (modules) => {
* @returns {number} the `if` its body is or unwraps to, printing `&&u)x` for its `if(t`; 0 for none
*/
const andedInner = (node) => {
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
const inner =
typeOf(consequent) === NodeType.BlockStatement
? unwrappedStatement(consequent, node)
@@ -21108,7 +21047,7 @@ const createNodePrinter = (modules) => {
*/
const printAndedBody = (node) => {
if (andedInner(node) === 0) output.print(")");
- printMaybeBracedBody(tree.field(0, Field.consequent, node));
+ printMaybeBracedBody(A.field(0, Field.consequent, node));
};
/**
@@ -21135,7 +21074,7 @@ const createNodePrinter = (modules) => {
// A call of a function written in place may print as its body.
const expression = childOf(Field.expression, statement);
return (
- tree.textOf(Part.directive, statement) === null &&
+ A.textOf(Part.directive, statement) === null &&
!(
isCallType(typeOf(expression)) &&
FUNCTION_TYPES[typeOf(childOf(Field.callee, expression))] === 1
@@ -21168,7 +21107,7 @@ const createNodePrinter = (modules) => {
// A `var` declares its names wherever it stands, as a body too.
case NodeType.VariableDeclaration:
return (
- tree.textOf(Part.kind, statement) === "var" &&
+ A.textOf(Part.kind, statement) === "var" &&
!printsNothing(statement) &&
!printsApart(statement)
);
@@ -21189,7 +21128,7 @@ const createNodePrinter = (modules) => {
return true;
case NodeType.VariableDeclaration:
return (
- tree.textOf(Part.kind, statement) === "var" && !printsApart(statement)
+ A.textOf(Part.kind, statement) === "var" && !printsApart(statement)
);
case NodeType.IfStatement: {
// A known test, or one joined to its loop's, prints the branch it keeps.
@@ -21222,19 +21161,19 @@ const createNodePrinter = (modules) => {
if (!compresses || !dropsDeadCode) return false;
if (typeOf(statement) === NodeType.TryStatement) {
if (emptyTries.size !== 0 && emptyTries.has(statement)) return true;
- const finalizer = tree.field(0, Field.finalizer, statement);
+ const finalizer = A.field(0, Field.finalizer, statement);
return (
- tree.field(0, Field.handler, statement) === 0 &&
+ A.field(0, Field.handler, statement) === 0 &&
finalizer !== 0 &&
listsNothing(finalizer)
);
}
- const body = tree.field(0, Field.body, statement);
+ const body = A.field(0, Field.body, statement);
if (typeOf(body) !== NodeType.BlockStatement) return false;
const value = evaluateConstant(childOf(Field.test, statement));
if (value !== undefined && !value) return true;
- for (let i = tree.fieldCount(Field.body, body) - 1; i >= 0; i--) {
- const item = tree.field(i, Field.body, body);
+ for (let i = A.fieldCount(Field.body, body) - 1; i >= 0; i--) {
+ const item = A.field(i, Field.body, body);
if (!printsNothing(item)) return isBareBreak(item);
}
return false;
@@ -21246,7 +21185,7 @@ const createNodePrinter = (modules) => {
*/
const printsElseOnly = (node) => {
if (elseOf(node) === 0 || hasEdgeComments(node)) return false;
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
return typeOf(consequent) === NodeType.BlockStatement
? bracesNothing(consequent, node)
: printsNothing(consequent);
@@ -21257,7 +21196,7 @@ const createNodePrinter = (modules) => {
* @returns {number} its `else`, 0 for none or one printing nothing, nor comments
*/
const elseOf = (node) => {
- const alternate = tree.field(0, Field.alternate, node);
+ const alternate = A.field(0, Field.alternate, node);
if (alternate === 0 || !compresses || hasEdgeComments(alternate)) {
return alternate;
}
@@ -21282,7 +21221,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
return typeOf(consequent) === NodeType.BlockStatement
? dropped[consequent] === 1 || bracesNothing(consequent, node)
: printsNothing(consequent);
@@ -21313,10 +21252,10 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.body, block);
+ const count = A.fieldCount(Field.body, block);
let printed = 0;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, block);
+ const item = A.field(i, Field.body, block);
if (printedNothing(item)) continue;
if (
typeOf(item) !== NodeType.ExpressionStatement ||
@@ -21337,9 +21276,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether every statement in it prints nothing
*/
const listsNothing = (block) => {
- const count = tree.fieldCount(Field.body, block);
+ const count = A.fieldCount(Field.body, block);
for (let i = 0; i < count; i++) {
- if (!printsNothing(tree.field(i, Field.body, block))) return false;
+ if (!printsNothing(A.field(i, Field.body, block))) return false;
}
return true;
};
@@ -21359,9 +21298,9 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.body, block);
+ const count = A.fieldCount(Field.body, block);
for (let i = 0; i < count; i++) {
- if (!printsNothing(tree.field(i, Field.body, block))) return false;
+ if (!printsNothing(A.field(i, Field.body, block))) return false;
}
return true;
};
@@ -21393,7 +21332,7 @@ const createNodePrinter = (modules) => {
return switchAsIf(node) !== 0;
} else if (HOLDS_BODY[type] === 1) {
parent = node;
- node = tree.field(0, Field.body, node);
+ node = A.field(0, Field.body, node);
} else if (type === NodeType.BlockStatement && parent !== 0) {
// A block printing as its one statement ends where that does.
const inner = compresses ? unwrappedStatement(node, parent) : 0;
@@ -21429,7 +21368,7 @@ const createNodePrinter = (modules) => {
? CONDITIONAL_FORM
: 0;
}
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
const alternate = elseOf(node);
if (alternate !== 0) {
if (
@@ -21614,12 +21553,12 @@ const createNodePrinter = (modules) => {
) {
const consequent = assignedBy(
isIf
- ? unwrappedBranch(tree.field(0, Field.consequent, node), node)
+ ? unwrappedBranch(A.field(0, Field.consequent, node), node)
: childOf(Field.consequent, node)
);
const alternate = assignedBy(
isIf
- ? unwrappedBranch(tree.field(0, Field.alternate, node), node)
+ ? unwrappedBranch(A.field(0, Field.alternate, node), node)
: childOf(Field.alternate, node)
);
if (
@@ -21663,7 +21602,7 @@ const createNodePrinter = (modules) => {
) {
return null;
}
- const operator = /** @type {string} */ (tree.textOf(Part.operator, node));
+ const operator = /** @type {string} */ (A.textOf(Part.operator, node));
const target = childOf(Field.left, node);
// A logical one runs its value only some of the time, which a pure test allows.
if (typeOf(target) !== NodeType.Identifier) return null;
@@ -21744,14 +21683,14 @@ const createNodePrinter = (modules) => {
hoisted === null ||
hoisted[0] !== "=" ||
hoistingHolder(-1) !== 0 ||
- tree.field(0, Field.alternate, node) === 0
+ A.field(0, Field.alternate, node) === 0
) {
return null;
}
/** @type {(boolean | undefined)[]} */
const values = [];
for (const field of [Field.consequent, Field.alternate]) {
- const branch = unwrappedBranch(tree.field(0, field, node), node);
+ const branch = unwrappedBranch(A.field(0, field, node), node);
if (
typeOf(branch) !== NodeType.ExpressionStatement ||
hasEdgeComments(branch)
@@ -21782,7 +21721,7 @@ const createNodePrinter = (modules) => {
* @returns {number} the `return` ending it, which then prints no value; 0 where it does not fold
*/
const foldedReturn = (node) => {
- const alternate = tree.field(0, Field.alternate, node);
+ const alternate = A.field(0, Field.alternate, node);
const end =
alternate === 0
? returnPairs.get(node)
@@ -21797,7 +21736,7 @@ const createNodePrinter = (modules) => {
const value = booleanOf(
childOf(
Field.argument,
- unwrappedBranch(tree.field(0, Field.consequent, node), node)
+ unwrappedBranch(A.field(0, Field.consequent, node), node)
)
);
return value !== undefined &&
@@ -21812,9 +21751,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether that `return` may print its value first: both return one value, no comment between
*/
const swapsReturn = (node, form) => {
- if (tree.field(0, Field.alternate, node) !== 0) return false;
+ if (A.field(0, Field.alternate, node) !== 0) return false;
const next = returnPairs.get(node);
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
return (
next !== undefined &&
exitsWith(next, form) &&
@@ -21940,8 +21879,8 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it printed so
*/
const printsAlikeBranches = (node, form, test, branch, afterReturn) => {
- const consequent = tree.field(0, Field.consequent, node);
- const alternate = tree.field(0, Field.alternate, node);
+ const consequent = A.field(0, Field.consequent, node);
+ const alternate = A.field(0, Field.alternate, node);
const context = /** @type {JavascriptPrintContext} */ (writer);
if (alternate === 0) {
return (
@@ -22024,7 +21963,7 @@ const createNodePrinter = (modules) => {
* @returns {number} the exit after it, where its own exit gives what that one does, else 0
*/
const alikeExit = (node, test) => {
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
const exit = unwrappedBranch(consequent, node);
const next = returnPairs.get(node);
if (
@@ -22063,7 +22002,7 @@ const createNodePrinter = (modules) => {
} else {
skipNode(test);
}
- skipNode(tree.field(0, Field.consequent, node));
+ skipNode(A.field(0, Field.consequent, node));
return true;
};
@@ -22077,15 +22016,15 @@ const createNodePrinter = (modules) => {
*/
const printKnownTestIf = (node, test, branch) => {
const kept = /** @type {number} */ (knownTests.get(node));
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
const gone =
- kept === consequent ? tree.field(0, Field.alternate, node) : consequent;
+ kept === consequent ? A.field(0, Field.alternate, node) : consequent;
if (gone !== 0) {
/** @type {JavascriptPrintContext} */ (writer).consume(gone);
}
const branchStatement =
typeOf(kept) === NodeType.BlockStatement
- ? tree.field(0, Field.body, kept)
+ ? A.field(0, Field.body, kept)
: kept;
// A test running nothing goes, where the branch opens the statement bare.
if (
@@ -22132,7 +22071,7 @@ const createNodePrinter = (modules) => {
!inReturnsChain(-1)
) {
const next =
- tree.field(0, Field.alternate, node) === 0 &&
+ A.field(0, Field.alternate, node) === 0 &&
dropsSideEffectFree &&
isPureValue(test)
? alikeExit(node, test)
@@ -22140,7 +22079,7 @@ const createNodePrinter = (modules) => {
if (next !== 0) {
// Its test runs nothing: it goes, the exit after it printing whole.
skipNode(test);
- skipNode(tree.field(0, Field.consequent, node));
+ skipNode(A.field(0, Field.consequent, node));
keyedExits.add(next);
return;
}
@@ -22151,7 +22090,7 @@ const createNodePrinter = (modules) => {
}
const folded = form === RETURN_FORM ? foldedReturn(node) : 0;
if (folded !== 0) {
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
const negates = !booleanOf(
childOf(Field.argument, unwrappedBranch(consequent, node))
)
@@ -22161,7 +22100,7 @@ const createNodePrinter = (modules) => {
: "!!";
skipNode(consequent);
printNegatedAs(test, negates);
- const alternate = tree.field(0, Field.alternate, node);
+ const alternate = A.field(0, Field.alternate, node);
if (alternate !== 0) {
skipNode(alternate);
output.semicolon();
@@ -22169,8 +22108,8 @@ const createNodePrinter = (modules) => {
return;
}
if (form === CONDITIONAL_FORM && mergedArgument(node) !== -1) {
- const consequent = tree.field(0, Field.consequent, node);
- const alternate = tree.field(0, Field.alternate, node);
+ const consequent = A.field(0, Field.consequent, node);
+ const alternate = A.field(0, Field.alternate, node);
if (
printsMergedCall(
node,
@@ -22191,8 +22130,8 @@ const createNodePrinter = (modules) => {
}
const negates = form === CONDITIONAL_FORM ? hoistedNegation(node) : null;
if (negates !== null) {
- skipNode(tree.field(0, Field.consequent, node));
- skipNode(tree.field(0, Field.alternate, node));
+ skipNode(A.field(0, Field.consequent, node));
+ skipNode(A.field(0, Field.alternate, node));
printNegatedAs(test, negates);
if (!branch) output.semicolon();
return;
@@ -22204,14 +22143,14 @@ const createNodePrinter = (modules) => {
(printsOr(
node,
test,
- tree.field(0, Field.consequent, node),
- tree.field(0, Field.alternate, node)
+ A.field(0, Field.consequent, node),
+ A.field(0, Field.alternate, node)
) ||
printsAnd(
node,
test,
- tree.field(0, Field.consequent, node),
- tree.field(0, Field.alternate, node)
+ A.field(0, Field.consequent, node),
+ A.field(0, Field.alternate, node)
))
) {
if (!branch) output.semicolon();
@@ -22226,10 +22165,10 @@ const createNodePrinter = (modules) => {
output.space();
output.print("?");
output.space();
- printNode(tree.field(0, Field.alternate, node));
+ printNode(A.field(0, Field.alternate, node));
output.space();
output.colon();
- printNode(tree.field(0, Field.consequent, node));
+ printNode(A.field(0, Field.consequent, node));
if (!branch) output.semicolon();
return;
}
@@ -22244,7 +22183,7 @@ const createNodePrinter = (modules) => {
output.space();
swappedReturns.set(
/** @type {number} */ (returnPairs.get(node)),
- tree.field(0, Field.consequent, node)
+ A.field(0, Field.consequent, node)
);
return;
}
@@ -22266,15 +22205,15 @@ const createNodePrinter = (modules) => {
output.space();
output.print("?");
output.space();
- printNode(tree.field(0, Field.consequent, node));
+ printNode(A.field(0, Field.consequent, node));
output.space();
output.colon();
if (form !== CONDITIONAL_FORM) {
- const alternate = tree.field(0, Field.alternate, node);
+ const alternate = A.field(0, Field.alternate, node);
if (alternate !== 0) printNode(alternate);
return;
}
- printNode(tree.field(0, Field.alternate, node));
+ printNode(A.field(0, Field.alternate, node));
if (!branch) output.semicolon();
};
@@ -22307,7 +22246,7 @@ const createNodePrinter = (modules) => {
!(
level !== -1 &&
parentType === NodeType.IfStatement &&
- tree.field(0, Field.alternate, parent) === node &&
+ A.field(0, Field.alternate, parent) === node &&
liftsElse(parent, parentAt(level + 1), level + 1)
)) ||
ifForm(node) !== 0
@@ -22318,7 +22257,7 @@ const createNodePrinter = (modules) => {
return (
alternate !== 0 &&
!hasEdgeComments(alternate) &&
- alwaysLeaves(tree.field(0, Field.consequent, node)) &&
+ alwaysLeaves(A.field(0, Field.consequent, node)) &&
(typeOf(alternate) === NodeType.BlockStatement
? !scopesLexically(alternate)
: !declaresLexically(alternate))
@@ -22333,8 +22272,8 @@ const createNodePrinter = (modules) => {
let last = statement;
if (typeOf(statement) === NodeType.BlockStatement) {
last = 0;
- for (let i = tree.fieldCount(Field.body, statement) - 1; i >= 0; i--) {
- const item = tree.field(i, Field.body, statement);
+ for (let i = A.fieldCount(Field.body, statement) - 1; i >= 0; i--) {
+ const item = A.field(i, Field.body, statement);
if (!printsNothing(item)) {
last = item;
break;
@@ -22351,18 +22290,18 @@ const createNodePrinter = (modules) => {
const alternate = elseOf(last);
return (
alternate !== 0 &&
- alwaysLeaves(tree.field(0, Field.consequent, last)) &&
+ alwaysLeaves(A.field(0, Field.consequent, last)) &&
alwaysLeaves(alternate)
);
}
case NodeType.TryStatement: {
// What `finally` leaves by is left by; else the block and handler both leave.
- const finalizer = tree.field(0, Field.finalizer, last);
+ const finalizer = A.field(0, Field.finalizer, last);
if (finalizer !== 0 && alwaysLeaves(finalizer)) return true;
- const handler = tree.field(0, Field.handler, last);
+ const handler = A.field(0, Field.handler, last);
return (
- alwaysLeaves(tree.field(0, Field.block, last)) &&
- (handler === 0 || alwaysLeaves(tree.field(0, Field.body, handler)))
+ alwaysLeaves(A.field(0, Field.block, last)) &&
+ (handler === 0 || alwaysLeaves(A.field(0, Field.body, handler)))
);
}
default:
@@ -22377,12 +22316,12 @@ const createNodePrinter = (modules) => {
const declaresLexically = (statement) => {
switch (typeOf(statement)) {
case NodeType.VariableDeclaration:
- return tree.textOf(Part.kind, statement) !== "var";
+ return A.textOf(Part.kind, statement) !== "var";
case NodeType.ClassDeclaration:
case NodeType.FunctionDeclaration:
return true;
case NodeType.LabeledStatement:
- return declaresLexically(tree.field(0, Field.body, statement));
+ return declaresLexically(A.field(0, Field.body, statement));
default:
return false;
}
@@ -22393,9 +22332,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether the first statement it prints is a string, which out of its braces may read as a directive
*/
const opensWithString = (block) => {
- const count = tree.fieldCount(Field.body, block);
+ const count = A.fieldCount(Field.body, block);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, block);
+ const item = A.field(i, Field.body, block);
if (printsNothing(item)) continue;
return (
typeOf(item) === NodeType.ExpressionStatement &&
@@ -22410,9 +22349,9 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether its braces scope a name
*/
const scopesLexically = (block) => {
- const count = tree.fieldCount(Field.body, block);
+ const count = A.fieldCount(Field.body, block);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, block);
+ const item = A.field(i, Field.body, block);
if (keepsLexicalName(item)) return true;
}
return false;
@@ -22434,7 +22373,7 @@ const createNodePrinter = (modules) => {
*/
const isPlainBreak = (statement) =>
typeOf(statement) === NodeType.BreakStatement &&
- tree.field(0, Field.label, statement) === 0 &&
+ A.field(0, Field.label, statement) === 0 &&
!hasEdgeComments(statement);
/**
@@ -22444,10 +22383,10 @@ const createNodePrinter = (modules) => {
*/
const doesNothing = (item) => {
if (childOf(Field.test, item) !== 0 || hasEdgeComments(item)) return false;
- const count = tree.fieldCount(Field.consequent, item);
+ const count = A.fieldCount(Field.consequent, item);
return (
count === 0 ||
- (count === 1 && isPlainBreak(tree.field(0, Field.consequent, item)))
+ (count === 1 && isPlainBreak(A.field(0, Field.consequent, item)))
);
};
@@ -22459,16 +22398,15 @@ const createNodePrinter = (modules) => {
const parent = parentAt(0);
// Past it, cases running nothing: a test matched skips the rest.
// The case is among them, which ends the walk.
- for (let i = tree.fieldCount(Field.cases, parent) - 1; ; i--) {
- const later = tree.field(i, Field.cases, parent);
+ for (let i = A.fieldCount(Field.cases, parent) - 1; ; i--) {
+ const later = A.field(i, Field.cases, parent);
if (later === item) return true;
- const count = tree.fieldCount(Field.consequent, later);
+ const count = A.fieldCount(Field.consequent, later);
if (
hasEdgeComments(later) ||
!(
count === 0 ||
- (count === 1 &&
- isPlainBreak(tree.field(0, Field.consequent, later))) ||
+ (count === 1 && isPlainBreak(A.field(0, Field.consequent, later))) ||
// One reached only falling into it, whose statements never run.
(unlabeledCases.size !== 0 &&
unlabeledCases.has(later) &&
@@ -22488,14 +22426,14 @@ const createNodePrinter = (modules) => {
for (let node = statement; ;) {
const type = typeOf(node);
if (type === NodeType.IfStatement) {
- const alternate = tree.field(0, Field.alternate, node);
+ const alternate = A.field(0, Field.alternate, node);
if (alternate === 0 || ifForm(node) !== 0) return false;
// One printing its test alone is no `if` to take it.
if (elseOf(node) === 0) return !runsOnlyTest(node);
if (printsElseOnly(node)) return true;
node = alternate;
} else if (HOLDS_BODY[type] === 1) {
- node = tree.field(0, Field.body, node);
+ node = A.field(0, Field.body, node);
} else {
// A block keeps its braces where it would.
return false;
@@ -22510,7 +22448,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const makeThen = (node) => {
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
if (
(output.option("ie8") &&
typeOf(consequent) === NodeType.DoWhileStatement) ||
@@ -22529,7 +22467,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const skipNode = (child) => {
- if (!inlinesNames || tree.type(child) !== NodeType.Identifier) {
+ if (!inlinesNames || A.type(child) !== NodeType.Identifier) {
/** @type {JavascriptPrintContext} */ (writer).consume(child);
}
};
@@ -22544,7 +22482,7 @@ const createNodePrinter = (modules) => {
if (type === NodeType.Identifier) return isGlobalUndefined(argument);
return (
type === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, argument) === "void" &&
+ A.textOf(Part.operator, argument) === "void" &&
isPureValue(childOf(Field.argument, argument))
);
};
@@ -22559,7 +22497,7 @@ const createNodePrinter = (modules) => {
return isGlobalUndefined(node);
case NodeType.UnaryExpression:
return (
- tree.textOf(Part.operator, node) === "void" &&
+ A.textOf(Part.operator, node) === "void" &&
isPureValue(childOf(Field.argument, node))
);
case NodeType.CallExpression:
@@ -22580,7 +22518,7 @@ const createNodePrinter = (modules) => {
const nullCheckedName = (comparison, operator) => {
if (
typeOf(comparison) !== NodeType.BinaryExpression ||
- tree.textOf(Part.operator, comparison) !== operator ||
+ A.textOf(Part.operator, comparison) !== operator ||
hasEdgeComments(comparison)
) {
return 0;
@@ -22606,7 +22544,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it is `null`
*/
const isNull = (node) =>
- typeOf(node) === NodeType.Literal && tree.value(node) === null;
+ typeOf(node) === NodeType.Literal && A.value(node) === null;
/**
* Whether a logical expression tests one name strictly against both
@@ -22615,7 +22553,7 @@ const createNodePrinter = (modules) => {
* @returns {number} the name, 0 where it does not
*/
const comparedWithNull = (node) => {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
const strict = operator === "||" ? "===" : operator === "&&" ? "!==" : "";
if (strict === "" || mangledNames === null) return 0;
const left = childOf(Field.left, node);
@@ -22649,7 +22587,7 @@ const createNodePrinter = (modules) => {
const nullCheckedTarget = (comparison, operator) => {
if (
typeOf(comparison) !== NodeType.BinaryExpression ||
- tree.textOf(Part.operator, comparison) !== operator ||
+ A.textOf(Part.operator, comparison) !== operator ||
holdsComments(comparison)
) {
return 0;
@@ -22661,7 +22599,7 @@ const createNodePrinter = (modules) => {
if (type === NodeType.Identifier) return isInlinedRead(side) ? 0 : side;
if (
type !== NodeType.AssignmentExpression ||
- tree.textOf(Part.operator, side) !== "="
+ A.textOf(Part.operator, side) !== "="
) {
return 0;
}
@@ -22676,7 +22614,7 @@ const createNodePrinter = (modules) => {
* @returns {number} the comparison that prints as `==null` or `!=null`, its right dropping, 0 for none
*/
const pairedNullCheck = (node) => {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
const strict = operator === "||" ? "===" : operator === "&&" ? "!==" : "";
if (strict === "" || mangledNames === null || beautifies) return 0;
const right = childOf(Field.right, node);
@@ -22684,7 +22622,7 @@ const createNodePrinter = (modules) => {
const left = childOf(Field.left, node);
const comparison =
typeOf(left) === NodeType.LogicalExpression &&
- tree.textOf(Part.operator, left) === operator &&
+ A.textOf(Part.operator, left) === operator &&
!hasEdgeComments(left)
? childOf(Field.right, left)
: left;
@@ -22726,11 +22664,11 @@ const createNodePrinter = (modules) => {
}
const context = /** @type {JavascriptPrintContext} */ (writer);
const text = context.get(comparison);
- const suffix = `${tree.textOf(Part.operator, comparison)}${
+ const suffix = `${A.textOf(Part.operator, comparison)}${
isNull(childOf(Field.right, comparison)) ? "null" : "void 0"
}`;
if (!text.endsWith(suffix)) return false;
- const operator = /** @type {string} */ (tree.textOf(Part.operator, node));
+ const operator = /** @type {string} */ (A.textOf(Part.operator, node));
if (comparison === right) {
printNode(left);
output.print(operator);
@@ -22752,7 +22690,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} true where the value goes
*/
const setsUndefinedAnew = (declarator, init) => {
- const id = tree.field(0, Field.id, declarator);
+ const id = A.field(0, Field.id, declarator);
if (
typeOf(id) !== NodeType.Identifier ||
hasEdgeComments(init) ||
@@ -22786,10 +22724,10 @@ const createNodePrinter = (modules) => {
const isStringValue = (node) => {
const type = typeOf(node);
return type === NodeType.Literal
- ? typeof tree.value(node) === "string"
+ ? typeof A.value(node) === "string"
: type === NodeType.TemplateLiteral ||
(type === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, node) === "typeof");
+ A.textOf(Part.operator, node) === "typeof");
};
/**
@@ -22799,9 +22737,9 @@ const createNodePrinter = (modules) => {
const isNumberValue = (node) => {
switch (typeOf(node)) {
case NodeType.Literal:
- return typeof tree.value(node) === "number";
+ return typeof A.value(node) === "number";
case NodeType.UnaryExpression:
- switch (tree.textOf(Part.operator, node)) {
+ switch (A.textOf(Part.operator, node)) {
case "+":
return true;
case "-":
@@ -22811,7 +22749,7 @@ const createNodePrinter = (modules) => {
}
case NodeType.AssignmentExpression:
return (
- tree.textOf(Part.operator, node) === "=" &&
+ A.textOf(Part.operator, node) === "=" &&
isNumberValue(childOf(Field.right, node))
);
default:
@@ -22825,14 +22763,14 @@ const createNodePrinter = (modules) => {
*/
const isTypeof = (node) =>
typeOf(node) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, node) === "typeof";
+ A.textOf(Part.operator, node) === "typeof";
/**
* @param {number} node an expression
* @returns {boolean} whether it is the string "undefined"
*/
const isUndefinedString = (node) =>
- typeOf(node) === NodeType.Literal && tree.value(node) === "undefined";
+ typeOf(node) === NodeType.Literal && A.value(node) === "undefined";
/**
* @param {string} operator an equality
@@ -22864,9 +22802,9 @@ const createNodePrinter = (modules) => {
const constantGoesFirst = (operator, left, right) =>
(operator === "==" || operator === "!=") &&
typeOf(left) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, left) === "typeof" &&
+ A.textOf(Part.operator, left) === "typeof" &&
typeOf(right) === NodeType.Literal &&
- typeof tree.value(right) === "string" &&
+ typeof A.value(right) === "string" &&
!hasEdgeComments(left) &&
!hasEdgeComments(right);
@@ -22923,7 +22861,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.params, fn);
+ const count = A.fieldCount(Field.params, fn);
for (let i = 0; i < count; i++) {
let param = itemOf(i, Field.params, fn);
if (typeOf(param) === NodeType.RestElement) {
@@ -22963,10 +22901,10 @@ const createNodePrinter = (modules) => {
if (
(type !== NodeType.FunctionExpression &&
type !== NodeType.ArrowFunctionExpression) ||
- tree.flag(Flag.async, fn) ||
- tree.flag(Flag.generator, fn) ||
+ A.flag(Flag.async, fn) ||
+ A.flag(Flag.generator, fn) ||
(type === NodeType.FunctionExpression &&
- (tree.field(0, Field.id, fn) !== 0 || readsArguments(fn)))
+ (A.field(0, Field.id, fn) !== 0 || readsArguments(fn)))
) {
return false;
}
@@ -23019,7 +22957,7 @@ const createNodePrinter = (modules) => {
*/
const printLoopControl = (node, keyword) => {
output.print(keyword);
- const label = tree.field(0, Field.label, node);
+ const label = A.field(0, Field.label, node);
if (label !== 0) {
const target = jumpTarget(label, keyword === "break");
if (target === 0) {
@@ -23040,7 +22978,7 @@ const createNodePrinter = (modules) => {
* @returns {number} the labeled statement it names, 0 where the nearest loop, or `switch` for a `break`, is that statement's
*/
const jumpTarget = (label, breaks) => {
- const name = tree.name(label);
+ const name = A.name(label);
// Past the nearest loop, or `switch` for a `break`, only labels on it.
let passed = false;
let own = true;
@@ -23048,7 +22986,7 @@ const createNodePrinter = (modules) => {
const ancestor = parentAt(level);
const type = typeOf(ancestor);
if (type === NodeType.LabeledStatement) {
- if (tree.name(tree.field(0, Field.label, ancestor)) === name) {
+ if (A.name(A.field(0, Field.label, ancestor)) === name) {
return compresses && passed && own ? 0 : ancestor;
}
} else if (passed) {
@@ -23098,7 +23036,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printMappedName = (node) => {
- if (tree.type(node) === NodeType.Literal) {
+ if (A.type(node) === NodeType.Literal) {
output.printString(moduleName(node), quoteOf(node));
} else {
printNode(node);
@@ -23111,10 +23049,10 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printForeignName = (node) => {
- if (tree.type(node) === NodeType.Literal) {
+ if (A.type(node) === NodeType.Literal) {
output.printString(moduleName(node), quoteOf(node));
} else {
- output.print(tree.name(node));
+ output.print(A.name(node));
}
};
@@ -23128,7 +23066,7 @@ const createNodePrinter = (modules) => {
const printNameMapping = (local, foreign, isImport) => {
// A local name mangling renamed no longer spells the other module's.
const printed =
- tree.type(local) === NodeType.Literal ? moduleName(local) : nameOf(local);
+ A.type(local) === NodeType.Literal ? moduleName(local) : nameOf(local);
if (printed === moduleName(foreign)) {
printMappedName(local);
return;
@@ -23149,11 +23087,11 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printSpecifiers = (node, from) => {
- const count = tree.fieldCount(Field.specifiers, node);
+ const count = A.fieldCount(Field.specifiers, node);
output.print("{");
for (let i = from; i < count; i++) {
output.space();
- printNode(tree.field(i, Field.specifiers, node));
+ printNode(A.field(i, Field.specifiers, node));
if (i < count - 1) output.print(",");
}
output.space();
@@ -23166,13 +23104,13 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printAttributes = (node) => {
- const count = tree.fieldCount(Field.attributes, node);
+ const count = A.fieldCount(Field.attributes, node);
if (count === 0) return;
output.print("with");
output.print("{");
for (let i = 0; i < count; i++) {
if (i) output.print(",");
- printNode(tree.field(i, Field.attributes, node));
+ printNode(A.field(i, Field.attributes, node));
}
output.print("}");
};
@@ -23183,7 +23121,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printSource = (node) => {
- const from = tree.field(0, Field.source, node);
+ const from = A.field(0, Field.source, node);
if (from !== 0) {
output.space();
output.print("from");
@@ -23202,7 +23140,7 @@ const createNodePrinter = (modules) => {
const printClass = (node) => {
output.print("class");
output.space();
- const id = tree.field(0, Field.id, node);
+ const id = A.field(0, Field.id, node);
if (
id !== 0 &&
typeOf(node) === NodeType.ClassExpression &&
@@ -23238,14 +23176,14 @@ const createNodePrinter = (modules) => {
if (parens) output.print(")");
else output.space();
}
- const body = tree.field(0, Field.body, node);
- const count = tree.fieldCount(Field.body, body);
+ const body = A.field(0, Field.body, node);
+ const count = A.fieldCount(Field.body, body);
// A base constructor returning an object installs a derived class's
// private members on it again, which throws: those stay.
const read = compresses && superClass === 0 ? privateNamesRead(body) : null;
let printed = 0;
for (let i = 0; i < count; i++) {
- const member = tree.field(i, Field.body, body);
+ const member = A.field(i, Field.body, body);
if (
(read !== null && dropsPrivateMember(member, read)) ||
(compresses && runsNothingStatic(member))
@@ -23273,8 +23211,8 @@ const createNodePrinter = (modules) => {
if (typeOf(member) !== NodeType.StaticBlock || holdsComments(member)) {
return false;
}
- for (let i = tree.fieldCount(Field.body, member) - 1; i >= 0; i--) {
- if (!printsNothing(tree.field(i, Field.body, member))) return false;
+ for (let i = A.fieldCount(Field.body, member) - 1; i >= 0; i--) {
+ if (!printsNothing(A.field(i, Field.body, member))) return false;
}
return true;
};
@@ -23285,12 +23223,12 @@ const createNodePrinter = (modules) => {
* @returns {Set | null} the names, null where a direct `eval` may read any or it declares none
*/
const privateNamesRead = (body) => {
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
/** @type {Set | undefined} */
let keys;
for (let i = 0; i < count; i++) {
- const key = childOf(Field.key, tree.field(i, Field.body, body));
- if (key !== 0 && tree.type(key) === NodeType.PrivateIdentifier) {
+ const key = childOf(Field.key, A.field(i, Field.body, body));
+ if (key !== 0 && A.type(key) === NodeType.PrivateIdentifier) {
(keys || (keys = new Set())).add(key);
}
}
@@ -23299,12 +23237,12 @@ const createNodePrinter = (modules) => {
/** @type {Set} */
const read = new Set();
const evaluates = findNode(body, (node) => {
- switch (tree.type(node)) {
+ switch (A.type(node)) {
case NodeType.PrivateIdentifier:
- if (!declared.has(node)) read.add(tree.name(node));
+ if (!declared.has(node)) read.add(A.name(node));
return;
case NodeType.Identifier:
- return tree.name(node) === "eval" ? true : undefined;
+ return A.name(node) === "eval" ? true : undefined;
}
});
return evaluates ? null : read;
@@ -23325,10 +23263,7 @@ const createNodePrinter = (modules) => {
return false;
}
const key = childOf(Field.key, member);
- if (
- tree.type(key) !== NodeType.PrivateIdentifier ||
- read.has(tree.name(key))
- ) {
+ if (A.type(key) !== NodeType.PrivateIdentifier || read.has(A.name(key))) {
return false;
}
if (type === NodeType.MethodDefinition) return true;
@@ -23343,14 +23278,14 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printLambda = (node, isMethod) => {
- let id = tree.field(0, Field.id, node);
+ let id = A.field(0, Field.id, node);
if (!isMethod) {
- if (tree.flag(Flag.async, node)) {
+ if (A.flag(Flag.async, node)) {
output.print("async");
output.space();
}
output.print("function");
- if (tree.flag(Flag.generator, node)) output.star();
+ if (A.flag(Flag.generator, node)) output.star();
if (
id !== 0 &&
(typeOf(node) === NodeType.FunctionExpression
@@ -23367,7 +23302,7 @@ const createNodePrinter = (modules) => {
if (id !== 0) printNode(id);
printArguments(node, Field.params);
output.space();
- printBraced(node, tree.field(0, Field.body, node));
+ printBraced(node, A.field(0, Field.body, node));
};
/**
@@ -23375,7 +23310,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it prints no argument, none written or each one a parameter inlines or nothing reads
*/
const printsNoArguments = (node) => {
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
if (
count !== 0 &&
constantArguments.size === 0 &&
@@ -23403,7 +23338,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printArguments = (node, field) => {
- const count = tree.fieldCount(field, node);
+ const count = A.fieldCount(field, node);
output.print("(");
let printed = 0;
for (let i = 0; i < count; i++) {
@@ -23448,7 +23383,7 @@ const createNodePrinter = (modules) => {
) {
return 0;
}
- const argument = tree.field(0, Field.argument, spread);
+ const argument = A.field(0, Field.argument, spread);
const type = typeOf(argument);
if (typeOf(container) !== NodeType.ObjectExpression) {
// A hole spreads as `undefined`, which a hole does not read as.
@@ -23458,26 +23393,26 @@ const createNodePrinter = (modules) => {
) {
return 0;
}
- const count = tree.fieldCount(Field.elements, argument);
+ const count = A.fieldCount(Field.elements, argument);
for (let i = 0; i < count; i++) {
- if (tree.field(i, Field.elements, argument) === 0) return 0;
+ if (A.field(i, Field.elements, argument) === 0) return 0;
}
return 2;
}
if (type === NodeType.ObjectExpression) {
- const count = tree.fieldCount(Field.properties, argument);
+ const count = A.fieldCount(Field.properties, argument);
for (let i = 0; i < count; i++) {
- const property = tree.field(i, Field.properties, argument);
+ const property = A.field(i, Field.properties, argument);
if (typeOf(property) === NodeType.SpreadElement) continue;
// A getter runs as it spreads, a method's `super` is its object,
// and `__proto__:` sets the prototype of what holds it.
if (
- tree.textOf(Part.kind, property) !== "init" ||
- (tree.flag(Flag.method, property) &&
+ A.textOf(Part.kind, property) !== "init" ||
+ (A.flag(Flag.method, property) &&
findNode(childOf(Field.value, property), findSuper)) ||
- (!tree.flag(Flag.computed, property) &&
- !tree.flag(Flag.shorthand, property) &&
- !tree.flag(Flag.method, property) &&
+ (!A.flag(Flag.computed, property) &&
+ !A.flag(Flag.shorthand, property) &&
+ !A.flag(Flag.method, property) &&
printedKeyOf(property, childOf(Field.key, property)) ===
"__proto__")
) {
@@ -23492,10 +23427,9 @@ const createNodePrinter = (modules) => {
type === NodeType.FunctionExpression ||
type === NodeType.ArrowFunctionExpression ||
(type === NodeType.Literal &&
- (typeof tree.value(argument) === "bigint" ||
- /** @type {string} */ (tree.textOf(Part.raw, argument)).charCodeAt(
- 0
- ) === 47))
+ (typeof A.value(argument) === "bigint" ||
+ /** @type {string} */ (A.textOf(Part.raw, argument)).charCodeAt(0) ===
+ 47))
) {
return hasEdgeComments(argument) ? 0 : 1;
}
@@ -23509,7 +23443,7 @@ const createNodePrinter = (modules) => {
// What spreads no own property: `null`, `undefined`, a boolean or a number.
if (
type === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, argument) === "void"
+ A.textOf(Part.operator, argument) === "void"
? !isPureValue(childOf(Field.argument, argument))
: !isPureValue(argument)
) {
@@ -23517,7 +23451,7 @@ const createNodePrinter = (modules) => {
}
const value =
type === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, argument) === "void"
+ A.textOf(Part.operator, argument) === "void"
? undefined
: evaluateConstant(argument);
return value === null ||
@@ -23525,7 +23459,7 @@ const createNodePrinter = (modules) => {
typeof value === "number" ||
(value === undefined &&
type === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, argument) === "void")
+ A.textOf(Part.operator, argument) === "void")
? 1
: 0;
};
@@ -23537,7 +23471,7 @@ const createNodePrinter = (modules) => {
*/
const spreadsFolded = (node, parent) =>
typeOf(parent) === NodeType.SpreadElement &&
- tree.field(0, Field.argument, parent) === node &&
+ A.field(0, Field.argument, parent) === node &&
spreadsAs(parent, parentAt(1)) === 2;
/**
@@ -23548,7 +23482,7 @@ const createNodePrinter = (modules) => {
*/
const printSpread = (spread, printed) => {
const context = /** @type {JavascriptPrintContext} */ (writer);
- const argument = tree.field(0, Field.argument, spread);
+ const argument = A.field(0, Field.argument, spread);
const field =
typeOf(argument) === NodeType.ArrayExpression
? Field.elements
@@ -23556,7 +23490,7 @@ const createNodePrinter = (modules) => {
? Field.properties
: 0;
if (field !== 0) {
- const count = tree.fieldCount(field, argument);
+ const count = A.fieldCount(field, argument);
for (let i = 0; i < count; i++) {
const item = itemOf(i, field, argument);
if (spreadsAs(item, argument) !== 0) {
@@ -23585,7 +23519,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const countPassed = (node, field) => {
- const count = tree.fieldCount(field, node);
+ const count = A.fieldCount(field, node);
for (let i = 0; i < count; i++) {
const item = itemOf(i, field, node);
if (typeOf(item) !== NodeType.SpreadElement) {
@@ -23593,7 +23527,7 @@ const createNodePrinter = (modules) => {
} else if (spreadsAs(item, node) === 0) {
passedSpreads++;
} else {
- countPassed(tree.field(0, Field.argument, item), Field.elements);
+ countPassed(A.field(0, Field.argument, item), Field.elements);
}
}
};
@@ -23608,14 +23542,14 @@ const createNodePrinter = (modules) => {
case NodeType.NewExpression: {
const callee = childOf(Field.callee, node);
return (
- !tree.flag(Flag.optional, node) &&
+ !A.flag(Flag.optional, node) &&
readsBuiltInConstructor(callee) &&
- tree.name(callee) === "Array" &&
+ A.name(callee) === "Array" &&
!writesBuiltIn("Array")
);
}
case NodeType.Literal:
- return typeof tree.value(node) !== "number";
+ return typeof A.value(node) !== "number";
case NodeType.TemplateLiteral:
case NodeType.ObjectExpression:
case NodeType.ArrayExpression:
@@ -23641,11 +23575,11 @@ const createNodePrinter = (modules) => {
if (
(parentType === NodeType.CallExpression
? childOf(Field.callee, parent) !== node ||
- tree.flag(Flag.optional, parent)
+ A.flag(Flag.optional, parent)
: parentType !== NodeType.TaggedTemplateExpression ||
childOf(Field.tag, parent) !== node) ||
- tree.flag(Flag.optional, node) ||
- tree.fieldCount(Field.arguments, node) !== 1 ||
+ A.flag(Flag.optional, node) ||
+ A.fieldCount(Field.arguments, node) !== 1 ||
hasEdgeComments(node)
) {
return false;
@@ -23655,14 +23589,14 @@ const createNodePrinter = (modules) => {
const type = typeOf(value);
if (
!readsBuiltInConstructor(callee) ||
- tree.name(callee) !== "Object" ||
+ A.name(callee) !== "Object" ||
holdsComments(callee) ||
writesBuiltIn("Object") ||
(type === NodeType.Identifier
- ? tree.type(value) !== NodeType.Identifier ||
+ ? A.type(value) !== NodeType.Identifier ||
(collapsed.size !== 0 && collapsed.has(value)) ||
isMovedRead(value)
- : type !== NodeType.MemberExpression || tree.flag(Flag.optional, value))
+ : type !== NodeType.MemberExpression || A.flag(Flag.optional, value))
) {
return false;
}
@@ -23691,15 +23625,15 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
(type !== NodeType.CallExpression && type !== NodeType.NewExpression) ||
- tree.fieldCount(Field.arguments, node) !== 0 ||
- tree.flag(Flag.optional, node)
+ A.fieldCount(Field.arguments, node) !== 0 ||
+ A.flag(Flag.optional, node)
) {
return false;
}
const callee = childOf(Field.callee, node);
return (
readsBuiltInConstructor(callee) &&
- tree.name(callee) === "Object" &&
+ A.name(callee) === "Object" &&
!hasEdgeComments(node) &&
!holdsComments(callee) &&
!writesBuiltIn("Object")
@@ -23715,9 +23649,9 @@ const createNodePrinter = (modules) => {
const arrayCallHoles = (node) => {
const callee = childOf(Field.callee, node);
if (
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
!readsBuiltInConstructor(callee) ||
- tree.name(callee) !== "Array" ||
+ A.name(callee) !== "Array" ||
hasEdgeComments(node) ||
holdsComments(callee) ||
writesBuiltIn("Array")
@@ -23732,9 +23666,9 @@ const createNodePrinter = (modules) => {
// `-0` is a length too, of no holes.
const negatesZero =
typeOf(passedFirst) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, passedFirst) === "-" &&
+ A.textOf(Part.operator, passedFirst) === "-" &&
isNumber(childOf(Field.argument, passedFirst)) &&
- tree.value(childOf(Field.argument, passedFirst)) === 0;
+ A.value(childOf(Field.argument, passedFirst)) === 0;
if (
passedItems === 1 &&
passedSpreads === 0 &&
@@ -23743,7 +23677,7 @@ const createNodePrinter = (modules) => {
// Up to 5 holes print no longer than the call.
const length = negatesZero
? 0
- : /** @type {number} */ (tree.value(passedFirst));
+ : /** @type {number} */ (A.value(passedFirst));
if (
!Number.isInteger(length) ||
length < 0 ||
@@ -23773,7 +23707,7 @@ const createNodePrinter = (modules) => {
const holes = arrayCallHoles(node);
if (holes === -2) return false;
const callee = childOf(Field.callee, node);
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
skipNode(callee);
output.print("[");
if (holes !== -1) {
@@ -23829,9 +23763,9 @@ const createNodePrinter = (modules) => {
}
/** @type {string | undefined} */
let name;
- const type = tree.type(key);
+ const type = A.type(key);
if (type === NodeType.Literal) {
- const value = tree.value(key);
+ const value = A.value(key);
if (typeof value === "string" || value === null) {
name = `${value}`;
} else if (typeof value === "number" && Number.isFinite(value)) {
@@ -23844,7 +23778,7 @@ const createNodePrinter = (modules) => {
// `[1/0]` is shorter than `Infinity:`.
(isGlobalUndefined(key, "Infinity") && !readsInfinity(key)))
) {
- name = tree.name(key);
+ name = A.name(key);
} else if (type !== NodeType.Identifier) {
// `[1 + 2]` and `[a ? "b" : c]` fold to the name they convert to.
const value = valueAtPrint(key);
@@ -23870,9 +23804,9 @@ const createNodePrinter = (modules) => {
// only a static method may be named `constructor` bare.
return (name === "constructor" &&
(memberType !== NodeType.MethodDefinition ||
- !tree.flag(Flag.static, member))) ||
+ !A.flag(Flag.static, member))) ||
name.charCodeAt(0) === 35 ||
- (name === "prototype" && tree.flag(Flag.static, member))
+ (name === "prototype" && A.flag(Flag.static, member))
? undefined
: name;
};
@@ -23926,7 +23860,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printMethod = (node, keyword) => {
- if (tree.flag(Flag.static, node)) {
+ if (A.flag(Flag.static, node)) {
output.print("static");
output.space();
}
@@ -23935,8 +23869,8 @@ const createNodePrinter = (modules) => {
output.space();
}
const key = childOf(Field.key, node);
- const isPrivate = tree.type(key) === NodeType.PrivateIdentifier;
- if (tree.flag(Flag.computed, node) && !isPrivate) {
+ const isPrivate = A.type(key) === NodeType.PrivateIdentifier;
+ if (A.flag(Flag.computed, node) && !isPrivate) {
printComputedKey(node, key);
} else if (isPrivate) {
output.print("#");
@@ -23944,7 +23878,7 @@ const createNodePrinter = (modules) => {
} else {
printPropertyName(printedKeyOf(node, key), keyQuoteOf(node), output);
}
- printLambda(tree.field(0, Field.value, node), true);
+ printLambda(A.field(0, Field.value, node), true);
};
/**
@@ -23952,11 +23886,11 @@ const createNodePrinter = (modules) => {
* @returns {string | undefined} the keyword its kind prints before its name
*/
const methodKeyword = (node) => {
- const kind = tree.textOf(Part.kind, node);
+ const kind = A.textOf(Part.kind, node);
if (kind === "get" || kind === "set") return kind;
- const value = tree.field(0, Field.value, node);
- const generator = tree.flag(Flag.generator, value);
- const async = tree.flag(Flag.async, value);
+ const value = A.field(0, Field.value, node);
+ const generator = A.flag(Flag.generator, value);
+ const async = A.flag(Flag.async, value);
if (generator && async) return "async*";
if (generator) return "*";
if (async) return "async";
@@ -23985,7 +23919,7 @@ const createNodePrinter = (modules) => {
const key = childOf(Field.key, node);
const value = childOf(Field.value, node);
const quote = keyQuoteOf(node);
- const name = tree.flag(Flag.computed, node) ? undefined : keyName(key);
+ const name = A.flag(Flag.computed, node) ? undefined : keyName(key);
// A key property mangling renames prints alone only where its value
// prints as the new name.
const printed = name === undefined ? undefined : printedKeyOf(node, key);
@@ -23997,7 +23931,7 @@ const createNodePrinter = (modules) => {
if (
tryShorthand &&
valueType === NodeType.Identifier &&
- tree.type(value) === NodeType.Identifier &&
+ A.type(value) === NodeType.Identifier &&
nameOf(value) === printed &&
!ALL_RESERVED_WORDS.has(printed)
) {
@@ -24045,7 +23979,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printElements = (node, field) => {
- const count = tree.fieldCount(field, node);
+ const count = A.fieldCount(field, node);
let printed = 0;
// A hole printed last takes a comma of its own after it.
let holeLast = false;
@@ -24147,7 +24081,7 @@ const createNodePrinter = (modules) => {
const templatePlus = (node) => {
if (
typeOf(node) !== NodeType.BinaryExpression ||
- tree.textOf(Part.operator, node) !== "+"
+ A.textOf(Part.operator, node) !== "+"
) {
return false;
}
@@ -24239,7 +24173,7 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
methodNameOf(callee) !== "concat" ||
hasEdgeComments(node) ||
hasEdgeComments(callee)
@@ -24249,7 +24183,7 @@ const createNodePrinter = (modules) => {
const receiver = childOf(Field.object, callee);
const literal =
typeOf(receiver) === NodeType.Literal &&
- typeof tree.value(receiver) === "string" &&
+ typeof A.value(receiver) === "string" &&
!hasEdgeComments(receiver);
// A template the source does not write takes ECMAScript 2015.
if (literal && output.option("ecma") < 2015) return false;
@@ -24268,12 +24202,12 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
if (count === 0) return false;
let converting = false;
// What the template reads up to each piece, which it must join.
let before = literal
- ? /** @type {string} */ (tree.value(receiver))
+ ? /** @type {string} */ (A.value(receiver))
: /** @type {string} */ (calleeText).slice(0, -".concat".length - 1);
for (let i = 0; i < count; i++) {
const argument = itemOf(i, Field.arguments, node);
@@ -24299,7 +24233,7 @@ const createNodePrinter = (modules) => {
skipNode(callee);
output.print("`");
output.printTemplateStringChars(
- /** @type {string} */ (tree.value(receiver))
+ /** @type {string} */ (A.value(receiver))
);
} else {
/** @type {JavascriptPrintContext} */ (writer).consume(callee);
@@ -24398,7 +24332,7 @@ const createNodePrinter = (modules) => {
const addedLiteral = (node) => {
if (
typeOf(node) !== NodeType.BinaryExpression ||
- tree.textOf(Part.operator, node) !== "+"
+ A.textOf(Part.operator, node) !== "+"
) {
return undefined;
}
@@ -24406,7 +24340,7 @@ const createNodePrinter = (modules) => {
if (typeOf(right) !== NodeType.Literal || hasEdgeComments(right)) {
return undefined;
}
- const value = tree.value(right);
+ const value = A.value(right);
return typeof value === "string" ||
typeof value === "number" ||
typeof value === "boolean"
@@ -24478,11 +24412,11 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printReduced = (node) => {
- const id = tree.field(0, Field.id, node);
+ const id = A.field(0, Field.id, node);
if (id !== 0) skipNode(id);
- const count = tree.fieldCount(Field.params, node);
+ const count = A.fieldCount(Field.params, node);
for (let i = 0; i < count; i++) {
- skipNode(tree.field(i, Field.params, node));
+ skipNode(A.field(i, Field.params, node));
}
for (const item of printedPrefix(node)) {
const start = output.text.length;
@@ -24518,12 +24452,12 @@ const createNodePrinter = (modules) => {
type === NodeType.ArrayExpression ||
type === NodeType.TemplateLiteral ||
(type === NodeType.Literal &&
- (typeof tree.value(value) === "string" ||
- tree.value(value) === null ||
+ (typeof A.value(value) === "string" ||
+ A.value(value) === null ||
isObjectValue(value) ||
// A member's `.` after it prints `..` where it needs one.
- (typeof tree.value(value) === "number" &&
- Number.isFinite(tree.value(value)))))
+ (typeof A.value(value) === "number" &&
+ Number.isFinite(A.value(value)))))
) {
return false;
}
@@ -24587,7 +24521,7 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
!dropsSideEffectFree ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
!valueUnread(node, parent) ||
!isPureCall(node)
) {
@@ -24672,10 +24606,10 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
typeOf(callee) !== NodeType.Identifier ||
!isGlobalUndefined(callee, "Boolean") ||
- tree.fieldCount(Field.arguments, node) !== 1 ||
+ A.fieldCount(Field.arguments, node) !== 1 ||
hasEdgeComments(callee) ||
writesBuiltIn("Boolean")
) {
@@ -24722,13 +24656,13 @@ const createNodePrinter = (modules) => {
answersWith ||
output.option("ecma") < 2016 ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
typeOf(callee) !== NodeType.MemberExpression ||
- tree.flag(Flag.computed, callee) ||
- tree.flag(Flag.optional, callee) ||
- tree.fieldCount(Field.arguments, node) !== 2 ||
+ A.flag(Flag.computed, callee) ||
+ A.flag(Flag.optional, callee) ||
+ A.fieldCount(Field.arguments, node) !== 2 ||
holdsComments(node) ||
- tree.name(childOf(Field.property, callee)) !== "pow"
+ A.name(childOf(Field.property, callee)) !== "pow"
) {
return false;
}
@@ -24782,7 +24716,7 @@ const createNodePrinter = (modules) => {
parentType === NodeType.LogicalExpression ||
parentType === NodeType.TemplateLiteral ||
(parentType === NodeType.BinaryExpression &&
- (tree.textOf(Part.operator, parent) !== "**" ||
+ (A.textOf(Part.operator, parent) !== "**" ||
childOf(Field.right, parent) === node));
if (!bare) output.print("(");
printSlice(POWER_OPERAND.test(baseText) ? baseText : `(${baseText})`);
@@ -24831,9 +24765,9 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
typeOf(callee) !== NodeType.Identifier ||
- tree.fieldCount(Field.arguments, node) !== 1 ||
+ A.fieldCount(Field.arguments, node) !== 1 ||
holdsComments(node) ||
!isGlobalUndefined(callee, "BigInt") ||
writesBuiltIn("BigInt")
@@ -24843,7 +24777,7 @@ const createNodePrinter = (modules) => {
const argument = itemOf(0, Field.arguments, node);
if (
typeOf(argument) !== NodeType.Literal ||
- typeof tree.value(argument) !== "bigint"
+ typeof A.value(argument) !== "bigint"
) {
return false;
}
@@ -24859,15 +24793,15 @@ const createNodePrinter = (modules) => {
const isBooleanValued = (node) => {
switch (typeOf(node)) {
case NodeType.Literal:
- return typeof tree.value(node) === "boolean";
+ return typeof A.value(node) === "boolean";
case NodeType.UnaryExpression:
return (
- tree.textOf(Part.operator, node) === "!" ||
- tree.textOf(Part.operator, node) === "delete"
+ A.textOf(Part.operator, node) === "!" ||
+ A.textOf(Part.operator, node) === "delete"
);
case NodeType.BinaryExpression:
return RELATIONS.has(
- /** @type {string} */ (tree.textOf(Part.operator, node))
+ /** @type {string} */ (A.textOf(Part.operator, node))
);
case NodeType.ConditionalExpression:
return (
@@ -24884,7 +24818,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether its elements join another literal as they are: no hole, which reads the prototypes, and no spread
*/
const joinsAsElements = (node) => {
- const count = tree.fieldCount(Field.elements, node);
+ const count = A.fieldCount(Field.elements, node);
for (let i = 0; i < count; i++) {
const element = itemOf(i, Field.elements, node);
if (element === 0 || typeOf(element) === NodeType.SpreadElement) {
@@ -24905,7 +24839,7 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node)
+ A.flag(Flag.optional, node)
) {
return -1;
}
@@ -24917,7 +24851,7 @@ const createNodePrinter = (modules) => {
if (
typeOf(object) === NodeType.ArrayExpression
? !joinsAsElements(object)
- : concatJoined(object) !== tree.fieldCount(Field.arguments, object)
+ : concatJoined(object) !== A.fieldCount(Field.arguments, object)
) {
return -1;
}
@@ -24932,7 +24866,7 @@ const createNodePrinter = (modules) => {
) {
return -1;
}
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
let joined = 0;
for (; joined < count; joined++) {
const argument = itemOf(joined, Field.arguments, node);
@@ -24953,13 +24887,13 @@ const createNodePrinter = (modules) => {
*/
const joinedLength = (node) => {
if (typeOf(node) === NodeType.ArrayExpression) {
- return tree.fieldCount(Field.elements, node);
+ return A.fieldCount(Field.elements, node);
}
if (concatJoined(node) < 0) return 1;
let length = joinedLength(
childOf(Field.object, childOf(Field.callee, node))
);
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
length += joinedLength(itemOf(i, Field.arguments, node));
}
@@ -25004,7 +24938,7 @@ const createNodePrinter = (modules) => {
const bare = printsAsElements(node);
if (!bare) output.print("[");
let printed = 0;
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = -1; i < joined; i++) {
const piece = i < 0 ? callee : itemOf(i, Field.arguments, node);
const length =
@@ -25046,13 +24980,13 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
typeOf(callee) !== NodeType.MemberExpression ||
- tree.flag(Flag.computed, callee) ||
- tree.flag(Flag.optional, callee) ||
+ A.flag(Flag.computed, callee) ||
+ A.flag(Flag.optional, callee) ||
holdsComments(node) ||
typeOf(childOf(Field.object, callee)) !== NodeType.Identifier ||
- tree.name(childOf(Field.property, callee)) !== "of" ||
+ A.name(childOf(Field.property, callee)) !== "of" ||
!isGlobalUndefined(childOf(Field.object, callee), "Array") ||
writesBuiltIn("Array.of")
) {
@@ -25061,7 +24995,7 @@ const createNodePrinter = (modules) => {
const context = /** @type {JavascriptPrintContext} */ (writer);
context.consume(callee);
output.print("[");
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
let printed = 0;
for (let i = 0; i < count; i++) {
const item = itemOf(i, Field.arguments, node);
@@ -25094,12 +25028,12 @@ const createNodePrinter = (modules) => {
typeOf(node) !== NodeType.CallExpression ||
(passes
? spreadsArgument(node)
- : tree.fieldCount(Field.arguments, node) !== 0) ||
- tree.flag(Flag.optional, node) ||
+ : A.fieldCount(Field.arguments, node) !== 0) ||
+ A.flag(Flag.optional, node) ||
(type !== NodeType.FunctionExpression &&
type !== NodeType.ArrowFunctionExpression) ||
- tree.flag(Flag.async, callee) ||
- tree.flag(Flag.generator, callee) ||
+ A.flag(Flag.async, callee) ||
+ A.flag(Flag.generator, callee) ||
holdsComments(node)
) {
return false;
@@ -25107,16 +25041,16 @@ const createNodePrinter = (modules) => {
const body = childOf(Field.body, callee);
if (
typeOf(body) !== NodeType.BlockStatement ||
- tree.fieldCount(Field.body, body) !== 0
+ A.fieldCount(Field.body, body) !== 0
) {
return false;
}
// A default or a pattern runs as the call binds it.
- const count = tree.fieldCount(Field.params, callee);
+ const count = A.fieldCount(Field.params, callee);
for (let i = 0; i < count; i++) {
- let param = tree.field(i, Field.params, callee);
+ let param = A.field(i, Field.params, callee);
if (typeOf(param) === NodeType.RestElement) {
- param = tree.field(0, Field.argument, param);
+ param = A.field(0, Field.argument, param);
}
if (typeOf(param) !== NodeType.Identifier) return false;
}
@@ -25139,7 +25073,7 @@ const createNodePrinter = (modules) => {
if (compresses && droppedConsole !== null && callsDroppedConsole(node)) {
// Where no list holds it, a dropped call prints as what it returns.
skipNode(callee);
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
skipNode(itemOf(i, Field.arguments, node));
}
@@ -25168,7 +25102,7 @@ const createNodePrinter = (modules) => {
if (joined !== undefined) {
// It prints as the string it makes.
skipNode(callee);
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
skipNode(itemOf(i, Field.arguments, node));
}
@@ -25185,7 +25119,7 @@ const createNodePrinter = (modules) => {
) {
// Printing as what it runs, the call passes nothing.
printNode(callee);
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
skipNode(itemOf(i, Field.arguments, node));
}
@@ -25198,7 +25132,7 @@ const createNodePrinter = (modules) => {
if (reducesToNothing(node, fn, value)) {
// Its statement runs nothing: what it returns runs nothing, nor what it passes.
skipNode(childOf(Field.callee, node));
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
skipNode(itemOf(i, Field.arguments, node));
}
@@ -25221,12 +25155,12 @@ const createNodePrinter = (modules) => {
if (
!parens &&
typeOf(value) === NodeType.Literal &&
- typeof tree.value(value) === "number" &&
+ typeof A.value(value) === "number" &&
printedPrefix(fn).length === 0
) {
output.literalLast = true;
}
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
skipNode(itemOf(i, Field.arguments, node));
}
@@ -25238,7 +25172,7 @@ const createNodePrinter = (modules) => {
) {
// It runs only its arguments, which an array literal runs in turn.
skipNode(childOf(Field.callee, node));
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
// An argument making nothing happen goes.
let runs = 0;
for (let i = 0; i < count; i++) {
@@ -25285,14 +25219,14 @@ const createNodePrinter = (modules) => {
if (
compresses &&
holdsValueBare(node) &&
- tree.fieldCount(Field.arguments, node) !== 0 &&
+ A.fieldCount(Field.arguments, node) !== 0 &&
isEmptyFunctionCall(node, callee, true)
) {
// `(() => {})(a)` as `void(a)`: what its arguments run, then its value.
skipNode(callee);
const parent = parentAt(0);
// A declarator that goes prints its value as a statement, unread.
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
let first = 0;
while (
first < count &&
@@ -25361,7 +25295,7 @@ const createNodePrinter = (modules) => {
if (typeOf(argument) === NodeType.Literal) {
skipNode(argument);
printEnumeratedString(
- /** @type {string} */ (tree.value(argument)),
+ /** @type {string} */ (A.value(argument)),
enumeration
);
} else if (typeOf(argument) === NodeType.ObjectExpression) {
@@ -25389,14 +25323,14 @@ const createNodePrinter = (modules) => {
}
printNode(childOf(Field.callee, node));
if (typeOf(node) === NodeType.NewExpression && printsNoArguments(node)) {
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
skipNode(itemOf(i, Field.arguments, node));
}
return;
}
if (
- tree.flag(Flag.optional, node) &&
+ A.flag(Flag.optional, node) &&
!(compresses && neverNullish(childOf(Field.callee, node)))
) {
output.print("?.");
@@ -25432,7 +25366,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
const item = itemOf(i, Field.arguments, node);
if (typeOf(item) === NodeType.SpreadElement || !isPureValue(item)) {
@@ -25450,7 +25384,7 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
hasEdgeComments(node)
) {
return false;
@@ -25460,7 +25394,7 @@ const createNodePrinter = (modules) => {
return (
(type === NodeType.FunctionExpression ||
type === NodeType.ArrowFunctionExpression) &&
- !tree.flag(Flag.generator, callee) &&
+ !A.flag(Flag.generator, callee) &&
!hasEdgeComments(callee) &&
EMPTY_FUNCTION.test(
/** @type {JavascriptPrintContext} */ (writer).get(callee)
@@ -25474,16 +25408,13 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether no argument prints: each is inlined as a constant where its parameter is read, or trimmed as one nothing reads
*/
const passesNothingPrinted = (call, fn) => {
- const count = tree.fieldCount(Field.arguments, call);
- const params = tree.fieldCount(Field.params, fn);
+ const count = A.fieldCount(Field.arguments, call);
+ const params = A.fieldCount(Field.params, fn);
for (let i = 0; i < count; i++) {
const argument = itemOf(i, Field.arguments, call);
if (
!(trimmedArguments.size !== 0 && trimmedArguments.has(argument)) &&
- !(
- i < params &&
- inlinesArgument(tree.field(i, Field.params, fn), argument)
- )
+ !(i < params && inlinesArgument(A.field(i, Field.params, fn), argument))
) {
return false;
}
@@ -25499,7 +25430,7 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
hasEdgeComments(node)
) {
return false;
@@ -25512,8 +25443,8 @@ const createNodePrinter = (modules) => {
(type === NodeType.FunctionExpression ||
type === NodeType.ArrowFunctionExpression ||
(moved !== 0 && type === NodeType.FunctionDeclaration)) &&
- !tree.flag(Flag.async, fn) &&
- !tree.flag(Flag.generator, fn) &&
+ !A.flag(Flag.async, fn) &&
+ !A.flag(Flag.generator, fn) &&
!hasEdgeComments(fn) &&
passesNothingPrinted(node, fn) &&
EMPTY_FUNCTION.test(
@@ -25535,7 +25466,7 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
typeOf(node) !== NodeType.CallExpression ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
hasEdgeComments(node)
) {
return false;
@@ -25550,20 +25481,20 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const async = tree.flag(Flag.async, callee);
- const body = tree.field(0, Field.body, callee);
+ const async = A.flag(Flag.async, callee);
+ const body = A.field(0, Field.body, callee);
if (hasEdgeComments(body)) return false;
- if (tree.flag(Flag.generator, callee)) {
+ if (A.flag(Flag.generator, callee)) {
// Its body runs later, if at all.
} else if (typeOf(body) !== NodeType.BlockStatement) {
// An arrow's value running nothing.
if (async || !isPureValue(body)) return false;
} else {
- const statements = tree.fieldCount(Field.body, body);
+ const statements = A.fieldCount(Field.body, body);
// What follows a `return` never runs.
let returned = false;
for (let i = 0; i < statements; i++) {
- const statement = tree.field(i, Field.body, body);
+ const statement = A.field(i, Field.body, body);
const type = typeOf(statement);
if (holdsComments(statement)) return false;
if (returned) continue;
@@ -25581,7 +25512,7 @@ const createNodePrinter = (modules) => {
if (type === NodeType.ReturnStatement) returned = true;
}
}
- const count = tree.fieldCount(Field.params, callee);
+ const count = A.fieldCount(Field.params, callee);
for (let i = 0; i < count; i++) {
let param = itemOf(i, Field.params, callee);
// A rest parameter collects an array.
@@ -25627,7 +25558,7 @@ const createNodePrinter = (modules) => {
ifForm(parent) === CONDITIONAL_FORM))
);
case NodeType.SequenceExpression: {
- const count = tree.fieldCount(Field.expressions, parent);
+ const count = A.fieldCount(Field.expressions, parent);
return itemOf(count - 1, Field.expressions, parent) !== node;
}
default:
@@ -25666,7 +25597,7 @@ const createNodePrinter = (modules) => {
const picked = pickedOperand(parent);
if (picked === node) break;
if (picked !== 0 || left !== node) return false;
- const operator = tree.textOf(Part.operator, parent);
+ const operator = A.textOf(Part.operator, parent);
const right = childOf(Field.right, parent);
if (holdsComments(right)) return false;
const truth =
@@ -25746,8 +25677,8 @@ const createNodePrinter = (modules) => {
const enumerationOf = (node) => {
if (
!compresses ||
- tree.flag(Flag.optional, node) ||
- tree.fieldCount(Field.arguments, node) !== 1 ||
+ A.flag(Flag.optional, node) ||
+ A.fieldCount(Field.arguments, node) !== 1 ||
hasEdgeComments(node)
) {
return;
@@ -25773,7 +25704,7 @@ const createNodePrinter = (modules) => {
if (hasEdgeComments(argument)) return;
const type = typeOf(argument);
if (type === NodeType.Literal) {
- return typeof tree.value(argument) === "string" ? method : undefined;
+ return typeof A.value(argument) === "string" ? method : undefined;
}
if (type === NodeType.ObjectExpression) {
return method === "keys" && objectKeysOf(argument) !== undefined
@@ -25781,7 +25712,7 @@ const createNodePrinter = (modules) => {
: undefined;
}
if (type !== NodeType.ArrayExpression) return;
- const count = tree.fieldCount(Field.elements, argument);
+ const count = A.fieldCount(Field.elements, argument);
for (let i = 0; i < count; i++) {
const element = itemOf(i, Field.elements, argument);
if (
@@ -25807,7 +25738,7 @@ const createNodePrinter = (modules) => {
const indices = [];
/** @type {string[]} */
const names = [];
- const count = tree.fieldCount(Field.properties, node);
+ const count = A.fieldCount(Field.properties, node);
for (let i = 0; i < count; i++) {
const property = itemOf(i, Field.properties, node);
if (typeOf(property) !== NodeType.Property || hasEdgeComments(property)) {
@@ -25816,13 +25747,13 @@ const createNodePrinter = (modules) => {
const key = childOf(Field.key, property);
/** @type {string} */
let name;
- if (tree.flag(Flag.computed, property)) {
+ if (A.flag(Flag.computed, property)) {
const value =
typeOf(key) === NodeType.Identifier &&
(isGlobalUndefined(key) ||
isGlobalUndefined(key, "NaN") ||
isGlobalUndefined(key, "Infinity"))
- ? tree.name(key)
+ ? A.name(key)
: evaluateConstant(key);
if (value === undefined || !isPureValue(key)) return;
name = String(value);
@@ -25830,16 +25761,16 @@ const createNodePrinter = (modules) => {
name = keyName(key);
if (
name === "__proto__" &&
- !tree.flag(Flag.shorthand, property) &&
- !tree.flag(Flag.method, property) &&
- tree.textOf(Part.kind, property) === "init"
+ !A.flag(Flag.shorthand, property) &&
+ !A.flag(Flag.method, property) &&
+ A.textOf(Part.kind, property) === "init"
) {
return;
}
}
if (
- tree.textOf(Part.kind, property) === "init" &&
- !tree.flag(Flag.method, property) &&
+ A.textOf(Part.kind, property) === "init" &&
+ !A.flag(Flag.method, property) &&
!isPureValue(childOf(Field.value, property))
) {
return;
@@ -25870,7 +25801,7 @@ const createNodePrinter = (modules) => {
if (typeOf(node) === NodeType.CallExpression) {
const object = childOf(Field.object, childOf(Field.callee, node));
if (constantElements(object, values) === undefined) return;
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
const argument = itemOf(i, Field.arguments, node);
// A joined argument that is no array literal is a constant.
@@ -25925,15 +25856,15 @@ const createNodePrinter = (modules) => {
*/
const joinedOf = (node) => {
const callee = childOf(Field.callee, node);
- const args = tree.fieldCount(Field.arguments, node);
+ const args = A.fieldCount(Field.arguments, node);
if (
typeOf(callee) !== NodeType.MemberExpression ||
- tree.flag(Flag.computed, callee) ||
- tree.flag(Flag.optional, callee) ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.computed, callee) ||
+ A.flag(Flag.optional, callee) ||
+ A.flag(Flag.optional, node) ||
args > 1 ||
holdsComments(node) ||
- tree.name(childOf(Field.property, callee)) !== "join"
+ A.name(childOf(Field.property, callee)) !== "join"
) {
return;
}
@@ -25957,9 +25888,7 @@ const createNodePrinter = (modules) => {
if (typeOf(object) === NodeType.ArrayExpression) {
values = constantElements(object, []);
if (values === undefined) return;
- } else if (
- concatJoined(object) === tree.fieldCount(Field.arguments, object)
- ) {
+ } else if (concatJoined(object) === A.fieldCount(Field.arguments, object)) {
values = constantElements(object, []);
if (values === undefined) return;
} else if (
@@ -25972,11 +25901,11 @@ const createNodePrinter = (modules) => {
values = /** @type {string[]} */ (objectKeysOf(argument));
break;
case NodeType.Literal:
- values = Object.keys(/** @type {string} */ (tree.value(argument)));
+ values = Object.keys(/** @type {string} */ (A.value(argument)));
break;
default: {
values = [];
- const count = tree.fieldCount(Field.elements, argument);
+ const count = A.fieldCount(Field.elements, argument);
for (let i = 0; i < count; i++) {
if (itemOf(i, Field.elements, argument) !== 0) values.push(`${i}`);
}
@@ -26016,7 +25945,7 @@ const createNodePrinter = (modules) => {
*/
const isNegation = (node) =>
typeOf(node) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, node) === "!";
+ A.textOf(Part.operator, node) === "!";
/**
* @param {number} node an expression
@@ -26027,21 +25956,21 @@ const createNodePrinter = (modules) => {
node = foldedTo(node);
switch (typeOf(node)) {
case NodeType.UnaryExpression:
- if (tree.textOf(Part.operator, node) === "delete") return true;
+ if (A.textOf(Part.operator, node) === "delete") return true;
// `!!x` read for its truth prints as `x`, no boolean.
return (
- tree.textOf(Part.operator, node) === "!" &&
+ A.textOf(Part.operator, node) === "!" &&
!isNegation(childOf(Field.argument, node))
);
case NodeType.BinaryExpression:
- switch (tree.textOf(Part.operator, node)) {
+ switch (A.textOf(Part.operator, node)) {
case "!=":
case "!==":
// A test of `0` read for its truth prints the integer.
return (
comparedInteger(
node,
- tree.textOf(Part.operator, node),
+ A.textOf(Part.operator, node),
childOf(Field.left, node),
childOf(Field.right, node)
) === 0
@@ -26061,13 +25990,13 @@ const createNodePrinter = (modules) => {
// the boolean they end in.
case NodeType.AssignmentExpression:
return (
- tree.textOf(Part.operator, node) === "=" &&
+ A.textOf(Part.operator, node) === "=" &&
givesBoolean(childOf(Field.right, node))
);
case NodeType.SequenceExpression:
return givesBoolean(
itemOf(
- tree.fieldCount(Field.expressions, node) - 1,
+ A.fieldCount(Field.expressions, node) - 1,
Field.expressions,
node
)
@@ -26101,10 +26030,10 @@ const createNodePrinter = (modules) => {
childOf(Field.test, parent) === node || readsTruth(parent, level + 1)
);
case NodeType.UnaryExpression:
- return tree.textOf(Part.operator, parent) === "!";
+ return A.textOf(Part.operator, parent) === "!";
case NodeType.LogicalExpression:
return (
- tree.textOf(Part.operator, parent) !== "??" &&
+ A.textOf(Part.operator, parent) !== "??" &&
(readsTruth(parent, level + 1) ||
valueUnread(parent, parentAt(level + 1)))
);
@@ -26123,7 +26052,7 @@ const createNodePrinter = (modules) => {
return (
typeOf(parent) === NodeType.SequenceExpression &&
itemOf(
- tree.fieldCount(Field.expressions, parent) - 1,
+ A.fieldCount(Field.expressions, parent) - 1,
Field.expressions,
parent
) === node &&
@@ -26155,7 +26084,7 @@ const createNodePrinter = (modules) => {
global
? keepsGlobalNames || keepsInfinity
: // A literal too big for a double, which the name would misread.
- tree.type(node) !== NodeType.Literal
+ A.type(node) !== NodeType.Literal
) {
return false;
}
@@ -26174,7 +26103,7 @@ const createNodePrinter = (modules) => {
const bare =
typeOf(parent) === NodeType.UnaryExpression
? !negative &&
- tree.textOf(Part.operator, parent) === "-" &&
+ A.textOf(Part.operator, parent) === "-" &&
holdsDivisionBare(parent, parentAt(1))
: holdsDivisionBare(node, parent);
if (!bare) output.print("(");
@@ -26204,7 +26133,7 @@ const createNodePrinter = (modules) => {
const holdsDivisionBare = (node, parent) => {
switch (typeOf(parent)) {
case NodeType.BinaryExpression: {
- const operator = tree.textOf(Part.operator, parent);
+ const operator = A.textOf(Part.operator, parent);
return (
operator !== "*" &&
operator !== "/" &&
@@ -26218,7 +26147,7 @@ const createNodePrinter = (modules) => {
case NodeType.MemberExpression:
// A computed key reads to its `]`.
return (
- tree.flag(Flag.computed, parent) &&
+ A.flag(Flag.computed, parent) &&
childOf(Field.property, parent) === node
);
case NodeType.UnaryExpression:
@@ -26240,7 +26169,7 @@ const createNodePrinter = (modules) => {
const builtInOwnerOf = (node) => {
const type = typeOf(node);
if (type === NodeType.Identifier) {
- const name = tree.name(node);
+ const name = A.name(node);
if (
name === "Math" ||
name === "Number" ||
@@ -26260,11 +26189,11 @@ const createNodePrinter = (modules) => {
? ""
: undefined;
}
- if (type !== NodeType.MemberExpression || tree.flag(Flag.computed, node)) {
+ if (type !== NodeType.MemberExpression || A.flag(Flag.computed, node)) {
return undefined;
}
const owner = builtInOwnerOf(childOf(Field.object, node));
- const key = tree.name(childOf(Field.property, node));
+ const key = A.name(childOf(Field.property, node));
// A constructor read off the global object: `globalThis.Object`.
if (owner === "" && ORDINARY_CONSTRUCTORS.includes(key)) return key;
if (key !== "prototype") return undefined;
@@ -26306,10 +26235,10 @@ const createNodePrinter = (modules) => {
}
if (typeOf(target) !== NodeType.MemberExpression) return;
const property = childOf(Field.property, target);
- const key = !tree.flag(Flag.computed, target)
- ? tree.name(property)
+ const key = !A.flag(Flag.computed, target)
+ ? A.name(property)
: typeOf(property) === NodeType.Literal
- ? String(tree.value(property))
+ ? String(A.value(property))
: "*";
// Any object's `__proto__` may be a built-in prototype under another name.
if (key === "__proto__") writes.add(PROTOTYPE_SET);
@@ -26341,17 +26270,17 @@ const createNodePrinter = (modules) => {
noteBuiltInWrite(childOf(Field.argument, node), true);
break;
case NodeType.UnaryExpression:
- if (tree.textOf(Part.operator, node) === "delete") {
+ if (A.textOf(Part.operator, node) === "delete") {
noteBuiltInWrite(childOf(Field.argument, node), true);
}
break;
case NodeType.ArrayPattern:
- for (let i = 0; i < tree.fieldCount(Field.elements, node); i++) {
+ for (let i = 0; i < A.fieldCount(Field.elements, node); i++) {
noteBuiltInWrite(itemOf(i, Field.elements, node), true);
}
break;
case NodeType.ObjectPattern:
- for (let i = 0; i < tree.fieldCount(Field.properties, node); i++) {
+ for (let i = 0; i < A.fieldCount(Field.properties, node); i++) {
const property = itemOf(i, Field.properties, node);
noteBuiltInWrite(
typeOf(property) === NodeType.Property
@@ -26366,7 +26295,7 @@ const createNodePrinter = (modules) => {
case NodeType.CallExpression: {
const callee = childOf(Field.callee, node);
if (
- tree.fieldCount(Field.arguments, node) === 0 ||
+ A.fieldCount(Field.arguments, node) === 0 ||
typeOf(callee) !== NodeType.MemberExpression
) {
break;
@@ -26375,19 +26304,19 @@ const createNodePrinter = (modules) => {
// `globalThis.Object.assign` names its writer as `Object.assign` does.
const owner =
typeOf(object) === NodeType.Identifier
- ? tree.name(object)
+ ? A.name(object)
: typeOf(object) === NodeType.MemberExpression &&
- !tree.flag(Flag.computed, object) &&
+ !A.flag(Flag.computed, object) &&
builtInOwnerOf(childOf(Field.object, object)) === ""
- ? tree.name(childOf(Field.property, object))
+ ? A.name(childOf(Field.property, object))
: "";
if (owner !== "Object" && owner !== "Reflect") break;
const property = childOf(Field.property, callee);
// `Reflect["set"]` names its writer as `Reflect.set` does.
- const name = !tree.flag(Flag.computed, callee)
- ? tree.name(property)
+ const name = !A.flag(Flag.computed, callee)
+ ? A.name(property)
: typeOf(property) === NodeType.Literal
- ? tree.value(property)
+ ? A.value(property)
: undefined;
if (
typeof name === "string" &&
@@ -26440,15 +26369,15 @@ const createNodePrinter = (modules) => {
const methodNameOf = (callee) => {
if (
typeOf(callee) !== NodeType.MemberExpression ||
- tree.flag(Flag.optional, callee)
+ A.flag(Flag.optional, callee)
) {
return "";
}
const property = childOf(Field.property, callee);
- if (!tree.flag(Flag.computed, callee)) return tree.name(property);
+ if (!A.flag(Flag.computed, callee)) return A.name(property);
const value =
typeOf(property) === NodeType.Literal && !hasEdgeComments(property)
- ? tree.value(property)
+ ? A.value(property)
: undefined;
return typeof value === "string" ? value : "";
};
@@ -26463,7 +26392,7 @@ const createNodePrinter = (modules) => {
const foldedFunctionOf = (callee) => {
const tables = foldedBuiltInTables();
if (typeOf(callee) === NodeType.Identifier) {
- const name = tree.name(callee);
+ const name = A.name(callee);
return (tables.globals.includes(name) ||
FOLDED_CONVERSIONS.includes(name)) &&
isGlobalUndefined(callee, name)
@@ -26483,9 +26412,9 @@ const createNodePrinter = (modules) => {
const object = childOf(Field.object, callee);
if (
typeOf(object) === NodeType.Identifier &&
- hasOwn(tables.statics, tree.name(object))
+ hasOwn(tables.statics, A.name(object))
) {
- const owner = tree.name(object);
+ const owner = A.name(object);
if (!tables.statics[owner].includes(name)) return undefined;
if (!isGlobalUndefined(object, owner)) return undefined;
const receiver =
@@ -26504,7 +26433,7 @@ const createNodePrinter = (modules) => {
? undefined
: [String.prototype.toString, text, "RegExp.prototype.toString"];
}
- const literal = tree.value(object);
+ const literal = A.value(object);
if (typeof literal === "bigint") {
return [
/** @type {BuiltInFunction} */ (BigInt.prototype.toString),
@@ -26585,13 +26514,13 @@ const createNodePrinter = (modules) => {
const printedSizeOf = (node, value) => {
// `undefined` prints as the global's name, else as `void 0` at least.
if (value === undefined) {
- return typeOf(node) === NodeType.Identifier ? tree.name(node).length : 6;
+ return typeOf(node) === NodeType.Identifier ? A.name(node).length : 6;
}
switch (typeOf(node)) {
case NodeType.Literal:
// A regular expression or BigInt receiver prints as written.
return typeof value === "bigint" || isRegExpLiteral(node)
- ? /** @type {string} */ (tree.textOf(Part.raw, node)).length
+ ? /** @type {string} */ (A.textOf(Part.raw, node)).length
: printedValueLength(value);
case NodeType.UnaryExpression: {
// The operator, then its operand: `-1`, `!0`, `-Infinity`.
@@ -26607,9 +26536,9 @@ const createNodePrinter = (modules) => {
);
}
case NodeType.Identifier:
- return tree.name(node).length;
+ return A.name(node).length;
case NodeType.TemplateLiteral:
- return tree.fieldCount(Field.expressions, node) === 0
+ return A.fieldCount(Field.expressions, node) === 0
? printedValueLength(value)
: Number.NaN;
case NodeType.CallExpression: {
@@ -26622,7 +26551,7 @@ const createNodePrinter = (modules) => {
case NodeType.ArrayExpression: {
// Its brackets, commas and elements, each printing no shorter than
// its value.
- const count = tree.fieldCount(Field.elements, node);
+ const count = A.fieldCount(Field.elements, node);
let size = 2 + Math.max(count - 1, 0);
// Measured with a value, as `joinedArrayOf` gives it, it has no hole.
for (let i = 0; i < count; i++) {
@@ -26641,7 +26570,7 @@ const createNodePrinter = (modules) => {
const right = childOf(Field.right, node);
return Math.min(
printedSizeOf(left, evaluateConstant(left)) +
- /** @type {string} */ (tree.textOf(Part.operator, node)).length +
+ /** @type {string} */ (A.textOf(Part.operator, node)).length +
printedSizeOf(right, evaluateConstant(right)),
printedValueLength(value)
);
@@ -26659,9 +26588,9 @@ const createNodePrinter = (modules) => {
const property = childOf(Field.property, node);
return Math.min(
printedSizeOf(object, evaluateConstant(object)) +
- (tree.flag(Flag.computed, node)
+ (A.flag(Flag.computed, node)
? 2 + printedSizeOf(property, evaluateConstant(property))
- : 1 + tree.name(property).length),
+ : 1 + A.name(property).length),
printedValueLength(value)
);
}
@@ -26685,7 +26614,7 @@ const createNodePrinter = (modules) => {
*/
const evaluateFoldedCall = (node) => {
if (
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.optional, node) ||
holdsComments(node) ||
keepsGlobalNames
) {
@@ -26707,7 +26636,7 @@ const createNodePrinter = (modules) => {
}
const name = qualified.slice(qualified.lastIndexOf(".") + 1);
const isMethod = qualified.includes(".prototype.");
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
/** @type {(string | number | boolean | null | undefined)[]} */
const args = [];
for (let i = 0; i < count; i++) {
@@ -26844,7 +26773,7 @@ const createNodePrinter = (modules) => {
(value < 0 || Object.is(value, -0)) &&
(!takesUnary(node) || isCalledOrAccessed(node, parentAt(0)));
skipNode(callee);
- const count = tree.fieldCount(Field.arguments, node);
+ const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) skipNode(itemOf(i, Field.arguments, node));
if (wrap) output.print("(");
printValue(value, takesUnary(node));
@@ -26859,7 +26788,7 @@ const createNodePrinter = (modules) => {
const flatElements = (array) => {
/** @type {number[]} */
const elements = [];
- const count = tree.fieldCount(Field.elements, array);
+ const count = A.fieldCount(Field.elements, array);
for (let i = 0; i < count; i++) {
const element = itemOf(i, Field.elements, array);
if (typeOf(element) !== NodeType.SpreadElement) {
@@ -26867,7 +26796,7 @@ const createNodePrinter = (modules) => {
continue;
}
if (spreadsAs(element, array) !== 2) return null;
- const inner = flatElements(tree.field(0, Field.argument, element));
+ const inner = flatElements(A.field(0, Field.argument, element));
if (inner === null) return null;
for (const item of inner) elements.push(item);
}
@@ -26879,9 +26808,9 @@ const createNodePrinter = (modules) => {
* @returns {string | undefined} its text where it substitutes nothing, undefined otherwise
*/
const templateValue = (node) =>
- tree.fieldCount(Field.expressions, node) === 0
+ A.fieldCount(Field.expressions, node) === 0
? /** @type {{ raw: string, cooked: string }} */ (
- tree.value(tree.field(0, Field.quasis, node))
+ A.value(A.field(0, Field.quasis, node))
).cooked
: undefined;
@@ -26892,9 +26821,9 @@ const createNodePrinter = (modules) => {
*/
const literalPropertyOf = (node, printed) => {
const property = childOf(Field.property, node);
- if (tree.flag(Flag.optional, node)) return undefined;
+ if (A.flag(Flag.optional, node)) return undefined;
// `x["length"]` reads what `x.length` does, and `"ab"[1]` a character.
- const computed = tree.flag(Flag.computed, node);
+ const computed = A.flag(Flag.computed, node);
const key = computed ? evaluateConstant(property) : undefined;
// `"ab"[1]` and `"ab"["1"]` read a code unit.
const index =
@@ -26910,7 +26839,7 @@ const createNodePrinter = (modules) => {
) {
return undefined;
}
- const name = computed ? String(key) : tree.name(property);
+ const name = computed ? String(key) : A.name(property);
if (name !== "length" && name !== "source" && index === -1) {
return undefined;
}
@@ -26921,7 +26850,7 @@ const createNodePrinter = (modules) => {
childOf(Field.callee, parent) === node) ||
parentType === NodeType.TaggedTemplateExpression ||
(parentType === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, parent) === "delete")
+ A.textOf(Part.operator, parent) === "delete")
) {
return undefined;
}
@@ -26953,7 +26882,7 @@ const createNodePrinter = (modules) => {
// makes.
const value =
type === NodeType.Literal
- ? tree.value(object)
+ ? A.value(object)
: type === NodeType.TemplateLiteral ||
type === NodeType.BinaryExpression ||
type === NodeType.ParenthesizedExpression ||
@@ -26979,10 +26908,10 @@ const createNodePrinter = (modules) => {
*/
const numberConstantOf = (node) => {
const object = childOf(Field.object, node);
- const property = tree.field(0, Field.property, node);
+ const property = A.field(0, Field.property, node);
if (
- tree.flag(Flag.computed, node) ||
- tree.flag(Flag.optional, node) ||
+ A.flag(Flag.computed, node) ||
+ A.flag(Flag.optional, node) ||
typeOf(object) !== NodeType.Identifier ||
typeOf(property) !== NodeType.Identifier ||
hasEdgeComments(object) ||
@@ -26994,14 +26923,14 @@ const createNodePrinter = (modules) => {
const parent = parentAt(0);
switch (typeOf(parent)) {
case NodeType.UnaryExpression:
- if (tree.textOf(Part.operator, parent) === "delete") return undefined;
+ if (A.textOf(Part.operator, parent) === "delete") return undefined;
break;
case NodeType.CallExpression:
// A call of a member binds `this` to its object.
if (childOf(Field.callee, parent) === node) return undefined;
break;
}
- return tree.name(property);
+ return A.name(property);
};
/**
@@ -27028,8 +26957,8 @@ const createNodePrinter = (modules) => {
name === "MAX_SAFE_INTEGER" &&
typeOf(parent) === NodeType.BinaryExpression &&
childOf(Field.right, parent) === node &&
- (tree.textOf(Part.operator, parent) === "+" ||
- tree.textOf(Part.operator, parent) === "-")
+ (A.textOf(Part.operator, parent) === "+" ||
+ A.textOf(Part.operator, parent) === "-")
);
return bare ? spelling : `(${spelling})`;
};
@@ -27057,7 +26986,7 @@ const createNodePrinter = (modules) => {
return UNARY_UNREAD_OPERAND;
}
if (typeOf(parent) === NodeType.UnaryExpression) {
- const operator = tree.textOf(Part.operator, parent);
+ const operator = A.textOf(Part.operator, parent);
return (operator === "!" || operator === "void") &&
!hasEdgeComments(parent) &&
!(pushedNegations.size !== 0 && pushedNegations.has(node)) &&
@@ -27102,8 +27031,8 @@ const createNodePrinter = (modules) => {
const printUnary = (node) => {
if (printsLiftedSequence(node)) return;
const argument = childOf(Field.argument, node);
- const operator = /** @type {string} */ (tree.textOf(Part.operator, node));
- if (!tree.flag(Flag.prefix, node)) {
+ const operator = /** @type {string} */ (A.textOf(Part.operator, node));
+ if (!A.flag(Flag.prefix, node)) {
printNode(argument);
output.print(operator);
return;
@@ -27292,7 +27221,7 @@ const createNodePrinter = (modules) => {
compresses &&
operator === "!" &&
typeOf(argument) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, argument) === "!" &&
+ A.textOf(Part.operator, argument) === "!" &&
!isNegation(childOf(Field.argument, argument)) &&
!holdsComments(argument) &&
readsTruthOrLast(node)
@@ -27413,7 +27342,7 @@ const createNodePrinter = (modules) => {
? /** @type {number} */ (collapsed.get(argument))
: argument;
const opens =
- tree.type(shown) === NodeType.Identifier ? 0 : heads[shown] & 0xffff;
+ A.type(shown) === NodeType.Identifier ? 0 : heads[shown] & 0xffff;
if (
/^[a-z]/i.test(operator) ||
(/[+-]$/.test(operator) && (opens === 43 || opens === 45))
@@ -27497,7 +27426,7 @@ const createNodePrinter = (modules) => {
case NodeType.NewExpression:
return childOf(Field.callee, parent) !== node;
case NodeType.BinaryExpression:
- return tree.textOf(Part.operator, parent) !== "**";
+ return A.textOf(Part.operator, parent) !== "**";
default:
return true;
}
@@ -27553,7 +27482,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- switch (tree.textOf(Part.operator, parent)) {
+ switch (A.textOf(Part.operator, parent)) {
case "-":
case "*":
case "/":
@@ -27653,7 +27582,7 @@ const createNodePrinter = (modules) => {
if (!holdsDirectives(owner)) return false;
const body = bodyOf(owner);
for (let i = 0; ; i++) {
- const other = tree.field(i, Field.body, body);
+ const other = A.field(i, Field.body, body);
if (other === statement) return true;
if (!isDirective(other) && typeOf(other) !== NodeType.EmptyStatement) {
return false;
@@ -27666,7 +27595,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether its body may open with directives
*/
const holdsDirectives = (owner) => {
- const type = tree.type(owner);
+ const type = A.type(owner);
return (
type === NodeType.Program ||
type === NodeType.FunctionDeclaration ||
@@ -27681,14 +27610,14 @@ const createNodePrinter = (modules) => {
* @returns {number} the node listing its statements
*/
const bodyOf = (owner) => {
- switch (tree.type(owner)) {
+ switch (A.type(owner)) {
case NodeType.Program:
return owner;
case NodeType.MethodDefinition:
case NodeType.Property:
- return tree.field(0, Field.body, tree.field(0, Field.value, owner));
+ return A.field(0, Field.body, A.field(0, Field.value, owner));
default:
- return tree.field(0, Field.body, owner);
+ return A.field(0, Field.body, owner);
}
};
@@ -27700,27 +27629,27 @@ const createNodePrinter = (modules) => {
*/
const usesAsm = (node) => {
if (!mayUseAsm) return false;
- const start = tree.start(node);
+ const start = A.start(node);
for (let level = 0; ; level++) {
const holder = ancestorOf(level);
if (holder === 0) return false;
- if (!isScopeType(tree.type(holder))) continue;
- const holderType = tree.type(holder);
+ if (!isScopeType(A.type(holder))) continue;
+ const holderType = A.type(holder);
// A class, or an arrow returning an expression, says nothing.
const body =
holderType === NodeType.Program || holderType === NodeType.StaticBlock
? holder
- : tree.field(0, Field.body, holder);
- if (body !== holder && tree.type(body) !== NodeType.BlockStatement) {
+ : A.field(0, Field.body, holder);
+ if (body !== holder && A.type(body) !== NodeType.BlockStatement) {
continue;
}
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.body, body);
+ const statement = A.field(i, Field.body, body);
if (!isDirective(statement)) break;
if (
- tree.textOf(Part.directive, statement) === "use asm" &&
- tree.start(statement) < start
+ A.textOf(Part.directive, statement) === "use asm" &&
+ A.start(statement) < start
) {
return true;
}
@@ -27734,7 +27663,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printRegExp = (node) => {
- const raw = /** @type {string} */ (tree.textOf(Part.raw, node));
+ const raw = /** @type {string} */ (A.textOf(Part.raw, node));
const end = raw.lastIndexOf("/");
const flags = raw.slice(end + 1);
let pattern = regexpSourceFix(regexpSourceAsRead(raw.slice(1, end)));
@@ -27765,9 +27694,9 @@ const createNodePrinter = (modules) => {
const returnsChain = (body) => {
if (!compresses || holdsComments(body)) return false;
let previous = 0;
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (printsNothing(item)) continue;
if (previous !== 0 && returnPairs.get(previous) !== item) return false;
if (typeOf(item) === NodeType.ReturnStatement) {
@@ -27775,7 +27704,7 @@ const createNodePrinter = (modules) => {
}
if (
typeOf(item) !== NodeType.IfStatement ||
- tree.field(0, Field.alternate, item) !== 0 ||
+ A.field(0, Field.alternate, item) !== 0 ||
ifForm(item) !== RETURN_FORM
) {
return false;
@@ -27794,7 +27723,7 @@ const createNodePrinter = (modules) => {
const type = typeOf(holder);
// An arrow's block body is passed over: its statements are the arrow's.
if (type === NodeType.ArrowFunctionExpression) {
- const block = tree.field(0, Field.body, holder);
+ const block = A.field(0, Field.body, holder);
return typeOf(block) === NodeType.BlockStatement && returnsChain(block);
}
return (
@@ -27810,7 +27739,7 @@ const createNodePrinter = (modules) => {
*/
const chainsBranch = (block, parent) =>
typeOf(parent) === NodeType.IfStatement &&
- tree.field(0, Field.consequent, parent) === block &&
+ A.field(0, Field.consequent, parent) === block &&
returnsChain(block) &&
ifForm(parent) === RETURN_FORM;
@@ -27819,12 +27748,12 @@ const createNodePrinter = (modules) => {
* @returns {number} its one statement, alone but for those printing nothing, 0 for none
*/
const soleStatement = (body) => {
- const count = tree.fieldCount(Field.body, body);
- if (count === 1) return soleOf(tree.field(0, Field.body, body));
+ const count = A.fieldCount(Field.body, body);
+ if (count === 1) return soleOf(A.field(0, Field.body, body));
if (!compresses || holdsComments(body)) return 0;
let statement = 0;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (printsNothing(item)) continue;
if (statement !== 0) return 0;
statement = item;
@@ -27847,11 +27776,11 @@ const createNodePrinter = (modules) => {
*/
const sequenceReturn = (body) => {
if (!compresses || holdsComments(body)) return 0;
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
let expressions = 0;
let last = 0;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (printsNothing(item)) continue;
if (last !== 0) return 0;
const type = typeOf(item);
@@ -27915,12 +27844,12 @@ const createNodePrinter = (modules) => {
isUnaryType(parentType) ||
(isCallType(parentType) && childOf(Field.callee, parent) === node);
if (parenthesized) output.print("(");
- if (tree.flag(Flag.async, node)) {
+ if (A.flag(Flag.async, node)) {
output.print("async");
output.space();
}
// The one parameter printing, a name, takes no parentheses.
- const params = tree.fieldCount(Field.params, node);
+ const params = A.fieldCount(Field.params, node);
let only = 0;
for (let i = 0; i < params; i++) {
const param = itemOf(i, Field.params, node);
@@ -27960,9 +27889,9 @@ const createNodePrinter = (modules) => {
? childOf(Field.argument, statement)
: 0;
// What prints nothing goes with the braces.
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (item !== statement) {
/** @type {JavascriptPrintContext} */ (writer).consume(item);
}
@@ -27977,16 +27906,16 @@ const createNodePrinter = (modules) => {
returnsUnread(-1) &&
isPureValue(childOf(Field.argument, last));
if (last !== 0 && !drops) {
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
let alone = true;
for (let i = 0; alone && i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
alone = item === last || printedNothing(item);
}
// The rest printing nothing, the value is what the arrow returns.
if (alone) {
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (item !== last) {
/** @type {JavascriptPrintContext} */ (writer).consume(item);
}
@@ -27999,10 +27928,10 @@ const createNodePrinter = (modules) => {
if (last !== 0) {
// terser's `sequences` of an arrow: `{a();return b}` is `(a(),b)`.
output.print(drops ? "{" : "(");
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
let printed = false;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (item !== last && printedNothing(item)) {
/** @type {JavascriptPrintContext} */ (writer).consume(item);
continue;
@@ -28018,17 +27947,17 @@ const createNodePrinter = (modules) => {
output.mightNeedSemicolon = false;
output.print(drops ? "}" : ")");
} else if (!returns && returnsChain(body)) {
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
// The chain opens with the first statement printing.
let first = 0;
for (let i = 0; first === 0 && i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (!printsNothing(item)) first = item;
}
const wraps = leftIsObject(childOf(Field.test, first));
if (wraps) output.print("(");
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, body);
+ const item = A.field(i, Field.body, body);
if (printsNothing(item)) {
/** @type {JavascriptPrintContext} */ (writer).consume(item);
} else {
@@ -28128,7 +28057,7 @@ const createNodePrinter = (modules) => {
printNode(childOf(Field.expression, node));
return;
}
- const directive = tree.textOf(Part.directive, node);
+ const directive = A.textOf(Part.directive, node);
const expression = childOf(Field.expression, node);
if (conditionalElses.size !== 0 && conditionalElses.has(node)) {
// The `else` of the `?:` the `if` before it printed.
@@ -28147,7 +28076,7 @@ const createNodePrinter = (modules) => {
return;
}
if (directive !== null) {
- const value = /** @type {string} */ (tree.value(expression));
+ const value = /** @type {string} */ (A.value(expression));
if (directive !== value) {
const quote = quoteOf(expression);
const spelled = output.option("inlineScript")
@@ -28200,7 +28129,7 @@ const createNodePrinter = (modules) => {
if (
compresses &&
typeOf(parent) === NodeType.IfStatement &&
- tree.field(0, Field.alternate, parent) === node &&
+ A.field(0, Field.alternate, parent) === node &&
liftsElse(parent, parentAt(1), 1)
) {
displayBody(node);
@@ -28225,7 +28154,7 @@ const createNodePrinter = (modules) => {
childOf(Field.body, parent) !== node)) &&
!scopesLexically(node) &&
!opensWithString(node) &&
- (tree.fieldCount(Field.body, node) !== 0 || !holdsComments(node)) &&
+ (A.fieldCount(Field.body, node) !== 0 || !holdsComments(node)) &&
// A block that is its braceless parent's one statement prints as one.
!(
typeOf(parent) === NodeType.BlockStatement &&
@@ -28237,9 +28166,9 @@ const createNodePrinter = (modules) => {
}
// A body printing as the value its `if` returns prints as that value.
if (compresses && chainsBranch(node, parent)) {
- const count = tree.fieldCount(Field.body, node);
+ const count = A.fieldCount(Field.body, node);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, node);
+ const item = A.field(i, Field.body, node);
if (printsNothing(item)) {
/** @type {JavascriptPrintContext} */ (writer).consume(item);
} else {
@@ -28255,9 +28184,9 @@ const createNodePrinter = (modules) => {
}
if (statement !== 0) {
const context = /** @type {JavascriptPrintContext} */ (writer);
- const count = tree.fieldCount(Field.body, node);
+ const count = A.fieldCount(Field.body, node);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, node);
+ const item = A.field(i, Field.body, node);
// One printing nothing, as a folded `if` may, is an empty statement.
if (item === statement && context.get(item).length !== 0) {
printNode(item);
@@ -28270,10 +28199,10 @@ const createNodePrinter = (modules) => {
}
if (compresses && joinsBody(node, parent)) {
// terser's `sequences` of a body: `a(),b()` needs no braces.
- const count = tree.fieldCount(Field.body, node);
+ const count = A.fieldCount(Field.body, node);
let printed = false;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.body, node);
+ const item = A.field(i, Field.body, node);
if (printedNothing(item)) {
/** @type {JavascriptPrintContext} */ (writer).consume(item);
continue;
@@ -28289,10 +28218,10 @@ const createNodePrinter = (modules) => {
}
if (compresses && bracesNothing(node, parent)) {
// terser's empty block as a body: `;` is shorter than `{}`.
- const count = tree.fieldCount(Field.body, node);
+ const count = A.fieldCount(Field.body, node);
for (let i = 0; i < count; i++) {
/** @type {JavascriptPrintContext} */ (writer).consume(
- tree.field(i, Field.body, node)
+ A.field(i, Field.body, node)
);
}
output.forceSemicolon();
@@ -28300,7 +28229,7 @@ const createNodePrinter = (modules) => {
}
if (
typeOf(parent) === NodeType.TryStatement &&
- tree.field(0, Field.finalizer, parent) === node
+ A.field(0, Field.finalizer, parent) === node
) {
output.print("finally");
output.space();
@@ -28314,7 +28243,7 @@ const createNodePrinter = (modules) => {
listedStatements === 1 &&
((LOOP_TYPES[typeOf(parent)] === 1 &&
typeOf(parent) !== NodeType.DoWhileStatement &&
- tree.field(0, Field.body, parent) === node) ||
+ A.field(0, Field.body, parent) === node) ||
typeOf(parent) === NodeType.IfStatement ||
// One a block holding only it prints as stands where that block does.
(typeOf(parent) === NodeType.BlockStatement &&
@@ -28353,7 +28282,7 @@ const createNodePrinter = (modules) => {
output.semicolon();
};
generators[NodeType.LabeledStatement] = (node) => {
- const body = tree.field(0, Field.body, node);
+ const body = A.field(0, Field.body, node);
if (
compresses &&
!jumpedLabels.has(node) &&
@@ -28366,7 +28295,7 @@ const createNodePrinter = (modules) => {
!hasEdgeComments(node)
) {
// No `break` or `continue` names it.
- skipNode(tree.field(0, Field.label, node));
+ skipNode(A.field(0, Field.label, node));
if (
dropsSideEffectFree &&
typeOf(body) === NodeType.ExpressionStatement &&
@@ -28387,14 +28316,14 @@ const createNodePrinter = (modules) => {
printNode(body);
return;
}
- printNode(tree.field(0, Field.label, node));
+ printNode(A.field(0, Field.label, node));
output.colon();
if (typeOf(body) === NodeType.EmptyStatement) output.forceSemicolon();
else printNode(body);
};
generators[NodeType.DoWhileStatement] = (node) => {
const test = childOf(Field.test, node);
- const body = tree.field(0, Field.body, node);
+ const body = A.field(0, Field.body, node);
const value =
compresses && dropsDeadCode && !holdsComments(node)
? evaluateConstant(test)
@@ -28461,7 +28390,7 @@ const createNodePrinter = (modules) => {
}
output.print("do");
output.space();
- makeBlock(tree.field(0, Field.body, node));
+ makeBlock(A.field(0, Field.body, node));
output.space();
output.print("while");
output.space();
@@ -28477,8 +28406,8 @@ const createNodePrinter = (modules) => {
return false;
}
let last = 0;
- for (let i = tree.fieldCount(Field.body, body) - 1; i >= 0; i--) {
- const statement = tree.field(i, Field.body, body);
+ for (let i = A.fieldCount(Field.body, body) - 1; i >= 0; i--) {
+ const statement = A.field(i, Field.body, body);
if (last === 0) {
if (printsNothing(statement)) continue;
if (!isBareBreak(statement)) return false;
@@ -28498,12 +28427,12 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether its body is a `break` leaving it, alone or in a block
*/
const breaksAtOnce = (node, parent) => {
- let body = tree.field(0, Field.body, node);
+ let body = A.field(0, Field.body, node);
if (
typeOf(body) === NodeType.BlockStatement &&
- tree.fieldCount(Field.body, body) === 1
+ A.fieldCount(Field.body, body) === 1
) {
- body = tree.field(0, Field.body, body);
+ body = A.field(0, Field.body, body);
}
return breaksOwnLoop(body, parent);
};
@@ -28521,7 +28450,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const label = tree.field(0, Field.label, statement);
+ const label = A.field(0, Field.label, statement);
return label !== 0 && namesLabel(label, parent);
};
@@ -28531,14 +28460,14 @@ const createNodePrinter = (modules) => {
*/
const setsOnlyPure = (declaration) => {
for (
- let i = tree.fieldCount(Field.declarations, declaration) - 1;
+ let i = A.fieldCount(Field.declarations, declaration) - 1;
i >= 0;
i--
) {
- const declarator = tree.field(i, Field.declarations, declaration);
+ const declarator = A.field(i, Field.declarations, declaration);
const init = childOf(Field.init, declarator);
if (
- typeOf(tree.field(0, Field.id, declarator)) !== NodeType.Identifier ||
+ typeOf(A.field(0, Field.id, declarator)) !== NodeType.Identifier ||
hasEdgeComments(declarator) ||
(init !== 0 && !isPureValue(init))
) {
@@ -28558,7 +28487,7 @@ const createNodePrinter = (modules) => {
const init =
typeOf(node) === NodeType.ForStatement ? childOf(Field.init, node) : 0;
const test = childOf(Field.test, node);
- const body = tree.field(0, Field.body, node);
+ const body = A.field(0, Field.body, node);
if (
!compresses ||
!dropsDeadCode ||
@@ -28580,7 +28509,7 @@ const createNodePrinter = (modules) => {
return false;
}
// A `let` or `const` start keeps the scope the loop gave it, in braces.
- const scopes = declares && tree.textOf(Part.kind, init) !== "var";
+ const scopes = declares && A.textOf(Part.kind, init) !== "var";
skipNode(body);
const update =
typeOf(node) === NodeType.ForStatement ? childOf(Field.update, node) : 0;
@@ -28640,14 +28569,14 @@ const createNodePrinter = (modules) => {
// terser's `loops`: a loop forever is `for(;;)`.
skipNode(test);
output.print("for(;;)");
- printMaybeBracedBody(tree.field(0, Field.body, node));
+ printMaybeBracedBody(A.field(0, Field.body, node));
return;
}
output.print("while");
output.space();
printTest(childOf(Field.test, node));
output.space();
- printMaybeBracedBody(tree.field(0, Field.body, node));
+ printMaybeBracedBody(A.field(0, Field.body, node));
};
generators[NodeType.ForStatement] = (node) => {
if (printsBrokenLoop(node)) return;
@@ -28657,7 +28586,7 @@ const createNodePrinter = (modules) => {
if (deadLoopInits.size !== 0 && deadLoopInits.has(node)) {
skipNode(test);
if (update !== 0) skipNode(update);
- skipNode(tree.field(0, Field.body, node));
+ skipNode(A.field(0, Field.body, node));
printNode(
init,
typeOf(init) !== NodeType.VariableDeclaration && opensAmbiguously(init)
@@ -28718,7 +28647,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printLoopBody = (node, exit) => {
- const body = tree.field(0, Field.body, node);
+ const body = A.field(0, Field.body, node);
if (body === exit && !breakElses.has(exit)) {
skipNode(body);
output.forceSemicolon();
@@ -28730,7 +28659,7 @@ const createNodePrinter = (modules) => {
node
) => {
output.print("for");
- if (tree.flag(Flag.await, node)) {
+ if (A.flag(Flag.await, node)) {
output.space();
output.print("await");
}
@@ -28743,14 +28672,14 @@ const createNodePrinter = (modules) => {
printNode(childOf(Field.right, node));
output.print(")");
output.space();
- printMaybeBracedBody(tree.field(0, Field.body, node));
+ printMaybeBracedBody(A.field(0, Field.body, node));
};
generators[NodeType.WithStatement] = (node) => {
output.print("with");
output.space();
printParenthesized(childOf(Field.object, node));
output.space();
- printMaybeBracedBody(tree.field(0, Field.body, node));
+ printMaybeBracedBody(A.field(0, Field.body, node));
};
generators[NodeType.ReturnStatement] = (node) => {
if (blockStatements.size !== 0 && blockStatements.has(node)) {
@@ -28859,11 +28788,11 @@ const createNodePrinter = (modules) => {
*/
const printTestedBranch = (node, kept) => {
const test = childOf(Field.test, node);
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
const context = /** @type {JavascriptPrintContext} */ (writer);
const printed = kept === 0 ? "" : context.get(kept);
context.consume(consequent);
- const alternate = tree.field(0, Field.alternate, node);
+ const alternate = A.field(0, Field.alternate, node);
if (alternate !== 0) context.consume(alternate);
const text =
printed.charCodeAt(printed.length - 1) === 59
@@ -28909,14 +28838,14 @@ const createNodePrinter = (modules) => {
if (unreadStatements.size !== 0 && unreadStatements.has(node)) {
// What it returns goes unread: its test runs, then the call ends.
printNode(childOf(Field.test, node));
- skipNode(tree.field(0, Field.consequent, node));
+ skipNode(A.field(0, Field.consequent, node));
return;
}
if (dropped[node] === 1) {
// A body never running, where no list skips it.
const context = /** @type {JavascriptPrintContext} */ (writer);
context.consume(childOf(Field.test, node));
- context.consume(tree.field(0, Field.consequent, node));
+ context.consume(A.field(0, Field.consequent, node));
output.print(";");
return;
}
@@ -28924,8 +28853,8 @@ const createNodePrinter = (modules) => {
if (kept !== undefined) {
const context = /** @type {JavascriptPrintContext} */ (writer);
context.consume(childOf(Field.test, node));
- const consequent = tree.field(0, Field.consequent, node);
- const alternate = tree.field(0, Field.alternate, node);
+ const consequent = A.field(0, Field.consequent, node);
+ const alternate = A.field(0, Field.alternate, node);
if (consequent !== kept) context.consume(consequent);
if (alternate !== 0 && alternate !== kept) context.consume(alternate);
const hoisted = hoistedFromDropped.get(node);
@@ -28973,7 +28902,7 @@ const createNodePrinter = (modules) => {
const test = childOf(Field.test, node);
printNode(test, opensAmbiguously(test));
/** @type {JavascriptPrintContext} */ (writer).consume(
- tree.field(0, Field.consequent, node)
+ A.field(0, Field.consequent, node)
);
output.semicolon();
return;
@@ -28994,23 +28923,23 @@ const createNodePrinter = (modules) => {
test,
bindsLooser(test) ||
(typeOf(test) === NodeType.LogicalExpression &&
- tree.textOf(Part.operator, test) === "??") ||
+ A.textOf(Part.operator, test) === "??") ||
// The first opens the statement, its exit gone.
(tested && (merged & 2) === 0 && opensAmbiguously(test))
);
if ((merged & 1) === 0 && tested) {
/** @type {JavascriptPrintContext} */ (writer).consume(
- tree.field(0, Field.consequent, node)
+ A.field(0, Field.consequent, node)
);
output.semicolon();
} else if ((merged & 1) !== 0) {
output.print("||");
/** @type {JavascriptPrintContext} */ (writer).consume(
- tree.field(0, Field.consequent, node)
+ A.field(0, Field.consequent, node)
);
} else {
output.print(")");
- printMaybeBracedBody(tree.field(0, Field.consequent, node));
+ printMaybeBracedBody(A.field(0, Field.consequent, node));
}
return;
}
@@ -29022,7 +28951,7 @@ const createNodePrinter = (modules) => {
output.space();
output.print("?");
output.space();
- printNode(tree.field(0, Field.consequent, node));
+ printNode(A.field(0, Field.consequent, node));
output.space();
output.colon();
guardedRests.add(elseRest);
@@ -29058,7 +28987,7 @@ const createNodePrinter = (modules) => {
if (ands) andedIfs.add(rest);
else output.print(")");
guardedRests.add(rest);
- skipNode(tree.field(0, Field.consequent, node));
+ skipNode(A.field(0, Field.consequent, node));
return;
}
if (compresses && !beautifies && guardsBlock(node)) {
@@ -29067,7 +28996,7 @@ const createNodePrinter = (modules) => {
output.print("if(");
if (!printsNegatedTest(test, false, true)) printNegatedAs(test, "!");
output.print("){");
- skipNode(tree.field(0, Field.consequent, node));
+ skipNode(A.field(0, Field.consequent, node));
guardedBlocks.add(node);
return;
}
@@ -29092,7 +29021,7 @@ const createNodePrinter = (modules) => {
output.print("if(");
if (!printsNegatedTest(test, false, true)) printNegatedAs(test, "!");
output.print(")");
- skipNode(tree.field(0, Field.consequent, node));
+ skipNode(A.field(0, Field.consequent, node));
printMaybeBracedBody(alternate);
return;
}
@@ -29110,8 +29039,8 @@ const createNodePrinter = (modules) => {
}
if (
alternate === 0 &&
- (printsOptionalIf(node, tree.field(0, Field.consequent, node), "!=") ||
- printsNullishIf(node, tree.field(0, Field.consequent, node), "=="))
+ (printsOptionalIf(node, A.field(0, Field.consequent, node), "!=") ||
+ printsNullishIf(node, A.field(0, Field.consequent, node), "=="))
) {
return;
}
@@ -29120,7 +29049,7 @@ const createNodePrinter = (modules) => {
const test = childOf(Field.test, node);
output.print("if(");
printNode(test, !joinsLogical(shownAs(test), "&&", false));
- printNode(tree.field(0, Field.consequent, node));
+ printNode(A.field(0, Field.consequent, node));
return;
}
}
@@ -29129,11 +29058,11 @@ const createNodePrinter = (modules) => {
printTest(childOf(Field.test, node));
output.space();
if (alternate === 0) {
- printMaybeBracedBody(tree.field(0, Field.consequent, node));
+ printMaybeBracedBody(A.field(0, Field.consequent, node));
return;
}
if (compresses && liftsElse(node, parentAt(0), 0)) {
- printMaybeBracedBody(tree.field(0, Field.consequent, node));
+ printMaybeBracedBody(A.field(0, Field.consequent, node));
// A bare `return` ending its function goes, as the function ends there.
if (endsFunctionLast(node, alternate)) skipNode(alternate);
else printNode(alternate);
@@ -29147,7 +29076,7 @@ const createNodePrinter = (modules) => {
else printMaybeBracedBody(alternate);
};
generators[NodeType.SwitchStatement] = (node) => {
- const count = tree.fieldCount(Field.cases, node);
+ const count = A.fieldCount(Field.cases, node);
const kept =
foldedSwitches.size === 0 ? undefined : foldedSwitches.get(node);
if (kept !== undefined) {
@@ -29173,7 +29102,7 @@ const createNodePrinter = (modules) => {
) {
for (let i = 0; i < count; i++) {
/** @type {JavascriptPrintContext} */ (writer).consume(
- tree.field(i, Field.cases, node)
+ A.field(i, Field.cases, node)
);
}
const discriminant = childOf(Field.discriminant, node);
@@ -29191,7 +29120,7 @@ const createNodePrinter = (modules) => {
}
output.print("{");
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.cases, node);
+ const item = A.field(i, Field.cases, node);
if (
i >= printed ||
(i === count - 1 && i > 0 && compresses && doesNothing(item)) ||
@@ -29215,10 +29144,10 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether the case goes
*/
const joinsDefault = (node, index) => {
- const count = tree.fieldCount(Field.cases, node);
+ const count = A.fieldCount(Field.cases, node);
const isEmpty = (/** @type {number} */ i) =>
- tree.fieldCount(Field.consequent, tree.field(i, Field.cases, node)) === 0;
- const item = tree.field(index, Field.cases, node);
+ A.fieldCount(Field.consequent, A.field(i, Field.cases, node)) === 0;
+ const item = A.field(index, Field.cases, node);
if (
childOf(Field.test, item) === 0 ||
!isEmpty(index) ||
@@ -29232,7 +29161,7 @@ const createNodePrinter = (modules) => {
return false;
}
for (let i = index + 1; i < count; i++) {
- const test = childOf(Field.test, tree.field(i, Field.cases, node));
+ const test = childOf(Field.test, A.field(i, Field.cases, node));
if (test === 0) continue;
const other = value === undefined ? undefined : evaluateConstant(test);
if (other === undefined || other === value || !isPureValue(test)) {
@@ -29244,7 +29173,7 @@ const createNodePrinter = (modules) => {
let end = index;
while (end < count - 1 && isEmpty(end)) end++;
for (let i = start; i <= end; i++) {
- const other = tree.field(i, Field.cases, node);
+ const other = A.field(i, Field.cases, node);
// A `default` past a case surely matching labels nothing to join.
if (
childOf(Field.test, other) === 0 &&
@@ -29272,10 +29201,10 @@ const createNodePrinter = (modules) => {
} else {
output.print("default:");
}
- const count = tree.fieldCount(Field.consequent, node);
+ const count = A.fieldCount(Field.consequent, node);
const last = count > 0 && compresses && endsSwitch(node) ? count - 1 : -1;
for (let i = 0; i < count; i++) {
- const statement = tree.field(i, Field.consequent, node);
+ const statement = A.field(i, Field.consequent, node);
if (
(i === last && isPlainBreak(statement)) ||
(compresses && printsNothing(statement))
@@ -29295,10 +29224,10 @@ const createNodePrinter = (modules) => {
*/
const endsInPlainBreak = (statement) => {
if (typeOf(statement) !== NodeType.BlockStatement) return false;
- const count = tree.fieldCount(Field.body, statement);
+ const count = A.fieldCount(Field.body, statement);
return (
count !== 0 &&
- isPlainBreak(tree.field(count - 1, Field.body, statement)) &&
+ isPlainBreak(A.field(count - 1, Field.body, statement)) &&
!hasEdgeComments(statement)
);
};
@@ -29368,8 +29297,8 @@ const createNodePrinter = (modules) => {
generators[NodeType.TryStatement] = (node) => {
if (emptyTries.size !== 0 && emptyTries.has(node)) {
const context = /** @type {JavascriptPrintContext} */ (writer);
- context.consume(tree.field(0, Field.block, node));
- const handler = tree.field(0, Field.handler, node);
+ context.consume(A.field(0, Field.block, node));
+ const handler = A.field(0, Field.handler, node);
if (handler !== 0) context.consume(handler);
const names = triedVars.size === 0 ? undefined : triedVars.get(node);
if (names !== undefined) {
@@ -29380,12 +29309,12 @@ const createNodePrinter = (modules) => {
}
output.semicolon();
}
- const finalizer = tree.field(0, Field.finalizer, node);
+ const finalizer = A.field(0, Field.finalizer, node);
if (finalizer !== 0) printBlockInPlace(finalizer);
return;
}
- const finalizer = tree.field(0, Field.finalizer, node);
- const handler = tree.field(0, Field.handler, node);
+ const finalizer = A.field(0, Field.finalizer, node);
+ const handler = A.field(0, Field.handler, node);
const emptyFinally =
finalizer !== 0 &&
dropsDeadCode &&
@@ -29394,12 +29323,12 @@ const createNodePrinter = (modules) => {
if (emptyFinally && handler === 0 && !hasEdgeComments(node)) {
// A `try` whose `finally` runs nothing runs as its block.
skipNode(finalizer);
- printBlockInPlace(tree.field(0, Field.block, node));
+ printBlockInPlace(A.field(0, Field.block, node));
return;
}
output.print("try");
output.space();
- printNode(tree.field(0, Field.block, node));
+ printNode(A.field(0, Field.block, node));
if (handler !== 0) {
output.space();
printNode(handler);
@@ -29415,7 +29344,7 @@ const createNodePrinter = (modules) => {
};
generators[NodeType.CatchClause] = (node) => {
output.print("catch");
- const param = tree.field(0, Field.param, node);
+ const param = A.field(0, Field.param, node);
// ES2019's optional binding: a name nothing reads or writes goes.
if (
param !== 0 &&
@@ -29430,14 +29359,14 @@ const createNodePrinter = (modules) => {
printParenthesized(param);
}
output.space();
- printBraced(node, tree.field(0, Field.body, node));
+ printBraced(node, A.field(0, Field.body, node));
};
/**
* @param {number} declarator a loop head's declarator whose reads print the name it aliases
* @returns {boolean} whether it goes: a name nothing reads, set to a name no value folds into, holding no comment
*/
const dropsUnreadAlias = (declarator) => {
- const id = tree.field(0, Field.id, declarator);
+ const id = A.field(0, Field.id, declarator);
const init = childOf(Field.init, declarator);
return (
dropsUnused &&
@@ -29452,10 +29381,10 @@ const createNodePrinter = (modules) => {
generators[NodeType.VariableDeclaration] = (node) => {
if (blockStatements.size !== 0 && blockStatements.has(node)) {
// Its one value, a call printing as its function's statements.
- printNode(tree.field(0, Field.declarations, node));
+ printNode(A.field(0, Field.declarations, node));
return;
}
- const count = tree.fieldCount(Field.declarations, node);
+ const count = A.fieldCount(Field.declarations, node);
const parent = parentAt(0);
const parentType = typeOf(parent);
const isLoopHead =
@@ -29467,7 +29396,7 @@ const createNodePrinter = (modules) => {
let listed = -1;
let printed = 0;
for (let i = 0; i < count; i++) {
- const declarator = tree.field(i, Field.declarations, node);
+ const declarator = A.field(i, Field.declarations, node);
// A loop head's declarator folded into the next prints nothing, nor
// an alias nothing reads where another declarator stays.
if (
@@ -29522,7 +29451,7 @@ const createNodePrinter = (modules) => {
printNode(init);
return;
}
- printNode(tree.field(0, Field.id, node));
+ printNode(A.field(0, Field.id, node));
if (init === 0) return;
if (deadInits.size !== 0 && deadInits.has(node)) {
skipNode(init);
@@ -29552,12 +29481,12 @@ const createNodePrinter = (modules) => {
printReexport(node);
return;
}
- const count = tree.fieldCount(Field.specifiers, node);
- const phase = tree.textOf(Part.phase, node);
+ const count = A.fieldCount(Field.specifiers, node);
+ const phase = A.textOf(Part.phase, node);
/** @type {number[]} */
const kept = [];
for (let i = 0; i < count; i++) {
- const specifier = tree.field(i, Field.specifiers, node);
+ const specifier = A.field(i, Field.specifiers, node);
// A `defer` or `source` import binds its one name or is no import.
if (compresses && !phase && isUnreadImport(specifier)) {
skipNode(specifier);
@@ -29574,7 +29503,7 @@ const createNodePrinter = (modules) => {
output.print(phase);
output.space();
}
- if (hasDefault) printNode(tree.field(0, Field.local, kept[0]));
+ if (hasDefault) printNode(A.field(0, Field.local, kept[0]));
if (named > 0) {
if (hasDefault) {
output.print(",");
@@ -29599,14 +29528,14 @@ const createNodePrinter = (modules) => {
output.print("from");
output.space();
}
- printNode(tree.field(0, Field.source, node));
+ printNode(A.field(0, Field.source, node));
printAttributes(node);
output.semicolon();
};
generators[NodeType.ImportSpecifier] = (node) => {
printNameMapping(
- tree.field(0, Field.local, node),
- tree.field(0, Field.imported, node),
+ A.field(0, Field.local, node),
+ A.field(0, Field.imported, node),
true
);
};
@@ -29615,12 +29544,12 @@ const createNodePrinter = (modules) => {
output.space();
output.print("as");
output.space();
- printNode(tree.field(0, Field.local, node));
+ printNode(A.field(0, Field.local, node));
};
generators[NodeType.ExportSpecifier] = (node) => {
printNameMapping(
- tree.field(0, Field.local, node),
- tree.field(0, Field.exported, node),
+ A.field(0, Field.local, node),
+ A.field(0, Field.exported, node),
false
);
};
@@ -29629,24 +29558,24 @@ const createNodePrinter = (modules) => {
exportLists.length !== 0 &&
(joinedLists.has(node) || exportLists[0] === node)
) {
- const count = tree.fieldCount(Field.specifiers, node);
+ const count = A.fieldCount(Field.specifiers, node);
for (let i = 0; i < count; i++) {
- skipNode(tree.field(i, Field.specifiers, node));
+ skipNode(A.field(i, Field.specifiers, node));
}
if (exportLists[0] === node) printJoinedLists();
return;
}
if (movedExports.size !== 0 && listsOnlyMoved(node)) {
// Every name it lists prints in an `export…from`.
- const count = tree.fieldCount(Field.specifiers, node);
+ const count = A.fieldCount(Field.specifiers, node);
for (let i = 0; i < count; i++) {
- skipNode(tree.field(i, Field.specifiers, node));
+ skipNode(A.field(i, Field.specifiers, node));
}
return;
}
output.print("export");
output.space();
- const declaration = tree.field(0, Field.declaration, node);
+ const declaration = A.field(0, Field.declaration, node);
if (declaration !== 0) {
printNode(declaration);
return;
@@ -29666,15 +29595,15 @@ const createNodePrinter = (modules) => {
const printJoinedLists = () => {
let listed = 0;
for (const list of exportLists) {
- const count = tree.fieldCount(Field.specifiers, list);
+ const count = A.fieldCount(Field.specifiers, list);
for (let i = 0; i < count; i++) {
- const specifier = tree.field(i, Field.specifiers, list);
+ const specifier = A.field(i, Field.specifiers, list);
if (movedExports.size !== 0 && movedExports.has(specifier)) continue;
output.print(listed++ ? "," : "export{");
- const local = tree.field(0, Field.local, specifier);
+ const local = A.field(0, Field.local, specifier);
const printed = nameOf(local);
output.printName(printed);
- const foreign = tree.field(0, Field.exported, specifier);
+ const foreign = A.field(0, Field.exported, specifier);
if (printed !== moduleName(foreign)) {
output.space();
output.print("as");
@@ -29692,10 +29621,10 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it lists names, each one an `export…from` prints
*/
const listsOnlyMoved = (node) => {
- const count = tree.fieldCount(Field.specifiers, node);
+ const count = A.fieldCount(Field.specifiers, node);
if (count === 0) return false;
for (let i = 0; i < count; i++) {
- if (!movedExports.has(tree.field(i, Field.specifiers, node))) {
+ if (!movedExports.has(A.field(i, Field.specifiers, node))) {
return false;
}
}
@@ -29707,11 +29636,11 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printKeptSpecifiers = (node) => {
- const count = tree.fieldCount(Field.specifiers, node);
+ const count = A.fieldCount(Field.specifiers, node);
output.print("{");
let listed = 0;
for (let i = 0; i < count; i++) {
- const specifier = tree.field(i, Field.specifiers, node);
+ const specifier = A.field(i, Field.specifiers, node);
if (movedExports.has(specifier)) {
skipNode(specifier);
continue;
@@ -29728,7 +29657,7 @@ const createNodePrinter = (modules) => {
output.print("export");
output.space();
output.print("*");
- const exported = tree.field(0, Field.exported, node);
+ const exported = A.field(0, Field.exported, node);
if (exported !== 0) {
output.space();
output.print("as");
@@ -29761,8 +29690,8 @@ const createNodePrinter = (modules) => {
generators[NodeType.Identifier] = (node) => {
// A literal infinity is a value everywhere but as a key named so.
if (
- tree.type(node) === NodeType.Literal &&
- (tree.flag(Flag.computed, parentAt(0)) ||
+ A.type(node) === NodeType.Literal &&
+ (A.flag(Flag.computed, parentAt(0)) ||
childOf(Field.key, parentAt(0)) !== node) &&
printsInfinity(node)
) {
@@ -29783,7 +29712,7 @@ const createNodePrinter = (modules) => {
// `delete` of a global's name is false, of any other value true.
const deleted =
typeOf(parentAt(0)) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, parentAt(0)) === "delete";
+ A.textOf(Part.operator, parentAt(0)) === "delete";
if (compresses && !deleted && globalDefs !== null) {
const value = globalDefOf(node);
const parent = parentAt(0);
@@ -29828,7 +29757,7 @@ const createNodePrinter = (modules) => {
output.print(`#${privateNameOf(node)}`);
};
generators[NodeType.Literal] = (node) => {
- let value = tree.value(node);
+ let value = A.value(node);
if (renamedStrings !== null && renamedStrings.has(node)) {
value = /** @type {PropertyNames} */ (renamedProperties).mangle(
/** @type {string} */ (value)
@@ -29889,7 +29818,7 @@ const createNodePrinter = (modules) => {
}
return;
}
- const raw = tree.textOf(Part.raw, node);
+ const raw = A.textOf(Part.raw, node);
if (typeof value === "number") {
output.print(
(output.option("keepNumbers") || usesAsm(node)) && raw
@@ -29917,7 +29846,7 @@ const createNodePrinter = (modules) => {
const owner = parentAt(1);
const body = bodyOf(owner);
for (let i = 0; ; i++) {
- const other = tree.field(i, Field.body, body);
+ const other = A.field(i, Field.body, body);
if (other === statement) break;
if (typeOf(other) !== NodeType.EmptyStatement) return false;
}
@@ -29925,7 +29854,7 @@ const createNodePrinter = (modules) => {
if (comment !== undefined) {
return /[;{]$/.test(comment.replace(/[ \n]+$/, ""));
}
- if (tree.type(owner) !== NodeType.Program) return true;
+ if (A.type(owner) !== NodeType.Program) return true;
const before = programPrefix.replace(/[ \n]+$/, "");
return before === "" || /[;{]$/.test(before);
};
@@ -29939,7 +29868,7 @@ const createNodePrinter = (modules) => {
* @returns {string | undefined} the comment as printed, undefined for none
*/
const lastCommentBefore = (owner, body, statement) => {
- const isProgram = tree.type(owner) === NodeType.Program;
+ const isProgram = A.type(owner) === NodeType.Program;
let from = 0;
let to = 0;
if (commentTokens !== null) {
@@ -29987,13 +29916,13 @@ const createNodePrinter = (modules) => {
};
generators[NodeType.MetaProperty] = (node) => {
output.print(
- tree.name(tree.field(0, Field.meta, node)) === "import"
+ A.name(A.field(0, Field.meta, node)) === "import"
? "import.meta"
: "new.target"
);
};
generators[NodeType.ArrayExpression] = (node) => {
- const count = tree.fieldCount(Field.elements, node);
+ const count = A.fieldCount(Field.elements, node);
const parent = parentAt(0);
if (compresses && printsAsElements(node)) {
printElements(node, Field.elements);
@@ -30060,7 +29989,7 @@ const createNodePrinter = (modules) => {
if (typeOf(element) !== NodeType.Literal || hasEdgeComments(element)) {
return false;
}
- const value = tree.value(element);
+ const value = A.value(element);
if (typeof value !== "string") return false;
if (value.length !== 1) single = false;
values.push(value);
@@ -30089,15 +30018,15 @@ const createNodePrinter = (modules) => {
output.print("}");
};
generators[NodeType.ObjectExpression] = (node) => {
- const count = tree.fieldCount(Field.properties, node);
+ const count = A.fieldCount(Field.properties, node);
if (spreadsFolded(node, parentAt(0))) return;
if (printsUnreadParts(node, Field.properties)) return;
if (printsPickedValue(node, 0)) {
const value = pickedElement(parentAt(0), 1);
const context = /** @type {JavascriptPrintContext} */ (writer);
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.properties, node);
- context.consume(tree.field(0, Field.key, item));
+ const item = A.field(i, Field.properties, node);
+ context.consume(A.field(0, Field.key, item));
// Parentheses around a value hold no text of their own.
const own = childOf(Field.value, item);
if (own === value) printNode(own);
@@ -30113,7 +30042,7 @@ const createNodePrinter = (modules) => {
output.print("{");
let printed = 0;
for (let i = 0; i < count; i++) {
- const property = tree.field(i, Field.properties, node);
+ const property = A.field(i, Field.properties, node);
if (spreadsAs(property, node) !== 0) {
printed = printSpread(property, printed);
continue;
@@ -30139,7 +30068,7 @@ const createNodePrinter = (modules) => {
const parent = parentAt(0);
if (
!keyValue ||
- tree.flag(Flag.computed, node) ||
+ A.flag(Flag.computed, node) ||
printedKeyOf(node, key) !== "__proto__" ||
typeOf(parent) !== NodeType.ObjectExpression
) {
@@ -30149,10 +30078,10 @@ const createNodePrinter = (modules) => {
}
const value = childOf(Field.value, node);
const asShorthand =
- tree.type(value) === NodeType.Identifier &&
- tree.name(value) === "__proto__" &&
+ A.type(value) === NodeType.Identifier &&
+ A.name(value) === "__proto__" &&
output.option("shorthand");
- if (tree.flag(Flag.shorthand, node)) {
+ if (A.flag(Flag.shorthand, node)) {
if (asShorthand && printsAs(value, "__proto__")) {
output.printName("__proto__");
} else {
@@ -30174,15 +30103,15 @@ const createNodePrinter = (modules) => {
printMethod(node, methodKeyword(node));
};
generators[NodeType.PropertyDefinition] = (node) => {
- if (tree.flag(Flag.static, node)) {
+ if (A.flag(Flag.static, node)) {
output.print("static");
output.space();
}
const key = childOf(Field.key, node);
- if (tree.type(key) === NodeType.PrivateIdentifier) {
+ if (A.type(key) === NodeType.PrivateIdentifier) {
output.print("#");
output.printName(privateNameOf(key));
- } else if (tree.flag(Flag.computed, node)) {
+ } else if (A.flag(Flag.computed, node)) {
printComputedKey(node, key);
} else {
printPropertyName(printedKeyOf(node, key), keyQuoteOf(node), output);
@@ -30213,7 +30142,7 @@ const createNodePrinter = (modules) => {
generators[NodeType.AssignmentPattern] = (node) => {
// A parameter's default counts toward its function's `length`.
if (
- FUNCTION_TYPES[tree.type(ancestorOf(0))] !== 1 &&
+ FUNCTION_TYPES[A.type(ancestorOf(0))] !== 1 &&
defaultsToUndefined(node)
) {
skipNode(childOf(Field.right, node));
@@ -30230,9 +30159,9 @@ const createNodePrinter = (modules) => {
const readsSameMember = (target, read) => {
if (
typeOf(read) !== NodeType.MemberExpression ||
- tree.flag(Flag.computed, target) ||
- tree.flag(Flag.computed, read) ||
- tree.flag(Flag.optional, read) ||
+ A.flag(Flag.computed, target) ||
+ A.flag(Flag.computed, read) ||
+ A.flag(Flag.optional, read) ||
hasEdgeComments(read)
) {
return false;
@@ -30241,7 +30170,7 @@ const createNodePrinter = (modules) => {
const readProperty = childOf(Field.property, read);
if (
typeOf(property) !== typeOf(readProperty) ||
- tree.name(property) !== tree.name(readProperty)
+ A.name(property) !== A.name(readProperty)
) {
return false;
}
@@ -30277,7 +30206,7 @@ const createNodePrinter = (modules) => {
if (
!compresses ||
mangledNames === null ||
- tree.textOf(Part.operator, node) !== "="
+ A.textOf(Part.operator, node) !== "="
) {
return false;
}
@@ -30286,7 +30215,7 @@ const createNodePrinter = (modules) => {
if (
typeOf(right) !== NodeType.BinaryExpression ||
COMPOUND_OPERATORS[
- /** @type {string} */ (tree.textOf(Part.operator, right))
+ /** @type {string} */ (A.textOf(Part.operator, right))
] !== 1 ||
hasEdgeComments(right)
) {
@@ -30315,11 +30244,11 @@ const createNodePrinter = (modules) => {
}
const context = /** @type {JavascriptPrintContext} */ (writer);
// The value prints that name, which no fold rewrites, then the operator.
- const prefix = context.get(left) + tree.textOf(Part.operator, right);
+ const prefix = context.get(left) + A.textOf(Part.operator, right);
const text = context.get(right);
printNode(left);
context.consume(right);
- output.print(`${tree.textOf(Part.operator, right)}=`);
+ output.print(`${A.textOf(Part.operator, right)}=`);
// No token merges across the `=`, which `x- -y` spaced from.
let value = text.slice(
text.charCodeAt(prefix.length) === 32 ? prefix.length + 1 : prefix.length
@@ -30391,7 +30320,7 @@ const createNodePrinter = (modules) => {
) {
// Its target and operator print once, before the `?:`.
printNode(childOf(Field.left, node));
- output.print(/** @type {string} */ (tree.textOf(Part.operator, node)));
+ output.print(/** @type {string} */ (A.textOf(Part.operator, node)));
const start = output.text.length;
printNode(childOf(Field.right, node));
mergedSpans.set(node, [start, output.text.length]);
@@ -30418,7 +30347,7 @@ const createNodePrinter = (modules) => {
const truthOperand = (node) => {
if (!dropsDeadCode) return 0;
const right = childOf(Field.right, node);
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
const reads = readsTruth(node);
// Left of the same operator, `(x&&t)&&y` reads `x` alike: its value where
// it decides, else past it to `y`.
@@ -30428,7 +30357,7 @@ const createNodePrinter = (modules) => {
!(
typeOf(parent) === NodeType.LogicalExpression &&
childOf(Field.left, parent) === node &&
- tree.textOf(Part.operator, parent) === operator
+ A.textOf(Part.operator, parent) === operator
)
) {
return 0;
@@ -30459,13 +30388,13 @@ const createNodePrinter = (modules) => {
case NodeType.ClassExpression:
return true;
case NodeType.Literal: {
- const raw = tree.textOf(Part.raw, node);
+ const raw = A.textOf(Part.raw, node);
// A regular expression is an object.
if (raw !== null && raw.charCodeAt(0) === 47) return true;
break;
}
case NodeType.UnaryExpression: {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
// Its string names a type, never empty.
if (operator === "typeof") return true;
if (operator === "void") return false;
@@ -30476,7 +30405,7 @@ const createNodePrinter = (modules) => {
break;
}
case NodeType.LogicalExpression: {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (operator === "??") break;
const left = knownTruth(childOf(Field.left, node));
const right = knownTruth(childOf(Field.right, node));
@@ -30497,13 +30426,13 @@ const createNodePrinter = (modules) => {
case NodeType.SequenceExpression:
return knownTruth(
itemOf(
- tree.fieldCount(Field.expressions, node) - 1,
+ A.fieldCount(Field.expressions, node) - 1,
Field.expressions,
node
)
);
case NodeType.AssignmentExpression:
- return tree.textOf(Part.operator, node) === "="
+ return A.textOf(Part.operator, node) === "="
? knownTruth(childOf(Field.right, node))
: undefined;
}
@@ -30572,14 +30501,14 @@ const createNodePrinter = (modules) => {
case NodeType.SequenceExpression:
return knownNonNullish(
itemOf(
- tree.fieldCount(Field.expressions, node) - 1,
+ A.fieldCount(Field.expressions, node) - 1,
Field.expressions,
node
)
);
case NodeType.UnaryExpression:
// Every unary operator but `void` gives a boolean, number or string.
- return tree.textOf(Part.operator, node) !== "void";
+ return A.textOf(Part.operator, node) !== "void";
case NodeType.Identifier:
return isGlobalUndefined(node) ? false : undefined;
}
@@ -30595,7 +30524,7 @@ const createNodePrinter = (modules) => {
*/
const knownLeftKept = (node, printing = false) => {
if (!dropsDeadCode || hasEdgeComments(node)) return 0;
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
const left = childOf(Field.left, node);
const right = childOf(Field.right, node);
// `??` reads whether the left is nullish: `(y, null) ?? 1` is `(y, 1)`.
@@ -30627,7 +30556,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it printed so
*/
const printsKnownLeft = (node) => {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (!dropsDeadCode || hasEdgeComments(node)) return false;
const left = childOf(Field.left, node);
const right = childOf(Field.right, node);
@@ -30653,7 +30582,7 @@ const createNodePrinter = (modules) => {
typeOf(left) !== NodeType.SequenceExpression &&
!(
typeOf(left) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, left) === "void" &&
+ A.textOf(Part.operator, left) === "void" &&
/** @type {JavascriptPrintContext} */ (writer)
.get(left)
.startsWith("void ")
@@ -30691,9 +30620,9 @@ const createNodePrinter = (modules) => {
if (!dropsSideEffectFree || holdsComments(left)) return text;
const type = typeOf(left);
if (type === NodeType.SequenceExpression) {
- const count = tree.fieldCount(Field.expressions, left);
+ const count = A.fieldCount(Field.expressions, left);
const last = itemOf(count - 1, Field.expressions, left);
- const value = typeOf(last) === NodeType.Literal ? tree.value(last) : 1;
+ const value = typeOf(last) === NodeType.Literal ? A.value(last) : 1;
const tail = value === null ? ",null" : "";
return tail !== "" && text.endsWith(tail)
? text.slice(0, -tail.length)
@@ -30701,7 +30630,7 @@ const createNodePrinter = (modules) => {
}
// `void x` runs `x`, which prints bare as an item where it did after `void `.
return type === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, left) === "void" &&
+ A.textOf(Part.operator, left) === "void" &&
text.startsWith("void ")
? text.slice(5)
: text;
@@ -30712,7 +30641,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it printed so
*/
const printsUnreadNullish = (node) => {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
const left = childOf(Field.left, node);
const right = childOf(Field.right, node);
if (
@@ -30777,7 +30706,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it printed so
*/
const printsOptionalChain = (node) => {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (
!compresses ||
answersWith ||
@@ -30808,10 +30737,10 @@ const createNodePrinter = (modules) => {
if (typeOf(body) !== NodeType.BlockStatement || holdsComments(body)) {
return false;
}
- const count = tree.fieldCount(Field.body, body);
+ const count = A.fieldCount(Field.body, body);
for (let i = 0; i < count; i++) {
if (
- typeOf(tree.field(i, Field.body, body)) !== NodeType.ExpressionStatement
+ typeOf(A.field(i, Field.body, body)) !== NodeType.ExpressionStatement
) {
return false;
}
@@ -30868,8 +30797,8 @@ const createNodePrinter = (modules) => {
: printed;
const wraps = !bindsTighterThanOr(text);
context.consume(test);
- context.consume(tree.field(0, Field.consequent, node));
- const alternate = tree.field(0, Field.alternate, node);
+ context.consume(A.field(0, Field.consequent, node));
+ const alternate = A.field(0, Field.alternate, node);
if (alternate !== 0) context.consume(alternate);
printSlice(name);
output.print(wraps ? "??(" : "??");
@@ -30917,8 +30846,8 @@ const createNodePrinter = (modules) => {
);
if (chain === null) return false;
context.consume(test);
- context.consume(tree.field(0, Field.consequent, node));
- const alternate = tree.field(0, Field.alternate, node);
+ context.consume(A.field(0, Field.consequent, node));
+ const alternate = A.field(0, Field.alternate, node);
if (alternate !== 0) context.consume(alternate);
printSlice(chain);
output.semicolon();
@@ -30958,9 +30887,9 @@ const createNodePrinter = (modules) => {
const next = text.charCodeAt(printed.length);
return base === chain ||
typeOf(base) !== NodeType.Identifier ||
- tree.name(base) !== tree.name(name) ||
+ A.name(base) !== A.name(name) ||
// `eval?.()` is no direct `eval`: it reads no local name.
- tree.name(base) === "eval" ||
+ A.name(base) === "eval" ||
// It prints first, `.`, `[` or `(` reading off it, which `?.` takes.
!text.startsWith(printed) ||
(next !== 46 && next !== 91 && next !== 40)
@@ -30986,7 +30915,7 @@ const createNodePrinter = (modules) => {
}
if (
typeOf(test) !== NodeType.BinaryExpression ||
- tree.textOf(Part.operator, test) !== operator ||
+ A.textOf(Part.operator, test) !== operator ||
holdsComments(test)
) {
return 0;
@@ -31004,12 +30933,12 @@ const createNodePrinter = (modules) => {
*/
const branchCall = (node, field) => {
if (typeOf(node) !== NodeType.IfStatement) return childOf(field, node);
- const branch = tree.field(0, field, node);
+ const branch = A.field(0, field, node);
if (branch === 0) return 0;
const statement = unwrappedBranch(branch, node);
return typeOf(statement) === NodeType.ExpressionStatement &&
!hasEdgeComments(statement) &&
- tree.textOf(Part.directive, statement) === null
+ A.textOf(Part.directive, statement) === null
? childOf(Field.expression, statement)
: 0;
};
@@ -31027,16 +30956,16 @@ const createNodePrinter = (modules) => {
index = -1;
const consequent = branchCall(node, Field.consequent);
const alternate = branchCall(node, Field.alternate);
- const count = tree.fieldCount(Field.arguments, consequent);
+ const count = A.fieldCount(Field.arguments, consequent);
const type = typeOf(consequent);
if (
compresses &&
(type === NodeType.CallExpression || type === NodeType.NewExpression) &&
typeOf(alternate) === type &&
- !tree.flag(Flag.optional, consequent) &&
- !tree.flag(Flag.optional, alternate) &&
+ !A.flag(Flag.optional, consequent) &&
+ !A.flag(Flag.optional, alternate) &&
!holdsComments(node) &&
- count === tree.fieldCount(Field.arguments, alternate) &&
+ count === A.fieldCount(Field.arguments, alternate) &&
sameLocalName(
childOf(Field.callee, consequent),
childOf(Field.callee, alternate)
@@ -31131,11 +31060,11 @@ const createNodePrinter = (modules) => {
typeOf(alternate) === NodeType.AssignmentExpression &&
!holdsComments(node)
) {
- const operator = tree.textOf(Part.operator, consequent);
+ const operator = A.textOf(Part.operator, consequent);
const left = childOf(Field.left, consequent);
const otherLeft = childOf(Field.left, alternate);
const test = childOf(Field.test, node);
- if (operator === tree.textOf(Part.operator, alternate)) {
+ if (operator === A.textOf(Part.operator, alternate)) {
if (typeOf(left) === NodeType.Identifier) {
const definition = mangledNames === null ? null : mangledNames[left];
merges =
@@ -31150,10 +31079,10 @@ const createNodePrinter = (modules) => {
operator === "=" &&
typeOf(left) === NodeType.MemberExpression &&
typeOf(otherLeft) === NodeType.MemberExpression &&
- !tree.flag(Flag.computed, left) &&
- !tree.flag(Flag.computed, otherLeft) &&
- tree.name(childOf(Field.property, left)) ===
- tree.name(childOf(Field.property, otherLeft))
+ !A.flag(Flag.computed, left) &&
+ !A.flag(Flag.computed, otherLeft) &&
+ A.name(childOf(Field.property, left)) ===
+ A.name(childOf(Field.property, otherLeft))
) {
const object = childOf(Field.object, left);
const otherObject = childOf(Field.object, otherLeft);
@@ -31241,7 +31170,7 @@ const createNodePrinter = (modules) => {
BELOW_OR[typeOf(otherPart)] !== 1 &&
!(
typeOf(otherPart) === NodeType.LogicalExpression &&
- tree.textOf(Part.operator, otherPart) === "??"
+ A.textOf(Part.operator, otherPart) === "??"
);
const and =
!or &&
@@ -31331,8 +31260,8 @@ const createNodePrinter = (modules) => {
for (const operator of ["&&", "||"]) {
const innerField = operator === "&&" ? Field.consequent : Field.alternate;
const outerField = operator === "&&" ? Field.alternate : Field.consequent;
- const innerHolder = tree.field(0, innerField, node);
- const outerHolder = tree.field(0, outerField, node);
+ const innerHolder = A.field(0, innerField, node);
+ const outerHolder = A.field(0, outerField, node);
if (innerHolder === 0 || outerHolder === 0) continue;
const inner = unwrappedBranch(innerHolder, node);
const length =
@@ -31401,7 +31330,7 @@ const createNodePrinter = (modules) => {
return false;
}
const sequence = typeOf(holder) === NodeType.SequenceExpression;
- const count = sequence ? tree.fieldCount(Field.expressions, holder) : 2;
+ const count = sequence ? A.fieldCount(Field.expressions, holder) : 2;
const first = sequence
? itemOf(0, Field.expressions, holder)
: childOf(Field.left, holder);
@@ -31414,7 +31343,7 @@ const createNodePrinter = (modules) => {
while (typeOf(last) === NodeType.SequenceExpression) {
many = true;
last = itemOf(
- tree.fieldCount(Field.expressions, last) - 1,
+ A.fieldCount(Field.expressions, last) - 1,
Field.expressions,
last
);
@@ -31516,7 +31445,7 @@ const createNodePrinter = (modules) => {
const type = typeOf(other);
if (
typeOf(kept) !== NodeType.Identifier ||
- tree.name(kept) !== tree.name(name) ||
+ A.name(kept) !== A.name(name) ||
// It stands bare after `??` as after `:`.
!(
NEGATES_BARE[type] ||
@@ -31567,7 +31496,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it printed so
*/
const printsUnreadNegation = (node) => {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
const left = childOf(Field.left, node);
if (
(operator !== "&&" && operator !== "||") ||
@@ -31636,9 +31565,7 @@ const createNodePrinter = (modules) => {
context.consume(childOf(Field.left, node));
context.consume(childOf(Field.right, node));
output.printName(nameOf(name));
- output.print(
- tree.textOf(Part.operator, node) === "||" ? "==null" : "!=null"
- );
+ output.print(A.textOf(Part.operator, node) === "||" ? "==null" : "!=null");
};
/**
* @param {number} node an expression
@@ -31672,12 +31599,12 @@ const createNodePrinter = (modules) => {
const left = childOf(Field.left, node);
const right = childOf(Field.right, node);
const typed = comparedName(left, and ? "==" : "!=", (side) => {
- const value = typeOf(side) === NodeType.Literal && tree.value(side);
+ const value = typeOf(side) === NodeType.Literal && A.value(side);
return value === "object";
});
if (
typeOf(typed) !== NodeType.UnaryExpression ||
- tree.textOf(Part.operator, typed) !== "typeof"
+ A.textOf(Part.operator, typed) !== "typeof"
) {
return false;
}
@@ -31685,7 +31612,7 @@ const createNodePrinter = (modules) => {
const compared = comparedName(
right,
and ? "!=" : "==",
- (side) => typeOf(side) === NodeType.Literal && tree.value(side) === null
+ (side) => typeOf(side) === NodeType.Literal && A.value(side) === null
);
if (
typeOf(name) !== NodeType.Identifier ||
@@ -31948,8 +31875,8 @@ const createNodePrinter = (modules) => {
if (type !== NodeType.IfStatement || childOf(Field.test, parent) !== test) {
return false;
}
- if (tree.field(0, Field.alternate, parent) !== 0) return true;
- const body = typeOf(tree.field(0, Field.consequent, parent));
+ if (A.field(0, Field.alternate, parent) !== 0) return true;
+ const body = typeOf(A.field(0, Field.consequent, parent));
return (
body === NodeType.BlockStatement ||
body === NodeType.ReturnStatement ||
@@ -32127,7 +32054,7 @@ const createNodePrinter = (modules) => {
*/
const comparesUnread = (node, level) => {
if (typeOf(node) !== NodeType.BinaryExpression) return false;
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
return (
(operator === "===" ||
operator === "!==" ||
@@ -32162,7 +32089,7 @@ const createNodePrinter = (modules) => {
switch (typeOf(parent)) {
case NodeType.BinaryExpression:
return (
- tree.textOf(Part.operator, parent) === "|" &&
+ A.textOf(Part.operator, parent) === "|" &&
childOf(Field.left, parent) === node
);
case NodeType.LogicalExpression:
@@ -32241,12 +32168,12 @@ const createNodePrinter = (modules) => {
const givesString = (node) => {
switch (typeOf(node)) {
case NodeType.Literal:
- return typeof tree.value(node) === "string";
+ return typeof A.value(node) === "string";
case NodeType.TemplateLiteral:
return true;
case NodeType.BinaryExpression:
return (
- tree.textOf(Part.operator, node) === "+" &&
+ A.textOf(Part.operator, node) === "+" &&
(givesString(childOf(Field.left, node)) ||
givesString(childOf(Field.right, node)))
);
@@ -32267,7 +32194,7 @@ const createNodePrinter = (modules) => {
if (
!dropsSideEffectFree ||
typeOf(right) !== NodeType.Literal ||
- typeof tree.value(right) !== "string" ||
+ typeof A.value(right) !== "string" ||
holdsComments(node) ||
!givesString(left) ||
!(
@@ -32307,7 +32234,7 @@ const createNodePrinter = (modules) => {
*/
const literal = (side) => {
if (typeOf(side) === NodeType.Literal) {
- return typeof tree.value(side) === "string" && tree.value(side) !== "";
+ return typeof A.value(side) === "string" && A.value(side) !== "";
}
const value = foldedOf(side);
return typeof value === "string" && value !== "" && isPureValue(side);
@@ -32360,7 +32287,7 @@ const createNodePrinter = (modules) => {
// which a test needs not and a `!` puts back.
const operation =
typeOf(other) === NodeType.BinaryExpression
- ? tree.textOf(Part.operator, other)
+ ? A.textOf(Part.operator, other)
: null;
const wrapped = operation === "|" || operation === "&" || operation === "^";
const read = !unread && !readsTruth(node);
@@ -32418,7 +32345,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it is the literal `0`
*/
const isZero = (node) =>
- typeOf(node) === NodeType.Literal && tree.value(node) === 0;
+ typeOf(node) === NodeType.Literal && A.value(node) === 0;
/**
* @param {number} node an expression
@@ -32427,7 +32354,7 @@ const createNodePrinter = (modules) => {
const givesInteger = (node) => {
switch (typeOf(node)) {
case NodeType.BinaryExpression:
- switch (tree.textOf(Part.operator, node)) {
+ switch (A.textOf(Part.operator, node)) {
case "|":
case "&":
case "^":
@@ -32438,7 +32365,7 @@ const createNodePrinter = (modules) => {
}
return false;
case NodeType.UnaryExpression:
- return tree.textOf(Part.operator, node) === "~";
+ return A.textOf(Part.operator, node) === "~";
default:
return false;
}
@@ -32452,14 +32379,14 @@ const createNodePrinter = (modules) => {
if (typeOf(node) !== NodeType.BinaryExpression || !givesInteger(node)) {
return false;
}
- if (tree.textOf(Part.operator, node) === ">>>") return true;
+ if (A.textOf(Part.operator, node) === ">>>") return true;
for (const field of [Field.left, Field.right]) {
const operand = childOf(field, node);
if (
(typeOf(operand) === NodeType.Literal &&
- typeof tree.value(operand) === "number") ||
+ typeof A.value(operand) === "number") ||
(typeOf(operand) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, operand) === "+") ||
+ A.textOf(Part.operator, operand) === "+") ||
givesNumber(operand)
) {
return true;
@@ -32484,12 +32411,12 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const operation = tree.textOf(Part.operator, right);
+ const operation = A.textOf(Part.operator, right);
if (operation !== "*" && operation !== "/" && operation !== "%") {
return false;
}
if (typeOf(left) === NodeType.Literal) {
- if (typeof tree.value(left) !== "number") return false;
+ if (typeof A.value(left) !== "number") return false;
} else {
const definition =
typeOf(left) === NodeType.Identifier && mangledNames !== null
@@ -32545,7 +32472,7 @@ const createNodePrinter = (modules) => {
const parent = parentAt(0);
if (
typeOf(parent) !== NodeType.BinaryExpression ||
- tree.textOf(Part.operator, parent) !== operator ||
+ A.textOf(Part.operator, parent) !== operator ||
holdsComments(node)
) {
return false;
@@ -32638,20 +32565,20 @@ const createNodePrinter = (modules) => {
node = unwrap(node);
switch (typeOf(node)) {
case NodeType.Literal:
- return typeof tree.value(node) === "string";
+ return typeof A.value(node) === "string";
case NodeType.TemplateLiteral:
return true;
case NodeType.UnaryExpression:
- return tree.textOf(Part.operator, node) === "typeof";
+ return A.textOf(Part.operator, node) === "typeof";
case NodeType.BinaryExpression:
return (
- tree.textOf(Part.operator, node) === "+" &&
+ A.textOf(Part.operator, node) === "+" &&
(isStringValued(childOf(Field.left, node)) ||
isStringValued(childOf(Field.right, node)))
);
case NodeType.AssignmentExpression: {
// `x+="s"` adds to a string, whatever `x` converts to.
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
return (
(operator === "=" || operator === "+=") &&
isStringValued(childOf(Field.right, node))
@@ -32687,7 +32614,7 @@ const createNodePrinter = (modules) => {
// Printed where `+` stood, it keeps the parentheses `+` gave it, as a
// binary right operand does; an assignment takes what its place needs.
(otherType === NodeType.AssignmentExpression
- ? typeOf(tree.field(0, Field.left, other)) !== NodeType.Identifier
+ ? typeOf(A.field(0, Field.left, other)) !== NodeType.Identifier
: (other === right && isBinary(other)) || bindsLooser(other)) ||
parentType === NodeType.BinaryExpression ||
parentType === NodeType.LogicalExpression ||
@@ -32717,9 +32644,9 @@ const createNodePrinter = (modules) => {
};
generators[NodeType.BinaryExpression] = (node) => {
- const operator = tree.textOf(Part.operator, node);
+ const operator = A.textOf(Part.operator, node);
if (isPrivateIn(node)) {
- printNode(tree.field(0, Field.left, node));
+ printNode(A.field(0, Field.left, node));
output.space();
output.print("in");
output.space();
@@ -33002,7 +32929,7 @@ const createNodePrinter = (modules) => {
kept === undefined ||
typeOf(kept) === NodeType.SequenceExpression ||
(typeOf(kept) === NodeType.AssignmentExpression &&
- typeOf(tree.field(0, Field.left, kept)) === NodeType.ObjectPattern)
+ typeOf(A.field(0, Field.left, kept)) === NodeType.ObjectPattern)
) {
printNode(node);
return;
@@ -33029,7 +32956,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.expressions, test);
+ const count = A.fieldCount(Field.expressions, test);
const last = itemOf(count - 1, Field.expressions, test);
// Bare, the last value is the test only where it binds tighter; one an
// assignment before it is printed as leaves that.
@@ -33373,7 +33300,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} false where it prints whole
*/
const collectUnreadParts = (node, field, parts) => {
- const count = tree.fieldCount(field, node);
+ const count = A.fieldCount(field, node);
for (let i = 0; i < count; i++) {
const item = itemOf(i, field, node);
if (item === 0) continue;
@@ -33381,9 +33308,9 @@ const createNodePrinter = (modules) => {
if (typeOf(item) === NodeType.Property) {
// A computed key folding to a primitive converts running nothing.
value =
- (tree.flag(Flag.computed, item) &&
- !isConstantKey(tree.field(0, Field.key, item))) ||
- tree.textOf(Part.kind, item) !== "init"
+ (A.flag(Flag.computed, item) &&
+ !isConstantKey(A.field(0, Field.key, item))) ||
+ A.textOf(Part.kind, item) !== "init"
? 0
: childOf(Field.value, item);
} else if (typeOf(item) === NodeType.SpreadElement) {
@@ -33518,7 +33445,7 @@ const createNodePrinter = (modules) => {
*/
const printUnreadItems = (node, field, parts, first) => {
const context = /** @type {JavascriptPrintContext} */ (writer);
- const count = tree.fieldCount(field, node);
+ const count = A.fieldCount(field, node);
for (let i = 0; i < count; i++) {
const item = itemOf(i, field, node);
if (item === 0) continue;
@@ -33650,7 +33577,7 @@ const createNodePrinter = (modules) => {
*/
const assignsObjectPattern = (node) =>
typeOf(node) === NodeType.AssignmentExpression &&
- typeOf(tree.field(0, Field.left, node)) === NodeType.ObjectPattern;
+ typeOf(A.field(0, Field.left, node)) === NodeType.ObjectPattern;
/**
* @param {number} node an operand
@@ -33751,7 +33678,7 @@ const createNodePrinter = (modules) => {
hasEdgeComments(other) ||
BELOW_OR[typeOf(other)] === 1 ||
(typeOf(other) === NodeType.LogicalExpression &&
- tree.textOf(Part.operator, other) === "??")
+ A.textOf(Part.operator, other) === "??")
) {
return false;
}
@@ -33834,12 +33761,12 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether it printed so
*/
const printsReturnedAnd = (node, test) => {
- const alternate = tree.field(0, Field.alternate, node);
+ const alternate = A.field(0, Field.alternate, node);
const next =
alternate === 0
? returnPairs.get(node)
: unwrappedBranch(alternate, node);
- const consequent = tree.field(0, Field.consequent, node);
+ const consequent = A.field(0, Field.consequent, node);
const exit = unwrappedBranch(consequent, node);
if (
next === undefined ||
@@ -33990,7 +33917,7 @@ const createNodePrinter = (modules) => {
}
};
generators[NodeType.SequenceExpression] = (node) => {
- const count = tree.fieldCount(Field.expressions, node);
+ const count = A.fieldCount(Field.expressions, node);
if (constructsPastSequence(node)) {
for (let i = 0; i < count - 1; i++) {
skipNode(itemOf(i, Field.expressions, node));
@@ -34026,10 +33953,10 @@ const createNodePrinter = (modules) => {
const type = typeOf(parent);
const operator =
type === NodeType.UnaryExpression
- ? /** @type {string} */ (tree.textOf(Part.operator, parent))
+ ? /** @type {string} */ (A.textOf(Part.operator, parent))
: type === NodeType.AwaitExpression
? "await"
- : tree.flag(Flag.delegate, parent)
+ : A.flag(Flag.delegate, parent)
? "yield*"
: "yield";
output.print(operator);
@@ -34070,7 +33997,7 @@ const createNodePrinter = (modules) => {
if (
typeOf(last) !== NodeType.Identifier ||
typeOf(before) !== NodeType.AssignmentExpression ||
- tree.textOf(Part.operator, before) !== "=" ||
+ A.textOf(Part.operator, before) !== "=" ||
hasEdgeComments(last) ||
isMovedRead(last) ||
(collapsed.size !== 0 && collapsed.has(last))
@@ -34104,7 +34031,7 @@ const createNodePrinter = (modules) => {
if (
type === NodeType.UnaryExpression
? !LIFTED_UNARIES.includes(
- /** @type {string} */ (tree.textOf(Part.operator, parent))
+ /** @type {string} */ (A.textOf(Part.operator, parent))
)
: type !== NodeType.AwaitExpression && type !== NodeType.YieldExpression
) {
@@ -34144,7 +34071,7 @@ const createNodePrinter = (modules) => {
* @returns {Uint8Array | null} by item, 1 where it prints; null where all do: one alone would take the parentheses the sequence took, open a statement as a declaration or bind `this`
*/
const keptItems = (node) => {
- const count = tree.fieldCount(Field.expressions, node);
+ const count = A.fieldCount(Field.expressions, node);
const last = itemOf(count - 1, Field.expressions, node);
if (
hasEdgeComments(node) ||
@@ -34226,7 +34153,7 @@ const createNodePrinter = (modules) => {
case NodeType.Property:
return (
childOf(Field.value, parent) === node &&
- tree.textOf(Part.kind, parent) === "init"
+ A.textOf(Part.kind, parent) === "init"
);
case NodeType.ArrayExpression:
case NodeType.SpreadElement:
@@ -34241,7 +34168,7 @@ const createNodePrinter = (modules) => {
case NodeType.MemberExpression:
return childOf(Field.object, parent) === node
? readsBareBeforeDot(item)
- : tree.flag(Flag.computed, parent);
+ : A.flag(Flag.computed, parent);
case NodeType.ConditionalExpression:
return childOf(Field.test, parent) !== node;
// A function or class there would read as a declaration.
@@ -34269,7 +34196,7 @@ const createNodePrinter = (modules) => {
case NodeType.MemberExpression:
return true;
case NodeType.Literal:
- return typeof tree.value(item) === "string";
+ return typeof A.value(item) === "string";
default:
return false;
}
@@ -34302,7 +34229,7 @@ const createNodePrinter = (modules) => {
return true;
case NodeType.FunctionExpression:
case NodeType.ClassExpression:
- return tree.field(0, Field.id, node) === 0;
+ return A.field(0, Field.id, node) === 0;
default:
return false;
}
@@ -34322,7 +34249,7 @@ const createNodePrinter = (modules) => {
isPureValue(childOf(Field.right, node))
);
case NodeType.SequenceExpression: {
- const count = tree.fieldCount(Field.expressions, node);
+ const count = A.fieldCount(Field.expressions, node);
for (let i = 0; i < count; i++) {
const item = itemOf(i, Field.expressions, node);
if (hasEdgeComments(item) || !valueRunsNothing(item)) return false;
@@ -34351,7 +34278,7 @@ const createNodePrinter = (modules) => {
if (typeOf(node) !== NodeType.SequenceExpression) {
return valueRunsNothing(node);
}
- const count = tree.fieldCount(Field.expressions, node);
+ const count = A.fieldCount(Field.expressions, node);
for (let i = 0; i < count; i++) {
const item = itemOf(i, Field.expressions, node);
if (hasEdgeComments(item) || !valueRunsNothing(item)) return false;
@@ -34364,7 +34291,7 @@ const createNodePrinter = (modules) => {
* @returns {boolean} whether its last item is a member or a name called with its scope or `this` whose reference is read, every other running nothing and printing other than `0`
*/
const zeroHeads = (node) => {
- const count = tree.fieldCount(Field.expressions, node);
+ const count = A.fieldCount(Field.expressions, node);
const last = itemOf(count - 1, Field.expressions, node);
if (
hasEdgeComments(node) ||
@@ -34395,7 +34322,7 @@ const createNodePrinter = (modules) => {
typeOf(last) === NodeType.Identifier &&
typeOf(referenceReader(node)) !== NodeType.UnaryExpression &&
!answersWith &&
- tree.name(last) !== "eval";
+ A.name(last) !== "eval";
// A string a number converts back to as written, short of losing digits.
const INTEGER_KEY = /^(?:0|-?[1-9]\d{0,14})$/;
@@ -34428,7 +34355,7 @@ const createNodePrinter = (modules) => {
typeOf(parent) === NodeType.UnaryExpression &&
!hasEdgeComments(parent) &&
dropsUnreadOperator(
- /** @type {string} */ (tree.textOf(Part.operator, parent)),
+ /** @type {string} */ (A.textOf(Part.operator, parent)),
node
) &&
unreadUnaryAt(parent, 1) === UNARY_UNREAD) ||
@@ -34449,7 +34376,7 @@ const createNodePrinter = (modules) => {
return true;
case NodeType.MemberExpression:
return (
- !tree.flag(Flag.optional, node) &&
+ !A.flag(Flag.optional, node) &&
isNewTarget(childOf(Field.object, node))
);
default:
@@ -34468,7 +34395,7 @@ const createNodePrinter = (modules) => {
!compresses ||
(parentType !== NodeType.NewExpression &&
(parentType !== NodeType.CallExpression ||
- tree.flag(Flag.optional, parent) ||
+ A.flag(Flag.optional, parent) ||
output.option("wrapIife"))) ||
childOf(Field.callee, parent) !== node ||
hasEdgeComments(node) ||
@@ -34476,7 +34403,7 @@ const createNodePrinter = (modules) => {
) {
return false;
}
- const count = tree.fieldCount(Field.expressions, node);
+ const count = A.fieldCount(Field.expressions, node);
const last = itemOf(count - 1, Field.expressions, node);
const lastType = typeOf(last);
if (
@@ -34511,7 +34438,7 @@ const createNodePrinter = (modules) => {
printCall(node);
};
generators[NodeType.ImportExpression] = (node) => {
- const phase = tree.textOf(Part.phase, node);
+ const phase = A.textOf(Part.phase, node);
output.print(phase ? `import.${phase}(` : "import(");
printNode(childOf(Field.source, node));
const options = childOf(Field.options, node);
@@ -34557,7 +34484,7 @@ const createNodePrinter = (modules) => {
innerType !== NodeType.CallExpression
) {
return (
- tree.flag(Flag.optional, link) &&
+ A.flag(Flag.optional, link) &&
(innerType === NodeType.ChainExpression
? shortCircuits(inner)
: isUndefinedValue(inner) ||
@@ -34604,21 +34531,21 @@ const createNodePrinter = (modules) => {
return undefined;
}
const key = childOf(Field.key, property);
- const value = tree.flag(Flag.computed, property)
+ const value = A.flag(Flag.computed, property)
? isPureValue(key)
? evaluate(key)
: undefined
: typeOf(key) === NodeType.Identifier
- ? tree.name(key)
- : tree.value(key);
+ ? A.name(key)
+ : A.value(key);
if (typeof value !== "string" && typeof value !== "number") {
return undefined;
}
const name = String(value);
// `__proto__:` sets the prototype, not a property.
return name === "__proto__" &&
- !tree.flag(Flag.computed, property) &&
- !tree.flag(Flag.shorthand, property)
+ !A.flag(Flag.computed, property) &&
+ !A.flag(Flag.shorthand, property)
? undefined
: name;
};
@@ -34633,27 +34560,27 @@ const createNodePrinter = (modules) => {
*/
const pickedValue = (object, member, evaluate) => {
const property = childOf(Field.property, member);
- const read = tree.flag(Flag.computed, member)
+ const read = A.flag(Flag.computed, member)
? typeOf(property) === NodeType.Literal
- ? tree.value(property)
+ ? A.value(property)
: evaluate(property)
: // `#x` reads a private field, which an object literal never holds.
typeOf(property) === NodeType.Identifier
- ? tree.name(property)
+ ? A.name(property)
: undefined;
if (typeof read !== "string" && typeof read !== "number") return 0;
const name = String(read);
- const count = tree.fieldCount(Field.properties, object);
+ const count = A.fieldCount(Field.properties, object);
let picked = 0;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.properties, object);
+ const item = A.field(i, Field.properties, object);
const key = plainKeyOf(item, evaluate);
if (key === undefined) return 0;
if (key === name) picked = item;
}
if (picked === 0) return 0;
for (let i = 0; i < count; i++) {
- const item = tree.field(i, Field.properties, object);
+ const item = A.field(i, Field.properties, object);
if (item !== picked && !isPureValue(childOf(Field.value, item))) {
return 0;
}
@@ -34666,7 +34593,7 @@ const createNodePrinter = (modules) => {
* @returns {number} the value `pickedValue` finds it reads off an object literal, itself read so or written; 0 for none
*/
const readValue = (member) => {
- if (tree.flag(Flag.optional, member)) return 0;
+ if (A.flag(Flag.optional, member)) return 0;
let object = childOf(Field.object, member);
if (typeOf(object) === NodeType.MemberExpression) {
object = readValue(object);
@@ -34700,7 +34627,7 @@ const createNodePrinter = (modules) => {
* @returns {number} the element or value it prints as, 0 for none
*/
const pickedElement = (member, level) => {
- if (!compresses || tree.flag(Flag.optional, member)) return 0;
+ if (!compresses || A.flag(Flag.optional, member)) return 0;
const array = childOf(Field.object, member);
const property = childOf(Field.property, member);
if (holdsComments(array) || hasEdgeComments(property)) return 0;
@@ -34714,20 +34641,20 @@ const createNodePrinter = (modules) => {
!firstInStatement(member, level, true) &&
!(
typeOf(parent) === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, parent) === "void"
+ A.textOf(Part.operator, parent) === "void"
)
? value
: 0;
}
if (
- !tree.flag(Flag.computed, member) ||
+ !A.flag(Flag.computed, member) ||
typeOf(array) !== NodeType.ArrayExpression
) {
return 0;
}
const index =
typeOf(property) === NodeType.Literal
- ? tree.value(property)
+ ? A.value(property)
: valueAtPrint(property);
if (typeof index !== "number" || !Number.isInteger(index) || index < 0) {
return 0;
@@ -34752,7 +34679,7 @@ const createNodePrinter = (modules) => {
* @returns {void}
*/
const printPickedElement = (array, element) => {
- const count = tree.fieldCount(Field.elements, array);
+ const count = A.fieldCount(Field.elements, array);
for (let i = 0; i < count; i++) {
const other = itemOf(i, Field.elements, array);
if (other === element) {
@@ -34760,10 +34687,10 @@ const createNodePrinter = (modules) => {
} else if (
other !== 0 &&
typeOf(other) === NodeType.SpreadElement &&
- tree.start(other) <= tree.start(element) &&
- tree.end(element) <= tree.end(other)
+ A.start(other) <= A.start(element) &&
+ A.end(element) <= A.end(other)
) {
- const inner = tree.field(0, Field.argument, other);
+ const inner = A.field(0, Field.argument, other);
printPickedElement(inner, element);
const context = /** @type {JavascriptPrintContext} */ (writer);
context.consume(inner);
@@ -34797,23 +34724,23 @@ const createNodePrinter = (modules) => {
switch (typeOf(element)) {
case NodeType.Identifier:
// `let[` opens a declaration.
- if (tree.name(element) === "let") return false;
+ if (A.name(element) === "let") return false;
break;
case NodeType.Literal:
// `1.x` reads a number's fraction; `1[x]` reads it whole.
if (
isNumber(element) &&
parentType === NodeType.MemberExpression &&
- !tree.flag(Flag.computed, parent)
+ !A.flag(Flag.computed, parent)
) {
return false;
}
// `true` prints as `!0`, which `.x` or `**` would not read whole.
if (
- typeof tree.value(element) === "boolean" &&
+ typeof A.value(element) === "boolean" &&
(parentType === NodeType.MemberExpression ||
(parentType === NodeType.BinaryExpression &&
- tree.textOf(Part.operator, parent) === "**" &&
+ A.textOf(Part.operator, parent) === "**" &&
childOf(Field.left, parent) === member))
) {
return false;
@@ -34836,7 +34763,7 @@ const createNodePrinter = (modules) => {
(isCallType(parentType) && childOf(Field.callee, parent) === member) ||
parentType === NodeType.TaggedTemplateExpression ||
(parentType === NodeType.UnaryExpression &&
- tree.textOf(Part.operator, parent) === "delete")
+ A.textOf(Part.operator, parent) === "delete")
);
};
/**
@@ -34857,13 +34784,13 @@ const createNodePrinter = (modules) => {
case NodeType.UpdateExpression:
return true;
case NodeType.Literal:
- return tree.value(node) !== null;
+ return A.value(node) !== null;
case NodeType.UnaryExpression:
- return tree.textOf(Part.operator, node) !== "void";
+ return A.textOf(Part.operator, node) !== "void";
case NodeType.LogicalExpression:
// `||` gives its left side only where truthy, `??` where not nullish.
return (
- (tree.textOf(Part.operator, node) !== "&&" ||
+ (A.textOf(Part.operator, node) !== "&&" ||
neverNullish(childOf(Field.left, node))) &[Page truncated to keep GeezerVison snappy.] |