Documentation
¶
Overview ¶
Package minify implements a token-aware JavaScript minifier used to shrink the embedded runtime sources before they're served.
Scope (tier-2):
- Strip line + block comments.
- Collapse whitespace, preserving newlines only where ASI cares.
- Distinguish regex literals from division.
- Preserve string + template-literal payloads byte-for-byte.
- Insert a single space when removing whitespace would fuse two adjacent tokens (`let a` → `leta`, `+ +` → `++`, `/ /` → `//`).
- Rewrite a `const` declaration keyword to `let`. For any program that runs without throwing, the two are semantically identical (same block scoping, same TDZ, same per-iteration for-of/for-in binding); const's extra assignment check can only fire in code that is already broken. Non-declaration uses (`a.const`, `{const: 1}`, `class A{const=1}`) are left alone: the rewrite applies only when the keyword follows a non-`.` token and the next token starts a binding (identifier, `{`, or `[`).
- Drop a `;` or `,` immediately before a `}` (`a=1;}` → `a=1}`, `{a:1,}` → `{a:1}`). In valid JS a `}` can only follow `;` as a statement/class-element terminator (droppable) and `,` as a trailing comma in an object literal / destructuring / import-specifier list (droppable; array-hole commas sit before `]`, which is never touched). Exception: a `;` whose previous token is `)` is never dropped — it may be an empty statement serving as an if/while/for body (`if(x);}` → `if(x)}` is a SyntaxError), and a scanner can't tell that apart from `g();}`. The same rule keeps the do-while terminator (`do{}while(x);}`).
Out of scope (would be tier-3): identifier renaming, dead-code elimination, constant folding, anything that requires a parser.
The output is intentionally still valid, readable-ish JavaScript — it stays parseable by the browser without source maps and a developer can still set breakpoints inside it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.