File tree Expand file tree Collapse file tree
compliance/tests/switch_statement Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -147,6 +147,8 @@ func (c *GoToTSCompiler) WriteStmtSwitch(exp *ast.SwitchStmt) error {
147147 if err := c .WriteValueExpr (exp .Tag ); err != nil {
148148 return fmt .Errorf ("failed to write switch tag expression: %w" , err )
149149 }
150+ } else {
151+ c .tsw .WriteLiterally ("true" ) // Write 'true' for switch without expression
150152 }
151153 c .tsw .WriteLiterally (") {" )
152154 c .tsw .WriteLine ("" )
Original file line number Diff line number Diff line change @@ -2,4 +2,13 @@ Integer switch:
22two
33
44String switch:
5- hello
5+ hello
6+
7+ Switch without expression:
8+ negative
9+
10+ Switch without expression (zero):
11+ zero
12+
13+ Switch without expression (positive):
14+ positive
Original file line number Diff line number Diff line change @@ -24,4 +24,36 @@ func main() {
2424 default :
2525 println ("other string" )
2626 }
27+ x := - 5
28+ println ("\n Switch without expression:" )
29+ switch {
30+ case x < 0 :
31+ println ("negative" )
32+ case x == 0 :
33+ println ("zero" )
34+ default : // x > 0
35+ println ("positive" )
36+ }
37+
38+ x = 0
39+ println ("\n Switch without expression (zero):" )
40+ switch {
41+ case x < 0 :
42+ println ("negative" )
43+ case x == 0 :
44+ println ("zero" )
45+ default : // x > 0
46+ println ("positive" )
47+ }
48+
49+ x = 10
50+ println ("\n Switch without expression (positive):" )
51+ switch {
52+ case x < 0 :
53+ println ("negative" )
54+ case x == 0 :
55+ println ("zero" )
56+ default : // x > 0
57+ println ("positive" )
58+ }
2759}
Original file line number Diff line number Diff line change @@ -7,32 +7,72 @@ export async function main(): Promise<void> {
77 let i = 2
88 console . log ( "Integer switch:" )
99 switch ( i ) {
10- case 1 :
11- console . log ( "one" )
12- break
13- case 2 :
14- console . log ( "two" )
15- break
16- case 3 :
17- console . log ( "three" )
18- break
19- default :
20- console . log ( "other integer" )
21- break
10+ case 1 :
11+ console . log ( "one" )
12+ break
13+ case 2 :
14+ console . log ( "two" )
15+ break
16+ case 3 :
17+ console . log ( "three" )
18+ break
19+ default :
20+ console . log ( "other integer" )
21+ break
2222 }
23-
23+
2424 let s = "hello"
2525 console . log ( "\nString switch:" )
2626 switch ( s ) {
27- case "world" :
28- console . log ( "world" )
29- break
30- case "hello" :
31- console . log ( "hello" )
32- break
33- default :
34- console . log ( "other string" )
35- break
27+ case "world" :
28+ console . log ( "world" )
29+ break
30+ case "hello" :
31+ console . log ( "hello" )
32+ break
33+ default :
34+ console . log ( "other string" )
35+ break
36+ }
37+ let x = - 5
38+ console . log ( "\nSwitch without expression:" )
39+ switch ( true ) {
40+ case x < 0 :
41+ console . log ( "negative" )
42+ break
43+ case x == 0 :
44+ console . log ( "zero" )
45+ break
46+ default : // x > 0
47+ console . log ( "positive" )
48+ break
3649 }
37- }
3850
51+ x = 0
52+ console . log ( "\nSwitch without expression (zero):" )
53+ switch ( true ) {
54+ case x < 0 :
55+ console . log ( "negative" )
56+ break
57+ case x == 0 :
58+ console . log ( "zero" )
59+ break
60+ default : // x > 0
61+ console . log ( "positive" )
62+ break
63+ }
64+
65+ x = 10
66+ console . log ( "\nSwitch without expression (positive):" )
67+ switch ( true ) {
68+ case x < 0 :
69+ console . log ( "negative" )
70+ break
71+ case x == 0 :
72+ console . log ( "zero" )
73+ break
74+ default : // x > 0
75+ console . log ( "positive" )
76+ break
77+ }
78+ }
You can’t perform that action at this time.
0 commit comments