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

js: fix match true {} in the js backend (#16317)

This commit is contained in:
Taegon Kim 2022-11-04 00:25:45 +09:00 committed by GitHub
parent 4e02cd8721
commit 962d0babdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 2 deletions

View File

@ -2431,7 +2431,7 @@ fn (mut g JsGen) match_expr(node ast.MatchExpr) {
}
if node.cond in [ast.Ident, ast.SelectorExpr, ast.IntegerLiteral, ast.StringLiteral, ast.FloatLiteral,
ast.CallExpr, ast.EnumVal] {
ast.BoolLiteral, ast.CallExpr, ast.EnumVal] {
cond_var = CondExpr{node.cond}
} else {
s := g.new_tmp_var()

View File

@ -1,4 +1,5 @@
Vec2d(42,43)
Vec2d(46,74,21)
life
V is running on JS
V is running on JS
c:

View File

@ -52,9 +52,21 @@ fn match_classic_string() {
}
}
fn match_bool_cond() {
volume := 'c:'
rooted := false
path_separator := '/'
println(match true {
volume.len != 0 { volume }
!rooted { '.' }
else { path_separator }
})
}
fn main() {
match_vec(Vec2d{42, 43})
match_vec(Vec3d{46, 74, 21})
match_classic_num()
match_classic_string()
match_bool_cond()
}