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:
parent
4e02cd8721
commit
962d0babdc
@ -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()
|
||||
|
3
vlib/v/gen/js/tests/testdata/match.out
vendored
3
vlib/v/gen/js/tests/testdata/match.out
vendored
@ -1,4 +1,5 @@
|
||||
Vec2d(42,43)
|
||||
Vec2d(46,74,21)
|
||||
life
|
||||
V is running on JS
|
||||
V is running on JS
|
||||
c:
|
12
vlib/v/gen/js/tests/testdata/match.v
vendored
12
vlib/v/gen/js/tests/testdata/match.v
vendored
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user