-
-
Notifications
You must be signed in to change notification settings - Fork 721
fix(minifier): improve quoted property key handling for class methods and properties #12999
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
|
@Boshen 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs. I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review. |
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. |
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
"constructor" as class method key|
Pretty insane that AI got all the right context. |
CodSpeed Instrumentation Performance ReportMerging #12999 will not alter performanceComparing Summary
|
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 fixes a bug in the minifier where quoted "constructor" class method keys were not being converted to unquoted identifiers, missing an optimization opportunity. The issue was that the minifier incorrectly treated string literal keys the same as computed property keys when determining whether to preserve quotes.
Key changes:
- Modified the conditional logic in
substitute_method_definitionto only check computed property restrictions for actual computed properties - Added comprehensive test cases to verify the fix works for various method types and scenarios
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/oxc_minifier/src/peephole/substitute_alternate_syntax.rs |
Fixed the buggy condition that was preventing quoted constructor methods from being optimized |
crates/oxc_minifier/src/peephole/convert_to_dotted_properties.rs |
Added test cases to verify the fix and prevent regressions |
crates/oxc_minifier/src/peephole/convert_to_dotted_properties.rs
Outdated
Show resolved
Hide resolved
…erty/accessor handling Addressed @sapphi-red's feedback: - Moved constructor tests from convert_to_dotted_properties.rs to substitute_alternate_syntax.rs - Added comprehensive tests for constructor handling across different property types - Applied the same computed property fix to PropertyDefinition and AccessorProperty methods - Aligned test expectations with existing behavior and syntax constraints Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
|
@copilot fix clippy failure |
…ted check to all property methods Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Fixed the clippy collapsible_if warning by collapsing the nested if statement and also applied the consistent |
The minifier was not consistently removing quotes around property keys in class definitions. The issue affected both method definitions and property/accessor definitions, where quoted strings like
"constructor"should be converted to unquoted identifiers when safe to do so.Problem
The minifier had inconsistent behavior with quoted property keys:
Root Cause
The
should_keep_as_computed_propertycheck was being applied to all string literal keys, not just computed properties. This caused the minifier to incorrectly treat quoted strings ("key") the same as computed properties (['key']), when they have different semantics and conversion rules.Solution
Fixed by modifying the condition in
substitute_method_definition,substitute_property_definition, andsubstitute_accessor_propertyto only apply computed property restrictions whenprop.computedis true:This ensures proper handling of:
"constructor") → converted to unquoted identifiers when safe['constructor']) → preserved based on semantic rules to avoid early errorsResults
class C { "constructor"() {} }→class C { constructor() {} }✅class C { static "constructor"() {} }→class C { static constructor() {} }✅class C { "method"() {} }→class C { method() {} }✅class C { ['constructor']() {} }→ stays unchanged ✅ (computed property preserved)class C { static ['constructor']() {} }→class C { static constructor() {} }✅Fixes #12992.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.