-
-
Notifications
You must be signed in to change notification settings - Fork 720
feat(ecmascript): add URI encoding/decoding support to constant evaluation #12934
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
feat(ecmascript): add URI encoding/decoding support to constant evaluation #12934
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. |
decodeURI, decodeURIComponent, encodeURI, encodeURIComponent support to @oxc-project/oxc/files/crates/oxc_ecmascript/src/constant_evaluation/call_expr.rs . To make sure the implementation is correct, download https://tc39.es/ecma262/2025/ l...
sapphi-red
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot check the comments
|
@sapphi-red Iirc, we need to be very careful with this optimization, there's some diff between how node vs web browsers encode certain url params that has caught me out before. let me see if i can find the issue |
|
@camc314 Does that mean Node or browsers has a bug? These functions were defined in the ECMA spec since ES3. |
|
Ah the issue was with how browser handle so this shouldn't affect these optimizations, Ignore me 🙂 |
|
FYI the |
All review comments have been addressed in commit 24dd1b3. The changes include:
All tests continue to pass. |
sapphi-red
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot check the comments
…mponent in constant evaluation Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
…imize URI encoding/decoding Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
…ction Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
… invalid input handling Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
1ab35c4 to
da5ba9e
Compare
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
33b7b1e to
79ff4e3
Compare
CodSpeed Instrumentation Performance ReportMerging #12934 will not alter performanceComparing Summary
Footnotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements constant evaluation support for the four global URI encoding/decoding functions (encodeURI, encodeURIComponent, decodeURI, and decodeURIComponent) to enable compile-time optimization of these function calls when used with literal string arguments.
- Extends the constant evaluation framework to handle global function calls (not just method calls)
- Adds URI encoding/decoding implementations following ECMA-262 specification with proper UTF-8 and error handling
- Includes comprehensive test coverage for all functions, edge cases, and roundtrip operations
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_minifier/src/peephole/replace_known_methods.rs | Adds extensive test cases covering all URI functions with various inputs including Unicode |
| crates/oxc_ecmascript/src/constant_evaluation/url_encoding/mod.rs | Module entry point exposing URI encoding/decoding functions |
| crates/oxc_ecmascript/src/constant_evaluation/url_encoding/enc.rs | URI encoding implementation with character set handling |
| crates/oxc_ecmascript/src/constant_evaluation/url_encoding/dec.rs | URI decoding implementation with error handling for malformed sequences |
| crates/oxc_ecmascript/src/constant_evaluation/mod.rs | Adds url_encoding module to constant evaluation |
| crates/oxc_ecmascript/src/constant_evaluation/call_expr.rs | Integrates URI functions into constant evaluation framework |

This PR implements constant evaluation support for the four global URI encoding/decoding functions:
encodeURI,encodeURIComponent,decodeURI, anddecodeURIComponent.Changes
Core Implementation
try_fold_known_global_methodsto support global functions (previously only handled method calls on objects)encodeURI()- Encodes URI while preserving reserved characters (;,/?:@&=+$#)encodeURIComponent()- Encodes URI component, only preserving unreserved characters (A-Za-z0-9-_.!~*'())decodeURI()- Decodes URI while preserving encoded reserved characters for safetydecodeURIComponent()- Decodes all percent-encoded sequencesTechnical Details
café→caf%C3%A9)Noneto prevent unsafe optimizations)Example Optimizations
Before:
After:
Testing
Added comprehensive tests covering:
All existing tests continue to pass, ensuring no regressions.
Benefits
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.