Skip to content

Commit 2a3a13c

Browse files
authored
Fix missing semicolons (#234)
1 parent cc65fc1 commit 2a3a13c

32 files changed

+160
-154
lines changed

hkmc2/shared/src/main/scala/hkmc2/codegen/js/JSBuilder.scala

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ class JSBuilder extends CodeBuilder:
194194
assert(clsDefn.paramsOpt.isEmpty)
195195
// doc"${mkThis(owner)}.${sym.nme} = new ${clsJS}"
196196
doc"const $clsTmp = ${clsJS}; # ${mkThis(owner)}.${sym.nme} = new ${clsTmp
197-
}; # ${mkThis(owner)}.${sym.nme}.class = $clsTmp"
197+
}; # ${mkThis(owner)}.${sym.nme}.class = $clsTmp;"
198198
case N => doc"const $clsTmp = ${clsJS}; const ${sym.nme} = new ${clsTmp
199-
}; # ${sym.nme}.class = $clsTmp"
199+
}; # ${sym.nme}.class = $clsTmp;"
200200
else
201201
val fun = clsDefn.paramsOpt match
202202
case S(params) =>
@@ -208,19 +208,19 @@ class JSBuilder extends CodeBuilder:
208208
val ths = mkThis(owner)
209209
fun match
210210
case S(f) =>
211-
doc"${ths}.${sym.nme} = ${f}; # ${ths}.${sym.nme}.class = ${clsJS}"
211+
doc"${ths}.${sym.nme} = ${f}; # ${ths}.${sym.nme}.class = ${clsJS};"
212212
case N =>
213-
doc"${ths}.${sym.nme} = ${clsJS}"
213+
doc"${ths}.${sym.nme} = ${clsJS};"
214214
case N =>
215215
fun match
216-
case S(f) => doc"${f}; # ${sym.nme}.class = ${clsJS}"
216+
case S(f) => doc"${f}; # ${sym.nme}.class = ${clsJS};"
217217
case N => clsJS
218218
thisProxy match
219-
case S(proxy) => doc" # const $proxy = this; # ${res.stripBreaks};${returningTerm(rst)}"
220-
case N => doc"$res;${returningTerm(rst)}"
219+
case S(proxy) => doc" # const $proxy = this; # ${res.stripBreaks}${returningTerm(rst)}"
220+
case N => doc"$res${returningTerm(rst)}"
221221
doc" # ${resJS}"
222222
case Return(res, true) => doc" # ${result(res)}"
223-
case Return(res, false) => doc" # return ${result(res)}"
223+
case Return(res, false) => doc" # return ${result(res)};"
224224

225225
// TODO factor out common logic
226226
case Match(scrut, Case.Lit(syntax.Tree.BoolLit(true)) -> trm :: Nil, els, rest) =>
@@ -262,13 +262,13 @@ class JSBuilder extends CodeBuilder:
262262
doc" # /* $msg */"
263263

264264
case Throw(res) =>
265-
doc" # throw ${result(res)}"
265+
doc" # throw ${result(res)};"
266266

267267
case Break(lbl, false) =>
268-
doc" # break ${getVar(lbl)}"
268+
doc" # break ${getVar(lbl)};"
269269

270270
case Break(lbl, true) =>
271-
doc" # continue ${getVar(lbl)}"
271+
doc" # continue ${getVar(lbl)};"
272272

273273
case Label(lbl, bod, rst) =>
274274
scope.allocateName(lbl)

hkmc2/shared/src/test/mlscript-compile/Example.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ const Example$class = class Example {
44

55
}
66
funnySlash(f, arg) {
7-
return f(arg)
7+
return f(arg);
88
}
99
inc(x) {
10-
return x + 1
10+
return x + 1;
1111
}
1212
toString() { return "Example"; }
1313
}; const Example = new Example$class;

hkmc2/shared/src/test/mlscript-compile/Option.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ const Option$class = class Option {
2929
}
3030
isDefined(x) {
3131
if (x instanceof this.Some.class) {
32-
return true
32+
return true;
3333
} else {
3434
if (x instanceof this.None.class) {
35-
return false
35+
return false;
3636
} else {
37-
throw new globalThis.Error("match error")
37+
throw new globalThis.Error("match error");
3838
}
3939
}
4040
}
4141
test() {
42-
return Predef.pipe(2134, Predef.print)
42+
return Predef.pipe(2134, Predef.print);
4343
}
4444
toString() { return "Option"; }
4545
}; const Option = new Option$class;

