Skip to content
Open
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
3 changes: 3 additions & 0 deletions internal/api/encoder/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ func getChildrenPropertyMask(node *ast.Node) uint8 {
case ast.KindIfStatement:
n := node.AsIfStatement()
return (boolToByte(n.Expression != nil) << 0) | (boolToByte(n.ThenStatement != nil) << 1) | (boolToByte(n.ElseStatement != nil) << 2)
case ast.KindDistributeStatement:
n := node.AsDistributeStatement()
return (boolToByte(n.Expression != nil) << 0) | (boolToByte(n.Statement != nil) << 1)
case ast.KindDoStatement:
n := node.AsDoStatement()
return (boolToByte(n.Statement != nil) << 0) | (boolToByte(n.Expression != nil) << 1)
Expand Down
53 changes: 53 additions & 0 deletions internal/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ type NodeFactory struct {
heritageClausePool core.Pool[HeritageClause]
identifierPool core.Pool[Identifier]
ifStatementPool core.Pool[IfStatement]
distributeStatementPool core.Pool[DistributeStatement]
importSpecifierPool core.Pool[ImportSpecifier]
indexedAccessTypeNodePool core.Pool[IndexedAccessTypeNode]
interfaceDeclarationPool core.Pool[InterfaceDeclaration]
Expand Down Expand Up @@ -389,6 +390,8 @@ func (n *Node) Expression() *Node {
return n.AsPartiallyEmittedExpression().Expression
case KindIfStatement:
return n.AsIfStatement().Expression
case KindDistributeStatement:
return n.AsDistributeStatement().Expression
case KindDoStatement:
return n.AsDoStatement().Expression
case KindWhileStatement:
Expand Down Expand Up @@ -1060,6 +1063,8 @@ func (n *Node) Statement() *Statement {
return n.AsWithStatement().Statement
case KindLabeledStatement:
return n.AsLabeledStatement().Statement
case KindDistributeStatement:
return n.AsDistributeStatement().Statement
}
panic("Unhandled case in Node.Statement: " + n.Kind.String())
}
Expand Down Expand Up @@ -1346,6 +1351,10 @@ func (n *Node) AsIfStatement() *IfStatement {
return n.data.(*IfStatement)
}

func (n *Node) AsDistributeStatement() *DistributeStatement {
return n.data.(*DistributeStatement)
}

func (n *Node) AsWhileStatement() *WhileStatement {
return n.data.(*WhileStatement)
}
Expand Down Expand Up @@ -2961,6 +2970,50 @@ func IsIfStatement(node *Node) bool {
return node.Kind == KindIfStatement
}

// DistributeStatement

type DistributeStatement struct {
StatementBase
compositeNodeBase
Expression *Expression // Expression
Statement *Statement // Statement
}

func (f *NodeFactory) NewDistributeStatement(expression *Expression, statement *Statement) *Node {
data := f.distributeStatementPool.New()
data.Expression = expression
data.Statement = statement
return f.newNode(KindDistributeStatement, data)
}

func (f *NodeFactory) UpdateDistributeStatement(node *DistributeStatement, expression *Expression, statement *Statement) *Node {
if expression != node.Expression || statement != node.Statement {
return updateNode(f.NewDistributeStatement(expression, statement), node.AsNode(), f.hooks)
}
return node.AsNode()
}

func (node *DistributeStatement) ForEachChild(v Visitor) bool {
return visit(v, node.Expression) || visit(v, node.Statement)
}

func (node *DistributeStatement) VisitEachChild(v *NodeVisitor) *Node {
return v.Factory.UpdateDistributeStatement(node, v.visitNode(node.Expression), v.visitEmbeddedStatement(node.Statement))
}

func (node *DistributeStatement) Clone(f NodeFactoryCoercible) *Node {
return cloneNode(f.AsNodeFactory().NewDistributeStatement(node.Expression, node.Statement), node.AsNode(), f.AsNodeFactory().hooks)
}

func (node *DistributeStatement) computeSubtreeFacts() SubtreeFacts {
return propagateSubtreeFacts(node.Expression) |
propagateSubtreeFacts(node.Statement) | SubtreeContainsTypeScript | SubtreeContainsDistributeStatement
}

func IsDistributeStatement(node *Node) bool {
return node.Kind == KindDistributeStatement
}

// DoStatement

type DoStatement struct {
Expand Down
1 change: 1 addition & 0 deletions internal/ast/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
FlowFlagsReduceLabel FlowFlags = 1 << 10 // Temporarily reduce antecedents of label
FlowFlagsReferenced FlowFlags = 1 << 11 // Referenced as antecedent once
FlowFlagsShared FlowFlags = 1 << 12 // Referenced as antecedent more than once
FlowFlagsDistribute FlowFlags = 1 << 13
FlowFlagsLabel = FlowFlagsBranchLabel | FlowFlagsLoopLabel
FlowFlagsCondition = FlowFlagsTrueCondition | FlowFlagsFalseCondition
)
Expand Down
2 changes: 2 additions & 0 deletions internal/ast/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ const (
KindForKeyword
KindFunctionKeyword
KindIfKeyword
KindDistributeKeyword
KindImportKeyword
KindInKeyword
KindInstanceOfKeyword
Expand Down Expand Up @@ -271,6 +272,7 @@ const (
KindVariableStatement
KindExpressionStatement
KindIfStatement
KindDistributeStatement
KindDoStatement
KindWhileStatement
KindForStatement
Expand Down
Loading