Skip to content

Comments

fix(transformer/typescript): panic occurs when declare property and definite property that has initializer#13785

Merged
graphite-app[bot] merged 1 commit intomainfrom
09-15-fix_transformer_typescript_panics_when_declare_property_and_definite_property_with_initializer
Sep 16, 2025
Merged

fix(transformer/typescript): panic occurs when declare property and definite property that has initializer#13785
graphite-app[bot] merged 1 commit intomainfrom
09-15-fix_transformer_typescript_panics_when_declare_property_and_definite_property_with_initializer

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Sep 15, 2025

Remove two incorrect assertions, which cause panic in the #13766.

The declare property with an initializer is allowed in TypeScript

class DeclareExample {
  declare readonly bar = "test";
  declare readonly foo = 1;
}

The ! (definite) with an initializer isn't allowed in TypeScript, but this is a recoverable error, so the AST can have such.

class DefiniteExample {
   readonly bar! = "test";
   readonly foo! = 1;
}

@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Sep 15, 2025
Copy link
Member Author

Dunqing commented Sep 15, 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.

This stack of pull requests is managed by Graphite. Learn more about stacking.

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 panic in the TypeScript transformer when handling class properties with both declare and definite assignment assertion modifiers that have initializers.

  • Removes assertion checks that were causing panics for declare and definite properties with initializers
  • Adds test coverage for the fixed behavior with both declare and definite properties

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
crates/oxc_transformer/src/typescript/annotations.rs Removes panic-causing assertions for declare and definite properties with initializers
tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/declare-and-definite-with-initializer/input.ts Test input showing declare and definite properties with initializers
tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/declare-and-definite-with-initializer/output.js Expected output after transformation
tasks/transform_conformance/snapshots/oxc.snap.md Updates test count to reflect new passing test
Comments suppressed due to low confidence (1)

crates/oxc_transformer/src/typescript/annotations.rs:352

  • The function removes TypeScript-specific property modifiers but lacks documentation explaining why declare and definite properties with initializers are now allowed, given that the removed assertions suggested this was previously considered invalid.
    fn enter_property_definition(
        &mut self,
        def: &mut PropertyDefinition<'a>,
        _ctx: &mut TraverseCtx<'a>,
    ) {
        def.accessibility = None;
        def.definite = false;
        def.r#override = false;
        def.optional = false;
        def.readonly = false;
        def.type_annotation = None;
    }

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 15, 2025

CodSpeed Instrumentation Performance Report

Merging #13785 will not alter performance

Comparing 09-15-fix_transformer_typescript_panics_when_declare_property_and_definite_property_with_initializer (7d0b8a1) with main (26af302)1

Summary

✅ 37 untouched

Footnotes

  1. No successful run was found on main (7d0b8a1) during the generation of this report, so 26af302 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@overlookmotel overlookmotel changed the title fix(transformer/typescript): panic occurs when declare poperty and definite property that has initializer fix(transformer/typescript): panic occurs when declare property and definite property that has initializer Sep 16, 2025
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Sep 16, 2025
Copy link
Member

overlookmotel commented Sep 16, 2025

Merge activity

… `definite` property that has initializer (#13785)

Remove two incorrect assertions, which cause panic in the #13766.

The `declare` property with an initializer is allowed in [TypeScript](https://www.typescriptlang.org/play/?useDefineForClassFields=true&target=7&noCheck=false&stripInternal=true&ts=5.9.2#code/MYGwhgzhAEAiCmowCd4FEAeYC2AHE80A3gFDTQAmi4q0qYFA9gHYgCe0ARitALzQAiAC7wIQgQG4ylaikL0mrDgDNGjPtACMUgL4kSSKHHjKAls1MjMOfIVLk68Bi3ZcUAQg3DR4qQ4UuKmqe-NokekA)
```ts
class DeclareExample {
  declare readonly bar = "test";
  declare readonly foo = 1;
}
```

The `!` (definite) with an initializer isn't allowed in [TypeScript](https://www.typescriptlang.org/play/?useDefineForClassFields=true&target=7&noCheck=false&stripInternal=true&ts=5.9.2#code/MYGwhgzhAEAiCmowCd4FEAeYC2AHE80A3gFDTQAmi4q0qYFA9gHYgCe0ARitALzQAiAC7wIQgQG4ylaikL0mrDgDNGjPtACMUgL5A), but this is a recoverable error, so the AST can have such.

```ts
class DefiniteExample {
   readonly bar! = "test";
   readonly foo! = 1;
}
```
@graphite-app graphite-app bot force-pushed the 09-15-fix_transformer_typescript_panics_when_declare_property_and_definite_property_with_initializer branch from f7381ba to 7d0b8a1 Compare September 16, 2025 12:56
@graphite-app graphite-app bot merged commit 7d0b8a1 into main Sep 16, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 09-15-fix_transformer_typescript_panics_when_declare_property_and_definite_property_with_initializer branch September 16, 2025 13:02
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Sep 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants