Skip to content

Commit d6ef6c5

Browse files
committed
Echo improvements
1 parent 8c23aee commit d6ef6c5

17 files changed

+134
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
definitions are not longer generated.
1313
([Louis Pilfold](https://github.com/lpil))
1414

15+
- `echo` now has better support for character lists, JavaScript errors, and
16+
JavaScript circular references.
17+
([Louis Pilfold](https://github.com/lpil))
18+
1519
### Build tool
1620

1721
- `gleam update`, `gleam deps update`, and `gleam deps download` will now print
@@ -28,7 +32,7 @@
2832
lustre 3.1.4 -> 5.1.1
2933
```
3034

31-
([Amjad Mohamed ](https://github.com/andho))
35+
([Amjad Mohamed](https://github.com/andho))
3236

3337

3438
### Language server

compiler-core/src/javascript.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ impl<'a> Generator<'a> {
140140
self.register_prelude_usage(&mut imports, "toList", None);
141141
};
142142

143-
if self.tracker.list_empty_class_used {
143+
if self.tracker.list_empty_class_used || self.tracker.echo_used {
144144
self.register_prelude_usage(&mut imports, "Empty", Some("$Empty"));
145145
};
146146

147-
if self.tracker.list_non_empty_class_used {
147+
if self.tracker.list_non_empty_class_used || self.tracker.echo_used {
148148
self.register_prelude_usage(&mut imports, "NonEmpty", Some("$NonEmpty"));
149149
};
150150

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/echo.rs
3+
assertion_line: 79
34
expression: "\npub fn main() {\n [1, 2, 3]\n |> echo\n |> wibble\n}\n\npub fn wibble(n) { n }\n"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -17,6 +19,8 @@ pub fn wibble(n) { n }
1719
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1820
import {
1921
toList,
22+
Empty as $Empty,
23+
NonEmpty as $NonEmpty,
2024
CustomType as $CustomType,
2125
bitArraySlice,
2226
bitArraySliceToInt,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/echo.rs
3+
assertion_line: 65
34
expression: "\npub fn main() {\n echo {\n Nil\n 1\n }\n}\n"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -15,6 +17,8 @@ pub fn main() {
1517
----- COMPILED JAVASCRIPT
1618
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1719
import {
20+
Empty as $Empty,
21+
NonEmpty as $NonEmpty,
1822
CustomType as $CustomType,
1923
bitArraySlice,
2024
bitArraySliceToInt,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/echo.rs
3+
assertion_line: 28
34
expression: "\npub fn main() {\n echo case 1 {\n _ -> 2\n }\n}\n"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -14,6 +16,8 @@ pub fn main() {
1416
----- COMPILED JAVASCRIPT
1517
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1618
import {
19+
Empty as $Empty,
20+
NonEmpty as $NonEmpty,
1721
CustomType as $CustomType,
1822
bitArraySlice,
1923
bitArraySliceToInt,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/echo.rs
3+
assertion_line: 52
34
expression: "\npub fn main() {\n echo wibble(1, 2)\n}\n\nfn wibble(n: Int, m: Int) { n + m }\n"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -14,6 +16,8 @@ fn wibble(n: Int, m: Int) { n + m }
1416
----- COMPILED JAVASCRIPT
1517
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1618
import {
19+
Empty as $Empty,
20+
NonEmpty as $NonEmpty,
1721
CustomType as $CustomType,
1822
bitArraySlice,
1923
bitArraySliceToInt,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ pub fn main() {
1414
----- COMPILED JAVASCRIPT
1515
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1616
import {
17+
Empty as $Empty,
18+
NonEmpty as $NonEmpty,
1719
CustomType as $CustomType,
1820
makeError,
1921
bitArraySlice,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/echo.rs
3+
assertion_line: 5
34
expression: "\npub fn main() {\n echo 1\n}\n"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -12,6 +14,8 @@ pub fn main() {
1214
----- COMPILED JAVASCRIPT
1315
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1416
import {
17+
Empty as $Empty,
18+
NonEmpty as $NonEmpty,
1519
CustomType as $CustomType,
1620
bitArraySlice,
1721
bitArraySliceToInt,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/echo.rs
3+
assertion_line: 112
34
expression: "\nimport other/inspect\n\npub fn main() {\n echo inspect.x\n}\n"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -15,6 +17,8 @@ pub fn main() {
1517
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
1618
import * as $inspect from "../../other/other/inspect.mjs";
1719
import {
20+
Empty as $Empty,
21+
NonEmpty as $NonEmpty,
1822
CustomType as $CustomType,
1923
bitArraySlice,
2024
bitArraySliceToInt,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
---
22
source: compiler-core/src/javascript/tests/echo.rs
3+
assertion_line: 94
34
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"
5+
snapshot_kind: text
46
---
57
----- SOURCE CODE
68

@@ -20,6 +22,8 @@ pub fn wibble(n) { n }
2022
import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs";
2123
import {
2224
toList,
25+
Empty as $Empty,
26+
NonEmpty as $NonEmpty,
2327
CustomType as $CustomType,
2428
bitArraySlice,
2529
bitArraySliceToInt,

0 commit comments

Comments
 (0)