Skip to content

Function initializers as properties #61636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3491,8 +3491,14 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
let excludes = SymbolFlags.None;
// Method-like
if (isFunctionLikeDeclaration(getAssignedExpandoInitializer(declaration)!)) {
Copy link
Member

Choose a reason for hiding this comment

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

Since you don't need a custom includes you can reduce this code change down to

Suggested change
if (isFunctionLikeDeclaration(getAssignedExpandoInitializer(declaration)!)) {
if (isPrototypeProperty && isFunctionLikeDeclaration(getAssignedExpandoInitializer(declaration)!)) {

and the default case at the bottom of the function will apply.

includes = SymbolFlags.Method;
excludes = SymbolFlags.MethodExcludes;
if (isPrototypeProperty) {
includes = SymbolFlags.Method;
excludes = SymbolFlags.MethodExcludes;
}
else {
includes = SymbolFlags.Method | SymbolFlags.Property;
Copy link
Member

Choose a reason for hiding this comment

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

This should just be Property, I'm pretty sure. They're a function property, but don't have useful this semantics, static vs instance distinction, etc.

excludes = SymbolFlags.PropertyExcludes;
}
}
// Maybe accessor-like
else if (isCallExpression(declaration) && isBindableObjectDefinePropertyCall(declaration)) {
Expand Down