Skip to content

Implement declaration emit for accessors in the js declaration emitter#33649

Merged
weswigham merged 2 commits intomicrosoft:masterfrom
weswigham:js-getters-setters-declarations
Sep 30, 2019
Merged

Implement declaration emit for accessors in the js declaration emitter#33649
weswigham merged 2 commits intomicrosoft:masterfrom
weswigham:js-getters-setters-declarations

Conversation

@weswigham
Copy link
Copy Markdown
Member

I also changed how Object.defineProperty binds symbols a little bit. It now includes the SetAccessor and GetAccessor symbol flags for define property calls that define setters and/or getters, like one may expect.

Fixes #33643

export class F {
set x(arg: number);
get x(): number;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very cool

Comment thread src/compiler/checker.ts Outdated
const rawName = unescapeLeadingUnderscores(p.escapedName);
const name = getPropertyNameNodeForSymbolFromNameType(p, context) || createIdentifier(rawName);
if (p.flags & (SymbolFlags.Property | SymbolFlags.Accessor | SymbolFlags.Variable)) {
const firstPropertyLikeDecl = find(p.declarations, d => isPropertyDeclaration(d) || isAccessor(d) || isVariableDeclaration(d) || isPropertySignature(d) || isBinaryExpression(d) || isPropertyAccessExpression(d));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const firstPropertyLikeDecl = find(p.declarations, d => isPropertyDeclaration(d) || isAccessor(d) || isVariableDeclaration(d) || isPropertySignature(d) || isBinaryExpression(d) || isPropertyAccessExpression(d));
const firstPropertyLikeDecl = find(p.declarations, or(isPropertyDeclaration, isAccessor, isVariableDeclaration, isPropertySignature, isBinaryExpression, isPropertyAccessExpression));

unless you need narrowing?

@weswigham weswigham merged commit 7f3c03d into microsoft:master Sep 30, 2019
@weswigham weswigham deleted the js-getters-setters-declarations branch September 30, 2019 18:09
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Getter/Setter declaration emit for javascript is missing

2 participants