Skip to content

More type checking #373

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

Merged
merged 5 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 1 addition & 4 deletions internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,6 @@ func (node *FunctionLikeBase) LocalsContainerData() *LocalsContainerBase {
return &node.LocalsContainerBase
}
func (node *FunctionLikeBase) FunctionLikeData() *FunctionLikeBase { return node }
func (node *FunctionLikeBase) BodyData() *BodyBase { return nil }

// BodyBase

Expand Down Expand Up @@ -2779,8 +2778,6 @@ func (node *FunctionDeclaration) Name() *DeclarationName {
return node.name
}

func (node *FunctionDeclaration) BodyData() *BodyBase { return &node.BodyBase }

func IsFunctionDeclaration(node *Node) bool {
return node.Kind == KindFunctionDeclaration
}
Expand Down Expand Up @@ -3127,8 +3124,8 @@ type ModuleDeclaration struct {
ExportableBase
ModifiersBase
LocalsContainerBase
BodyBase
name *ModuleName // ModuleName
Body *ModuleBody // ModuleBody. Optional (may be nil in ambient module declaration)
}

func (f *NodeFactory) NewModuleDeclaration(modifiers *ModifierList, name *ModuleName, body *ModuleBody, flags NodeFlags) *Node {
Expand Down
2 changes: 1 addition & 1 deletion internal/ast/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const (
InternalSymbolNameFunction = InternalSymbolNamePrefix + "function" // Unnamed function expression
InternalSymbolNameComputed = InternalSymbolNamePrefix + "computed" // Computed property name declaration with dynamic name
InternalSymbolNameResolving = InternalSymbolNamePrefix + "resolving" // Indicator symbol used to mark partially resolved type aliases
InternalSymbolNameExportEquals = InternalSymbolNamePrefix + "export=" // Export assignment symbol
InternalSymbolNameInstantiationExpression = InternalSymbolNamePrefix + "instantiationExpression" // Instantiation expressions
InternalSymbolNameImportAttributes = InternalSymbolNamePrefix + "importAttributes"
InternalSymbolNameExportEquals = "export=" // Export assignment symbol
InternalSymbolNameDefault = "default" // Default export symbol (technically not wholly internal, but included here for usability)
InternalSymbolNameThis = "this"
)
Expand Down
3 changes: 2 additions & 1 deletion internal/ast/symbolflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ const (
SymbolFlagsModuleExports SymbolFlags = 1 << 27 // Symbol for CommonJS `module` of `module.exports`
SymbolFlagsConstEnumOnlyModule SymbolFlags = 1 << 28 // Module contains only const enums or other modules with only const enums
SymbolFlagsReplaceableByMethod SymbolFlags = 1 << 29
SymbolFlagsAll SymbolFlags = 0xFFFFFFFF
SymbolFlagsGlobalLookup SymbolFlags = 1 << 30 // Flag to signal this is a global lookup
SymbolFlagsAll SymbolFlags = 1<<30 - 1 // All flags except SymbolFlagsGlobalLookup

SymbolFlagsEnum = SymbolFlagsRegularEnum | SymbolFlagsConstEnum
SymbolFlagsVariable = SymbolFlagsFunctionScopedVariable | SymbolFlagsBlockScopedVariable
Expand Down
21 changes: 17 additions & 4 deletions internal/ast/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ func GetAssignmentTarget(node *Node) *Node {
}
}

func isLogicalBinaryOperator(token Kind) bool {
func IsLogicalBinaryOperator(token Kind) bool {
return token == KindBarBarToken || token == KindAmpersandAmpersandToken
}

func IsLogicalOrCoalescingBinaryOperator(token Kind) bool {
return isLogicalBinaryOperator(token) || token == KindQuestionQuestionToken
return IsLogicalBinaryOperator(token) || token == KindQuestionQuestionToken
}

func IsLogicalOrCoalescingBinaryExpression(expr *Node) bool {
Expand Down Expand Up @@ -858,8 +858,7 @@ func SetParentInChildren(parent *Node) {
// Walks up the parents of a node to find the ancestor that matches the callback
func FindAncestor(node *Node, callback func(*Node) bool) *Node {
for node != nil {
result := callback(node)
if result {
if callback(node) {
return node
}
node = node.Parent
Expand Down Expand Up @@ -1589,6 +1588,16 @@ func GetExternalModuleName(node *Node) *Expression {
panic("Unhandled case in getExternalModuleName")
}

func GetImportAttributes(node *Node) *Node {
switch node.Kind {
case KindImportDeclaration:
return node.AsImportDeclaration().Attributes
case KindExportDeclaration:
return node.AsExportDeclaration().Attributes
}
panic("Unhandled case in getImportAttributes")
}

func getImportTypeNodeLiteral(node *Node) *Node {
if IsImportTypeNode(node) {
importTypeNode := node.AsImportTypeNode()
Expand Down Expand Up @@ -2139,6 +2148,10 @@ func NodeHasName(statement *Node, id *Node) bool {
return false
}

func IsInternalModuleImportEqualsDeclaration(node *Node) bool {
return IsImportEqualsDeclaration(node) && node.AsImportEqualsDeclaration().ModuleReference.Kind != KindExternalModuleReference
}

func GetAssertedTypeNode(node *Node) *Node {
switch node.Kind {
case KindAsExpression:
Expand Down
2 changes: 1 addition & 1 deletion internal/binder/nameresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ loop:
}
if result == nil {
if !excludeGlobals {
result = r.lookup(r.Globals, name, meaning)
result = r.lookup(r.Globals, name, meaning|ast.SymbolFlagsGlobalLookup)
}
}
if nameNotFoundMessage != nil {
Expand Down
Loading
Loading