diff --git a/parser/lexer.go b/parser/lexer.go index 4b0e804..d2ed91a 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -239,14 +239,22 @@ func (self *_parser) scan() (tkn token.Token, literal string, idx file.Idx) { tkn = self.switch2(token.MULTIPLY, token.MULTIPLY_ASSIGN) case '/': if self.chr == '/' { - runes := self.readSingleLineComment() - literal = string(runes) - tkn = token.COMMENT - return + if self.mode & StoreComments != 0 { + runes := self.readSingleLineComment() + literal = string(runes) + tkn = token.COMMENT + return + } + self.skipSingleLineComment() + continue } else if self.chr == '*' { - literal = string(self.readMultiLineComment()) - tkn = token.COMMENT - return + if self.mode & StoreComments != 0 { + literal = string(self.readMultiLineComment()) + tkn = token.COMMENT + return + } + self.skipMultiLineComment() + continue } else { // Could be division, could be RegExp literal tkn = self.switch2(token.SLASH, token.QUOTIENT_ASSIGN) diff --git a/parser/parser.go b/parser/parser.go index 73a5294..35ee172 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -49,6 +49,7 @@ type Mode uint const ( IgnoreRegExpErrors Mode = 1 << iota // Ignore RegExp compatibility errors (allow backtracking) + StoreComments // Store the comments from source to the comments map ) type _parser struct { @@ -285,8 +286,12 @@ func (self *_parser) position(idx file.Idx) file.Position { // Comments on the same line will be grouped together and returned. // After the first line break, comments will be added as statement comments. func (self *_parser) findComments(ignoreLineBreak bool) []*ast.Comment { + if self.mode & StoreComments == 0 { + return nil + } comments := make([]*ast.Comment, 0) + newline := false for self.implicitSemicolon == false || ignoreLineBreak {