Skip to content

Commit

Permalink
JS: accept shebang comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Mar 15, 2021
1 parent 7ec26ab commit 6b56eb6
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion js/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ type Parser struct {

// Parse returns a JS AST tree of.
func Parse(r *parse.Input) (*AST, error) {
ast := &AST{}
p := &Parser{
l: NewLexer(r),
tt: WhitespaceToken, // trick so that next() works
}

ast := &AST{}
// process shebang
if r.Peek(0) == '#' && r.Peek(1) == '!' {
r.Move(2)
p.l.consumeSingleLineComment() // consume till end-of-line
ast.Comments = append(ast.Comments, r.Shift())
}

p.tt, p.data = p.l.Next()
for p.tt == CommentToken || p.tt == CommentLineTerminatorToken {
ast.Comments = append(ast.Comments, p.data)
Expand Down

0 comments on commit 6b56eb6

Please sign in to comment.