fix(domain): classify TypeScript parameter properties as declarations rather than identifier reads (#4465)

* fix(domain): classify TypeScript parameter properties as declarations rather than identifier reads

Recognize TSParameterProperty in isPatternOwnerDeclaration, isDeclarationIdentifier, and patternContains so parameter property definitions are not emitted as identifier reads, while retaining valid initializer reads. Fixes #4371

* test(domain): assert constructor body parameter property reads survive
This commit is contained in:
Kevin Joshua L
2026-10-16 21:49:40 +05:30
committed by GitHub
parent ffeba6aae0
commit 2bba39bc2b
2 changed files with 43 additions and 0 deletions
@@ -533,6 +533,44 @@ describe("JavaScript semantic analysis: write references", () => {
"read", // const observed = total
]);
});
it("treats TypeScript parameter-property declarations as bindings rather than reads", () => {
const ir = analyzeJavaScriptSemantics(`
const seed = 1;
class Service {
constructor(
public x: number,
public y = 1,
public z = seed,
) {
console.log(this.x);
console.log(y);
}
}
`);
const referencesFor = (name: string) =>
ir.references.filter((reference) => reference.name === name);
// Parameter properties are definitions, not source identifier reads.
expect(referencesFor("x")).toEqual([]);
expect(referencesFor("z")).toEqual([]);
// Actual reads in constructor body survive.
expect(referencesFor("y")).toEqual([
expect.objectContaining({
name: "y",
role: "read",
}),
]);
// Actual reads in parameter default values remain references.
expect(referencesFor("seed")).toEqual([
expect.objectContaining({
name: "seed",
role: "read",
}),
]);
});
});
describe("JavaScript semantic analysis: dynamic and case scopes", () => {