Skip to content

Commit 2a615d2

Browse files
committed
feat: moving nil check to call sites of IsFunctionLikeDeclaration
# Conflicts: # internal/ast/utilities.go
1 parent 12cbd18 commit 2a615d2

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

internal/ast/utilities.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,9 @@ func isFunctionLikeDeclarationKind(kind Kind) bool {
514514
}
515515

516516
// Determines if a node is function-like (but is not a signature declaration)
517+
// ensure node != nil before calling this
517518
func IsFunctionLikeDeclaration(node *Node) bool {
518-
// TODO(rbuckton): Move `node != nil` test to call sites
519-
return node != nil && isFunctionLikeDeclarationKind(node.Kind)
519+
return isFunctionLikeDeclarationKind(node.Kind)
520520
}
521521

522522
func IsFunctionLikeKind(kind Kind) bool {

internal/checker/checker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7656,7 +7656,7 @@ func (c *Checker) checkSuperExpression(node *ast.Node) *Type {
76567656

76577657
func (c *Checker) isInConstructorArgumentInitializer(node *ast.Node, constructorDecl *ast.Node) bool {
76587658
return ast.FindAncestorOrQuit(node, func(n *ast.Node) ast.FindAncestorResult {
7659-
if ast.IsFunctionLikeDeclaration(n) {
7659+
if n != nil && ast.IsFunctionLikeDeclaration(n) {
76607660
return ast.FindAncestorQuit
76617661
}
76627662
if ast.IsParameter(n) && n.Parent == constructorDecl {
@@ -11415,7 +11415,7 @@ func (c *Checker) isNodeUsedDuringClassInitialization(node *ast.Node) bool {
1141511415
return ast.FindAncestorOrQuit(node, func(element *ast.Node) ast.FindAncestorResult {
1141611416
if ast.IsConstructorDeclaration(element) && ast.NodeIsPresent(element.Body()) || ast.IsPropertyDeclaration(element) {
1141711417
return ast.FindAncestorTrue
11418-
} else if ast.IsClassLike(element) || ast.IsFunctionLikeDeclaration(element) {
11418+
} else if ast.IsClassLike(element) || (element != nil && ast.IsFunctionLikeDeclaration(element)) {
1141911419
return ast.FindAncestorQuit
1142011420
}
1142111421
return ast.FindAncestorFalse
@@ -19474,7 +19474,7 @@ func (c *Checker) createGeneratorType(yieldType *Type, returnType *Type, nextTyp
1947419474

1947519475
func (c *Checker) reportErrorsFromWidening(declaration *ast.Node, t *Type, wideningKind WideningKind) {
1947619476
if c.noImplicitAny && t.objectFlags&ObjectFlagsContainsWideningType != 0 {
19477-
if wideningKind == WideningKindNormal || ast.IsFunctionLikeDeclaration(declaration) && c.shouldReportErrorsFromWideningWithContextualSignature(declaration, wideningKind) {
19477+
if wideningKind == WideningKindNormal || declaration != nil && ast.IsFunctionLikeDeclaration(declaration) && c.shouldReportErrorsFromWideningWithContextualSignature(declaration, wideningKind) {
1947819478
// Report implicit any error within type if possible, otherwise report error on declaration
1947919479
if !c.reportWideningErrorsInType(t) {
1948019480
c.reportImplicitAny(declaration, t, wideningKind)

internal/checker/grammarchecks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (c *Checker) checkGrammarModifiers(node *ast.Node /*Union[HasModifiers, Has
295295
parent := node.Parent
296296

297297
if node.Kind == ast.KindTypeParameter {
298-
if !(ast.IsFunctionLikeDeclaration(parent) || ast.IsClassLike(parent) ||
298+
if !((parent != nil && ast.IsFunctionLikeDeclaration(parent)) || ast.IsClassLike(parent) ||
299299
ast.IsFunctionTypeNode(parent) || ast.IsConstructorTypeNode(parent) ||
300300
ast.IsCallSignatureDeclaration(parent) || ast.IsConstructSignatureDeclaration(parent) ||
301301
ast.IsMethodSignatureDeclaration(parent)) {

0 commit comments

Comments
 (0)