Skip to content

Commit

Permalink
parser: fix comments parsing on map init (#18389)
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jun 9, 2023
1 parent 42db392 commit 3e5f254
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions vlib/v/fmt/tests/map_init_comments_keep.vv
@@ -0,0 +1,9 @@
enum HttpHeader {
user_agent
referer
}

headers := {
HttpHeader.user_agent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' // content_length: '17' // <-- will be deleted
.referer: 'wwww.google.com' // content_length: '17' // <-- won't be deleted
}
3 changes: 2 additions & 1 deletion vlib/v/parser/expr.v
Expand Up @@ -456,7 +456,8 @@ fn (mut p Parser) check_expr(precedence int) !ast.Expr {
p.if_cond_comments << p.eat_comments()
}
if p.pref.is_fmt && p.tok.kind == .comment && p.peek_tok.kind.is_infix() && !p.inside_infix
&& !(p.peek_tok.kind == .mul && p.peek_tok.pos().line_nr != p.tok.pos().line_nr) {
&& !p.inside_map_init && !(p.peek_tok.kind == .mul
&& p.peek_tok.pos().line_nr != p.tok.pos().line_nr) {
p.left_comments = p.eat_comments()
}
return p.expr_with_left(node, precedence, is_stmt_ident)
Expand Down

0 comments on commit 3e5f254

Please sign in to comment.