hkmc2/shared/src/test/mlscript-compile/Predef.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ const Predef$class = class Predef {
33

44
}
55
id(x) {
6-
return x
6+
return x;
77
}
88
pipe(x1, f) {
9-
return f(x1)
9+
return f(x1);
1010
}
1111
call(receiver, f1) {
1212
return (arg) => {
13-
return f1.call(receiver, arg)
14-
}
13+
return f1.call(receiver, arg);
14+
};
1515
}
1616
print(x2) {
1717
let tmp;
1818
tmp = String(x2);
19-
return console.log(tmp)
19+
return console.log(tmp);
2020
}
2121
toString() { return "Predef"; }
2222
}; const Predef = new Predef$class;

hkmc2/shared/src/test/mlscript-compile/Stack.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ const Stack$class = class Stack {
2020
}
2121
isEmpty(xs) {
2222
if (xs instanceof this.Nil.class) {
23-
return true
23+
return true;
2424
} else {
25-
return false
25+
return false;
2626
}
2727
}
2828
toString() { return "Stack"; }

hkmc2/shared/src/test/mlscript/basics/MultiParamLists.mls

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
fun f(n1: Int): Int = n1
88
//│ JS:
9-
//│ function f(n1) { return n1 }; undefined
9+
//│ function f(n1) { return n1; } undefined
1010

1111
f(42)
1212
//│ JS:
@@ -15,7 +15,7 @@ f(42)
1515

1616
fun f(n1: Int)(n2: Int): Int = (10 * n1 + n2)
1717
//│ JS:
18-
//│ function f(n1) { return (n2) => { let tmp; tmp = 10 * n1; return tmp + n2 } }; undefined
18+
//│ function f(n1) { return (n2) => { let tmp; tmp = 10 * n1; return tmp + n2; }; } undefined
1919

2020
f(4)(2)
2121
//│ JS:
@@ -31,10 +31,10 @@ fun f(n1: Int)(n2: Int)(n3: Int): Int = 10 * (10 * n1 + n2) + n3
3131
//│ tmp = 10 * n1;
3232
//│ tmp1 = tmp + n2;
3333
//│ tmp2 = 10 * tmp1;
34-
//│ return tmp2 + n3
35-
//│ }
36-
//│ }
37-
//│ };
34+
//│ return tmp2 + n3;
35+
//│ };
36+
//│ };
37+
//│ }
3838
//│ undefined
3939

4040
f(4)(2)(0)
@@ -54,11 +54,11 @@ fun f(n1: Int)(n2: Int)(n3: Int)(n4: Int): Int = 10 * (10 * (10 * n1 + n2) + n3)
5454
//│ tmp2 = 10 * tmp1;
5555
//│ tmp3 = tmp2 + n3;
5656
//│ tmp4 = 10 * tmp3;
57-
//│ return tmp4 + n4
58-
//│ }
59-
//│ }
60-
//│ }
61-
//│ };
57+
//│ return tmp4 + n4;
58+
//│ };
59+
//│ };
60+
//│ };
61+
//│ }
6262
//│ undefined
6363

6464
f(3)(0)(3)(1)

hkmc2/shared/src/test/mlscript/codegen/BadThis.mls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
:js
22

33

4-
globalThis.navigator
5-
//│ = Navigator {}
4+
globalThis.clearInterval
5+
//│ = [Function: clearInterval]
66

77
class A
88

@@ -16,7 +16,7 @@ if 0 is A then 1
1616
val globalThis = "oops"
1717
//│ globalThis = 'oops'
1818

19-
globalThis.navigator
19+
globalThis.clearInterval
2020

2121
:re
2222
if 0 is A then 1

hkmc2/shared/src/test/mlscript/codegen/CaseOfCase.mls

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,22 @@ fun test(x) =
2929
//│ if (x instanceof globalThis.None.class) {
3030
//│ tmp1 = globalThis.None;
3131
//│ } else {
32-
//│ throw new globalThis.Error("match error")
32+
//│ throw new globalThis.Error("match error");
3333
//│ }
3434
//│ }
3535
//│ scrut = tmp1;
3636
//│ if (scrut instanceof globalThis.Some.class) {
3737
//│ param01 = scrut.value;
3838
//│ v1 = param01;
39-
//│ return globalThis.log(v1)
39+
//│ return globalThis.log(v1);
4040
//│ } else {
4141
//│ if (scrut instanceof globalThis.None.class) {
42-
//│ return globalThis.log("none")
42+
//│ return globalThis.log("none");
4343
//│ } else {
44-
//│ throw new globalThis.Error("match error")
44+
//│ throw new globalThis.Error("match error");
4545
//│ }
4646
//│ }
47-
//│ };
47+
//│ }
4848
//│ undefined
4949

