Skip to content

Commit

Permalink
avoid wasm stack overflow in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Feb 3, 2023
1 parent efd6590 commit d720969
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/js_parser/js_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -8926,6 +8926,17 @@ func (p *parser) visitLoopBody(stmt js_ast.Stmt) js_ast.Stmt {
}

func (p *parser) visitSingleStmt(stmt js_ast.Stmt, kind stmtsKind) js_ast.Stmt {
// To reduce stack depth, special-case blocks and process their children directly
if block, ok := stmt.Data.(*js_ast.SBlock); ok {
p.pushScopeForVisitPass(js_ast.ScopeBlock, stmt.Loc)
block.Stmts = p.visitStmts(block.Stmts, kind)
p.popScope()
if p.options.minifySyntax {
stmt = stmtsToSingleStmt(stmt.Loc, block.Stmts)
}
return stmt
}

// Introduce a fake block scope for function declarations inside if statements
fn, ok := stmt.Data.(*js_ast.SFunction)
hasIfScope := ok && fn.Fn.HasIfScope
Expand Down

0 comments on commit d720969

Please sign in to comment.