Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion _submodules/TypeScript
Submodule TypeScript updated 10777 files
14 changes: 7 additions & 7 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/binder/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/checker/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/checker/grammarchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

The nil check is only applied to the first condition in the OR expression. The call to ast.IsClassLike(parent) and other functions on subsequent lines also need nil checks for parent.

Copilot uses AI. Check for mistakes.

ast.IsFunctionTypeNode(parent) || ast.IsConstructorTypeNode(parent) ||
ast.IsCallSignatureDeclaration(parent) || ast.IsConstructSignatureDeclaration(parent) ||
ast.IsMethodSignatureDeclaration(parent)) {
Expand Down Expand Up @@ -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)) {
Copy link
Preview

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

The nil check is only applied to the first condition in the OR expression. The call to ast.IsAccessor(node.Parent) also needs a nil check for node.Parent.

Suggested change
if !links.hasReportedStatementInAmbientContext && (node.Parent != nil && ast.IsFunctionLike(node.Parent) || ast.IsAccessor(node.Parent)) {
if !links.hasReportedStatementInAmbientContext && node.Parent != nil && (ast.IsFunctionLike(node.Parent) || ast.IsAccessor(node.Parent)) {

Copilot uses AI. Check for mistakes.

links.hasReportedStatementInAmbientContext = c.grammarErrorOnFirstToken(node, diagnostics.An_implementation_cannot_be_declared_in_ambient_contexts)
return links.hasReportedStatementInAmbientContext
}
Expand Down