Skip to content

Commit 2ce0346

Browse files
committed
Add NestedExprLimit and NestedStmtLimit as variables
1 parent e08c019 commit 2ce0346

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

js/parse.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import (
1010
"github.com/tdewolff/parse/v2/buffer"
1111
)
1212

13+
var NestedStmtLimit = 1000
14+
var NestedExprLimit = 1000
15+
1316
type Options struct {
1417
WhileToFor bool
1518
Inline bool
@@ -223,7 +226,7 @@ func (p *Parser) parseModule() (module BlockStmt) {
223226

224227
func (p *Parser) parseStmt(allowDeclaration bool) (stmt IStmt) {
225228
p.stmtLevel++
226-
if 1000 < p.stmtLevel {
229+
if NestedStmtLimit < p.stmtLevel {
227230
p.failMessage("too many nested statements")
228231
return nil
229232
}
@@ -1613,7 +1616,7 @@ func (p *Parser) parseAsyncExpression(prec OpPrec, async []byte) IExpr {
16131616
// parseExpression parses an expression that has a precedence of prec or higher.
16141617
func (p *Parser) parseExpression(prec OpPrec) IExpr {
16151618
p.exprLevel++
1616-
if 1000 < p.exprLevel {
1619+
if NestedExprLimit < p.exprLevel {
16171620
p.failMessage("too many nested expressions")
16181621
return nil
16191622
}

0 commit comments

Comments
 (0)