Skip to content

Commit 1d89569

Browse files
feat(javascript): read camelCase minify option names, terser's kept as aliases
The minifier's options are spelled in camelCase (`keepFnames`, `asciiOnly`, `dropConsole`, ...) and read that way throughout. terser's snake_case names stay accepted as aliases, so a terser configuration minifies unchanged; where a group names both, the camelCase one wins. The default `minimizeOptions` keep terser's spelling, which terser itself reads outside `futureDefaults`. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent 1b98b3e commit 1d89569

9 files changed

Lines changed: 646 additions & 223 deletions

File tree

‎.changeset/040-javascript-source-processor.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": minor
33
---
44

5-
Add a JavaScript `SourceProcessor` that minifies faster; drop `printer.load()`.
5+
Add a JavaScript `SourceProcessor` that minifies faster and reads camelCase option names; drop `printer.load()`.

‎lib/config/defaults.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2538,7 +2538,7 @@ const applyOptimizationDefaults = (
25382538
esmLibrary
25392539
? {
25402540
compress: { passes: 2 },
2541-
// eslint-disable-next-line camelcase
2541+
// eslint-disable-next-line camelcase -- terser's spelling, as terser reads these outside `futureDefaults`
25422542
format: { preserve_annotations: true }
25432543
}
25442544
: { compress: { passes: 2 } }

‎lib/javascript/ScopeAnalyzer.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,9 +1319,9 @@ class MinifierLabel {
13191319
* @property {boolean=} module whether the program is a module, so strict
13201320
* @property {boolean=} ie8 whether catch parameters belong to their function
13211321
* @property {boolean=} safari10 whether a loop's scope reads its parent's names, and catch parameters belong to their function
1322-
* @property {boolean | RegExp=} keep_fnames which function names survive, collecting the declarators naming one
1323-
* @property {boolean | RegExp=} keep_classnames which class names survive, collecting the declarators naming one under `classDeclarators`
1324-
* @property {boolean=} classDeclarators whether, under `keep_classnames`, the names declarators give anonymous classes are kept as `keep_fnames` keeps a function's
1322+
* @property {boolean | RegExp=} keepFnames which function names survive, collecting the declarators naming one
1323+
* @property {boolean | RegExp=} keepClassnames which class names survive, collecting the declarators naming one under `classDeclarators`
1324+
* @property {boolean=} classDeclarators whether, under `keepClassnames`, the names declarators give anonymous classes are kept as `keepFnames` keeps a function's
13251325
* @property {boolean=} parameterScopes whether names are scoped as the spec scopes them where terser does not: a parameter list's or a catch parameter's reads skip what the body declares, and a block's async or generator function stays in the block
13261326
* @property {boolean=} withNames whether a scope a `with` reaches keeps only the names its body spells, mangling the rest
13271327
* @property {number=} spelledNames which names to collect that the mangler may give the name beside them to write less: 1 for an import's or export's, 2 for a key's too
@@ -1335,8 +1335,8 @@ class MinifierLabel {
13351335
* @property {MinifierLabel[]} labels every label, in the same order
13361336
* @property {Map<string, MinifierVariable>} globals the names nothing declares, in the order first read
13371337
* @property {Set<MinifierScope>} blockDefunScopes the function scopes holding a function declared in a block
1338-
* @property {NamedIdentifier[] | null} functionDeclarators under `keep_fnames`, the names declarators give anonymous functions, in the order the mangler asks `keep_fnames` of them
1339-
* @property {NamedIdentifier[] | null} classDeclarators under `classDeclarators` and `keep_classnames`, the names declarators give anonymous classes
1338+
* @property {NamedIdentifier[] | null} functionDeclarators under `keepFnames`, the names declarators give anonymous functions, in the order the mangler asks `keepFnames` of them
1339+
* @property {NamedIdentifier[] | null} classDeclarators under `classDeclarators` and `keepClassnames`, the names declarators give anonymous classes
13401340
* @property {NamedIdentifier[]} catchParameters unless `ie8` or `safari10` move them, the catch parameters, each named where the mangler's walk meets its scope
13411341
* @property {boolean} namesPrivate whether the program names a private member, which renaming walks it for
13421342
* @property {SpelledNames | null} spelledNames under `spelledNames`, the names a key or an import or export spells for a name beside it
@@ -1590,10 +1590,10 @@ class MinifierTreeScopeAnalyzer {
15901590
/** @type {Set<MinifierScope>} */
15911591
this.blockDefunScopes = new Set();
15921592
/** @type {number[] | null} */
1593-
this.functionDeclarators = options.keep_fnames ? [] : null;
1593+
this.functionDeclarators = options.keepFnames ? [] : null;
15941594
/** @type {number[] | null} */
15951595
this.classDeclarators =
1596-
options.classDeclarators && options.keep_classnames ? [] : null;
1596+
options.classDeclarators && options.keepClassnames ? [] : null;
15971597
/** @type {number[] | null} the `let` and `const` declarators set to a name */
15981598
this.aliasDeclarators = options.substitutesAliases ? [] : null;
15991599
/** @type {number[] | null} each declarator set to a function, and the start and end of the statements listing it */

‎lib/javascript/side-effects.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const { Field, Flag, NodeType, Part } = require("./syntax-parser");
2121
* @property {(node: number) => PrimitiveKind | undefined} nameKind what a name's value converts as, undefined where it is not known
2222
* @property {(node: number) => boolean} isPureCall whether a call or `new` is marked pure, only its arguments then running code
2323
* @property {boolean=} pureConversions whether converting a value to a primitive is taken to run no code, as webpack's `isPure` takes it
24-
* @property {boolean=} comparesConvert whether a comparison or an object's computed key converting what may be an object runs code, as the compressor's `pure_conversions: false` has it
24+
* @property {boolean=} comparesConvert whether a comparison or an object's computed key converting what may be an object runs code, as the compressor's `pureConversions: false` has it
2525
* @property {((node: number) => boolean | undefined)=} decides what the caller answers for a node before the rules read it, undefined to leave it to them
2626
* @property {((node: number) => number)=} readValue the value a name prints as where it is read, 0 for none
2727
* @property {((node: number) => boolean)=} heritageConstructs whether a class's heritage, past parentheses, is known to be a constructor or `null`, where a class extending anything else may throw; unset, any heritage making nothing happen is taken as one
@@ -32,7 +32,7 @@ const { Field, Flag, NodeType, Part } = require("./syntax-parser");
3232
* or `true` when every condition holds.
3333
* @param {NativeCondition[]} conditions what the entry is gated on, in order
3434
* @param {CompressOptions["unsafe"]} sloppy the compressor's `unsafe` option, as given
35-
* @param {CompressOptions["builtins_ecma"]} es the compressor's `builtins_ecma` option, as given
35+
* @param {CompressOptions["builtinsEcma"]} es the compressor's `builtinsEcma` option, as given
3636
* @returns {boolean} `true`, or the falsy value the chain stops at
3737
*/
3838
const evaluateNativeConditions = (conditions, sloppy, es) => {
@@ -47,7 +47,7 @@ const evaluateNativeConditions = (conditions, sloppy, es) => {
4747
* The set terser's `makePredicate(remove_false([...]))` builds from a list.
4848
* @param {NativeName[]} names the list, with its conditions
4949
* @param {CompressOptions["unsafe"]} sloppy the compressor's `unsafe` option, as given
50-
* @param {CompressOptions["builtins_ecma"]} es the compressor's `builtins_ecma` option, as given
50+
* @param {CompressOptions["builtinsEcma"]} es the compressor's `builtinsEcma` option, as given
5151
* @returns {Set<PropertyKey>} each name whose conditions hold
5252
*/
5353
const selectNativeNames = (names, sloppy, es) => {
@@ -93,7 +93,7 @@ const readGlobalsByOptions = new Map();
9393
* webpack's improvements read them: every global the language or a browser
9494
* page defines, terser's `pure_access_globals` among them.
9595
* @param {CompressOptions["unsafe"]} sloppy the `unsafe` option, as given
96-
* @param {CompressOptions["builtins_ecma"]} es the `builtins_ecma` option, as given
96+
* @param {CompressOptions["builtinsEcma"]} es the `builtinsEcma` option, as given
9797
* @returns {Set<PropertyKey>} the globals, shared: never changed
9898
*/
9999
const globalsReadWithoutEffect = (sloppy, es) => {

‎lib/javascript/syntax-parser.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20961,7 +20961,7 @@ const parserGoal = (sourceType) => ({
2096120961
/**
2096220962
* @typedef {object} JavascriptReadOptions what the JavaScript `SourceProcessor` reads its source as, and prints it with
2096320963
* @property {JavascriptSourceType=} sourceType what the source is: a module (the default), a script, or a function's body, a CommonJS module's or an event handler's
20964-
* @property {Partial<import("./syntax-printer").FormatSettings>=} format terser's format options a print reads, as `minify` reads them under `format`; `comments` is read where it compresses or mangles
20964+
* @property {import("./syntax-printer").GivenFormatOptions=} format terser's format options a print reads, as `minify` reads them under `format`; `comments` is read where it compresses or mangles
2096520965
*/
2096620966
/**
2096720967
* The JavaScript `SourceProcessor`'s options: a print given `compress` or

0 commit comments

Comments
 (0)