1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: fix comments parsing on map init (#18389)

This commit is contained in:
Felipe Pena 2023-06-09 20:28:56 -03:00 committed by GitHub
parent 42db392e76
commit 3e5f2541f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -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
}

View File

@ -456,7 +456,8 @@ fn (mut p Parser) check_expr(precedence int) !ast.Expr {
p.if_cond_comments << p.eat_comments() 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 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() p.left_comments = p.eat_comments()
} }
return p.expr_with_left(node, precedence, is_stmt_ident) return p.expr_with_left(node, precedence, is_stmt_ident)