Fork of daniellemaywood.uk/gleam — Wasm codegen work
2

Configure Feed

Select the types of activity you want to include in your feed.

use the public Dict API inside `echo`

+30 -25
+2 -1
compiler-core/src/javascript.rs
··· 266 266 AssignName::Variable("stdlib$dict".into()), 267 267 SrcSpan::default(), 268 268 )); 269 - self.register_import(imports, "gleam_stdlib", "dict", &value, &[]); 269 + 270 + self.register_import(imports, "gleam_stdlib", "gleam/dict", &value, &[]); 270 271 } 271 272 self.register_prelude_usage(imports, "BitArray", Some("$BitArray")); 272 273 self.register_prelude_usage(imports, "List", Some("$List"));
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__blocks__blocks_whose_values_are_unused_do_not_generate_assignments.snap
··· 21 21 22 22 23 23 ----- COMPILED JAVASCRIPT 24 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 24 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 25 25 import { 26 26 Empty as $Empty, 27 27 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_evaluates_printed_value_before_message.snap
··· 15 15 16 16 17 17 ----- COMPILED JAVASCRIPT 18 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 18 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 19 19 import { 20 20 Empty as $Empty, 21 21 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_in_a_pipeline.snap
··· 14 14 15 15 16 16 ----- COMPILED JAVASCRIPT 17 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 17 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 18 18 import { 19 19 toList, 20 20 Empty as $Empty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_in_a_pipeline_with_message.snap
··· 14 14 15 15 16 16 ----- COMPILED JAVASCRIPT 17 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 17 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 18 18 import { 19 19 toList, 20 20 Empty as $Empty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_block.snap
··· 13 13 14 14 15 15 ----- COMPILED JAVASCRIPT 16 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 16 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 17 17 import { 18 18 Empty as $Empty, 19 19 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_block_as_a_message.snap
··· 13 13 14 14 15 15 ----- COMPILED JAVASCRIPT 16 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 16 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 17 17 import { 18 18 Empty as $Empty, 19 19 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_case_expression.snap
··· 12 12 13 13 14 14 ----- COMPILED JAVASCRIPT 15 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 15 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 16 16 import { 17 17 Empty as $Empty, 18 18 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_function_call.snap
··· 12 12 13 13 14 14 ----- COMPILED JAVASCRIPT 15 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 15 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 16 16 import { 17 17 Empty as $Empty, 18 18 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_function_call_and_a_message.snap
··· 13 13 14 14 15 15 ----- COMPILED JAVASCRIPT 16 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 16 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 17 17 import { 18 18 Empty as $Empty, 19 19 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_panic.snap
··· 10 10 11 11 12 12 ----- COMPILED JAVASCRIPT 13 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 13 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 14 14 import { 15 15 Empty as $Empty, 16 16 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_simple_expression.snap
··· 10 10 11 11 12 12 ----- COMPILED JAVASCRIPT 13 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 13 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 14 14 import { 15 15 Empty as $Empty, 16 16 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_a_simple_expression_and_a_message.snap
··· 10 10 11 11 12 12 ----- COMPILED JAVASCRIPT 13 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 13 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 14 14 import { 15 15 Empty as $Empty, 16 16 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__echo_with_complex_expression_as_a_message.snap
··· 15 15 16 16 17 17 ----- COMPILED JAVASCRIPT 18 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 18 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 19 19 import { 20 20 Empty as $Empty, 21 21 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__module_named_inspect.snap
··· 12 12 13 13 14 14 ----- COMPILED JAVASCRIPT 15 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 15 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 16 16 import * as $inspect from "../../other/other/inspect.mjs"; 17 17 import { 18 18 Empty as $Empty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__multiple_echos_in_a_pipeline.snap
··· 17 17 18 18 19 19 ----- COMPILED JAVASCRIPT 20 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 20 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 21 21 import { 22 22 toList, 23 23 Empty as $Empty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__echo__multiple_echos_inside_expression.snap
··· 11 11 12 12 13 13 ----- COMPILED JAVASCRIPT 14 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 14 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 15 15 import { 16 16 Empty as $Empty, 17 17 NonEmpty as $NonEmpty,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__inlining__inline_function_with_use_becomes_tail_recursive.snap
··· 14 14 15 15 16 16 ----- COMPILED JAVASCRIPT 17 - import * as $stdlib$dict from "../../gleam_stdlib/dict.mjs"; 18 17 import * as $bool from "../../gleam_stdlib/gleam/bool.mjs"; 18 + import * as $stdlib$dict from "../../gleam_stdlib/gleam/dict.mjs"; 19 19 import { 20 20 Empty as $Empty, 21 21 NonEmpty as $NonEmpty,
+11 -7
compiler-core/templates/echo.mjs
··· 31 31 try { 32 32 // We can only check if an object is a stdlib Dict if it is one of the 33 33 // project's dependencies. 34 - // The `Dict` class is the default export of `stdlib/dict.mjs` 35 - // that we import as `$stdlib$dict`. 36 - return value instanceof $stdlib$dict.default; 37 - } catch { 34 + // We import the public gleam/dict module, so to check if something is a 35 + // dict we compare the `constructor` field on the object with that of a 36 + // new dict. 37 + const emptyDict = $stdlib$dict.new$(); 38 + const dictClass = emptyDict.constructor; 39 + return value instanceof dictClass; 40 + } catch (e) { 38 41 // If stdlib is not one of the project's dependencies then `$stdlib$dict` 39 42 // will not have been imported and the check will throw an exception meaning 40 43 // we can't check if something is actually a `Dict`. ··· 115 118 let body = "dict.from_list(["; 116 119 let first = true; 117 120 118 - let key_value_pairs = []; 119 - map.forEach((value, key) => { 120 - key_value_pairs.push([key, value]); 121 + const key_value_pairs = $stdlib$dict.fold(map, [], (pairs, key, value) => { 122 + pairs.push([key, value]); 123 + return pairs; 121 124 }); 125 + 122 126 key_value_pairs.sort(); 123 127 key_value_pairs.forEach(([key, value]) => { 124 128 if (!first) body = body + ", ";