Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
…ions Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
…plete integration Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
try_fold_known_global_methods from @oxc-project/oxc/files/crates/oxc_minifier/src/peephole/replace_known_methods.rs to @oxc-project/oxc/files/crates/oxc_ecmascript/src/constant_evaluation/mod.rs by adding `Expression::CallExpres...
CodSpeed Instrumentation Performance ReportMerging #12672 will degrade performances by 3.52%Comparing Summary
Benchmarks breakdown
|
|
@copilot please move the remaining methods from |
…ascript crate Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Completed! I've moved all the remaining methods from String methods: Only All tests pass: ✅ Commit: 7b4bfd2 |
8573cb9 to
57eee2d
Compare
This PR moves string method evaluation logic from the minifier to the constant evaluation system in the
oxc_ecmascriptcrate, making these optimizations available system-wide.Changes Made
1. Added CallExpression support to constant evaluation
Expression::CallExpression(e) => e.evaluate_value_to(ctx, target_ty)to theConstantEvaluationtrait implementation forExpressionConstantEvaluationforCallExpressionto handle known string methods2. Moved string method evaluation functions
The following functions were moved from
oxc_minifier/src/peephole/replace_known_methods.rstooxc_ecmascript/src/constant_evaluation/mod.rs:String methods:
try_fold_string_casing- HandlestoLowerCase,toUpperCase,trim,trimStart,trimEndtry_fold_string_index_of- HandlesindexOf,lastIndexOftry_fold_string_substring_or_slice- Handlessubstring,slicetry_fold_string_char_at- HandlescharAttry_fold_string_char_code_at- HandlescharCodeAttry_fold_starts_with- HandlesstartsWithtry_fold_string_replace- Handlesreplace,replaceAlltry_fold_string_from_char_code- HandlesString.fromCharCodetry_fold_to_string- HandlestoStringNumber methods:
try_fold_number_methods- HandlesNumber.isFinite,isNaN,isInteger,isSafeIntegerMath methods:
try_fold_roots- HandlesMath.sqrt,cbrttry_fold_math_unary- Handlesabs,ceil,floor,round,fround,trunc,signtry_fold_math_variadic- Handlesmin,max3. Updated minifier to use constant evaluation
The minifier's
try_fold_known_global_methodsnow:concat,pow,Array.of)ConstantValueresults back to AST expressions when optimization is possible4. Added dependencies
cow-utilsdependency tooxc_ecmascriptcrate for string manipulation methodsExample Usage
Benefits
All existing tests pass, confirming that the functionality remains intact while being more broadly accessible.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.