Skip to content

Incorrect renaming of constructor parameter property causes broken this reference in target es2016 #21116

@pranavjindal999

Description

@pranavjindal999

Target ES2016

When a constructor parameter property name collides with a type used in a class field arrow function parameter, OXC incorrectly renames the property (e.g. Foo_Foo) only in the constructor, but does not update its usages elsewhere in the class.

This leads to broken runtime behavior.

🔁 Minimal Reproduction

import type { Foo } from './types';

class A {
  constructor(private Foo: any) {}

  method = (x: Foo) => x;

  myMethod() {
    console.log(this.Foo);
  }
}

❌ Transpiled Output

import _defineProperty from "@oxc-project/runtime/helpers/defineProperty";

class A {
  constructor(_Foo) {
    this._Foo = _Foo;

    _defineProperty(this, "method", (x) => x);
  }

  myMethod() {
    console.log(this.Foo); // ❌ still refers to Foo, not _Foo
  }
}

💥 Problem
• Constructor parameter Foo is renamed to _Foo
• Property becomes this._Foo
• But usages like this.Foo are not updated

⚠️ This is critical because it
• Produces invalid runtime code
• Silent bug (no compile error, breaks at runtime)

Reproducible Playground link

Metadata

Metadata

Assignees

Labels

A-transformerArea - Transformer / Transpiler

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions