fix(es/minifier): Remove duplicate accessed_props field from rebase
Remove duplicate accessed_props field declaration that was introduced
during the cherry-pick rebase. The main branch now uses Wtf8Atom
instead of Atom for accessed_props.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
b1b0ad7
8 days ago
by github-actions[bot]
-1.39%
fix(es/minifier): Enable parameter inlining for all safe constant values
This commit addresses the core issue preventing parameter inlining from working
for literal values like numbers, strings, and booleans.
## Changes Made
1. **Fixed params.rs (lines 162-176)**: Removed the overly restrictive check that
only allowed `undefined` values to be inlined. Now all safe constant values
(literals, undefined, simple unary expressions) are inlined when they pass the
`is_safe_constant_for_param_inline()` check.
2. **Updated storage signature**: Changed `record_call_site_args` to accept
`&[Option<Box<Expr>>]` instead of `Vec<Box<Expr>>` to avoid requiring callers
to clone the entire vector, improving performance per maintainer feedback.
3. **Updated data structures**: Changed `VarUsageInfo.call_site_args` from
`Vec<Vec<Box<Expr>>>` to `Vec<Vec<Option<Box<Expr>>>>` to properly represent
implicit undefined arguments (None) vs explicit arguments (Some(expr)).
4. **Updated test outputs**: Ran `UPDATE=1 cargo test -p swc_ecma_minifier` to
regenerate expected outputs for all affected tests. The optimization now works
correctly across many existing test cases.
## Examples
**literal_values test**: Now properly inlines string constants:
```js
// Before: function literals(str, num, bool, nil)
// After: function literals() { let str = "hello"; ... }
```
**multiple_params test**: Successfully inlines all parameters:
```js
// Before: function calc(a, b, c) { return a + b + c; }
// After: function calc() { return 6; } // Fully optimized!
```
Addresses review feedback from PR #11156.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
4a6451a
8 days ago
by github-actions[bot]
+0.44%
fix(es/minifier): Update quagga2 test snapshot for parameter inlining
Updates the expected output for the quagga2 test to reflect parameter
inlining optimization. The change removes an unused parameter from an
inline function while maintaining functional correctness.
Changes:
- Function signature changes from `function(buffer, start, length)` to
`function(buffer, start)`
- The `length` parameter was unused (replaced with literal `4` in loop)
- Call site adjusted accordingly
The output is functionally equivalent and represents valid minification.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
09974fc
8 days ago
by github-actions[bot]
-0.71%
fix(es/minifier): Fix parameter inlining issues
This commit fixes two bugs in the parameter inlining optimization:
1. **Variable shadowing bug**: Prevent inlining parameters that are shadowed
by function declarations in the function body. When a parameter has the
same name as a function declaration inside the body, inlining it as a
`let` declaration would cause a "Identifier already declared" error due
to function declaration hoisting.
Example that was failing:
```js
function f(a) {
function a() { return 1; }
return a();
}
```
2. **Single-call-site conflict**: Disable parameter inlining for functions
with only one call site. For single-use functions, parameter inlining
doesn't provide any code size benefit (we're just moving values from the
call site to the function body), and it can interfere with function body
inlining which is a more powerful optimization. This was causing issues
where parameter inlining would modify the function, and then function
body inlining would produce incorrect results.
Example that was failing:
```js
function run(str, r) {
let m;
while(m = r.exec(str)) {
console.log(m);
}
}
run('abcda', /a/g);
```
Fixes test failures: issue_6279_1, issue_6279_2, terser_reduce_vars_func_modified
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
20aaed2
8 days ago
by github-actions[bot]
-0.19%
fix(es/minifier): Fix parameter inlining safety checks
This commit fixes two critical issues with parameter inlining:
1. **Function name shadowing**: Prevent inlining parameters that have the
same name as the function itself. When a parameter has the same name as
the containing function, inlining it as a `let` declaration would shadow
the function name, breaking code that references the function internally.
Example that was failing:
```js
function long_name(long_name) {
return typeof long_name;
}
```
2. **Non-contiguous parameter inlining**: Restrict parameter inlining to only
inline contiguous suffixes of parameters. Previously, we could inline
parameter 0 while leaving parameter 1 intact, creating asymmetric
parameter lists that confused other optimizations. Now we only inline
parameters if they form a contiguous sequence from some index to the end.
Example that was failing:
```js
function applyCb(errorMessage, callback) {
return callback(errorMessage);
}
applyCb("FAIL", () => console.log("PASS"));
```
Previously, only `errorMessage` was inlined (leaving `callback` as-is),
which caused issues with other optimizations. Now neither is inlined
because they don't form a complete suffix.
3. **Remove single-call-site restriction**: The previous commit added a check
to skip functions with a single call site to avoid interfering with
function body inlining. However, this was too conservative - if a function
is NOT inlined (e.g., too complex), parameter inlining is still beneficial.
The restriction has been removed because:
- If function WILL be body-inlined, parameter changes don't matter
- If function WON'T be body-inlined, parameter inlining is beneficial
These changes ensure parameter inlining only applies when it's safe and
doesn't interfere with other optimizations.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
07c844a
8 days ago
by github-actions[bot]
+8.55%
fix(es/minifier): Prevent parameter inlining when var declarations shadow parameters
Fixed a bug where the parameter inlining optimization would incorrectly
inline parameters that are shadowed by var declarations in the function body.
In JavaScript, var declarations are hoisted to the function scope, which
means they shadow parameters even when declared inside nested blocks:
```js
function g(arg) {
if (condition) {
var arg = 2; // This shadows the parameter due to hoisting
}
return arg;
}
```
The fix adds comprehensive shadowing detection that recursively checks
all statements in the function body for:
- Function declarations (already handled)
- Var declarations (new fix)
- Nested blocks, if/else, loops, try/catch, switch, etc.
This ensures the optimizer doesn't break code semantics by preventing
parameter inlining when shadowing occurs.
Fixes test: crates/swc/tests/exec/issues-5xxx/5645/exec.js
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
70181ed
8 days ago
by github-actions[bot]
-8.28%
fix(es/minifier): Fix clippy warning in parameter inlining
Replace `map_or(false, ...)` with `is_some_and(...)` to fix the
unnecessary_map_or clippy warning.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
52d5ef1
8 days ago
by github-actions[bot]
+0.31%
fix(test): Update test snapshots for parameter inlining optimization
Updated test output files to reflect the changes introduced by the
parameter inlining optimization. The optimization correctly transforms
code by replacing repeated constant parameter values with variable
declarations, which results in different but improved minified output.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>