Skip to content

Commit 886ffac

Browse files
committed
Mangle optimizations
1 parent ca960dc commit 886ffac

File tree

14 files changed

+166
-167
lines changed

14 files changed

+166
-167
lines changed

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
make lint
22
make check
3-
make pretty
3+
make format
44
make types
55
git add ./

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ size-html:
5656
version:
5757
@node utils/version.cjs
5858

59-
pretty:
59+
format:
6060
@npx prettier ./ --write --cache --log-level=silent
6161

6262
lint:
@@ -84,7 +84,7 @@ serve:
8484
node --watch ./utils/express.js & \
8585
wait
8686

87-
prepare-release: build test check types doc pretty gzip version size-html
87+
prepare-release: build test check types doc format gzip version size-html
8888

8989
PLAYWRIGHT_TEST := npx playwright test
9090

@@ -110,4 +110,3 @@ coverage-open:
110110

111111
hugo:
112112
hugo server --source=docs --disableFastRender
113-

src/core/parse/ast/ast.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class AST {
203203
while ((token = this._expect("==", "!=", "===", "!=="))) {
204204
left = {
205205
_type: ASTType._BinaryExpression,
206-
_operator: /** @type {Token} */ token.text,
206+
_operator: /** @type {Token} */ token._text,
207207
_left: left,
208208
_right: this._relational(),
209209
};
@@ -224,7 +224,7 @@ export class AST {
224224
while ((token = this._expect("<", ">", "<=", ">="))) {
225225
left = {
226226
_type: ASTType._BinaryExpression,
227-
_operator: /** @type {Token} */ token.text,
227+
_operator: /** @type {Token} */ token._text,
228228
_left: left,
229229
_right: this._additive(),
230230
};
@@ -245,7 +245,7 @@ export class AST {
245245
while ((token = this._expect("+", "-"))) {
246246
left = {
247247
_type: ASTType._BinaryExpression,
248-
_operator: /** @type {Token} */ token.text,
248+
_operator: /** @type {Token} */ token._text,
249249
_left: left,
250250
_right: this._multiplicative(),
251251
};
@@ -266,7 +266,7 @@ export class AST {
266266
while ((token = this._expect("*", "/", "%"))) {
267267
left = {
268268
_type: ASTType._BinaryExpression,
269-
_operator: token.text,
269+
_operator: token._text,
270270
_left: left,
271271
_right: this._unary(),
272272
};
@@ -299,7 +299,7 @@ export class AST {
299299

300300
return {
301301
_type: ASTType._UpdateExpression,
302-
_operator: /** @type {Token} */ token.text,
302+
_operator: /** @type {Token} */ token._text,
303303
_prefix: true,
304304
_argument: argument,
305305
};
@@ -309,7 +309,7 @@ export class AST {
309309
if ((token = this._expect("+", "-", "!"))) {
310310
return {
311311
_type: ASTType._UnaryExpression,
312-
_operator: /** @type {Token} */ token.text,
312+
_operator: /** @type {Token} */ token._text,
313313
_prefix: true,
314314
_argument: this._unary(),
315315
};
@@ -339,7 +339,7 @@ export class AST {
339339

340340
expr = {
341341
_type: ASTType._UpdateExpression,
342-
_operator: /** @type {Token} */ token.text,
342+
_operator: /** @type {Token} */ token._text,
343343
_prefix: false,
344344
_argument: expr,
345345
};
@@ -364,18 +364,18 @@ export class AST {
364364
primary = this._arrayDeclaration();
365365
} else if (this._expect("{")) {
366366
primary = this._object();
367-
} else if (hasOwn(this._selfReferential, (peekToken as Token).text)) {
367+
} else if (hasOwn(this._selfReferential, (peekToken as Token)._text)) {
368368
primary = cloneSelfReferentialNode(
369-
this._selfReferential[this._consume().text],
369+
this._selfReferential[this._consume()._text],
370370
);
371-
} else if (hasOwn(literals, (peekToken as Token).text)) {
371+
} else if (hasOwn(literals, (peekToken as Token)._text)) {
372372
primary = {
373373
_type: ASTType._Literal,
374-
_value: literals[this._consume().text as keyof typeof literals],
374+
_value: literals[this._consume()._text as keyof typeof literals],
375375
};
376-
} else if ((peekToken as Token).identifier) {
376+
} else if ((peekToken as Token)._identifier) {
377377
primary = this._identifier();
378-
} else if ((peekToken as Token).constant) {
378+
} else if ((peekToken as Token)._constant) {
379379
primary = this._constant();
380380
} else {
381381
this._throwError("not a primary expression", this._peek() as Token);
@@ -384,22 +384,22 @@ export class AST {
384384
let next: Token | false;
385385

386386
while ((next = this._expect("(", "[", "."))) {
387-
if (next.text === "(") {
387+
if (next._text === "(") {
388388
primary = {
389389
_type: ASTType._CallExpression,
390390
_callee: primary,
391391
_arguments: this._parseArguments(),
392392
};
393393
this._consume(")");
394-
} else if (next.text === "[") {
394+
} else if (next._text === "[") {
395395
primary = {
396396
_type: ASTType._MemberExpression,
397397
_object: primary,
398398
_property: this._assignment(),
399399
_computed: true,
400400
};
401401
this._consume("]");
402-
} else if (next.text === ".") {
402+
} else if (next._text === ".") {
403403
primary = {
404404
_type: ASTType._MemberExpression,
405405
_object: primary,
@@ -443,7 +443,7 @@ export class AST {
443443
_parseArguments(): ASTNode[] {
444444
const args: ASTNode[] = [];
445445

446-
if (this._peekToken().text !== ")") {
446+
if (this._peekToken()._text !== ")") {
447447
do {
448448
args.push(this._filterChain());
449449
} while (this._expect(","));
@@ -459,11 +459,11 @@ export class AST {
459459
_identifier(): ASTNode {
460460
const token = this._consume();
461461

462-
if (!token.identifier) {
462+
if (!token._identifier) {
463463
this._throwError("is not a valid identifier", token);
464464
}
465465

466-
return { _type: ASTType._Identifier, _name: token.text };
466+
return { _type: ASTType._Identifier, _name: token._text };
467467
}
468468

469469
/**
@@ -472,7 +472,7 @@ export class AST {
472472
*/
473473
_constant(): ASTNode {
474474
// TODO check that it is a constant
475-
return { _type: ASTType._Literal, _value: this._consume().value };
475+
return { _type: ASTType._Literal, _value: this._consume()._value };
476476
}
477477

478478
/**
@@ -482,7 +482,7 @@ export class AST {
482482
_arrayDeclaration(): ASTNode {
483483
const elements: ASTNode[] = [];
484484

485-
if (this._peekToken().text !== "]") {
485+
if (this._peekToken()._text !== "]") {
486486
do {
487487
if (this._peek("]")) {
488488
// Support trailing commas per ES5.1.
@@ -505,7 +505,7 @@ export class AST {
505505

506506
let property: ObjectPropertyNode;
507507

508-
if (this._peekToken().text !== "}") {
508+
if (this._peekToken()._text !== "}") {
509509
do {
510510
if (this._peek("}")) {
511511
// Support trailing commas per ES5.1.
@@ -520,12 +520,12 @@ export class AST {
520520
_computed: false,
521521
};
522522

523-
if (nextToken.constant) {
523+
if (nextToken._constant) {
524524
property._key = this._constant();
525525
property._computed = false;
526526
this._consume(":");
527527
property._value = this._assignment();
528-
} else if (nextToken.identifier) {
528+
} else if (nextToken._identifier) {
529529
property._key = this._identifier();
530530
property._computed = false;
531531

@@ -562,11 +562,11 @@ export class AST {
562562
throw $parseMinErr(
563563
"syntax",
564564
"Syntax Error: Token '{0}' {1} at column {2} of the expression [{3}] starting at [{4}].",
565-
token.text,
565+
token._text,
566566
msg,
567-
token.index + 1,
567+
token._index + 1,
568568
this._text,
569-
this._text?.substring(token.index),
569+
this._text?.substring(token._index),
570570
);
571571
}
572572

@@ -626,7 +626,7 @@ export class AST {
626626

627627
if (!j) return token;
628628

629-
const txt = token.text;
629+
const txt = token._text;
630630

631631
if (expected.length === 1) return expected[0] === txt ? token : false;
632632

src/core/parse/interpreter.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class ASTInterpreter {
6161
* @param {ASTNode} ast - The AST to compile.
6262
* @returns {CompiledExpression}
6363
*/
64-
compile(ast: ASTNode): CompiledExpression {
64+
_compile(ast: ASTNode): CompiledExpression {
6565
const decoratedNode = findConstantAndWatchExpressions(ast, this._$filter);
6666

6767
const { _body: body } = decoratedNode as BodyNode;
@@ -160,7 +160,7 @@ export class ASTInterpreter {
160160

161161
switch (ast._type) {
162162
case ASTType._Literal:
163-
return this.value((ast as LiteralNode)._value, context);
163+
return this._value((ast as LiteralNode)._value, context);
164164
case ASTType._UnaryExpression:
165165
right = this._recurse((ast as ExpressionNode)._argument as ASTNode);
166166

@@ -183,7 +183,7 @@ export class ASTInterpreter {
183183
context,
184184
);
185185
case ASTType._Identifier:
186-
return self.identifier(
186+
return self._identifier(
187187
(ast as LiteralNode)._name as string,
188188
context,
189189
create,
@@ -210,7 +210,7 @@ export class ASTInterpreter {
210210
context,
211211
create,
212212
)
213-
: this.nonComputedMember(left, right as string, context, create);
213+
: this._nonComputedMember(left, right as string, context, create);
214214
case ASTType._CallExpression:
215215
args = [];
216216
const callArguments = (ast as ExpressionNode)._arguments as ASTNode[];
@@ -798,7 +798,7 @@ export class ASTInterpreter {
798798
* @param {Object} [context] - The context.
799799
* @returns {CompiledExpressionFunction} The function returning the literal value.
800800
*/
801-
value(value: any, context?: LinkContext): CompiledExpressionFunction {
801+
_value(value: any, context?: LinkContext): CompiledExpressionFunction {
802802
return () =>
803803
context ? { context: undefined, name: undefined, value } : value;
804804
}
@@ -810,7 +810,7 @@ export class ASTInterpreter {
810810
* @param {boolean|1} [create] - Whether to create the identifier if it does not exist.
811811
* @returns {CompiledExpressionFunction} The function returning the identifier value.
812812
*/
813-
identifier(
813+
_identifier(
814814
name: string,
815815
context?: LinkContext,
816816
create?: CreateFlag,
@@ -889,7 +889,7 @@ export class ASTInterpreter {
889889
* @param {boolean|1} [create] - Whether to create the member if it does not exist.
890890
* @returns {CompiledExpressionFunction} The function returning the non-computed member value.
891891
*/
892-
nonComputedMember(
892+
_nonComputedMember(
893893
left: CompiledExpressionFunction,
894894
right: string,
895895
context?: LinkContext,

0 commit comments

Comments
 (0)