diff --git a/vlib/v/fmt/tests/map_init_comments_keep.vv b/vlib/v/fmt/tests/map_init_comments_keep.vv new file mode 100644 index 00000000000000..5aedda6540c741 --- /dev/null +++ b/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 +} diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index 9e61b664d6a401..b5c8860b20fdb7 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -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)