Skip to content

Commit 40a1a38

Browse files
avoid clases with user defined types
1 parent 6ff16c8 commit 40a1a38

10 files changed

+59
-16
lines changed

compiler-core/src/javascript.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ impl<'a> Generator<'a> {
182182
)),
183183
&[],
184184
);
185-
self.register_prelude_usage(&mut imports, "BitArray", None);
186-
self.register_prelude_usage(&mut imports, "List", None);
187-
self.register_prelude_usage(&mut imports, "UtfCodepoint", None);
188-
self.register_prelude_usage(&mut imports, "CustomType", None);
185+
self.register_prelude_usage(&mut imports, "BitArray", Some("$BitArray"));
186+
self.register_prelude_usage(&mut imports, "List", Some("$List"));
187+
self.register_prelude_usage(&mut imports, "UtfCodepoint", Some("$UtfCodepoint"));
188+
self.register_prelude_usage(&mut imports, "CustomType", Some("$CustomType"));
189189
docvec![line(), std::include_str!("../templates/echo.mjs"), line()]
190190
} else {
191191
nil()

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_in_a_pipeline.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ source: compiler-core/src/javascript/tests/echo.rs
33
expression: "\npub fn main() {\n [1, 2, 3]\n |> echo\n |> wibble\n}\n\npub fn wibble(n) { n }\n"
44
---
55
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
6-
import { toList, BitArray, List, UtfCodepoint, CustomType } from "../gleam.mjs";
6+
import {
7+
toList,
8+
BitArray as $BitArray,
9+
List as $List,
10+
UtfCodepoint as $UtfCodepoint,
11+
CustomType as $CustomType,
12+
} from "../gleam.mjs";
713

814
export function wibble(n) {
915
return n;

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_block.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ source: compiler-core/src/javascript/tests/echo.rs
33
expression: "\npub fn main() {\n echo {\n Nil\n 1\n }\n}\n"
44
---
55
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
6-
import { BitArray, List, UtfCodepoint, CustomType } from "../gleam.mjs";
6+
import {
7+
BitArray as $BitArray,
8+
List as $List,
9+
UtfCodepoint as $UtfCodepoint,
10+
CustomType as $CustomType,
11+
} from "../gleam.mjs";
712

813
export function main() {
914
return echo(

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_case_expression.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ source: compiler-core/src/javascript/tests/echo.rs
33
expression: "\npub fn main() {\n echo case 1 {\n _ -> 2\n }\n}\n"
44
---
55
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
6-
import { BitArray, List, UtfCodepoint, CustomType } from "../gleam.mjs";
6+
import {
7+
BitArray as $BitArray,
8+
List as $List,
9+
UtfCodepoint as $UtfCodepoint,
10+
CustomType as $CustomType,
11+
} from "../gleam.mjs";
712

813
export function main() {
914
return echo(

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_function_call.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ source: compiler-core/src/javascript/tests/echo.rs
33
expression: "\npub fn main() {\n echo wibble(1, 2)\n}\n\nfn wibble(n: Int, m: Int) { n + m }\n"
44
---
55
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
6-
import { BitArray, List, UtfCodepoint, CustomType } from "../gleam.mjs";
6+
import {
7+
BitArray as $BitArray,
8+
List as $List,
9+
UtfCodepoint as $UtfCodepoint,
10+
CustomType as $CustomType,
11+
} from "../gleam.mjs";
712

813
function wibble(n, m) {
914
return n + m;

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_panic.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ source: compiler-core/src/javascript/tests/echo.rs
33
expression: "\npub fn main() {\n echo panic\n}\n"
44
---
55
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
6-
import { makeError, BitArray, List, UtfCodepoint, CustomType } from "../gleam.mjs";
6+
import {
7+
makeError,
8+
BitArray as $BitArray,
9+
List as $List,
10+
UtfCodepoint as $UtfCodepoint,
11+
CustomType as $CustomType,
12+
} from "../gleam.mjs";
713

814
export function main() {
915
return echo(

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_simple_expression.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ source: compiler-core/src/javascript/tests/echo.rs
33
expression: "\npub fn main() {\n echo 1\n}\n"
44
---
55
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
6-
import { BitArray, List, UtfCodepoint, CustomType } from "../gleam.mjs";
6+
import {
7+
BitArray as $BitArray,
8+
List as $List,
9+
UtfCodepoint as $UtfCodepoint,
10+
CustomType as $CustomType,
11+
} from "../gleam.mjs";
712

813
export function main() {
914
return echo(1);

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__multiple_echos_in_a_pipeline.snap

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ source: compiler-core/src/javascript/tests/echo.rs
33
expression: "\npub fn main() {\n [1, 2, 3]\n |> echo\n |> wibble\n |> echo\n |> wibble\n |> echo\n}\n\npub fn wibble(n) { n }\n"
44
---
55
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
6-
import { toList, BitArray, List, UtfCodepoint, CustomType } from "../gleam.mjs";
6+
import {
7+
toList,
8+
BitArray as $BitArray,
9+
List as $List,
10+
UtfCodepoint as $UtfCodepoint,
11+
CustomType as $CustomType,
12+
} from "../gleam.mjs";
713

814
export function wibble(n) {
915
return n;

compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__multiple_echos_inside_expression.snap

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ source: compiler-core/src/javascript/tests/echo.rs
33
expression: "\npub fn main() {\n echo 1\n echo 2\n}\n"
44
---
55
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
6-
import { BitArray, List, UtfCodepoint, CustomType } from "../gleam.mjs";
6+
import {
7+
BitArray as $BitArray,
8+
List as $List,
9+
UtfCodepoint as $UtfCodepoint,
10+
CustomType as $CustomType,
11+
} from "../gleam.mjs";
712

813
export function main() {
914
echo(1);

compiler-core/templates/echo.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,10 @@ function $inspect(v) {
7575
if (t === "string") return $inspectString(v);
7676
if (t === "bigint" || t === "number") return v.toString();
7777
if (Array.isArray(v)) return `#(${v.map($inspect).join(", ")})`;
78-
if (v instanceof List) return `[${v.toArray().map($inspect).join(", ")}]`;
79-
if (v instanceof UtfCodepoint) return `//utfcodepoint(${String.fromCodePoint(v.value)})`;
80-
if (v instanceof BitArray) return `<<${Array.from(v.buffer).join(", ")}>>`;
81-
if (v instanceof CustomType) return $inspectCustomType(v);
78+
if (v instanceof $List) return `[${v.toArray().map($inspect).join(", ")}]`;
79+
if (v instanceof $UtfCodepoint) return `//utfcodepoint(${String.fromCodePoint(v.value)})`;
80+
if (v instanceof $BitArray) return `<<${Array.from(v.buffer).join(", ")}>>`;
81+
if (v instanceof $CustomType) return $inspectCustomType(v);
8282
if ($isDict(v)) return $inspectDict(v);
8383
if (v instanceof Set) return `//js(Set(${[...v].map($inspect).join(", ")}))`;
8484
if (v instanceof RegExp) return `//js(${v})`;

0 commit comments

Comments
 (0)