Skip to content

Commit ebb5380

Browse files
authored
More type checking (#184)
1 parent 84681cd commit ebb5380

File tree

7 files changed

+1280
-128
lines changed

7 files changed

+1280
-128
lines changed

internal/ast/ast.go

+13
Original file line numberDiff line numberDiff line change
@@ -4260,6 +4260,10 @@ func (node *TupleTypeNode) ForEachChild(v Visitor) bool {
42604260
return visitNodeList(v, node.Elements)
42614261
}
42624262

4263+
func IsTupleTypeNode(node *Node) bool {
4264+
return node.Kind == KindTupleType
4265+
}
4266+
42634267
// NamedTupleTypeMember
42644268

42654269
type NamedTupleMember struct {
@@ -4287,6 +4291,7 @@ func (node *NamedTupleMember) ForEachChild(v Visitor) bool {
42874291
func (node *NamedTupleMember) Name() *DeclarationName {
42884292
return node.name
42894293
}
4294+
42904295
func IsNamedTupleMember(node *Node) bool {
42914296
return node.Kind == KindNamedTupleMember
42924297
}
@@ -4308,6 +4313,10 @@ func (node *OptionalTypeNode) ForEachChild(v Visitor) bool {
43084313
return visit(v, node.Type)
43094314
}
43104315

4316+
func IsOptionalTypeNode(node *Node) bool {
4317+
return node.Kind == KindOptionalType
4318+
}
4319+
43114320
// RestTypeNode
43124321

43134322
type RestTypeNode struct {
@@ -4325,6 +4334,10 @@ func (node *RestTypeNode) ForEachChild(v Visitor) bool {
43254334
return visit(v, node.Type)
43264335
}
43274336

4337+
func IsRestTypeNode(node *Node) bool {
4338+
return node.Kind == KindRestType
4339+
}
4340+
43284341
// ParenthesizedTypeNode
43294342

43304343
type ParenthesizedTypeNode struct {

internal/ast/utilities.go

+15
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,13 @@ func SkipParentheses(node *Expression) *Expression {
553553
return SkipOuterExpressions(node, OEKParentheses)
554554
}
555555

556+
func SkipTypeParentheses(node *Node) *Node {
557+
for IsParenthesizedTypeNode(node) {
558+
node = node.AsParenthesizedTypeNode().Type
559+
}
560+
return node
561+
}
562+
556563
func SkipPartiallyEmittedExpressions(node *Expression) *Expression {
557564
return SkipOuterExpressions(node, OEKPartiallyEmittedExpressions)
558565
}
@@ -843,6 +850,14 @@ func IsImportMeta(node *Node) bool {
843850
return false
844851
}
845852

853+
func WalkUpBindingElementsAndPatterns(binding *Node) *Node {
854+
node := binding.Parent
855+
for IsBindingElement(node.Parent) {
856+
node = node.Parent.Parent
857+
}
858+
return node.Parent
859+
}
860+
846861
func IsInJSFile(node *Node) bool {
847862
return node != nil && node.Flags&NodeFlagsJavaScriptFile != 0
848863
}

0 commit comments

Comments
 (0)