Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 11, 2025

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:

// Method definitions - partially working
class C { "constructor"() {} }     // ❌ Not converted
class C { "method"() {} }          // ✅ Converted to method()

// Property definitions - not working  
class C { "prop" = value }         // ❌ Not converted
class C { accessor "prop" = value } // ❌ Not converted

Root Cause

The should_keep_as_computed_property check 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, and substitute_accessor_property to only apply computed property restrictions when prop.computed is true:

// Before (buggy)
if let PropertyKey::StringLiteral(str) = &prop.key {
    if property_key_parent.should_keep_as_computed_property(&str.value) {
        return;
    }
}

// After (fixed)
if prop.computed
    && let PropertyKey::StringLiteral(str) = &prop.key
    && property_key_parent.should_keep_as_computed_property(&str.value)
{
    return;
}

This ensures proper handling of:

  • String literals ("constructor") → converted to unquoted identifiers when safe
  • Computed properties (['constructor']) → preserved based on semantic rules to avoid early errors

Results

  • 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.

Copy link
Contributor Author

Copilot AI commented Aug 11, 2025

@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.

@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 11, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

Copilot AI and others added 3 commits August 11, 2025 16:27
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Copilot AI changed the title [WIP] Minifier: Can remove quotes around "constructor" as class method key Fix minifier to remove quotes around "constructor" as class method key Aug 11, 2025
Copilot finished work on behalf of Boshen August 11, 2025 16:42
Copilot AI requested a review from Boshen August 11, 2025 16:42
@Boshen Boshen requested a review from sapphi-red August 11, 2025 16:49
@github-actions github-actions bot added the A-minifier Area - Minifier label Aug 11, 2025
@Boshen
Copy link
Member

Boshen commented Aug 11, 2025

Pretty insane that AI got all the right context.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 11, 2025

CodSpeed Instrumentation Performance Report

Merging #12999 will not alter performance

Comparing copilot/fix-12992 (9d547f8) with main (ca91a26)

Summary

✅ 34 untouched benchmarks

@Boshen Boshen marked this pull request as ready for review August 11, 2025 17:05
Copilot AI review requested due to automatic review settings August 11, 2025 17:05
@Boshen Boshen changed the title Fix minifier to remove quotes around "constructor" as class method key fix(minifier): remove quotes around "constructor" as class method key Aug 11, 2025
Copy link
Contributor

Copilot AI left a 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_definition to 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

@github-actions github-actions bot added the C-bug Category - Bug label Aug 11, 2025
…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>
Copilot AI changed the title fix(minifier): remove quotes around "constructor" as class method key fix(minifier): improve quoted property key handling for class methods and properties Aug 11, 2025
Copilot finished work on behalf of sapphi-red August 11, 2025 17:28
Copilot AI requested a review from sapphi-red August 11, 2025 17:28
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot finished work on behalf of sapphi-red August 11, 2025 17:43
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copilot finished work on behalf of sapphi-red August 11, 2025 18:08
@sapphi-red
Copy link
Member

@copilot fix clippy failure

…ted check to all property methods

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 11, 2025

@copilot fix clippy failure

Fixed the clippy collapsible_if warning by collapsing the nested if statement and also applied the consistent prop.computed check to all three property methods (substitute_method_definition, substitute_property_definition, and substitute_accessor_property). All tests pass and clippy warnings are resolved. Fixed in commit 9d547f8.

Copilot finished work on behalf of sapphi-red August 11, 2025 18:28
@Boshen Boshen merged commit 64326c1 into main Aug 12, 2025
30 checks passed
@Boshen Boshen deleted the copilot/fix-12992 branch August 12, 2025 01:25
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-minifier Area - Minifier C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Minifier: Can remove quotes around "constructor" as class method key

3 participants