Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: infinite loop regression in literal (parse/ast) mode #620

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/thick-wombats-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/compiler': patch
---

Fix regression introduced to `parse` handling in the last patch
56 changes: 29 additions & 27 deletions internal/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2670,36 +2670,38 @@ func frontmatterIM(p *parser) bool {

// Handle content very literally
func inLiteralIM(p *parser) bool {
if !p.exitLiteralIM() {
switch p.tok.Type {
case ErrorToken:
p.oe.pop()
case TextToken:
p.addText(p.tok.Data)
return true
case StartTagToken:
p.addElement()
if p.hasSelfClosingToken {
p.oe.pop()
p.acknowledgeSelfClosingTag()
}
return true
case EndTagToken:
p.addLoc()
p.oe.pop()
return true
case StartExpressionToken:
p.addExpression()
return true
case EndExpressionToken:
p.addLoc()
shouldExit := p.exitLiteralIM()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Immediately check if we should exit after this token is handled

switch p.tok.Type {
case ErrorToken:
// Stop parsing.
case TextToken:
p.addText(p.tok.Data)
case StartTagToken:
p.addElement()
if p.hasSelfClosingToken {
p.oe.pop()
return true
p.acknowledgeSelfClosingTag()
}
case CommentToken:
p.addChild(&Node{
Type: CommentNode,
Data: p.tok.Data,
Loc: p.generateLoc(),
})
case EndTagToken:
p.addLoc()
p.oe.pop()
case StartExpressionToken:
p.addExpression()
case EndExpressionToken:
p.addLoc()
p.oe.pop()
}
p.im = p.originalIM
p.originalIM = nil
return p.tok.Type == EndTagToken
if shouldExit {
p.im = p.originalIM
p.originalIM = nil
}
Comment on lines +2704 to +2707
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we should exit, do it! Resets to the previous insertion mode

return true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise, consider this token handled and continue inLiteralIM

}

func inExpressionIM(p *parser) bool {
Expand Down