Skip to content

fix(transformer/typescript): preserve computed-key static block when class has an empty constructor#21562

Merged
graphite-app[bot] merged 1 commit intomainfrom
fix/transformer-ts-class-computed-key-static-init
Apr 20, 2026
Merged

fix(transformer/typescript): preserve computed-key static block when class has an empty constructor#21562
graphite-app[bot] merged 1 commit intomainfrom
fix/transformer-ts-class-computed-key-static-init

Conversation

@Dunqing
Copy link
Copy Markdown
Member

@Dunqing Dunqing commented Apr 20, 2026

Summary

When a TypeScript class used a computed-key static property together with a constructor that has no parameter-property assignments, the early return in transform_class_fields dropped the computed_key_assignment_static_block that initializes the temp var, leaving it declared but never assigned.

export class SampleClass {
  static [Symbol.toPrimitive] = "test"
  constructor() {}
}

previously emitted:

let _Symbol$toPrimitive;
export class SampleClass {
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}

Now emits (matching TypeScript's own output under useDefineForClassFields: false):

let _Symbol$toPrimitive;
export class SampleClass {
  static {
    _Symbol$toPrimitive = Symbol.toPrimitive;
  }
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}

Test plan

  • Added fixtures computed-static-property-with-constructor (exact repro) and computed-static-property-with-constructor-super (super() + multiple computed keys) under babel-plugin-transform-typescript.
  • Verified output against tsc 5.7 with useDefineForClassFields: false.

Closes rolldown/rolldown#9121

Copy link
Copy Markdown
Member Author

Dunqing commented Apr 20, 2026


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 changes, fast-track this PR to the front of 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.

@github-actions github-actions Bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Apr 20, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 20, 2026

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing fix/transformer-ts-class-computed-key-static-init (91e5bde) with main (50e9d26)

Open in CodSpeed

Footnotes

  1. 7 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Dunqing Dunqing marked this pull request as ready for review April 20, 2026 04:32
@Dunqing Dunqing requested a review from overlookmotel as a code owner April 20, 2026 04:32
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Apr 20, 2026
Copy link
Copy Markdown
Member Author

Dunqing commented Apr 20, 2026

Merge activity

  • Apr 20, 4:33 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Apr 20, 4:33 AM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Apr 20, 4:35 AM UTC: The Graphite merge queue couldn't merge this PR because it was in draft mode.
  • Apr 20, 5:08 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Apr 20, 5:11 AM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Apr 20, 5:42 AM UTC: This pull request was removed from the Graphite merge queue because the batch it was included in timed out. Please re-enqueue the PR to retry merge.
  • Apr 20, 7:58 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Apr 20, 7:58 AM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Apr 20, 8:03 AM UTC: Merged by the Graphite merge queue.

@Dunqing Dunqing marked this pull request as draft April 20, 2026 04:33
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Apr 20, 2026
@Dunqing Dunqing marked this pull request as ready for review April 20, 2026 05:08
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Apr 20, 2026
graphite-app Bot pushed a commit that referenced this pull request Apr 20, 2026
…class has an empty constructor (#21562)

## Summary

When a TypeScript class used a computed-key static property together with a constructor that has no parameter-property assignments, the early return in `transform_class_fields` dropped the `computed_key_assignment_static_block` that initializes the temp var, leaving it declared but never assigned.

```ts
export class SampleClass {
  static [Symbol.toPrimitive] = "test"
  constructor() {}
}
```

previously emitted:

```js
let _Symbol$toPrimitive;
export class SampleClass {
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}
```

Now emits (matching TypeScript's own output under `useDefineForClassFields: false`):

```js
let _Symbol$toPrimitive;
export class SampleClass {
  static {
    _Symbol$toPrimitive = Symbol.toPrimitive;
  }
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}
```

## Test plan

- Added fixtures `computed-static-property-with-constructor` (exact repro) and `computed-static-property-with-constructor-super` (super() + multiple computed keys) under `babel-plugin-transform-typescript`.
- Verified output against `tsc` 5.7 with `useDefineForClassFields: false`.

Closes rolldown/rolldown#9121
@graphite-app graphite-app Bot force-pushed the fix/transformer-ts-class-computed-key-static-init branch from fd738c7 to eac25b1 Compare April 20, 2026 05:12
@Dunqing Dunqing force-pushed the fix/transformer-ts-class-computed-key-static-init branch from eac25b1 to a422954 Compare April 20, 2026 05:18
graphite-app Bot pushed a commit that referenced this pull request Apr 20, 2026
…class has an empty constructor (#21562)

## Summary

When a TypeScript class used a computed-key static property together with a constructor that has no parameter-property assignments, the early return in `transform_class_fields` dropped the `computed_key_assignment_static_block` that initializes the temp var, leaving it declared but never assigned.

```ts
export class SampleClass {
  static [Symbol.toPrimitive] = "test"
  constructor() {}
}
```

previously emitted:

```js
let _Symbol$toPrimitive;
export class SampleClass {
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}
```

Now emits (matching TypeScript's own output under `useDefineForClassFields: false`):

```js
let _Symbol$toPrimitive;
export class SampleClass {
  static {
    _Symbol$toPrimitive = Symbol.toPrimitive;
  }
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}
```

## Test plan

- Added fixtures `computed-static-property-with-constructor` (exact repro) and `computed-static-property-with-constructor-super` (super() + multiple computed keys) under `babel-plugin-transform-typescript`.
- Verified output against `tsc` 5.7 with `useDefineForClassFields: false`.

Closes rolldown/rolldown#9121
@graphite-app graphite-app Bot force-pushed the fix/transformer-ts-class-computed-key-static-init branch from a422954 to fc65ced Compare April 20, 2026 05:19
graphite-app Bot pushed a commit that referenced this pull request Apr 20, 2026
…class has an empty constructor (#21562)

## Summary

When a TypeScript class used a computed-key static property together with a constructor that has no parameter-property assignments, the early return in `transform_class_fields` dropped the `computed_key_assignment_static_block` that initializes the temp var, leaving it declared but never assigned.

```ts
export class SampleClass {
  static [Symbol.toPrimitive] = "test"
  constructor() {}
}
```

previously emitted:

```js
let _Symbol$toPrimitive;
export class SampleClass {
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}
```

Now emits (matching TypeScript's own output under `useDefineForClassFields: false`):

```js
let _Symbol$toPrimitive;
export class SampleClass {
  static {
    _Symbol$toPrimitive = Symbol.toPrimitive;
  }
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}
```

## Test plan

- Added fixtures `computed-static-property-with-constructor` (exact repro) and `computed-static-property-with-constructor-super` (super() + multiple computed keys) under `babel-plugin-transform-typescript`.
- Verified output against `tsc` 5.7 with `useDefineForClassFields: false`.

Closes rolldown/rolldown#9121
@graphite-app graphite-app Bot force-pushed the fix/transformer-ts-class-computed-key-static-init branch from fc65ced to 06687ed Compare April 20, 2026 05:31
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Apr 20, 2026
…class has an empty constructor (#21562)

## Summary

When a TypeScript class used a computed-key static property together with a constructor that has no parameter-property assignments, the early return in `transform_class_fields` dropped the `computed_key_assignment_static_block` that initializes the temp var, leaving it declared but never assigned.

```ts
export class SampleClass {
  static [Symbol.toPrimitive] = "test"
  constructor() {}
}
```

previously emitted:

```js
let _Symbol$toPrimitive;
export class SampleClass {
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}
```

Now emits (matching TypeScript's own output under `useDefineForClassFields: false`):

```js
let _Symbol$toPrimitive;
export class SampleClass {
  static {
    _Symbol$toPrimitive = Symbol.toPrimitive;
  }
  static {
    this[_Symbol$toPrimitive] = "test";
  }
  constructor() {}
}
```

## Test plan

- Added fixtures `computed-static-property-with-constructor` (exact repro) and `computed-static-property-with-constructor-super` (super() + multiple computed keys) under `babel-plugin-transform-typescript`.
- Verified output against `tsc` 5.7 with `useDefineForClassFields: false`.

Closes rolldown/rolldown#9121
@Dunqing Dunqing force-pushed the fix/transformer-ts-class-computed-key-static-init branch from 06687ed to 91e5bde Compare April 20, 2026 07:58
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Apr 20, 2026
@graphite-app graphite-app Bot merged commit 91e5bde into main Apr 20, 2026
35 checks passed
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label Apr 20, 2026
@graphite-app graphite-app Bot deleted the fix/transformer-ts-class-computed-key-static-init branch April 20, 2026 08:03
camc314 added a commit that referenced this pull request Apr 20, 2026
### 🐛 Bug Fixes

- 48967e8 isolated_declarations: Drop required type check for private
parameter properties on private constructors (#21515) (Dunqing)
- 91e5bde transformer/typescript: Preserve computed-key static block
when class has an empty constructor (#21562) (Dunqing)
- 50e9d26 mangler: Assign correct slot to shadowed function-expression
names (#21535) (Dunqing)
- 065ce47 isolated_declarations: Collect types from private accessors
for paired inference (#21516) (Dunqing)
- 00fc136 codegen: Preserve coverage comments before object properties
(#21312) (bab)
- d676e0c minifier: Mark LHS of `??=` as read when converting from `==
null &&` (#21546) (Gunnlaugur Thor Briem)

### ⚡ Performance

- e45efc5 parser: Reduce `try_parse` usage in favour of `lookahead`
(#21532) (Boshen)
- ddb1bf8 parser: Avoid redundant `IdentifierReference` clone in
shorthand property (#21511) (Boshen)
- be2b392 allocator: Store pointers directly in `Arena` (#21483)
(overlookmotel)

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: Cameron <cameron.clark@hey.com>
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.

[Bug]: Static property initialization with computed Symbol keys fails when class has a constructor

1 participant