mirror of
https://github.com/morluto/rea
synced 2026-10-27 06:33:32 -04:00
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:
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user