Skip to content

Commit

Permalink
Generate Array with qualified globalThis prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
chengluyu authored and LPTK committed Nov 15, 2024
1 parent c9662ec commit bddb9d5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class JSBuilder extends CodeBuilder:
case N => doc""
t :: e :: returningTerm(rest)
case Match(scrut, Case.Tup(len, inf) -> trm :: Nil, els, rest) =>
val test = doc"Array.isArray(${ result(scrut) }) && ${ result(scrut) }.length ${if inf then ">=" else "==="} ${len}"
val test = doc"globalThis.Array.isArray(${ result(scrut) }) && ${ result(scrut) }.length ${if inf then ">=" else "==="} ${len}"
val t = doc" # if (${ test }) { #{ ${
returningTerm(trm)
} #} # }"
Expand Down
12 changes: 6 additions & 6 deletions hkmc2/shared/src/test/mlscript/ucs/patterns/RestTuple.mls
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fun nonsense(xs) = if xs is
//│ JS:
//│ function nonsense(xs) {
//│ let rest, ys;
//│ if (Array.isArray(xs) && xs.length >= 0) {
//│ if (globalThis.Array.isArray(xs) && xs.length >= 0) {
//│ rest = globalThis.Predef.tupleSlice(xs, 0, 0);
//│ ys = rest;
//│ return ys;
Expand Down Expand Up @@ -61,7 +61,7 @@ fun lead_and_last(xs) = if xs is
//│ JS:
//│ function lead_and_last(xs) {
//│ let last0, rest, first0, x, ys, y;
//│ if (Array.isArray(xs) && xs.length >= 2) {
//│ if (globalThis.Array.isArray(xs) && xs.length >= 2) {
//│ first0 = xs[0];
//│ rest = globalThis.Predef.tupleSlice(xs, 1, 1);
//│ last0 = globalThis.Predef.tupleGet(xs, -1);
Expand All @@ -70,7 +70,7 @@ fun lead_and_last(xs) = if xs is
//│ y = last0;
//│ return x + y;
//│ } else {
//│ if (Array.isArray(xs) && xs.length === 0) {
//│ if (globalThis.Array.isArray(xs) && xs.length === 0) {
//│ return 0;
//│ } else {
//│ throw new globalThis.Error("match error");
Expand Down Expand Up @@ -114,12 +114,12 @@ fun nested_tuple_patterns(xs) = if xs is
//│ JS:
//│ function nested_tuple_patterns(xs) {
//│ let last0, rest, first0, x, first1, first01, y, z, w, tmp, tmp1;
//│ if (Array.isArray(xs) && xs.length >= 2) {
//│ if (globalThis.Array.isArray(xs) && xs.length >= 2) {
//│ first0 = xs[0];
//│ rest = globalThis.Predef.tupleSlice(xs, 1, 1);
//│ last0 = globalThis.Predef.tupleGet(xs, -1);
//│ x = first0;
//│ if (Array.isArray(rest) && rest.length === 2) {
//│ if (globalThis.Array.isArray(rest) && rest.length === 2) {
//│ first01 = rest[0];
//│ first1 = rest[1];
//│ y = first01;
Expand All @@ -132,7 +132,7 @@ fun nested_tuple_patterns(xs) = if xs is
//│ throw new globalThis.Error("match error");
//│ }
//│ } else {
//│ if (Array.isArray(xs) && xs.length === 0) {
//│ if (globalThis.Array.isArray(xs) && xs.length === 0) {
//│ return 0;
//│ } else {
//│ throw new globalThis.Error("match error");
Expand Down

0 comments on commit bddb9d5

Please sign in to comment.