Commit dbaa230
fix(es/minifier): Restrict parameter inlining to undefined values only
This commit addresses the PR review feedback by:
1. **Fixing the USED_AS_REF check**: The previous implementation incorrectly
checked for `USED_AS_REF` flag which is always set when a function is
referenced (even when called). The fix changes this to check for `USED_AS_ARG`
which specifically indicates the function is passed as an argument.
2. **Restricting inlining to undefined only**: To avoid being too aggressive
and breaking existing tests, parameter inlining now only applies to `undefined`
values (both implicit and explicit). This matches the original use case of
eliminating optional callbacks and configuration parameters.
3. **Updating test outputs**: Test expectation files have been updated to reflect
the correct behavior where undefined parameters are inlined as `let` declarations.
The optimization now correctly handles cases like:
```javascript
function complex(foo, fn) {
return fn?.(foo);
}
complex("foo"); // fn is implicitly undefined
```
Which becomes:
```javascript
function complex(foo) {
let fn;
return fn?.(foo);
}
complex("foo");
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>1 parent 41fdbe2 commit dbaa230
3 files changed
+23
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
72 | 79 | | |
73 | 80 | | |
74 | 81 | | |
| |||
153 | 160 | | |
154 | 161 | | |
155 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
156 | 166 | | |
157 | | - | |
158 | | - | |
159 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
160 | 174 | | |
161 | 175 | | |
162 | 176 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
0 commit comments