-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Add JSDocFunctionTypeParameter node kind #18213
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main advantage of this change is that it's impossible to say JSDocFunctionTypeParameter.name
now, right? The code bloats more than I expected with this change, so unless this makes using parameters more fool-proof, then I don't think it's worth it.
type: TypeNode; | ||
} | ||
|
||
export const enum JSDocFunctionTypeParameterSort { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-Kind is a better suffix than -Sort here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better: name: JSDocParameterSpecialName
, with Regular renamed to None.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or specialName so that it isn't structurally compatible with other named things.
export interface JSDocFunctionTypeParameterDeclaration extends Declaration { | ||
kind: SyntaxKind.JSDocFunctionTypeParameter; | ||
parent: JSDocFunctionType; | ||
sort: JSDocFunctionTypeParameterSort; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jsdocKind or parameterKind or jsdocParameterKind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even better, just name
or maybe nameKind
.
@@ -2047,6 +2050,8 @@ namespace ts { | |||
return declareSymbolAndAddToSymbolTable(<Declaration>node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); | |||
case SyntaxKind.Parameter: | |||
return bindParameter(<ParameterDeclaration>node); | |||
case SyntaxKind.JSDocFunctionTypeParameter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation
case JSDocFunctionTypeParameterSort.New: | ||
return "new" as __String; | ||
case JSDocFunctionTypeParameterSort.This: | ||
return "this" as __String; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think these names matter since won't be used later.
@@ -360,6 +360,7 @@ namespace ts { | |||
JSDocNonNullableType, | |||
JSDocOptionalType, | |||
JSDocFunctionType, | |||
JSDocFunctionTypeParameter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSDocParameter
is a better name
@@ -6423,14 +6427,14 @@ namespace ts { | |||
const classType = declaration.kind === SyntaxKind.Constructor ? | |||
getDeclaredTypeOfClassOrInterface(getMergedSymbol((<ClassDeclaration>declaration.parent).symbol)) | |||
: undefined; | |||
const typeParameters = classType ? classType.localTypeParameters : getTypeParametersFromDeclaration(declaration); | |||
const typeParameters = classType ? classType.localTypeParameters : declaration.kind === SyntaxKind.JSDocFunctionType ? emptyArray : getTypeParametersFromDeclaration(declaration); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like getTypeParametersFromDeclaration
could handle jsdoc functions too, since it calls getEffectiveTypeParameters
to provide precisely that level of abstraction.
@@ -2085,8 +2086,23 @@ namespace ts { | |||
type: TypeNode; | |||
} | |||
|
|||
export interface JSDocFunctionType extends JSDocType, SignatureDeclaration { | |||
export interface JSDocFunctionType extends JSDocType, Declaration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to remove SyntaxKind.JSDocFunctionType
from SignatureDeclaration.kind
.
This, | ||
New, | ||
} | ||
export interface JSDocFunctionTypeParameterDeclaration extends Declaration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similarly, rename to JSDocParameterDeclaration
@Andy-MS is this still needed? |
Does not seem to be needed. closing for now. please reopen if that is not the case. |
Fixes #17403
In order to keep
ParameterDeclaration.name
defined, we should stop reusing it for nodes that do not have names. A parameter infunction(number, number): string
(Ref: #17074, #17326)