Closed pglass closed 1 year ago
This fixes a panic when the a mixin contains a block. (This might only happen when it is the first mixin in a file?)
To reproduce, run jade on the following test.pug file
test.pug
mixin func1 div if len(block) > 0 block +func1 +func1 p test
$ jade test.pug 2023/05/05 22:54:29 file: "/Users/pglass/code/jade-test/test.pug" panic: runtime error: index out of range [-1] goroutine 1 [running]: main.(*goAST).checkUnresolvedBlock.func1({0x149f898?, 0xc000105000?}) /Users/pglass/go/pkg/mod/github.com/!joker/jade@v1.1.3/cmd/jade/go_ast_unbk.go:35 +0x17d go/ast.inspector.Visit(0xc000bb5800, {0x149f898?, 0xc000105000?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:386 +0x31 go/ast.Walk({0x149eec0?, 0xc000bb5800?}, {0x149f898?, 0xc000105000?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:51 +0x5f go/ast.Walk({0x149eec0?, 0xc000bb5800?}, {0x149fa50?, 0xc000055560?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:206 +0xbeb go/ast.walkStmtList({0x149eec0, 0xc000bb5800}, {0xc000055570?, 0x1, 0x149f848?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:32 +0x69 go/ast.Walk({0x149eec0?, 0xc000bb5800?}, {0x149f848?, 0xc0001bc3f0?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:234 +0xe0d go/ast.Walk({0x149eec0?, 0xc000bb5800?}, {0x149fc08?, 0xc000105040?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:241 +0xebd go/ast.walkStmtList({0x149eec0, 0xc000bb5800}, {0xc000104f80?, 0x4, 0x112fcb1?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:32 +0x69 go/ast.Walk({0x149eec0?, 0xc000bb5800?}, {0x149f848?, 0xc0001bc420?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:234 +0xe0d go/ast.walkStmtList({0x149eec0, 0xc000bb5800}, {0xc000022e20?, 0x2, 0x149f848?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:32 +0x69 go/ast.Walk({0x149eec0?, 0xc000bb5800?}, {0x149f848?, 0xc0001bc540?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:234 +0xe0d go/ast.Walk({0x149eec0?, 0xc000bb5800?}, {0x149fb18?, 0xc0001bc570?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:357 +0x173c go/ast.walkDeclList({0x149eec0, 0xc000bb5800}, {0xc000105440?, 0x3, 0x100cd4d?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:38 +0x69 go/ast.Walk({0x149eec0?, 0xc000bb5800?}, {0x149fac8?, 0xc00014a870?}) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:366 +0x17ac go/ast.Inspect(...) /usr/local/Cellar/go/1.20.3/libexec/src/go/ast/walk.go:397 main.(*goAST).checkUnresolvedBlock(0xc000ae3bc0) /Users/pglass/go/pkg/mod/github.com/!joker/jade@v1.1.3/cmd/jade/go_ast_unbk.go:11 +0xc5 main.genFile({0xc0000261e0, 0x25}, {0xc00002c1e0, 0x1c}, {0x1c?, 0x1415c4f?}) /Users/pglass/go/pkg/mod/github.com/!joker/jade@v1.1.3/cmd/jade/main.go:143 +0xa45 main.main() /Users/pglass/go/pkg/mod/github.com/!joker/jade@v1.1.3/cmd/jade/main.go:205 +0x33c
This fixes a panic when the a mixin contains a block. (This might only happen when it is the first mixin in a file?)
To reproduce, run jade on the following
test.pug
file