Skip to content

Commit

Permalink
Add NestedExprLimit and NestedStmtLimit as variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jan 19, 2025
1 parent e08c019 commit 2ce0346
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions js/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/tdewolff/parse/v2/buffer"
)

var NestedStmtLimit = 1000
var NestedExprLimit = 1000

type Options struct {
WhileToFor bool
Inline bool
Expand Down Expand Up @@ -223,7 +226,7 @@ func (p *Parser) parseModule() (module BlockStmt) {

func (p *Parser) parseStmt(allowDeclaration bool) (stmt IStmt) {
p.stmtLevel++
if 1000 < p.stmtLevel {
if NestedStmtLimit < p.stmtLevel {
p.failMessage("too many nested statements")
return nil
}
Expand Down Expand Up @@ -1613,7 +1616,7 @@ func (p *Parser) parseAsyncExpression(prec OpPrec, async []byte) IExpr {
// parseExpression parses an expression that has a precedence of prec or higher.
func (p *Parser) parseExpression(prec OpPrec) IExpr {
p.exprLevel++
if 1000 < p.exprLevel {
if NestedExprLimit < p.exprLevel {
p.failMessage("too many nested expressions")
return nil
}
Expand Down

0 comments on commit 2ce0346

Please sign in to comment.