fix(transformer/typescript): panic occurs when declare property and definite property that has initializer#13785
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
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
declareand definite properties with initializers - Adds test coverage for the fixed behavior with both
declareand 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 Instrumentation Performance ReportMerging #13785 will not alter performanceComparing Summary
Footnotes |
declare poperty and definite property that has initializerdeclare property and definite property that has initializer
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; } ```
f7381ba to
7d0b8a1
Compare

Remove two incorrect assertions, which cause panic in the #13766.
The
declareproperty with an initializer is allowed in TypeScriptThe
!(definite) with an initializer isn't allowed in TypeScript, but this is a recoverable error, so the AST can have such.