GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(minify): fold typeof facts, constant calls and dead blocks; drop nullish chains by alexander-akait · Pull Request #23398 · webpack/webpack

feat(minify): fold typeof facts, constant calls and dead blocks; drop nullish chains #23398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
alexander-akait merged 28 commits into main from feat/minify-gap-sweep-2
Nov 17, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat(minify): fold typeof facts, constant calls and dead blocks; drop nullish chains #23398

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e7f6796
feat(minify): close more one-pass minifier gaps to swc and oxc
alexander-akait Nov 16, 2026
09abb6b
test: retire oxc rows no longer bigger
alexander-akait Nov 16, 2026
9999a31
feat(minify): print an if/else whose else is a known-test if as ?:
alexander-akait Nov 16, 2026
f6cdf06
feat(minify): move single-use top-level functions top_retain does not…
alexander-akait Nov 16, 2026
0abe1a5
feat(minify): fold a known switch keeping its bare var declarations
alexander-akait Nov 16, 2026
9c599bf
feat(minify): print the effects of any static field value of an unrea…
alexander-akait Nov 16, 2026
d3b2438
feat(minify): drop a write a returned sequence reads back
alexander-akait Nov 16, 2026
dc4d825
test: record new one-pass prints and retire closed rows
alexander-akait Nov 16, 2026
f43e298
feat(minify): fold the effects of an unread object literal's computed…
alexander-akait Nov 16, 2026
2278284
feat(minify): reduce an in-place call whose unpassed parameter only f…
alexander-akait Nov 16, 2026
37afacd
test: record new one-pass prints and retire closed rows
alexander-akait Nov 16, 2026
cafd5ed
fix(minify): keep a picked block's if out of ?: where a block holds it
alexander-akait Nov 16, 2026
72c3eaf
test: retire an oxc row no longer bigger
alexander-akait Nov 16, 2026
65eb95f
feat(minify): fold a known if whose dead block declares a function
alexander-akait Nov 16, 2026
e3b8dea
feat(minify): drop an unread ~, - or + of a pure IIFE returning a pri…
alexander-akait Nov 16, 2026
143f07e
feat(minify): fold typeof of a moved function and typeof string facts
alexander-akait Nov 16, 2026
2bc1db8
feat(minify): fold a function written in place returning a literal to…
alexander-akait Nov 16, 2026
1797337
feat(minify): drop optional chains on known nullish or non-nullish bases
alexander-akait Nov 16, 2026
0521bd5
fix(minify): keep a constant call stable across passes, record prints…
alexander-akait Nov 16, 2026
7686dee
test: restore the external corpus submodules
alexander-akait Nov 16, 2026
c5c9a09
Merge main into feat/minify-gap-sweep-2
alexander-akait Nov 16, 2026
5459be3
feat(minify): print a number constant where a member reads it
alexander-akait Nov 16, 2026
a0a118d
fix(minify): keep parameter typeof errors, spread conversions, privat…
alexander-akait Nov 16, 2026
feb3ead
fix(minify): type a constant call's null return
alexander-akait Nov 16, 2026
c9b3e48
test(minify): hold a strict class declaration's private-name key
alexander-akait Nov 16, 2026
17dcdf8
chore: keep trims and number members in the combined changeset
alexander-akait Nov 16, 2026
83999c5
test: keep one-pass-dead-stores alike on every engine
alexander-akait Nov 16, 2026
044ce4b
test: retire the swc row the minifier now matches
alexander-akait Nov 16, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
feat(minify): drop optional chains on known nullish or non-nullish bases
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013FhutQK3ZQTi3EjTDvtMgz
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@alexander-akait @claude
alexander-akait and claude committed Nov 16, 2026
commit 1797337bc8a92d9b733b5700eb204cce4820ef2d

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

138 changes: 138 additions & 0 deletions 138 lib/javascript/syntax-printer.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -6536,6 +6536,9 @@ const createNodePrinter = (modules) => {
// The `a=x,a` a `return` returns, printed as `a=x` with its read uncounted.
/** @type {Set<number>} */
const returnedWrites = new Set();
// An unread chain's links and the `(a(),null)` it starts on, printed as `a()`.
/** @type {Set<number>} */
const nullishChainParts = new Set();
// By definition, the declarator of a constant each read prints the value
// of, terser's `reduce_vars` and `evaluate`.
/** @type {Map<MinifierVariable, number>} */
Expand Down Expand Up @@ -8152,6 +8155,16 @@ const createNodePrinter = (modules) => {
case NodeType.SequenceExpression: {
if (isPrivateInRight(node, level)) return true;
if (opensStatementBare(node, level)) return false;
// What an unread chain starts on prints in the chain's place.
if (
level === 0 &&
compresses &&
dropsDeadCode &&
dropsSideEffectFree &&
startsNullishChain(node)
) {
return false;
}
// Among what an unread array, object or call runs, it is an item.
if (level === 0 && printsBareUnreadPart(node, parent)) return false;
if (
Expand Down Expand Up @@ -22540,6 +22553,7 @@ const createNodePrinter = (modules) => {
voidedCalls.clear();
droppedReads.clear();
returnedWrites.clear();
nullishChainParts.clear();
constantCalls.clear();
undefinedNames.clear();
bodyFunctions.clear();
Expand Down Expand Up @@ -31684,6 +31698,14 @@ const createNodePrinter = (modules) => {
*/
const printCall = (node) => {
const callee = childOf(Field.callee, node);
if (nullishChainParts.size !== 0 && nullishChainParts.has(node)) {
printNode(callee);
const count = A.fieldCount(Field.arguments, node);
for (let i = 0; i < count; i++) {
skipNode(itemOf(i, Field.arguments, node));
}
return;
}
if (joinTemplates.size !== 0 && joinTemplates.has(node)) {
printJoinTemplate(
node,
Expand Down Expand Up @@ -41822,6 +41844,20 @@ const createNodePrinter = (modules) => {
}
};
generators[NodeType.SequenceExpression] = (node) => {
if (
compresses &&
dropsDeadCode &&
dropsSideEffectFree &&
startsNullishChain(node)
) {
const count = A.fieldCount(Field.expressions, node);
for (let i = 0; i < count - 1; i++) {
if (i > 0) output.comma();
printNode(itemOf(i, Field.expressions, node));
}
skipNode(itemOf(count - 1, Field.expressions, node));
return;
}
if (returnedWrites.size !== 0 && returnedWrites.has(node)) {
printNode(itemOf(0, Field.expressions, node));
skipNode(itemOf(1, Field.expressions, node));
Expand Down Expand Up @@ -42542,6 +42578,93 @@ const createNodePrinter = (modules) => {
}
printNode(expression);
};
/**
* Notes `(a(),null)?.b` unread, printing as `a()`: the sequence and the
* links of the chain it starts.
* @param {number} node a sequence, being printed
* @returns {boolean} whether it starts such a chain
*/
const startsNullishChain = (node) => {
let child = node;
let level = 0;
for (;;) {
const parent = parentAt(level);
const type = typeOf(parent);
if (
(type === NodeType.MemberExpression &&
childOf(Field.object, parent) === child) ||
(type === NodeType.CallExpression &&
childOf(Field.callee, parent) === child)
) {
child = parent;
level++;
continue;
}
if (
type !== NodeType.ChainExpression ||
child === node ||
nullishSequenceBase(parent, level + 1) !== node
) {
return false;
}
break;
}
for (let link = child; link !== node;) {
nullishChainParts.add(link);
link =
typeOf(link) === NodeType.CallExpression
? childOf(Field.callee, link)
: childOf(Field.object, link);
}
nullishChainParts.add(node);
return true;
};
/**
* @param {number} chain an optional chain
* @param {number} level where its parent is among the printed one's
* @returns {number} the sequence its first link is optional on, ending in a pure nullish value, where nothing reads the chain; else 0
*/
const nullishSequenceBase = (chain, level) => {
const chainParent = parentAt(level);
if (holdsComments(chain) || !valueUnread(chain, chainParent)) return 0;
const parentType = typeOf(chainParent);
if (
parentType !== NodeType.ExpressionStatement &&
parentType !== NodeType.SequenceExpression
) {
return 0;
}
let link = childOf(Field.expression, chain);
for (;;) {
const inner =
typeOf(link) === NodeType.CallExpression
? childOf(Field.callee, link)
: childOf(Field.object, link);
const innerType = typeOf(inner);
if (
innerType === NodeType.MemberExpression ||
innerType === NodeType.CallExpression
) {
link = inner;
continue;
}
if (
innerType !== NodeType.SequenceExpression ||
!A.flag(Flag.optional, link) ||
holdsComments(inner)
) {
return 0;
}
const count = A.fieldCount(Field.expressions, inner);
const last = itemOf(count - 1, Field.expressions, inner);
const first = itemOf(0, Field.expressions, inner);
return (isUndefinedValue(last) ||
(evaluateConstant(last) === null && isPureValue(last))) &&
!opensAmbiguously(first)
? inner
: 0;
}
};
/**
* terser's `evaluate` of an optional chain: `null?.a.b()` is `undefined`
* without reading anything past its start.
Expand Down Expand Up @@ -42965,6 +43088,16 @@ const createNodePrinter = (modules) => {
A.textOf(Part.operator, node) === "=" &&
neverNullish(childOf(Field.right, node))
);
case NodeType.Identifier: {
// A name printing as the value set before it is that value.
const value = collapsedValue(node);
return value !== 0 && neverNullish(value);
}
case NodeType.MemberExpression: {
// An element of an inlined constant prints as its value.
const element = inlinedElement(node);
return element !== undefined && element !== null;
}
default:
return false;
}
Expand Down Expand Up @@ -43062,6 +43195,11 @@ const createNodePrinter = (modules) => {
generators[NodeType.MemberExpression] = (node) => {
const object = childOf(Field.object, node);
const property = childOf(Field.property, node);
if (nullishChainParts.size !== 0 && nullishChainParts.has(node)) {
printNode(object);
skipNode(property);
return;
}
if (joinTemplates.size !== 0 && joinTemplates.has(parentAt(0))) {
// A `join` printing as a template prints its array's pieces.
skipNode(property);
Expand Down
9 changes: 9 additions & 0 deletions 9 test/fixtures/javascript/one-pass-optional-chain-base/index.js
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var i = 0;
(i++, null)?.unused;
(i++, null)?.a.b, (i++, void 0)?.(i++);
(i++, null)?.[i++].c?.(i++);
var kept = (i++, null)?.d;
(i++, {})?.e;
const obj = { key: 42 };
const val = obj.key?.toString();
console.log(i, kept, val);
1 change: 1 addition & 0 deletions 1 test/fixtures/javascript/one-pass-optional-chain-base/options.json
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"mode":"minify","compress":{"toplevel":true,"passes":2},"mangle":{"toplevel":true},"behavior":true},{"mode":"minify","compress":{},"mangle":false},{"mode":"minify","compress":{"toplevel":true,"inline":false},"mangle":false}]
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.