5050

hkmc2/shared/src/test/mlscript/codegen/CaseShorthand.mls

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,35 @@ case x then x
1111
:sjs
1212
case { x then x }
1313
//│ JS:
14-
//│ (caseScrut) => { let x; x = caseScrut; return x }
14+
//│ (caseScrut) => { let x; x = caseScrut; return x; }
1515
//│ = [Function (anonymous)]
1616

1717
:sjs
1818
x => if x is
1919
0 then true
2020
//│ JS:
21-
//│ (x) => { if (x === 0) { return true } else { throw new this.Error("match error") } }
21+
//│ (x) => { if (x === 0) { return true; } else { throw new this.Error("match error"); } }
2222
//│ = [Function (anonymous)]
2323

2424
:sjs
2525
case
2626
0 then true
2727
//│ JS:
28-
//│ (caseScrut) => { if (caseScrut === 0) { return true } else { throw new this.Error("match error") } }
28+
//│ (caseScrut) => {
29+
//│ if (caseScrut === 0) {
30+
//│ return true;
31+
//│ } else {
32+
//│ throw new this.Error("match error");
33+
//│ }
34+
//│ }
2935
//│ = [Function (anonymous)]
3036

3137
:sjs
3238
case
3339
0 then true
3440
_ then false
3541
//│ JS:
36-
//│ (caseScrut) => { if (caseScrut === 0) { return true } else { return false } }
42+
//│ (caseScrut) => { if (caseScrut === 0) { return true; } else { return false; } }
3743
//│ = [Function (anonymous)]
3844

3945
class Some(value)
@@ -46,12 +52,12 @@ val isDefined = case
4652
//│ JS:
4753
//│ this.isDefined = (caseScrut) => {
4854
//│ if (caseScrut instanceof this.Some.class) {
49-
//│ return true
55+
//│ return true;
5056
//│ } else {
5157
//│ if (caseScrut instanceof this.None.class) {
52-
//│ return false
58+
//│ return false;
5359
//│ } else {
54-
//│ throw new this.Error("match error")
60+
//│ throw new this.Error("match error");
5561
//│ }
5662
//│ }
5763
//│ };

hkmc2/shared/src/test/mlscript/codegen/ClassInClass.mls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Outer(a, b) with
4040
//│ this$Outer.b,
4141
//│ this.c,
4242
//│ d
43-
//│ ]
43+
//│ ];
4444
//│ }
4545
//│ toString() { return "Inner(" + this.c + ")"; }
4646
//│ };
@@ -51,12 +51,12 @@ class Outer(a, b) with
5151
//│ globalThis.log(tmp2)
5252
//│ }
5353
//│ o1(c) {
54-
//│ return this.Inner(c)
54+
//│ return this.Inner(c);
5555
//│ }
5656
//│ o2(c1, d) {
5757
//│ let tmp;
5858
//│ tmp = this.Inner(c1);
59-
//│ return tmp.i1(d)
59+
//│ return tmp.i1(d);
6060
//│ }
6161
//│ toString() { return "Outer(" + this.a + ", " + this.b + ")"; }
6262
//│ };

hkmc2/shared/src/test/mlscript/codegen/ClassInFun.mls

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ fun test(a) =
1515
//│ this.x = a;
1616
//│ }
1717
//│ toString() { return "C"; }
18-
//│ };
19-
//│ return new C()
20-
//│ };
18+
//│ }
19+
//│ return new C();
20+
//│ }
2121
//│ undefined
2222

2323
test(12)
@@ -41,8 +41,8 @@ fun test(x) =
4141
//│ toString() { return "Foo(" + this.a + ", " + this.b + ")"; }
4242
//│ };
4343
//│ tmp = x + 1;
44-
//│ return Foo(x, tmp)
45-
//│ };
44+
//│ return Foo(x, tmp);
45+
//│ }
4646
//│ undefined
4747

4848

0 commit comments

Comments
 (0)