From 2a615d2044d9068c26f84e8916d90a86a2764874 Mon Sep 17 00:00:00 2001
From: SoulPancake <angbpy@gmail.com>
Date: Tue, 18 Mar 2025 13:07:45 +0530
Subject: [PATCH 1/8] feat: moving nil check to call sites of
 IsFunctionLikeDeclaration

# Conflicts:
#	internal/ast/utilities.go
---
 internal/ast/utilities.go         | 4 ++--
 internal/checker/checker.go       | 6 +++---
 internal/checker/grammarchecks.go | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go
index 5c5fd2314d..de58dea839 100644
--- a/internal/ast/utilities.go
+++ b/internal/ast/utilities.go
@@ -514,9 +514,9 @@ func isFunctionLikeDeclarationKind(kind Kind) bool {
 }
 
 // Determines if a node is function-like (but is not a signature declaration)
+// ensure node != nil before calling this
 func IsFunctionLikeDeclaration(node *Node) bool {
-	// TODO(rbuckton): Move `node != nil` test to call sites
-	return node != nil && isFunctionLikeDeclarationKind(node.Kind)
+	return isFunctionLikeDeclarationKind(node.Kind)
 }
 
 func IsFunctionLikeKind(kind Kind) bool {
diff --git a/internal/checker/checker.go b/internal/checker/checker.go
index 75b2f72d53..ed856db253 100644
--- a/internal/checker/checker.go
+++ b/internal/checker/checker.go
@@ -7656,7 +7656,7 @@ func (c *Checker) checkSuperExpression(node *ast.Node) *Type {
 
 func (c *Checker) isInConstructorArgumentInitializer(node *ast.Node, constructorDecl *ast.Node) bool {
 	return ast.FindAncestorOrQuit(node, func(n *ast.Node) ast.FindAncestorResult {
-		if ast.IsFunctionLikeDeclaration(n) {
+		if n != nil && ast.IsFunctionLikeDeclaration(n) {
 			return ast.FindAncestorQuit
 		}
 		if ast.IsParameter(n) && n.Parent == constructorDecl {
@@ -11415,7 +11415,7 @@ func (c *Checker) isNodeUsedDuringClassInitialization(node *ast.Node) bool {
 	return ast.FindAncestorOrQuit(node, func(element *ast.Node) ast.FindAncestorResult {
 		if ast.IsConstructorDeclaration(element) && ast.NodeIsPresent(element.Body()) || ast.IsPropertyDeclaration(element) {
 			return ast.FindAncestorTrue
-		} else if ast.IsClassLike(element) || ast.IsFunctionLikeDeclaration(element) {
+		} else if ast.IsClassLike(element) || (element != nil && ast.IsFunctionLikeDeclaration(element)) {
 			return ast.FindAncestorQuit
 		}
 		return ast.FindAncestorFalse
@@ -19474,7 +19474,7 @@ func (c *Checker) createGeneratorType(yieldType *Type, returnType *Type, nextTyp
 
 func (c *Checker) reportErrorsFromWidening(declaration *ast.Node, t *Type, wideningKind WideningKind) {
 	if c.noImplicitAny && t.objectFlags&ObjectFlagsContainsWideningType != 0 {
-		if wideningKind == WideningKindNormal || ast.IsFunctionLikeDeclaration(declaration) && c.shouldReportErrorsFromWideningWithContextualSignature(declaration, wideningKind) {
+		if wideningKind == WideningKindNormal || declaration != nil && ast.IsFunctionLikeDeclaration(declaration) && c.shouldReportErrorsFromWideningWithContextualSignature(declaration, wideningKind) {
 			// Report implicit any error within type if possible, otherwise report error on declaration
 			if !c.reportWideningErrorsInType(t) {
 				c.reportImplicitAny(declaration, t, wideningKind)
diff --git a/internal/checker/grammarchecks.go b/internal/checker/grammarchecks.go
index cd3cca23f3..eddd9b4181 100644
--- a/internal/checker/grammarchecks.go
+++ b/internal/checker/grammarchecks.go
@@ -295,7 +295,7 @@ func (c *Checker) checkGrammarModifiers(node *ast.Node /*Union[HasModifiers, Has
 				parent := node.Parent
 
 				if node.Kind == ast.KindTypeParameter {
-					if !(ast.IsFunctionLikeDeclaration(parent) || ast.IsClassLike(parent) ||
+					if !((parent != nil && ast.IsFunctionLikeDeclaration(parent)) || ast.IsClassLike(parent) ||
 						ast.IsFunctionTypeNode(parent) || ast.IsConstructorTypeNode(parent) ||
 						ast.IsCallSignatureDeclaration(parent) || ast.IsConstructSignatureDeclaration(parent) ||
 						ast.IsMethodSignatureDeclaration(parent)) {

From 65eca1ecdc7eb42197001f89e14c42d080112ce8 Mon Sep 17 00:00:00 2001
From: SoulPancake <angbpy@gmail.com>
Date: Tue, 18 Mar 2025 13:13:40 +0530
Subject: [PATCH 2/8] feat: revert whitespace

---
 internal/ast/utilities.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go
index de58dea839..ede9af9246 100644
--- a/internal/ast/utilities.go
+++ b/internal/ast/utilities.go
@@ -2561,12 +2561,12 @@ func GetImpliedNodeFormatForEmitWorker(fileName string, emitModuleKind core.Modu
 	}
 	if sourceFileMetaData.ImpliedNodeFormat == core.ModuleKindCommonJS &&
 		(sourceFileMetaData.PackageJsonType == "commonjs" ||
-			tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
+		tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
 		return core.ModuleKindCommonJS
 	}
 	if sourceFileMetaData.ImpliedNodeFormat == core.ModuleKindESNext &&
 		(sourceFileMetaData.PackageJsonType == "module" ||
-			tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
+		tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
 		return core.ModuleKindESNext
 	}
 	return core.ModuleKindNone

From 89c8a5b2d739bf8b39d2e2a099593e4399d7072b Mon Sep 17 00:00:00 2001
From: SoulPancake <angbpy@gmail.com>
Date: Tue, 18 Mar 2025 13:58:15 +0530
Subject: [PATCH 3/8] feat: also move the nil checks to callers for
 IsFunctionLike

---
 internal/ast/utilities.go         | 10 +++++-----
 internal/binder/binder.go         |  2 +-
 internal/checker/checker.go       |  8 ++++----
 internal/checker/flow.go          |  2 +-
 internal/checker/grammarchecks.go |  2 +-
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go
index ede9af9246..d97ba5b7a0 100644
--- a/internal/ast/utilities.go
+++ b/internal/ast/utilities.go
@@ -534,9 +534,9 @@ func IsFunctionLikeKind(kind Kind) bool {
 }
 
 // Determines if a node is function- or signature-like.
+// Ensure node != nil before calling this
 func IsFunctionLike(node *Node) bool {
-	// TODO(rbuckton): Move `node != nil` test to call sites
-	return node != nil && IsFunctionLikeKind(node.Kind)
+	return isFunctionLikeKind(node.Kind)
 }
 
 func IsFunctionLikeOrClassStaticBlockDeclaration(node *Node) bool {
@@ -1149,7 +1149,7 @@ func CanHaveDecorators(node *Node) bool {
 }
 
 func IsFunctionOrModuleBlock(node *Node) bool {
-	return IsSourceFile(node) || IsModuleBlock(node) || IsBlock(node) && IsFunctionLike(node.Parent)
+	return IsSourceFile(node) || IsModuleBlock(node) || IsBlock(node) && node.Parent != nil && IsFunctionLike(node.Parent)
 }
 
 func IsFunctionExpressionOrArrowFunction(node *Node) bool {
@@ -2561,12 +2561,12 @@ func GetImpliedNodeFormatForEmitWorker(fileName string, emitModuleKind core.Modu
 	}
 	if sourceFileMetaData.ImpliedNodeFormat == core.ModuleKindCommonJS &&
 		(sourceFileMetaData.PackageJsonType == "commonjs" ||
-		tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
+			tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
 		return core.ModuleKindCommonJS
 	}
 	if sourceFileMetaData.ImpliedNodeFormat == core.ModuleKindESNext &&
 		(sourceFileMetaData.PackageJsonType == "module" ||
-		tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
+			tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
 		return core.ModuleKindESNext
 	}
 	return core.ModuleKindNone
diff --git a/internal/binder/binder.go b/internal/binder/binder.go
index f37f203fe3..30a1e896db 100644
--- a/internal/binder/binder.go
+++ b/internal/binder/binder.go
@@ -2599,7 +2599,7 @@ func GetContainerFlags(node *ast.Node) ContainerFlags {
 	case ast.KindCatchClause, ast.KindForStatement, ast.KindForInStatement, ast.KindForOfStatement, ast.KindCaseBlock:
 		return ContainerFlagsIsBlockScopedContainer | ContainerFlagsHasLocals
 	case ast.KindBlock:
-		if ast.IsFunctionLike(node.Parent) || ast.IsClassStaticBlockDeclaration(node.Parent) {
+		if node.Parent != nil && (ast.IsFunctionLike(node.Parent) || ast.IsClassStaticBlockDeclaration(node.Parent)) {
 			return ContainerFlagsNone
 		} else {
 			return ContainerFlagsIsBlockScopedContainer | ContainerFlagsHasLocals
diff --git a/internal/checker/checker.go b/internal/checker/checker.go
index ed856db253..3bb5e1658d 100644
--- a/internal/checker/checker.go
+++ b/internal/checker/checker.go
@@ -5706,7 +5706,7 @@ func (c *Checker) checkVarDeclaredNamesNotShadowed(node *ast.Node) {
 				}
 				// names of block-scoped and function scoped variables can collide only
 				// if block scoped variable is defined in the function\module\source file scope (because of variable hoisting)
-				namesShareScope := container != nil && (ast.IsBlock(container) && ast.IsFunctionLike(container.Parent) ||
+				namesShareScope := container != nil && (ast.IsBlock(container) && container.Parent != nil && ast.IsFunctionLike(container.Parent) ||
 					ast.IsModuleBlock(container) || ast.IsModuleDeclaration(container) || ast.IsSourceFile(container))
 				// here we know that function scoped variable is "shadowed" by block scoped one
 				// a var declaration can't hoist past a lexical declaration and it results in a SyntaxError at runtime
@@ -11149,7 +11149,7 @@ func (c *Checker) isUncalledFunctionReference(node *ast.Node, symbol *ast.Symbol
 			return ast.IsCallOrNewExpression(parent) && ast.IsIdentifier(node) && c.hasMatchingArgument(parent, node)
 		}
 		return core.Every(symbol.Declarations, func(d *ast.Node) bool {
-			return !ast.IsFunctionLike(d) || c.IsDeprecatedDeclaration(d)
+			return d == nil || !ast.IsFunctionLike(d) || c.IsDeprecatedDeclaration(d)
 		})
 	}
 	return true
@@ -18874,7 +18874,7 @@ func (c *Checker) getSignaturesOfSymbol(symbol *ast.Symbol) []*Signature {
 	}
 	var result []*Signature
 	for i, decl := range symbol.Declarations {
-		if !ast.IsFunctionLike(decl) {
+		if decl == nil || !ast.IsFunctionLike(decl) {
 			continue
 		}
 		// Don't include signature if node is the implementation of an overloaded function. A node is considered
@@ -30094,7 +30094,7 @@ func (c *Checker) getSymbolAtLocation(node *ast.Node, ignoreErrors bool) *ast.Sy
 		fallthrough
 	case ast.KindThisKeyword:
 		container := c.getThisContainer(node, false /*includeArrowFunctions*/, false /*includeClassComputedPropertyName*/)
-		if ast.IsFunctionLike(container) {
+		if container != nil && ast.IsFunctionLike(container) {
 			sig := c.getSignatureFromDeclaration(container)
 			if sig.thisParameter != nil {
 				return sig.thisParameter
diff --git a/internal/checker/flow.go b/internal/checker/flow.go
index b8e1841171..9fb55e4f0d 100644
--- a/internal/checker/flow.go
+++ b/internal/checker/flow.go
@@ -2169,7 +2169,7 @@ func (c *Checker) hasTypePredicateOrNeverReturnType(sig *Signature) bool {
 
 func (c *Checker) getExplicitThisType(node *ast.Node) *Type {
 	container := ast.GetThisContainer(node, false /*includeArrowFunctions*/, false /*includeClassComputedPropertyName*/)
-	if ast.IsFunctionLike(container) {
+	if container != nil && ast.IsFunctionLike(container) {
 		signature := c.getSignatureFromDeclaration(container)
 		if signature.thisParameter != nil {
 			return c.getExplicitTypeOfSymbol(signature.thisParameter, nil)
diff --git a/internal/checker/grammarchecks.go b/internal/checker/grammarchecks.go
index eddd9b4181..8e6543c1ec 100644
--- a/internal/checker/grammarchecks.go
+++ b/internal/checker/grammarchecks.go
@@ -2069,7 +2069,7 @@ func (c *Checker) checkGrammarStatementInAmbientContext(node *ast.Node) bool {
 	if node.Flags&ast.NodeFlagsAmbient != 0 {
 		// Find containing block which is either Block, ModuleBlock, SourceFile
 		links := c.nodeLinks.Get(node)
-		if !links.hasReportedStatementInAmbientContext && (ast.IsFunctionLike(node.Parent) || ast.IsAccessor(node.Parent)) {
+		if !links.hasReportedStatementInAmbientContext && (node.Parent != nil && ast.IsFunctionLike(node.Parent) || ast.IsAccessor(node.Parent)) {
 			links.hasReportedStatementInAmbientContext = c.grammarErrorOnFirstToken(node, diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts)
 			return links.hasReportedStatementInAmbientContext
 		}

From 6355e4838decf2715eafa8ae6b2539d9a8de7069 Mon Sep 17 00:00:00 2001
From: SoulPancake <angbpy@gmail.com>
Date: Tue, 18 Mar 2025 14:11:15 +0530
Subject: [PATCH 4/8] feat: revert whitespace

---
 internal/ast/utilities.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go
index d97ba5b7a0..426989f4d6 100644
--- a/internal/ast/utilities.go
+++ b/internal/ast/utilities.go
@@ -2561,12 +2561,12 @@ func GetImpliedNodeFormatForEmitWorker(fileName string, emitModuleKind core.Modu
 	}
 	if sourceFileMetaData.ImpliedNodeFormat == core.ModuleKindCommonJS &&
 		(sourceFileMetaData.PackageJsonType == "commonjs" ||
-			tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
+		tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
 		return core.ModuleKindCommonJS
 	}
 	if sourceFileMetaData.ImpliedNodeFormat == core.ModuleKindESNext &&
 		(sourceFileMetaData.PackageJsonType == "module" ||
-			tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
+		tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
 		return core.ModuleKindESNext
 	}
 	return core.ModuleKindNone

From fd4cf87941cc176ef593167d17816a79e52e4fb7 Mon Sep 17 00:00:00 2001
From: SoulPancake <angbpy@gmail.com>
Date: Wed, 25 Jun 2025 11:25:28 +0530
Subject: [PATCH 5/8] feat: rebase success

---
 _submodules/TypeScript | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/_submodules/TypeScript b/_submodules/TypeScript
index add6971195..52c59dbcbe 160000
--- a/_submodules/TypeScript
+++ b/_submodules/TypeScript
@@ -1 +1 @@
-Subproject commit add697119549734b24d46b30b9f6d2e757c6d53a
+Subproject commit 52c59dbcbee274e523ef39e6c8be1bd5e110c2f1

From 77cb9b8f3bd2408f5208b8226b0bb057fa36d08e Mon Sep 17 00:00:00 2001
From: SoulPancake <angbpy@gmail.com>
Date: Wed, 25 Jun 2025 11:49:25 +0530
Subject: [PATCH 6/8] feat: kuych toih huya

---
 _submodules/TypeScript | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/_submodules/TypeScript b/_submodules/TypeScript
index 52c59dbcbe..0aac72020e 160000
--- a/_submodules/TypeScript
+++ b/_submodules/TypeScript
@@ -1 +1 @@
-Subproject commit 52c59dbcbee274e523ef39e6c8be1bd5e110c2f1
+Subproject commit 0aac72020ee8414218273f654eb7ce1dc2dd0d6b

From 2dc87d8d504da3bebe43f4bcbad1fb2e1916aff6 Mon Sep 17 00:00:00 2001
From: SoulPancake <angbpy@gmail.com>
Date: Wed, 25 Jun 2025 12:52:34 +0530
Subject: [PATCH 7/8] feat: submodule fix:

---
 _submodules/TypeScript | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/_submodules/TypeScript b/_submodules/TypeScript
index 0aac72020e..add6971195 160000
--- a/_submodules/TypeScript
+++ b/_submodules/TypeScript
@@ -1 +1 @@
-Subproject commit 0aac72020ee8414218273f654eb7ce1dc2dd0d6b
+Subproject commit add697119549734b24d46b30b9f6d2e757c6d53a

From 8723013e63e6566f880788bc10c0f58080311038 Mon Sep 17 00:00:00 2001
From: SoulPancake <angbpy@gmail.com>
Date: Fri, 27 Jun 2025 10:56:40 +0530
Subject: [PATCH 8/8] fix: remove pvt call to pub func

---
 internal/ast/utilities.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/internal/ast/utilities.go b/internal/ast/utilities.go
index 426989f4d6..e756048ccd 100644
--- a/internal/ast/utilities.go
+++ b/internal/ast/utilities.go
@@ -536,7 +536,7 @@ func IsFunctionLikeKind(kind Kind) bool {
 // Determines if a node is function- or signature-like.
 // Ensure node != nil before calling this
 func IsFunctionLike(node *Node) bool {
-	return isFunctionLikeKind(node.Kind)
+	return IsFunctionLikeKind(node.Kind)
 }
 
 func IsFunctionLikeOrClassStaticBlockDeclaration(node *Node) bool {
@@ -2561,12 +2561,12 @@ func GetImpliedNodeFormatForEmitWorker(fileName string, emitModuleKind core.Modu
 	}
 	if sourceFileMetaData.ImpliedNodeFormat == core.ModuleKindCommonJS &&
 		(sourceFileMetaData.PackageJsonType == "commonjs" ||
-		tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
+			tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionCjs, tspath.ExtensionCts})) {
 		return core.ModuleKindCommonJS
 	}
 	if sourceFileMetaData.ImpliedNodeFormat == core.ModuleKindESNext &&
 		(sourceFileMetaData.PackageJsonType == "module" ||
-		tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
+			tspath.FileExtensionIsOneOf(fileName, []string{tspath.ExtensionMjs, tspath.ExtensionMts})) {
 		return core.ModuleKindESNext
 	}
 	return core.ModuleKindNone