Skip to content

Commit 17cc25c

Browse files
committed
feat: moving nil check to call sites of IsFunctionLikeDeclaration
1 parent 026e5f9 commit 17cc25c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

internal/ast/utilities.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,9 @@ func isFunctionLikeDeclarationKind(kind Kind) bool {
494494
}
495495

496496
// Determines if a node is function-like (but is not a signature declaration)
497+
// ensure node != nil before calling this
497498
func IsFunctionLikeDeclaration(node *Node) bool {
498-
// TODO(rbuckton): Move `node != nil` test to call sites
499-
return node != nil && isFunctionLikeDeclarationKind(node.Kind)
499+
return isFunctionLikeDeclarationKind(node.Kind)
500500
}
501501

502502
func isFunctionLikeKind(kind Kind) bool {
@@ -2369,12 +2369,12 @@ func GetImpliedNodeFormatForEmitWorker(sourceFile *SourceFile, options *core.Com
23692369
}
23702370
if sourceFile.ImpliedNodeFormat == core.ModuleKindCommonJS &&
23712371
( /*sourceFile.packageJsonScope.contents.packageJsonContent.type == "commonjs" ||*/ // !!!
2372-
tspath.FileExtensionIsOneOf(sourceFile.FileName(), []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
2372+
tspath.FileExtensionIsOneOf(sourceFile.FileName(), []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
23732373
return core.ModuleKindCommonJS
23742374
}
23752375
if sourceFile.ImpliedNodeFormat == core.ModuleKindESNext &&
23762376
( /*sourceFile.packageJsonScope?.contents.packageJsonContent.type === "module" ||*/ // !!!
2377-
tspath.FileExtensionIsOneOf(sourceFile.fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
2377+
tspath.FileExtensionIsOneOf(sourceFile.fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
23782378
return core.ModuleKindESNext
23792379
}
23802380
return core.ModuleKindNone

internal/checker/checker.go

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

73667366
func (c *Checker) isInConstructorArgumentInitializer(node *ast.Node, constructorDecl *ast.Node) bool {
73677367
return ast.FindAncestorOrQuit(node, func(n *ast.Node) ast.FindAncestorResult {
7368-
if ast.IsFunctionLikeDeclaration(n) {
7368+
if n != nil && ast.IsFunctionLikeDeclaration(n) {
73697369
return ast.FindAncestorQuit
73707370
}
73717371
if ast.IsParameter(n) && n.Parent == constructorDecl {
@@ -11128,7 +11128,7 @@ func (c *Checker) isNodeUsedDuringClassInitialization(node *ast.Node) bool {
1112811128
return ast.FindAncestorOrQuit(node, func(element *ast.Node) ast.FindAncestorResult {
1112911129
if ast.IsConstructorDeclaration(element) && ast.NodeIsPresent(element.Body()) || ast.IsPropertyDeclaration(element) {
1113011130
return ast.FindAncestorTrue
11131-
} else if ast.IsClassLike(element) || ast.IsFunctionLikeDeclaration(element) {
11131+
} else if ast.IsClassLike(element) || (element != nil && ast.IsFunctionLikeDeclaration(element)) {
1113211132
return ast.FindAncestorQuit
1113311133
}
1113411134
return ast.FindAncestorFalse
@@ -18582,7 +18582,7 @@ func (c *Checker) createGeneratorType(yieldType *Type, returnType *Type, nextTyp
1858218582

1858318583
func (c *Checker) reportErrorsFromWidening(declaration *ast.Node, t *Type, wideningKind WideningKind) {
1858418584
if c.noImplicitAny && t.objectFlags&ObjectFlagsContainsWideningType != 0 {
18585-
if wideningKind == WideningKindNormal || ast.IsFunctionLikeDeclaration(declaration) && c.shouldReportErrorsFromWideningWithContextualSignature(declaration, wideningKind) {
18585+
if wideningKind == WideningKindNormal || declaration != nil && ast.IsFunctionLikeDeclaration(declaration) && c.shouldReportErrorsFromWideningWithContextualSignature(declaration, wideningKind) {
1858618586
// Report implicit any error within type if possible, otherwise report error on declaration
1858718587
if !c.reportWideningErrorsInType(t) {
1858818588
c.reportImplicitAny(declaration, t, wideningKind)

internal/checker/grammarchecks.go

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

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

0 commit comments

Comments
 (0)