Commit Graph

238 Commits

Author SHA1 Message Date
Changsu Seong 116c8b8303 fix(transformer/class-properties): keep private methods in class-expression scope (#26308)
Private methods lowered from a class expression inside a concise arrow
were inserted next to the arrow's outer statement, while private field
storage remained inside the arrow. Starting with Oxc 0.143, this could
leave the generated helper unable to resolve the private field and throw
a `ReferenceError` at runtime.

Concise arrow bodies have no statement list where the helper declaration
can be inserted. In that context, the helper is now emitted as an
assignment in the class-expression sequence, with its `var` binding
inside the expanded arrow body. Ordinary statement-backed class
expressions keep block-local function declarations so classes created by
repeated block evaluation retain their own captured values. The
generated symbol flags and scope parents match the emitted form in both
cases.

## Example

```js
const makeClass = () => class {
  #field = 41;
  #read() { return this.#field; }
  run() { return this.#read() + 1; }
};

new (makeClass())().run();
```

Before Oxc emitted a helper outside `makeClass`, and the call threw
`ReferenceError: _field is not defined`. After this change it returns
`42`.

Verified with the private-method transform conformance suite, runtime
regressions for concise arrows and repeated block evaluation, `cargo
test -p oxc_transformer`, and transformer clippy.

Fixes the upstream cause of
[rolldown/rolldown#10818](https://github.com/rolldown/rolldown/issues/10818).

AI assistance: Cursor was used for the original patch; OpenAI Codex was
used for follow-up review, fixes, and testing.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Dunqing <dengqing0821@gmail.com>
2026-09-07 20:47:40 +08:00
Dunqing 3d95477214 fix(transformer): gate async-only rewrites by owning transform (#26326)
For targets that support async functions but not async generators, async-only converter mode still treated every async function as if the enabled transform would move its body. Plain async arrows and methods gained generated `this` and `super` bindings, and class-field arrows were wrapped unnecessarily.

Use the shared body-movement predicate for every async-only rewrite. Functions left native by the selected target now remain untouched, while async generator functions that are lowered keep their required lexical captures.

## Example

A plain async method using `super` previously gained a generated `_superprop_getValue` binding even though the method remained native. This made `eval("typeof _superprop_getValue")` return `"function"` instead of `"undefined"`. The method now remains unchanged.

Verified with focused output/runtime conformance, full transformer output conformance, and `cargo test -p oxc_transformer`.

Stacked on #26317.

AI assistance was used to diagnose the remaining transform boundaries, implement the predicate checks, and add tests. I remain responsible for reviewing and understanding the changes before merge.
2026-09-07 07:21:47 +00:00
Dunqing f45a9ee58b fix(transformer): limit arguments capture to lowered async functions (#26317)
For targets that support async functions but not async generators, plain async methods and arrows remain native. Async-only converter mode still captured `arguments` for all of them, exposing generated `_arguments` bindings even though their bodies never move.

Gate `arguments` capture on the transform that owns the function body. Native async functions now remain untouched, while lowered async generator methods still capture their original arguments.

## Example

This native async method previously changed from:

```js
async method() {
  void arguments;
  return eval("typeof _arguments");
}
```

to:

```js
async method() {
  var _arguments = arguments;
  void _arguments;
  return eval("typeof _arguments");
}
```

The generated binding changed the return value from `"undefined"` to `"object"`. The method now remains unchanged.

Verified with focused output/runtime conformance, full transformer output conformance, and `cargo test -p oxc_transformer`.

Stacked on #26227.

AI assistance was used to diagnose the transform boundary, implement the fix, and add tests. I remain responsible for reviewing and understanding the changes before merge.
2026-09-07 07:05:01 +00:00
Dunqing 789969f8a1 fix(transformer): gate this capture by owning async transform (#26227)
For targets that support async functions but not async generators, plain async methods remain native. The shared arrow converter still captured `this` whenever either async transform was active, injecting an observable `_this` binding into methods whose bodies never move.

Track async-to-generator and async-generator lowering separately. Plain async methods are now left untouched when only async generators require lowering, while transformed async generator methods still preserve their receiver.

## Example

With a Chrome 55 target, this method previously gained a generated binding:

```js
async method() {
  var _this = this;
  void _this;
  return eval("typeof _this");
}
```

It now remains unchanged, so the direct evaluation returns `"undefined"` as it does in the source program.

Verified with a Chrome 55 target output/runtime fixture, full transformer output conformance, and `cargo test -p oxc_transformer`.

AI assistance was used to diagnose the transform boundary, implement the fix, and add tests. I remain responsible for reviewing and understanding the changes before merge.
2026-09-07 07:05:01 +00:00
camc314 243b685c3d fix(transformer/object-rest): lower multiple declarators correctly (#26147)
## Summary

Fix ES2018 object-rest lowering when one variable declaration contains multiple object-rest declarators.

### Before

Given:

```js
let { a, ...r } = x, { b, ...s } = y;
```

Oxc produced:

```js
let { a } = x, { b } = y,
  s = babelHelpers.objectWithoutProperties(y, ["b"]),
  {} = null;
```

The `r` binding was lost.

Each replacement was recorded using its original declarator index. Replacing the first declarator expanded it into multiple entries, shifting the second declarator. The subsequent replacement still used the old index and overwrote part of the first expansion.

### After

Oxc now produces:

```js
let { a } = x,
  r = babelHelpers.objectWithoutProperties(x, ["a"]),
  { b } = y,
  s = babelHelpers.objectWithoutProperties(y, ["b"]);
```

Queued replacements are applied from right to left. Replacing a later declarator cannot change the index of an earlier one, so every recorded index remains valid.

Regression coverage includes multiple `let`, `const`, and `var` declarators.
2026-08-28 14:02:19 +00:00
camc314 caeb0a61d1 test(transformer): cover re-export extension rewriting (#25087)
## Summary

- add transformer conformance coverage for named re-exports from `.mts` modules
- verify `export { x } from "./a.mts"` rewrites to the `.mjs` extension
2026-07-29 15:38:57 +00:00
camc314 ce5f40f575 fix(transformer): declare temp for renamed anonymous class (#24230)
## Summary

- declare the class-properties temp when another transform names an anonymous class
- prevent static-field initialization from referencing an undeclared temp
- add legacy-decorator/class-properties conformance coverage

## Transformation

```mermaid
flowchart LR
    A["Anonymous class"] --> B["Class properties reserves _Class"]
    B --> C["Decorator names class _default"]
    C --> D["Declare var _Class"]
    D --> E["_Class = _default"]
    E --> F["Initialize static fields"]
```

```ts
export default class {
  @dec
  static foo = 0;
}
```

```js
var _Class;
export default class _default {}
_Class = _default;
babelHelpers.defineProperty(_Class, "foo", 0);
```
2026-07-06 15:05:12 +00:00
Dunqing 6c0bdf0486 feat(transformer/react-refresh): support module.property.useHook() (#23190)
## Summary

Ports facebook/react#35318 to the React Refresh plugin: hook calls through a nested member expression such as `FancyHook.property.useNestedThing()` are now collected into the `$RefreshSig$` custom-hooks list, so components using them no longer lose state on every fast-refresh update. As in the Babel plugin, the binding is resolved through one extra static member level, and a force reset is emitted when the root object has no binding in scope. Deeper nesting (`A.B.C.useHook()`) remains uncollected, same as upstream; note that Babel additionally emits `forceReset = true` in that case while oxc does not — a pre-existing, intentional divergence from #6143 that this PR does not change.

closes #16571

## Example

Input:

```jsx
import FancyHook from 'fancy';

export default function App() {
  const foo = FancyHook.property.useNestedThing();
  return <h1>{foo}</h1>;
}
```

Signature before:

```js
_s(App, "useNestedThing{foo}");
```

Signature after:

```js
_s(App, "useNestedThing{foo}", false, function() {
  return [FancyHook.property.useNestedThing];
});
```

---

This PR was prepared with AI assistance; I reviewed, tested, and verified the changes.
2026-06-12 02:04:52 +00:00
Boshen bb0ed44541 feat(transformer)!: disable styled-components transpileTemplateLiterals by default (#23171)
## Summary

Closes #13398.

The styled-components transform's `transpileTemplateLiterals` option rewrites tagged template literals into the array-call form:

```js
// in
styled.div`width: 100%;`
// out — transpileTemplateLiterals: true
styled.div(["width: 100%;"])
```

This form is only more compact when template literals are *also* down-levelled to ES5 — which is why `babel-plugin-styled-components` enables it by default, to pre-empt Babel's verbose `_taggedTemplateLiteral` output. Oxc does not down-level template literals below ES6, so the array-call form is strictly *larger* than leaving the tagged template untouched.

This PR flips the default to `false`, as agreed with @Dunqing in #13398.

## Changes

- `StyledComponentsOptions::transpile_template_literals` now defaults to `false` (both the `serde` field default and the `Default` impl), with docs explaining why.
- napi: `transpileTemplateLiterals` is documented `@default false` (`transformer.rs` + `index.d.ts`), and the styled-components napi test snapshot now reflects the non-transpiled default output.
- Conformance fixtures that relied on the old default and whose reference output is transpiled now pin `transpileTemplateLiterals: true`, so they keep matching `babel-plugin-styled-components`' reference output. The conformance snapshot is unchanged — `plugin-styled-components` stays at 25/40.

## Breaking change

`transpileTemplateLiterals` now defaults to `false`. Pass `transpileTemplateLiterals: true` to restore the previous behavior.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-06-10 03:26:40 +00:00
Kyle Cannon ee659b6785 feat(transformer/legacy-decorator): add strictNullChecks option for nullable-union design:type (#22266)
## Summary

Adds a `strictNullChecks` field to `DecoratorOptions` (default `true`)
that
controls whether `null` and `undefined` are elided from union
`design:type`
metadata. The default preserves tsc strict semantics (`T | null` →
`Object`);
setting `strictNullChecks: false` matches
babel-plugin-transform-typescript-metadata
and tsc with `--strictNullChecks=false`, emitting the underlying
primitive
(`T | null` → `String` when `T = string`).

Originally this PR unconditionally elided null/undefined. Per @Dunqing's
review, it's now opt-in so the default-strict behaviour is preserved.

## Motivation

When `strictNullChecks` is off, tsc emits the constructor of the
underlying
primitive. babel-plugin-transform-typescript-metadata always elides null
and
undefined regardless of tsconfig. Downstream consumers (NestJS Swagger,
class-validator, TypeORM, AutoMapper) treat `Object` as "no metadata"
and
silently drop fields, so users with `strictNullChecks: false` (common in
older codebases) get worse behaviour under OXC than under tsc/babel.

## Implementation

```rust
pub struct DecoratorOptions {
    pub legacy: bool,
    pub emit_decorator_metadata: bool,
    #[serde(default = "default_as_true")]
    pub strict_null_checks: bool, // default true
}
```

Threaded through `Decorator::new(options) →
LegacyDecorator::new(&options) →
LegacyDecoratorMetadata::new(&options)` (matching the established
`TypeScript::new(&TypeScriptOptions)` precedent), and gated in
`serialize_union_or_intersection_constituents`:

```rust
TSType::TSNullKeyword(_) | TSType::TSUndefinedKeyword(_)
    if !is_intersection && !self.strict_null_checks => continue,
```

Mirrored at the napi binding (`napi/transform/src/transformer.rs`) so
direct
Node consumers can flip it the day this lands. Consumers that wire
tsconfig
(rolldown, bundlers) can forward `compilerOptions.strictNullChecks` to
it.

## Behaviour matrix

| Source | `strictNullChecks: true` (default) | `strictNullChecks:
false` |
|---|---|---|
| `string \| null` | `Object` (matches tsc strict, current behaviour) |
`String` (matches babel, tsc non-strict) |
| `number \| undefined` | `Object` | `Number` |
| `boolean \| null \| undefined` | `Object` | `Boolean` |
| `null \| undefined` | `void 0` | `void 0` |
| `string \| number` | `Object` | `Object` (distinct primitives) |
| `string & null` | `Object` | `Object` (intersection unchanged) |

## Test plan

- [x] 7 unit tests in `tests/integrations/decorator_metadata.rs`
covering
`T | null` under both `strictNullChecks: true` (emits `Object`, current
  behaviour) and `strictNullChecks: false` (emits primitive), plus
`T | undefined`, `T | null | undefined`, the `null | undefined`
void-only
case, the `string | number` distinct-primitive case (still `Object`),
and
  the intersection-with-null regression
- [x] New conformance fixture `oxc/metadata/nullable-union/` with its
own
  `options.json` setting `strictNullChecks: false`
- [x] `cargo test -p oxc_transformer` passes (31 unit + 11 integration)
- [x] `cargo run -p oxc_transform_conformance` shows 0 regressions;
baseline
  fixtures still pass plus the new `nullable-union`
- [x] `cargo fmt -p oxc_transformer -p oxc_transform_napi` and
  `cargo clippy --tests --no-deps` clean

AI assistance was used in writing this patch and tests; the contributor
has
reviewed and tested locally.

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2026-05-25 13:42:41 +08:00
Kyle Cannon 69a6ba6353 fix(transformer/legacy-decorator): emit Array for ReadonlyArray<T> in decorator metadata (#22265)
## Summary

`ReadonlyArray<T>` is a TypeScript-only utility type with no runtime
value. The legacy decorator metadata emit currently wraps it in the
runtime guard `typeof (_ref = typeof X !== "undefined" && X) ===
"function" ? _ref : Object`, which always falls through to `Object`
because there is no runtime `ReadonlyArray` binding. tsc resolves this
through the checker and emits `Array`; OXC's existing handling of the
short form `readonly T[]` already emits `Array`, so the generic form is
the only divergent shape.

## The bug

```ts
class Entity {
  @D() shortForm!: readonly string[];           // tsc: Array, OXC: Array  (already correct)
  @D() genericForm!: ReadonlyArray<string>;     // tsc: Array, OXC: Object (bug)
  @D() nestedReadonly!: ReadonlyArray<ReadonlyArray<number>>; // same
}
```

The two surface forms describe the same type but produce different
runtime metadata. Downstream consumers (TypeORM `@Column` array
inference, NestJS Swagger schema, AutoMapper field detection) rely on
the `Array` constructor; `Object` causes silent degradation.

## Fix

In `serialize_type_reference_node`, recognize `ReadonlyArray` by name
when the symbol is unresolved or type-only. Emit `global_array(ctx)`
directly, bypassing the wrapper. A user-shadowed `class ReadonlyArray
{}` would have a value symbol and falls through to the normal
class-handling path, so the shadow case is preserved.

```rust
if ident.name == "ReadonlyArray"
    && symbol_id.is_none_or(|sid| ctx.scoping().symbol_flags(sid).is_type())
{
    return Self::global_array(ctx);
}
```

## Scope

Only `ReadonlyArray` is handled in this PR. `ReadonlyMap`,
`ReadonlySet`, `WeakMap`, `WeakSet`, and `Readonly<Array<T>>` peel are
left for a follow-up because tsc's spec emit for those is less
unambiguous and warrants case-by-case verification. The same
predicate-style approach extends naturally if reviewers want them folded
in.

## Test plan

- [x] 4 unit tests in `decorator_metadata_readonly_array.rs`: bare
ReadonlyArray, nested ReadonlyArray, regression on `readonly T[]` short
form, and a user-shadowed `class ReadonlyArray {}` regression
- [x] New conformance fixture `oxc/metadata/readonly-array/`
- [x] `cargo test -p oxc_transformer` passes (31 unit + 9 integration)
- [x] `cargo run -p oxc_transform_conformance` shows 229 OXC fixtures
still passing, +1 new fixture (`readonly-array`); 0 regressions
- [x] `cargo fmt -p oxc_transformer` and `cargo clippy -p
oxc_transformer --tests --no-deps` clean

AI assistance was used in writing this patch and tests; the contributor
has reviewed and tested locally.

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2026-05-21 18:19:35 +08:00
Dunqing e421ef0f84 fix(transformer/legacy-decorator): return runtime binding for design:type (#22640)
Closes #22227.
Closes #22228.

## Summary

- Switch `design:type` / `design:paramtypes` / `design:returntype` emit from `typeof X === "function" ? X : Object` to `typeof X === "undefined" ? Object : X`, matching SWC and Babel. Cross-file imported enums and namespace-imported enums (`NS.E`) now return the actual enum object instead of silently degrading to `Object` — consumers like type-graphql, typeorm, NestJS Swagger, AutoMapper, and class-validator can introspect via `Object.values()`.
- Cases where the runtime binding is genuinely missing still fall back to `Object` (stale ambient declarations, erased type imports, unresolved references), so existing behavior is preserved everywhere else.
- See #14740 for the design rationale: matching SWC/Babel rather than tsc's primitive-type emit (which requires cross-file type information OXC doesn't have).
- Conformance: 5 existing fixtures updated for the new emit shape, 6 new fixtures cover the bug paths and predicate boundaries; no `Output mismatch` regressions.

## Example

Input:
```ts
import { StringEnum } from './enums';

class Source {
  @dec value!: StringEnum;
}
```

Before:
```js
// design:type === Object — StringEnum is an enum object, typeof !== "function"
babelHelpers.decorateMetadata("design:type",
  typeof (_ref = typeof StringEnum !== "undefined" && StringEnum) === "function"
    ? _ref : Object)
```

After:
```js
// design:type === StringEnum (the enum object — introspectable via Object.values)
babelHelpers.decorateMetadata("design:type",
  typeof StringEnum === "undefined" ? Object : StringEnum)
```

## Note on the SWC enum-metadata debate

[swc-project/swc#11033](https://github.com/swc-project/swc/issues/11033) argues SWC's emit is wrong for cross-file enums — the runtime returns the enum object (an `{...}`) rather than `Number` / `String` / `Object` as tsc would. This PR adopts the same emit shape SWC and Babel use, so it has the same property: cross-file enum metadata is the enum binding itself, not a primitive constructor.

OXC chose this side of the debate deliberately in #14740 — returning the enum object is what type-graphql, typeorm, NestJS Swagger, AutoMapper, and class-validator depend on to introspect enum members. Matching tsc's primitive emit would require cross-file type information OXC doesn't have, and would unblock no real consumer. If TypeScript publishes a position on what non-type-checker transformers should emit, this can be revisited.

AI disclosure: drafted with Claude Code, reviewed manually.
2026-05-21 09:50:07 +00:00
Dunqing e6090e7ccc fix(transformer): keep enum IIFE when a non-inlinable value reference remains (#22501)
Refs vitejs/vite#22452 (comment).

The optimize pass dropped the enum declaration whenever the members were all evaluable — regardless of whether some non-inlinable value reference still named the enum at runtime. The result referenced a binding that no longer existed:

```ts
const enum Phase { one = 'one' }
export default Phase;
// -> export default Phase;  // ReferenceError at runtime

enum Direction { Up }
Direction.Up.toString();
// -> Direction.Up.toString();  // ReferenceError at runtime
```

## Fix

Decide based on the remaining resolved references: drop only when none of them is a value reference (`Read`/`Write`). Type references (`as E`, `: E`) are kept here and stripped later by `annotations.rs`, so they don't block removal. `typeof E` in JS expression position is `Read` and correctly keeps the IIFE; `typeof E` in TS type position is `ValueAsType` (not in `Value`) and doesn't.

Unifies the rule for regular and const enums — the previous asymmetry (const always dropped, regular dropped only when no refs at all) had no principled basis.

## Compatibility

Diverges from Babel on two `optimize-const-enums/*` fixtures where the input has a bare value reference to the enum that we can't inline. Three engines disagree on what to do:

| Engine | Inline `E.X` member accesses | Preserve `E` binding (IIFE) | Result for `E.unknown` / bare `E` |
|---|---|---|---|
| Babel `transform-typescript` (optimize-const-enums) | yes | **no** | runtime ReferenceError / TypeError |
| tsc `--isolatedModules` | no | yes | `undefined` / resolves |
| oxc after this PR | yes | yes | `undefined` / resolves |

We now hybridize: inline what's inlinable (Babel) **and** keep the binding (tsc). Local overrides under `tasks/transform_conformance/overrides/` record the new expected output for the two affected Babel fixtures.

### `optimize-const-enums/local`

Input:

```ts
const enum A {
  x, y
}

A.x;
A["y"];
A.z;
A;
```

Babel (and oxc before this PR):

```js
0;
1;
A.z;
A;
```

`A.z` is `TypeError: cannot read properties of undefined`; `A;` is `ReferenceError`.

tsc (`--isolatedModules`):

```js
var A;
(function (A) {
    A[A["x"] = 0] = "x";
    A[A["y"] = 1] = "y";
})(A || (A = {}));
A.x;
A["y"];
A.z;
A;
```

Keeps the IIFE binding, no member-access inlining. `A.z` evaluates to `undefined`; `A;` is a no-op.

oxc after this PR (`overrides/.../optimize-const-enums/local/output.mjs`):

```js
var A = /* @__PURE__ */ function(A) {
  A[A["x"] = 0] = "x";
  A[A["y"] = 1] = "y";
  return A;
}(A || {});
0;
1;
A.z;
A;
```

Hybrid: inlines `A.x` / `A["y"]` like Babel, **and** keeps the IIFE binding like tsc — so `A.z` evaluates to `undefined` (not crash) and `A;` resolves.

### `optimize-const-enums/merged`

Input:

```ts
const enum A {
  x, y
}

const enum A {
  z
}

A.x;
A["y"];
A.z;
A.w;
A;
```

Babel (and oxc before this PR):

```js
0;
1;
0;
A.w;
A;
```

`A.w` is `TypeError: cannot read properties of undefined`; `A;` is `ReferenceError`.

tsc (`--isolatedModules`):

```js
var A;
(function (A) {
    A[A["x"] = 0] = "x";
    A[A["y"] = 1] = "y";
})(A || (A = {}));
(function (A) {
    A[A["z"] = 0] = "z";
})(A || (A = {}));
A.x;
A["y"];
A.z;
A.w;
A;
```

Both IIFEs emitted, no inlining. `A.w` is `undefined`; `A;` resolves.

oxc after this PR (`overrides/.../optimize-const-enums/merged/output.mjs`):

```js
var A = /* @__PURE__ */ function(A) {
  A[A["x"] = 0] = "x";
  A[A["y"] = 1] = "y";
  return A;
}(A || {});
A = /* @__PURE__ */ function(A) {
  A[A["z"] = 0] = "z";
  return A;
}(A || {});
0;
1;
0;
A.w;
A;
```

Hybrid: both enum bodies lower (the second reuses the first's binding via `A = (function(A) { … })(A || {})` — assignment, not `var`) **and** members are inlined like Babel. `A.w` evaluates to `undefined`; `A;` resolves.

## Verification

New fixtures cover the bug shapes:
- `babel-plugin-transform-typescript/const-enum-value-ref-kept/` — `export default Phase`
- `babel-plugin-transform-typescript/const-enum-mixed-refs/` — member access + bare ref combined

Existing `optimize-enums/type-cast` updated to drop the IIFE for the all-type-refs case (the regular-enum side of the unified rule).
2026-05-18 02:19:11 +00:00
Dunqing 931b7d6b97 fix(transformer): inline const enum members through type-cast wrappers (#22500)
Closes #22444.

`Phase.idle as Phase`, `Phase.idle satisfies Phase`, `Phase.idle!`, and `<Phase>Phase.idle` failed to inline under `optimizeConstEnums`. The const enum declaration was stripped while the member access was left as `Phase.idle`, producing a runtime `ReferenceError`.

## Cause

The enum inliner's `enter_expression` matched only bare `StaticMemberExpression`/`ComputedMemberExpression`. `annotations.rs` strips TS-only wrappers in its own `enter_expression`, but `walk_expression` only calls `enter_expression` once per node — after the strip the inner `Phase.idle` was never revisited.

## Fix

Peek through the wrappers via `Expression::get_inner_expression_mut()` (it already handles `TSAsExpression`, `TSSatisfiesExpression`, `TSNonNullExpression`, `TSTypeAssertion`, `TSInstantiationExpression`, `ParenthesizedExpression`). The outer `*expr = …` replacement then drops the wrapper along with the inlined value.

## Example

```ts
const enum Phase { idle, active }

class Foo {
  #foo = Phase.idle as Phase;
}
```

Before:
```js
class Foo {
  #foo = Phase.idle;  // dangling reference
}
```

After:
```js
class Foo {
  #foo = 0;
}
```

## Verification

New fixtures cover all wrapper shapes for const + regular enums:
- `babel-plugin-transform-typescript/const-enum-type-cast/`
- `babel-plugin-transform-typescript/optimize-enums/type-cast/`
2026-05-18 02:19:10 +00:00
camc314 ecfd3ca7c5 fix(transformer/async-to-generator): move only parameter bindings (#22503)
Previously, given:

```js
class C {
  async method(x = function y() {}) {}
}
```

The async-to-generator transform generates:

```js
class C {
  method(x = function y() {}) {
    return babelHelpers.asyncToGenerator(function* () {})();
  }
}
```

The method parameter stays on the outer wrapper method, while only the original body moves into the inner generator function.

Before this change, `BindingMover` walked the full parameter AST while moving those parameter bindings. That meant it also visited default initializer expressions, so bindings created inside the initializer, like `y` above, could be moved out of their own function/class scope and into the wrapper method scope.

After transform, rebuilt semantics would disagree with the transformed scope tree because the parameter binding was correct, but nested initializer bindings had the wrong owning scope.

This PR makes `BindingMover` only visit the binding positions for formal parameters, rest parameters, and the left side of assignment patterns. It skips initializer expressions so nested function/class bindings stay in the scopes created for those expressions.
2026-05-17 17:22:46 +00:00
camc314 8e79de8f86 fix(transformer): preserve for-await statement bodies (#22361) 2026-05-12 18:28:15 +00:00
leaysgur d3d0b18fde fix(traverse): handle ChainElement::TSNonNullExpression in GatherNodeParts (#22247)
Fixes #22246, transformer panics with `const x = a[b?.c!]?.["d"];` under es2020 target.

(I wasn't sure where to put the test, but I've confirmed that it works on my end for now.)
2026-05-11 09:37:46 +00:00
camc314 4e880de872 fix(transformer/object-rest-spread): declare temp vars for computed keys (#22284)
Given some code like
```js
const {
  [({ ...rest }) => {
    let { ...b } = {};
  }]: a,
  [({ ...d } = {})]: c,
} = {};

export {}; // necessary so we are in strict mode
```
It would previously be transformed to:
```js
const { [(_ref) => {
	let rest = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
	let _ref2 = {}, b = _extends({}, (_objectDestructuringEmpty(_ref2), _ref2));
}]: a, [(_ref3 = {}, {} = _ref3, d = _extends({}, (_objectDestructuringEmpty(_ref3), _ref3)), _ref3)]: c } = {};
export {};
```

This is a problem because there was no declaration to `_ref3`

This causes runtime errors.

After this PR, we now emit:

This new code includes `var _ref3`, fixing the unresolved reference issue.

```js
var _ref3;
const {
  [_ref => {
    let rest = babelHelpers.extends({}, (babelHelpers.objectDestructuringEmpty(_ref), _ref));
    let _ref2 = {},
      b = babelHelpers.extends({}, (babelHelpers.objectDestructuringEmpty(_ref2), _ref2));
  }]: a,
  [(_ref3 = {}, {} = _ref3, d = babelHelpers.extends({}, (babelHelpers.objectDestructuringEmpty(_ref3), _ref3)), _ref3)]: c
} = {};

```

This aligns with Babel.

----

This has been fixed by walking up to find the containing statement, and inserting the var declaration before it.

Previously, the `var` declaration would only be inserted if we were inside `ExpressionStatementExpression` which was not guaranteed.
2026-05-11 09:14:25 +00:00
Dunqing dd88726b8c fix(transformer/legacy-decorator): preserve accessor type annotation for emitDecoratorMetadata (#21966)
Fixes bug 7 of https://github.com/oxc-project/oxc/issues/21922.

## The bug

`@dec accessor x: T` always emitted `design:type = Object` regardless of `T`:

```ts
class Entity {
  @dec accessor name: string = "";   // tsc: design:type = String
  @dec accessor count: number = 0;   // tsc: design:type = Number
}
```

`Reflect.getMetadata("design:type", entity, "name")` returned `Object` instead of `String`. Frameworks reading `design:type` (NestJS Swagger, class-validator, TypeORM column metadata) silently degraded for every typed accessor field.

## Cause

`lower_accessor_properties` (in `enter_class`) rewrites
```ts
@dec accessor x: T = init;
```
into three members — a private storage field, a synthesized getter, and a synthesized setter — and transfers the decorators to the getter so the existing decorator pipeline picks them up. But it dropped the type annotation: the synth getter was constructed with `return_type: NONE`.

The metadata pass runs later and takes the getter branch:

```rust
if method.kind.is_get() {
    (self.serialize_type_annotation(method.value.return_type.as_ref(), ctx), None)
}
```

`return_type` is `None` because lowering discarded it, so `serialize_type_annotation` correctly fell through to `Object` for what it sees as an untyped getter.

The metadata pass's `enter_accessor_property` dispatch exists, but it never fires because the `AccessorProperty` no longer exists by the time traversal reaches the class body.

## Fix

Stop dropping the type annotation. In `lower_accessor_properties`:

```rust
let decorators = std::mem::replace(&mut accessor.decorators, ctx.ast.vec());
let type_annotation = accessor.type_annotation.take();
```

Thread `type_annotation` through `create_accessor_method` to the getter (setter passes `None`). To avoid a post-construction patch on the synthesized `MethodDefinition`, `create_class_method` now takes a `return_type: Option<ArenaBox<TSTypeAnnotation>>` parameter and threads it directly into the function's return-type slot. The other caller (`create_class_constructor_with_params`) passes `None`.

The lowered AST is now self-consistent — the synth getter for `accessor x: T` reads as a getter that returns `T`, which is what it semantically is, and the existing getter-metadata path serializes it correctly.

## Out of scope (architectural limit)

`type Uuid = string; @dec accessor x: Uuid` still emits `Object`, same as for non-accessor properties. Resolving type-alias references to their primitive constituent requires a name-based alias-resolution pass (the same one that `tsc`'s checker provides via `getTypeReferenceSerializationKind`). That's bug 1 of #21922 and a separate change from this fix; flagged here so reviewers don't mistake it for an omission.

## Test plan

- [x] Conformance fixture `oxc/metadata/accessor` covers primitives, untyped (correctly stays `Object`), `string[]` → `Array`, `static accessor`, and computed-key (`@dec accessor ["computed"]: number`)
- [x] `cargo test -p oxc_transformer` — 31 + 5 passed
- [x] `cargo run -p oxc_transform_conformance -- --filter legacy-decorators` — 73 pass / 23 fail (baseline 72/24, +1 new fixture, **0 regressions**)
- [x] `cargo run -p oxc_transform_conformance -- --exec` — accessor exec test verifies `Reflect.getMetadata` returns the correct constructor at runtime
- [x] `cargo fmt -p oxc_transformer`
2026-05-07 14:17:45 +00:00
Dunqing 0c7c01c63b fix(transformer/typescript): inline optional-chain enum member access (#21834)
## Summary

Closes #21813.
Closes #21828.

`c_num?.x` and `c_num?.['x']` were not handled by the enum-inlining pass in `enter_expression`, which only matched `Expression::StaticMemberExpression` and `Expression::ComputedMemberExpression`. When the es2020 optional-chain plugin lowered the chain first, the member access became:

```js
c_num === null || c_num === void 0 ? void 0 : c_num.x
```

Then the inline pass saw the inner `c_num.x` and replaced it with the constant + deleted *that one* reference — but the two references in the test condition stayed live. With `optimizeConstEnums: true`, the const-enum declaration is then unconditionally removed, leaving dangling references to a binding that no longer exists.

The same shape underlies the rolldown report ([rolldown/rolldown#9181](https://github.com/rolldown/rolldown/issues/9181)) where rolldown's cross-module enum inlining drops the import that `c_num` was bound to.

## Fix

Match `Expression::ChainExpression` whose top element is an optional `StaticMemberExpression` or `ComputedMemberExpression` on an enum identifier, and inline the entire chain to the constant **before** es2020 sees it. Reuses the existing `try_inline_enum_member` / `try_inline_computed_enum_member` helpers — they don't care about the `optional` flag.

## Fixtures

- `optimize-enums/optional-chain-issue-21813/` — the bug case + an `exec.ts` that runs the transformed output to verify runtime semantics
- `optimize-enums/optional-chain-value-kept/` — IIFE preserved when a bare `Foo` ref also exists
- `optimize-enums/optional-chain-deeper-access/` — `Foo?.x.toString()` / `Bar?.['y']?.toString()` exercise nested chains where the inner inline still fires via the existing arms
- `const-enum-optional-chain/` — const-enum path with `optimizeConstEnums: true`

## Known limitation

Deeper chains under es2020 lowering — `c_num?.x.y` or `c_num?.x()` where the optional access is below the chain element — still produce dangling refs because the chain element is non-optional or a `CallExpression` and this fix's match arm doesn't trigger. Without es2020 lowering they work (the inner `?.x` gets visited as a regular `Expression::StaticMemberExpression`), so the conformance fixtures pass. A more general fix would walk the chain to find the leftmost optional-on-enum access; out of scope for this PR.

## Test plan

- [x] `cargo run -p oxc_transform_conformance -- --filter optimize-enums/optional-chain` — all three pass
- [x] `cargo run -p oxc_transform_conformance -- --filter const-enum-optional-chain` — passes
- [x] `cargo run -p oxc_transform_conformance -- --exec --filter optimize-enums/optional-chain-issue-21813` — runtime check passes
- [x] `cargo test -p oxc_transformer` — green
- [x] `cargo clippy -p oxc_transformer -- -D warnings` — clean
- [x] CI Conformance — green (snapshots updated for `oxc.snap.md` + `oxc_exec.snap.md`)
2026-05-07 09:04:41 +00:00
Ido Rosenthal 9593ec8b6b feat(transformer/jsx): add jsxDEV source metadata for fragments (#21932)
Before this change, fragment transforms omitted source location
metadata:

```js
_jsxDEV(_Fragment, { children: "test" }, void 0, false);
```

After this change, fragments receive the same trailing development
metadata as other JSX `jsxDEV` calls:

```js
_jsxDEV(_Fragment, { children: "test" }, void 0, false, {
  fileName: _jsxFileName,
  lineNumber: 2,
  columnNumber: 10
}, this);
```

## Motivation

This came from
[#21042](https://github.com/oxc-project/oxc/issues/21042).

TypeScript's `react: reactJSXDev` transform also emits fragment source
locations and `this` for same case:

https://www.typescriptlang.org/play/?jsx=5#code/DwPgUABBwCYJYDcTAPTyZa7lseV4QA

## Changes

- allow fragment `jsxDEV` calls to receive source metadata in the JSX
transformer
- update the local transform conformance fixture for
`fragment-static-children`

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2026-04-30 14:39:49 +08:00
Dunqing e3399ec3a6 fix(transformer/class-properties): preserve RHS in logical-assignment to static private field (#21950)
fixes #21874

`transform_static_assignment_expression` took `assign_expr.right` once at the top of the function (correct for the `=` branch), then took it a second time inside the `else` branch that handles compound operators. The second `take_in` returned a `NullLiteral` dummy, so `??=` / `&&=` / `||=` (and the binary ops) on a static private field where the receiver isn't a direct class reference — e.g. `this.#shared ??= 1` inside a static method — emitted `null` in place of the RHS:

```js
// before
class Singleton {
  static #shared;
  static shared() {
    this.#shared ??= 1;
    return this.#shared;
  }
}

// transformer output (broken):
_assertClassBrand(Singleton, this, _shared)._ ?? (_shared._ = _assertClassBrand(Singleton, this, null));
//                                                                                              ^^^^ should be 1
```

Removes the redundant inner `let class_ident = …; let value = assign_expr.right.take_in(…);` shadowing so the compound-operator branches use the already-captured outer `value` (the real RHS) when building the `_assertClassBrand(Class, object, value)` call. Output now matches Babel.

Adds a `private-static-logical-assignment` conformance fixture covering `??=`, `&&=`, and `||=`, plus an `exec.js` to verify runtime behavior.
2026-04-30 00:39:26 +00:00
Dunqing c59c1990bc fix(transformer/typescript): emit class fields for parameter properties (#21831)
## Summary

Fixes a long-standing inconsistency in the TypeScript transformer's handling of constructor parameter properties under the documented default (`useDefineForClassFields: true` per [`compiler_assumptions.rs:137-139`](https://github.com/oxc-project/oxc/blob/main/crates/oxc_transformer/src/compiler_assumptions.rs#L137-L139)).

The transformer already emitted TS-true-aligned output for **declared** fields (kept `boom: number;` as `boom;`) but silently dropped the field declaration for **parameter properties**, so downstream tools that re-analyze the transformed AST saw the property only as a `this.*` write, not as a declared class field.

```ts
// input
class Foo {
  boom: number;                  // declared field
  constructor(public foo) {}     // parameter property
}
```

```js
// before — inconsistent
class Foo {
  boom;                          // ✅ kept (TS-true)
  constructor(foo) {             // ❌ missing `foo;` (TS-false-style for params only)
    this.foo = foo;
  }
}

// after — consistent
class Foo {
  foo;                           // ✅ now matches `boom;`
  boom;
  constructor(foo) {
    this.foo = foo;
  }
}
```

This is **not a policy change** — the documented default has always been `useDefineForClassFields: true` (set both `set_public_class_fields` and `remove_class_fields_without_initializer` to `true` to opt into `false` semantics). The fix just closes the missing case for parameter properties.

## Implementation

- Add `add_parameter_property_fields` to the `enter_class` path that runs when `set_public_class_fields` is `false`, mirroring the existing branch that calls `transform_class_fields` when it is `true`.
- Skip parameter properties whose name matches an existing instance field on the same class (matches tsc's dedup). Static, private, and `declare`-only fields are different bindings, so they don't suppress the new field.
- Early-bail before allocating the dedup set when the class has no parameter properties — keeps the transformer-allocations snapshot at baseline.

No new option is added; the existing `set_public_class_fields` assumption already maps cleanly to `useDefineForClassFields` (the playground's `useDefineForClassFields: true` already toggles `set_public_class_fields = false`).

Closes #21600
Closes #21831
2026-04-30 00:39:25 +00:00
Dunqing 91e5bde420 fix(transformer/typescript): preserve computed-key static block when 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
2026-04-20 15:58:31 +08:00
Dunqing 56af2f4fe0 fix(transformer/async-to-generator): correct scope of inferred named FE in async-to-generator (#21458)
When the async-to-generator transform wraps an async arrow / anonymous async function expression whose name is inferred from its parent (e.g. `const foo = async () => {}`, `{ foo: async () => {} }`), it emits a named function expression as the caller:

```js
const foo = function () {
  var _ref = asyncToGenerator(function* () { /* body */ });
  return function foo() { return _ref.apply(this, arguments); };
}();
```

Per the JS spec, the inferred name `foo` binds only inside the named FE itself — not in the enclosing wrapper IIFE scope.

But the previous code had two bugs that together caused oxc to emit an AST that a fresh semantic analysis (e.g. Rolldown's minifier in Vite, or oxc's own minifier) would misread:

1. `create_function` set `FunctionType::FunctionDeclaration` whenever `id.is_some()`, even for callers using the result as a function expression. Any fresh semantic pass trusts `r#type` and treats the node as a declaration — which binds the name in the enclosing wrapper scope.
2. The inferred id's binding was registered in `wrapper_scope_id` rather than the function's own scope.

Combined, downstream minifiers resolve a body reference like `typeNext()` inside `const typeNext = async () => { typeNext(); }` to the inner caller instead of the outer `const typeNext`. The outer const then looks unused, gets inlined away, and the body reference fails at runtime with `ReferenceError: typeNext is not defined`.

## Fix

Pass `FunctionType` explicitly (via new `create_function_expression` and `create_function_declaration` helpers), and place the inferred id's binding in the caller function's own scope.

## Runtime verification

Ran input → oxc transform → oxc compress (same pipeline Rolldown/Vite uses):

**Pre-fix** output (matches the exact bug in the Vite issue — outer const inlined away):
```js
(function() {
  var _ref = _asyncToGenerator(function* () { ..., typeNext(); });
  return function typeNext() { return _ref.apply(this, arguments); };
})()();
```
Runtime: `ReferenceError: typeNext is not defined` ✗

**Post-fix** output (outer const preserved; minifier correctly drops the now-unused inner FE name):
```js
const typeNext = function() {
  var _ref = _asyncToGenerator(function* () { ..., typeNext(); });
  return function() { return _ref.apply(this, arguments); };
}();
typeNext();
```
Runtime: works correctly ✓

Closes #21125
Closes #21445
2026-04-15 14:06:08 +00:00
Dunqing 4fb73a7af9 fix(transformer/typescript): preserve execution order for accessor with useDefineForClassFields: false (#21369)
## Summary

When `useDefineForClassFields: false` (`setPublicClassFields` assumption), the TypeScript transform moves public/TS-private field initializers into the constructor. However, private field initializers (including `accessor` backing fields from the legacy decorator transform) were left as class field declarations, causing them to execute **before** the constructor body. This broke execution order when the initializer depended on other fields that were already moved to the constructor.

**Input:**
```ts
class Hello {
    private input = { foo };
    accessor util = this.input.foo();
}
```

**Before (broken):** `this.input.foo()` runs before `this.input = { foo }`
```js
class Hello {
    constructor() { this.input = { foo }; }
    #_util_accessor_storage = this.input.foo(); // ← runs BEFORE constructor
}
```

**After (fixed):** all instance initializers in the constructor, in source order
```js
class Hello {
    constructor() {
        this.input = { foo };
        this.#_util_accessor_storage = this.input.foo();
    }
    #_util_accessor_storage;
}
```

### Approach

Matches TypeScript's [`WillHoistInitializersToConstructor`](https://github.com/microsoft/TypeScript/blob/7b8cb3bdf82f400642b73173f941335775d6f730/src/compiler/transformers/classFields.ts#L339) logic in [`shouldTransformAutoAccessorsInCurrentClass`](https://github.com/microsoft/TypeScript/blob/7b8cb3bdf82f400642b73173f941335775d6f730/src/compiler/transformers/classFields.ts#L1069-L1073):

- Pre-scan the class body to check if any non-private instance field has an initializer that will be hoisted
- When hoisting occurs, include **all** instance fields (including `#` private) in the hoisting to preserve execution order
- When no public fields are being hoisted, private fields stay as class field declarations

No changes needed to the decorator/legacy transform — the fix is entirely in `transform_class_fields`.

Fixes #21365

## Test plan

- [x] Added test fixture: `accessor-use-define-for-class-fields` (with hoisted + non-hoisted cases)
- [x] Updated `use-define-for-class-fields-without-class-properties` expected output to match TypeScript behavior
- [x] `cargo test -p oxc_transformer` — all pass
- [x] `cargo run -p oxc_transform_conformance` — no regressions, previously failing test now passes

🤖 Generated with [Claude Code](https://claude.ai/code)
2026-04-15 01:22:15 +00:00
Dunqing 995e13eb1e test(transformer): add test for string enum alias member (#20652)
## Summary

- Add a conformance test for string enum alias members (e.g. `Default = Theme.Light`) covering both const and non-const enum cases
- Verifies no incorrect reverse mapping is generated for string alias members (relates to https://github.com/rolldown/rolldown/issues/8866)

## Test plan

- `cargo run -p oxc_transform_conformance -- --filter enum-string-alias-member` passes

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-04-13 08:49:24 +00:00
Dunqing e7e1aead4c feat(transformer/typescript): add optimize_enums option for regular enum inlining (#20539)
This is required in Rolldown to align with `esbuild`, which could inline a regular enum as long as all its enum members can be evaluated. See https://github.com/rolldown/rolldown/pull/8796
## Summary

Depends on #20508.

- Add `optimize_enums` option to `TypeScriptOptions` that treats regular enums with all-evaluable members the same as const enums: inlines member accesses and removes non-exported declarations
- Regular enums are only removed when no runtime value references remain (e.g., `typeof Foo`, passing as argument)
- Includes 14 conformance test fixtures covering basic, string values, binary expressions, cross-member/cross-enum references, merged enums, exported (kept), non-evaluable (kept), template literals, unary expressions, typeof/value-usage/passed-as-argument (kept), and re-exported (kept)

## Test plan

- [x] 14 new conformance test fixtures under `optimize-enums/`
- [x] `cargo run -p oxc_transform_conformance` passes
- [x] `cargo test -p oxc_transformer` passes
2026-04-13 08:49:23 +00:00
Amal Jossy af1a586501 fix(transformer/class-properties): use correct property name when converting parameter properties (#21268)
## Summary

Fixes #21116 where TypeScript constructor parameter properties emit the
wrong property name when the parameter name clashes with a free variable
referenced in a class field initializer.

## Problem

When targeting pre-ES2022 (or with `transform-class-properties`
enabled), the class properties plugin detects that a constructor
parameter name shadows an outer variable referenced in a field
initializer, and renames the parameter binding (e.g. `x` → `_x`) to
preserve the initializer's semantics.

`convert_constructor_params` (TypeScript plugin) ran after this rename
and read `id.name` — which had already been mutated — to produce the
`this.X = X` assignment. This caused:

```ts
let x = 10;
class Foo {
  field = x;
  constructor(public x: number) {}
}
```

to incorrectly emit:

```js
constructor(_x) {
  this._x = _x; // ❌ property name should be x
  ...
}
```

## Root Cause

Both plugins share a single traversal pass with interleaved hooks.
`enter_class_body` (class properties) fires before
`enter_method_definition` (TypeScript), so by the time
`convert_constructor_params` runs, `BindingIdentifier.name` has already
been mutated by `ConstructorSymbolRenamer`.

## Fix

Recover the property name from `id.span.source_text(source_text)`
instead of `id.name`. Spans are set by the parser and never mutated by
any transformer, so this always returns the original user-written
identifier regardless of renames.

```ts
constructor(_x) {
  this.x = _x; // ✅
  ...
}
```

## AI Disclosure

This fix was developed with Claude Code assistance.

Co-authored-by: Dunqing <dengqing0821@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-13 10:57:24 +08:00
Dunqing eab13b39e3 fix(transformer/decorators): avoid accessor storage name collisions (#21106)
## Summary

- Use raw property/identifier names instead of `get_var_name_from_node` (which strips leading underscores) when generating private backing field names for accessor properties
- For non-computed keys, use `PropertyKey::name()` which preserves leading underscores
- For computed keys, match on `Expression::Identifier` to get the raw name directly
- No counters, maps, or helper functions needed — collisions are avoided at the source

This prevents `accessor prop` and `accessor _prop` from producing the same `#_prop_accessor_storage` name, which caused a runtime `TypeError: Cannot initialize the same private elements twice on an object`.

Closes #20946
Supersedes #21023

## Test plan

- [x] Added test fixture covering both non-computed (`prop`/`_prop`) and computed (`[prop]`/`[_prop]`) accessor name collisions
- [x] All existing accessor tests pass unchanged
- [x] `cargo test -p oxc_transformer` passes
- [x] Full `cargo run -p oxc_transform_conformance` passes
- [x] `cargo clippy` clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-04-08 02:22:25 +00:00
camc314 07e8a30f33 fix(transformer/react-refresh): handle parenthesized variable initializers (#21047)
fixes https://github.com/oxc-project/oxc/issues/21024
2026-04-07 02:08:05 +00:00
Dunqing 3931b98132 fix(transformer): ignore @jsxImportSource inside inline code spans in comments (#20674)
## Summary

- Fix JSX pragma scanner incorrectly matching `@jsxImportSource` inside backtick code spans (e.g. `` `@jsxImportSource custom/source` ``) in doc comments
- Add validation that `@` must be preceded by whitespace, `*`, or be at the start of the comment

## Problem

The `memchr`-based `@` search found pragma directives anywhere in a comment, including inside inline code spans. This caused:
1. A `@jsxImportSource` inside a doc comment overriding the actual file-level pragma
2. The trailing backtick being included in the import specifier (`` custom/source` ``)

This broke Vite 8 dev server when `.tsx` files had JSDoc comments mentioning `@jsxImportSource`.

## Design

| Tool | `@` position check |
|------|-------------------|
| esbuild | None — matches `@jsx` anywhere in comment |
| Babel | Full start-of-line regex (`^\s*(?:\*\s*)?@jsx`) |
| **Oxc (this PR)** | Preceding byte must be whitespace, `*`, or start of comment |

We intentionally sit between esbuild and Babel — checking only the immediately preceding byte is sufficient for the backtick case without being as strict as Babel's full start-of-line regex.

Fixes #20669

## Test plan

- [x] Unit tests added for backtick-wrapped pragmas
- [x] Conformance test fixture added (`issue-20669`)
- [x] All existing transformer tests pass
- [x] Clippy clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-03-24 09:22:51 +00:00
Dunqing 3d761217e7 fix(transformer): incorrect output with multiple JSX spread children in automatic mode (#20647)
## Summary

- Multiple JSX spread children like `{...[1,2,3]} {...[4,5,6]}` were each wrapped in individual arrays, producing `[[...[1,2,3]], [...[4,5,6]]]` instead of `[...[1,2,3], ...[4,5,6]]`
- Changed `transform_jsx_child_automatic` to return `ArrayExpressionElement` so spread children become direct spread elements in the final children array
- Added conformance tests for multiple spreads and mixed spread/non-spread children

Closes #20600

## Test plan

- [x] Existing `spread-children-automatic` test still passes
- [x] New `spread-children-multiple-automatic` test passes (the reported bug)
- [x] New `spread-children-mixed-automatic` test passes (spread + non-spread children)
- [x] Full transformer conformance suite passes
- [x] `cargo test -p oxc_transformer` passes

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-03-23 09:51:28 +00:00
Dunqing 3bbd0cd262 fix(transformer): emit Object instead of void 0 for untyped getter/setter design:type metadata (#20488)
## Summary

- Fix `design:type` metadata for getter/setter decorators without type annotations emitting `void 0` instead of `Object`
- Use `serialize_type_annotation` (which defaults to `Object`) instead of `serialize_return_type_of_node` (which defaults to `void 0`) for getter `design:type`
- Verified output matches TypeScript's behavior

Closes #20368

## Test plan

- [x] Added untyped getter/setter test cases to `getter-setter-method` fixture
- [x] Verified output matches TypeScript compiler output
- [x] All conformance tests pass with no regressions
- [x] Clippy clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-03-18 09:52:45 +00:00
Dunqing 7215d9e559 feat(transformer): support lowering accessor with legacy decorators (#20348)
## Summary

Closes #20133

- Lower decorated `accessor` properties to private backing field + getter/setter pair when `experimentalDecorators` is enabled, matching TypeScript's `classFields.ts` `transformAutoAccessor`
- Only accessors with decorators are lowered — undecorated accessors are left as-is
- Support computed accessor keys (e.g. `@dec accessor [expr]`) via temp var to ensure the key expression is evaluated only once
- Accessor lowering runs in `enter_class` (Decorator plugin) so es2022 class-properties can further transform the generated private fields
- Decorators are transferred from the accessor to the generated getter, so the legacy decorator transform emits `_decorate()` calls

### Transform example

```ts
// Input
class C {
  @dec accessor prop: string = "hello";
  @dec accessor [expr]: any;
}
```

```js
// Output (without class-properties)
var _a = expr;
class C {
  #_prop_accessor_storage = "hello";
  get prop() { return this.#_prop_accessor_storage; }
  set prop(value) { this.#_prop_accessor_storage = value; }
  #_a;
  get [_a]() { return this.#_a; }
  set [_a](value) { this.#_a = value; }
}
babelHelpers.decorate([dec], C.prototype, "prop", null);
babelHelpers.decorate([dec], C.prototype, _a, null);
```

## Test plan

- [x] New test `oxc/accessor` — decorated accessors without class-properties plugin (instance, static, initialized, computed key)
- [x] New test `oxc/accessor-with-class-properties` — full pipeline with class-properties plugin (private fields transformed to WeakMap/brand patterns)
- [x] New test `decoratorOnClassAccessorProperty1` — instance, static, and initialized accessor properties with decorators
- [x] Existing `decoratorOnClassProperty13` output updated for accessor lowering
- [x] Undecorated accessors are not lowered (`oxc-13284.js` coverage test passes)
- [x] `cargo clippy`, `just fmt` clean

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-03-18 07:44:58 +00:00
bab 11f96959b0 fix(transformer): legacy decorator on computed property key leaves variable unassigned (#20430)
This PR has two fixes. The second fix exposed a pre-existing bug that
needed to be fixed first.

- 24a72d7bc: `create_read_write_target` was used for a simple `=`
assignment when creating a temp var for decorated computed property
keys. Should be `create_write_target`.

- f0affc6f4: `transform_class_on_exit` was removing all no-initializer
properties unconditionally. But the legacy decorator embeds an
assignment in the computed key (`[FIELD_NAME]` → `[_a =
FIELD_NAME]`), so removing the property also removes the assignment,
leaving `_a` undefined in `_decorate()`. Keep properties whose computed
keys have side effects, matching TypeScript's
  behavior.

  Fixes #20418

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2026-03-17 23:31:26 +08:00
bab 1f65c3f181 fix(transformer): emit design:paramtypes when class has static anonymous class expression (#20382)
related https://github.com/rolldown/rolldown/discussions/8684

Fix `design:paramtypes` being silently dropped in release builds when a
decorated class has static properties with anonymous class expression
initializers (`static Foo = class extends Error
  {}`).

`pop_constructor_metadata()` was inside `debug_assert!`, which is a
no-op in release builds, causing stack imbalance and missing metadata.

---------

Co-authored-by: Dunqing <dengqing0821@gmail.com>
2026-03-15 22:10:43 +08:00
bab fa70d5c283 fix(transformer): use implementation signature for design:paramtypes when constructor is overloaded (#20394)
fixes https://github.com/oxc-project/oxc/issues/20369
2026-03-15 21:25:05 +08:00
Sverre Johansen 1ff5c1dfe9 fix(transformer/typescript): rewrite extensions in dynamic import() expressions (#20121)
Closes #20120

`rewriteImportExtensions` was not handling dynamic `import()`
expressions, only static `import`/`export` declarations. TypeScript's
`rewriteRelativeImportExtensions` handles both (via
`visitImportOrRequireCall` in the ESNext module transformer).

The fix adds `enter_import_expression` visitors at three levels of the
transformer dispatch chain. When the `import()` source is a string
literal, it is rewritten the same way as static imports. Non-literal
sources (e.g., `import(variable)`) are left unchanged.

Test fixtures added for both `"rewrite"` and `"remove"` modes covering
dynamic imports.

> Disclosure: AI-assisted (Claude). All changes reviewed and tested by
the contributor.

---------

Co-authored-by: Sverre Johansen <sverre.johansen@microsoft.com>
2026-03-13 07:54:50 +08:00
Boshen deed3d851b fix(transformer): remove unnecessary trailing expression in object rest spread assignment (#19259)
## Summary

- Skip the trailing reference (e.g. `_c`) in the generated sequence expression when the destructuring assignment is directly inside an `ExpressionStatement`, since the expression result is not consumed
- Before: `_c = c2, {a2} = _c, b2 = objectWithoutProperties(_c, ["a2"]), _c;`
- After: `_c = c2, {a2} = _c, b2 = objectWithoutProperties(_c, ["a2"]);`
- The trailing reference is still kept when the result is consumed, e.g. `console.log((..., _c))`

Closes #7389 (issue 1)

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-02-11 11:43:24 +00:00
Boshen 40ef7eef0b test(transformer): add test for async arrow with super in static property (#18075)
## Summary
- Adds a test case covering the interaction between `transform-class-properties` and `transform-async-to-generator` when `super` is accessed in an async arrow function within a static class property
- Verifies that `super` references are correctly hoisted before async transformation

## Test plan
- [x] Test passes with `cargo run -p oxc_transform_conformance -- --filter static-async-super`
- [x] Conformance tests pass with `just conformance`

Closes #8326

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-01-16 11:52:13 +00:00
Dunqing 30026499d2 fix(transformer/typescript): remove unused import equals declaration (#16776)
close: #16628
2025-12-17 01:44:05 +00:00
Copilot 99c022eb58 fix(transformer): revert "fix(transformer): validate JSX pragma values and reject invalid identifiers" (#16793)
Reverts commit 853c20d45 which added JSX pragma validation. The
validation rejected invalid pragma values (backticks, numbers, keywords)
and emitted warnings while falling back to defaults.

## Changes

- **`crates/oxc_transformer/src/jsx/comments.rs`**: Removed
`is_valid_pragma_value()` function and validation checks for `@jsx` and
`@jsxFrag` pragmas. Invalid pragma values are now accepted without
validation.

- **`crates/oxc_transformer/src/jsx/diagnostics.rs`**: Removed
`invalid_pragma_value()` diagnostic.

- **Test fixtures**: Removed `invalid-jsx` and `invalid-jsx-frag` test
cases.

## Behavior

Invalid pragma values are now used as-is in transformation:

```jsx
// @jsxRuntime classic
console.log(<></>) // @jsxFrag `
```

Transforms to invalid code:
```js
console.log(React.createElement(`, null));
```

<!-- START COPILOT CODING AGENT SUFFIX -->



<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> Revert #16675


</details>



<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/oxc-project/oxc/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
2025-12-15 11:38:14 +08:00
Copilot 853c20d452 fix(transformer): validate JSX pragma values and reject invalid identifiers (#16675)
Invalid JSX pragma values in comments (e.g., backticks) were being used
as-is, generating broken JavaScript code. The transformer now validates
pragma values and emits warnings when they're invalid.

## Changes

- **Validation**: Added `is_valid_pragma_value()` to validate `@jsx` and
`@jsxFrag` pragma values against JavaScript identifier rules
  - Accepts single identifiers: `h`, `Fragment`
  - Accepts dotted identifiers: `React.Fragment`, `Preact.h`
  - Accepts special forms: `this.foo`, `import.meta.bar`
  - Rejects invalid syntax: backticks, numbers, empty strings

- **Diagnostics**: Added `invalid_pragma_value()` warning diagnostic
that guides users to fix malformed pragmas

- **Fallback behavior**: Invalid pragmas are ignored and defaults
(`React.createElement`, `React.Fragment`) are used

## Example

**Before:**
```js
// @jsxRuntime classic
console.log(<></>) // @jsxFrag `

// Transforms to invalid code:
console.log(React.createElement(`, null));
```

**After:**
```js
// Emits warning: Invalid @jsxFrag value "`". It will be ignored.
// Transforms to valid code:
console.log(React.createElement(React.Fragment, null));
```

This aligns with esbuild's behavior of warning users about invalid
pragmas while continuing transformation with defaults.

<!-- START COPILOT ORIGINAL PROMPT -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>transformer: ``// @jsxFrag ` `` generates invalid
code</issue_title>
> <issue_description>```js
> // @jsxRuntime classic
> console.log(<></>) // @jsxFrag `
> ```
> is transformed to
> ```js
> // @jsxRuntime classic
> console.log(/* @__PURE__ */ React.createElement(`, null));
> ```
> . But this should be
> ```js
> // @jsxRuntime classic
> console.log(/* @__PURE__ */ React.createElement(React.Fragment,
null));
> ```
> (the pragma comment should be ignored).
>
[playground](https://playground.oxc.rs/#eNptU8Fu2zAM/ZVApw3I1mGnIiiKDe0CDOjWrh3WSw+TZdpVKkseRScpgvz7nhxLyaEnW48i+fj4tFNGLdTZ2ezLKm7vBy+2o5lxOkZrnrwJPgZHH11o311cXpxdvp9NV5es29nfJ6/mKqjFTvHg08dZL2rRaBdprprAnRYhLoiw9jHBaiE8ALAor4Xqa0JP1mLRsNzePFuh2GtDBeq0b93xaELXM8VjSjShR/hQPL52VXD5ZJp2urafq15zTLx2irZCPqIvZMBcmEc7Fzb3JAP720GirWk5eJOo5VKpJ/Ga7jQjN6Nj3p/z717YoqIpgUigLdZ8Yw48oeCQtBo54P9Eqp0aIv3W1XEo0dWjreVZLT7PFfn6trmxHlMq14Buj24yxc8/oZtNEv0aghx1wmAPb8D/0umOQ49eSscPnqimGjWxJwt67VXoOp1izgHFHLYMi1k2eX7EN/o14krF2ryQPGBpSM+XM6o7OjCf+odqRUYeWfeokUVNjUauXwVCVgMYEp+kQa1io4Neorkl2E5R9FgnCkDBa2qQswx8lcy8tOTqshDa9sQwuhft4LwA45XFINpZKegPEl1rgQjT1t527E5FkO2xe2Kv4blM1YSaWhrfhk87LnZcxTrg6U1qeh9krJURR22+O1bJPk9myY8Ak4f+htZUir4Q9T+hcvbOmAo/BreEN1PGmrgK8URL69MOUqj87QHXo3wJLn/7hCeZ80z7/ygugu8=)
> 
> Probably a warning should be output like esbuild does ([esbuild
try](https://esbuild.github.io/try/#dAAwLjI3LjEALS1sb2FkZXI9anN4AC8vIEBqc3hSdW50aW1lIGNsYXNzaWMKY29uc29sZS5sb2coPD48Lz4pIC8vIEBqc3hGcmFnIGA)).
> 
> related:
https://github.com/evanw/esbuild/commit/2102e068368dea39713b8b071a08b5222020de5f</issue_description>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

- Fixes oxc-project/oxc#16653

<!-- START COPILOT CODING AGENT TIPS -->
---

✨ Let Copilot coding agent [set things up for
you](https://github.com/oxc-project/oxc/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.

---------

Signed-off-by: Dunqing <dengqing0821@gmail.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
Co-authored-by: Dunqing <dengqing0821@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-12-11 16:30:11 +08:00
Dunqing 2c275bfbd5 fix(transformer/styled-components): named styled import doesn't work (#16573)
close: https://github.com/rolldown/rolldown/issues/7292
2025-12-08 11:19:58 +00:00
Dunqing 7c46a9e9bb fix(transformer/tagged-template-transform): handle \n escape sequences (#15830)
Fixes the issue identified in #15664 where the tagged template transform plugin incorrectly handled template literals containing escape sequences.

### Examples

```js
// Input
foo`</script>\n`
// Before (incorrect):
foo(_t || (_t = taggedTemplateLiteral(["</script>\\n"])));
// After (correct):
foo(_t || (_t = taggedTemplateLiteral(["</script>\n"], ["</script>\\n"])));

// Input with invalid escape
foo`</script>\u`
// Before (syntax error):
foo(_t || (_t = taggedTemplateLiteral(["</script>\\u"])));
// After (correct):
foo(_t || (_t = taggedTemplateLiteral([void 0], ["</script>\\u"])));
2025-11-19 23:36:21 +00:00
Dunqing 1b18457e05 feat(transformer): support tagged template expression with </script transformation (#15664)
Implement a transformation plugin for tagged template expressions containing </script> tags to prevent script tag issues in browser environments.

  This plugin transforms tagged template literals containing `</script` (case-insensitive) to use a helper function call with template caching, matching esbuild's behavior.

 ### Example

  Transforms tagged templates to use cached template objects with a helper function:

  Input:
```js
foo`</script>`
bar`<script>${content}</script>`
```
  Output:
```js
var _templateObject, _templateObject2;
foo(_templateObject || (_templateObject = babelHelpers.taggedTemplateLiteral(["<\/script>"])));
bar(_templateObject2 || (_templateObject2 = babelHelpers.taggedTemplateLiteral(["<script>", "<\/script>"])), content);
```

 Closes #15306
2025-11-17 11:55:13 +00:00
Copilot 7a5c011a14 fix(transformer): convert enum numbers to strings in template literals (#15183)
- [x] Explore repository structure and understand the issue
- [x] Identify the bug in enum.rs (lines 430-434) - missing
number-to-string conversion in template literals
- [x] Create test case for enum template literal with numbers
- [x] Fix the bug by converting numbers to strings in template literal
evaluation
- [x] Verify the fix with manual testing (regular numbers, mixed types,
negative numbers, floats, Infinity, NaN)
- [x] Run unit tests - all passing
- [x] Run code review - reviewed, minor comment about exhaustiveness
(already handled)
- [x] Run security check - no issues found
- [x] Update transform conformance snapshots per CI feedback
- [x] Fix template literal quasi bug (use enumerate instead of zip)
- [x] Add test case for trailing quasi edge case
- [x] Task completed

## Summary
Fixed a bug where numeric enum values in TypeScript were not converted
to strings when used in template literals. The fix converts
`ConstantValue::Number` to strings using `to_js_string()` method.

Fixed an additional bug where the last quasi (suffix) in template
literals was being dropped due to using `zip` instead of properly
iterating over all quasis with conditional expression access.

Updated the transform conformance snapshots to include both test cases.

## Security Summary
No security vulnerabilities were found in the changes.

<!-- START COPILOT CODING AGENT SUFFIX -->



<details>

<summary>Original prompt</summary>

> 
> ----
> 
> *This section details on the original issue you should resolve*
> 
> <issue_title>transformer: computed enum with number in string template
is incorrect</issue_title>
>
<issue_description>[playground](https://playground.oxc.rs/#eNptVMFOGzEQ/ZXI6gGkgELggFL1UAGRKgFJC5RLpOLdnQSD197aswlotf/eZyfeTQWneN945s28eU4jcjER9FZZxwMydTm4rcuM3FU4NgszGNw+3Pw5GXwbnIxGo2ECxgDG+8ApgNN94AzA2RZoF2Zh9ikubFnVTEVPcjG7mT/cX11GpqcvTd/EceRvjz5g4/YpknWpoaePqaefpJ7F1NhWbo23mo61XR3MshfK+XgtdU3+YL/Jw8OvCyOGwopJI1xtwo9WhsVkKbWnoVhaV0pmch3CThofYDFhVwNQ4JGod0m5lk6yAnN3e/OsmHwlc+qgUpqV7j9ztOPI9yk+txXC2+L+vcysTl/5crW71g5FJZ0PfTXYMpPx4MXG2b9hHqm13fwirp2Z1exVQdPa5KG1VCpwklvTXDrkJjTm/T7/YdgpVMy7gCe0zSq/cs66HYoeglaxB5z3pGpE7eleZv1QLLNHVfCzmIyHgkwxW14rgymFXqLdCmy8i5+PwKaCRD9ry71OL/7t7hP4b/iaO1uBS0h/ZIgKKlATe1Job4V1lzLEtAaKOVQ3LGbZpPkR38h3jyuZk/kr8R2WhvR0OaGypG3nO34bvfXoZIUaSdRAFHv9zhAyg9vm5P5Lw6shp0oyLPUMR8nWza1X2xUFhQQk7by2FZWlWxG8Kcjj2TFYIPMlLVF4at2Flt5PFemi29o+C+xpI00fLRV36A2xLCRDqd1qP7d1IzwmqmAQckbCmMmNuS1oRfEBmWCEzrMvvrD4K9pJbozlWCshmlbpbqySHkNwVHopmNxW17SmrugrUXWLVSSDxVSY1uopDBwy1uQy65PgYR4TFhVC3akFXET5Atyd2oAHmdNM7T8OrNw+)
> Original report: https://github.com/vitejs/rolldown-vite/issues/472
> 
> ### Input
> ```ts
> export enum NumberEnum {
>   NUM_1 = 1000,
>   NUM_2 = 2000,
>   NUM_3 = 3000,
>   NUM_4 = 4000,
> }
> 
> export enum ComputedEnum {
>   COMPUTED_1 = `${NumberEnum.NUM_1}-${NumberEnum.NUM_2}`,
>   COMPUTED_2 = `${NumberEnum.NUM_3}-${NumberEnum.NUM_4}`,
> }
> 
> console.log(Object.values(ComputedEnum));
> ```
> ### Actual
> ```js
> export let NumberEnum = /* @__PURE__ */ function(NumberEnum) {
> 	NumberEnum[NumberEnum["NUM_1"] = 1e3] = "NUM_1";
> 	NumberEnum[NumberEnum["NUM_2"] = 2e3] = "NUM_2";
> 	NumberEnum[NumberEnum["NUM_3"] = 3e3] = "NUM_3";
> 	NumberEnum[NumberEnum["NUM_4"] = 4e3] = "NUM_4";
> 	return NumberEnum;
> }({});
> export let ComputedEnum = /* @__PURE__ */ function(ComputedEnum) {
> 	ComputedEnum["COMPUTED_1"] = "-";
> 	ComputedEnum["COMPUTED_2"] = "-";
> 	return ComputedEnum;
> }({});
> console.log(Object.values(ComputedEnum));
> ```
> 
> ### Expected
> ```js
> export let NumberEnum = /* @__PURE__ */ function(NumberEnum) {
> 	NumberEnum[NumberEnum["NUM_1"] = 1e3] = "NUM_1";
> 	NumberEnum[NumberEnum["NUM_2"] = 2e3] = "NUM_2";
> 	NumberEnum[NumberEnum["NUM_3"] = 3e3] = "NUM_3";
> 	NumberEnum[NumberEnum["NUM_4"] = 4e3] = "NUM_4";
> 	return NumberEnum;
> }({});
> export let ComputedEnum = /* @__PURE__ */ function(ComputedEnum) {
> 	ComputedEnum["COMPUTED_1"] = "1000-2000";
> 	ComputedEnum["COMPUTED_2"] = "3000-4000";
> 	return ComputedEnum;
> }({});
> console.log(Object.values(ComputedEnum));
> ```
> </issue_description>
> 
> <agent_instructions>We should take a look at
./crates/oxc_transformer/src/typescript/enum.rs to check if there is a
bug</agent_instructions>
> 
> ## Comments on the Issue (you are @copilot in this section)
> 
> <comments>
> </comments>
> 


</details>

- Fixes oxc-project/oxc#15182

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Dunqing <29533304+Dunqing@users.noreply.github.com>
2025-11-04 11:44:34 +08:00
Dunqing 2bc1978d48 fix(transformer/legacy-decorator): correct generating metadata for getter/setter methods (#14495)
* Fixes: #14493

Getter and setter methods should not have `design:returntype` metadata according to TypeScript's `emitDecoratorMetadata` behavior. They should only have `design:type` and `design:paramtypes`.

**And `design:type` is different for the getter and setter:**

Getter: `design:type` is the same as the return type of method.
Setter: `design:type` is the same as the type of the first parameter of the method
2025-10-22 08:57:24 +00:00
Dunqing 5ec92095b2 fix(transformer/class-properties): don't transform properties that have declare modifier (#13766)
* Fixes #13733

Fixes the issue where `declare` fields were incorrectly transformed instead of being removed, causing inheritance issues where child `declare` fields would interfere with parent class property initialization.

Only in the `enter_*` phase do we have to skip the `declare` field; in the exit phase, the `declare` fields have already been removed in the `TypeScript` plugin.
2025-09-17 14:49:59 +00:00