-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(es/minifier): Preserve array.join
with nullable values
#10937
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.
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
Conversation
The minifier was incorrectly optimizing array.join('''') to string concatenation when the array contained optional chaining or member expressions that could produce undefined values. This caused undefined to be converted to the string undefined instead of an empty string. Fixed by preventing the optimization when array contains: - OptChain expressions (e.g., obj?.prop) - Member expressions that might be undefined Fixes #10936 Co-authored-by: Donny/강동윤 <[email protected]>
|
🦋 Changeset detectedLatest commit: 273f021 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Claude finished @kdy1's task —— View job I'll conduct a thorough code review of this PR that fixes array.join optimization with nullable values. Todo List:
Code Review: array.join Optimization FixSummaryThis PR fixes an issue where the SWC minifier incorrectly optimized Code Quality & Best Practices: ✅ EXCELLENTStrengths:
Correctness Analysis: ✅ CORRECTCore Fix Analysis ( .any(|v| match &*v.expr {
e if is_pure_undefined(self.expr_ctx, e) => false,
Expr::Lit(lit) => !matches!(lit, Lit::Str(..) | Lit::Num(..) | Lit::Null(..)),
// All other expressions can potentially be null/undefined
_ => true,
}) What's Safe to Optimize:
What Prevents Optimization (Correctly):
This is the correct approach because in JavaScript: [1, null, 2].join('') === "12" // null becomes empty string
[1, undefined, 2].join('') === "12" // undefined becomes empty string Test Coverage: ✅ COMPREHENSIVEThe test cases in
The expected output correctly shows:
Performance Considerations: ✅ OPTIMALPerformance Impact:
Bundle Size Impact:
Security Considerations: ✅ SAFE
Edge Cases & Robustness: ✅ WELL HANDLEDCorrectly Handles:
Potential Improvements (Minor):
Final Assessment
Recommendation: APPROVE ✅This is a well-implemented fix that correctly addresses the reported issue. The solution is conservative, well-tested, and maintains good performance characteristics. The trade-off between optimization aggressiveness and correctness is appropriate. Minor Suggestions:
|
CodSpeed Performance ReportMerging #10937 will not alter performanceComparing Summary
Footnotes |
array.join
with nullable values
@claude Update the test references of |
Claude finished @kdy1's task —— View job Completed Tasks:
Tasks Requiring Approval:
I've successfully:
To complete the remaining tasks (updating test references and running cargo fmt), I need approval to run cargo commands. You can either:
|
…cases Co-authored-by: Donny/강동윤 <[email protected]>
@claude Think more carefully about all kinds of javascript expressions that can be null or undefined
Also, as I approved, run |
Claude finished @kdy1's task —— View job Todo List:
JavaScript Expressions That Can Be Null/UndefinedAfter analyzing the code and thinking about JavaScript semantics, here are the expression types that can evaluate to null or undefined:
Update AppliedI've updated the code in I've also added test cases for function calls and other expressions to ensure they're handled correctly. Changes Made:
Note: I need approval to run the cargo commands ( |
@claude think more carefully about all kinds of javascript expressions that can be null or undefined and handle them just like identifier, which also can be a null or undefined
|
Claude finished @kdy1's task —— View job Claude finished @kdy1's task —— View job Completed Tasks:
Tasks Requiring Approval:
Changes Made:I've made the array.join optimization more conservative as requested. The key change is in .any(|v| match &*v.expr {
e if is_pure_undefined(self.expr_ctx, e) => false,
Expr::Lit(lit) => !matches!(lit, Lit::Str(..) | Lit::Num(..) | Lit::Null(..)),
// All other expressions can potentially be null/undefined
_ => true,
}) What this means:
This is much more conservative than before, where identifiers, optional chains, and member expressions were incorrectly marked as safe. I've also added test cases for function calls and other nullable expressions to ensure they're handled correctly. To complete the remaining tasks (formatting and updating test references), you'll need to either:
|
Only allow optimization for literals (string, number, null) and pure undefined. All other expressions (identifiers, function calls, member expressions, etc.) can potentially be null/undefined and should prevent optimization. Co-authored-by: Donny/강동윤 <[email protected]>
Related issue:
es/minifier
: .join is not ignoring null values anymore #10936