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

Configure Feed

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

Replace collapse `if-else` into just `if` when the body is empty

+66 -133
+15
compiler-core/src/javascript/decision.rs
··· 92 92 if_body, 93 93 else_body, 94 94 .. 95 + } if if_body.is_empty() => docvec![ 96 + "if (!(", 97 + break_("", "") 98 + .append(check) 99 + .nest(INDENT) 100 + .append(break_("", "")) 101 + .group(), 102 + ")) ", 103 + else_body, 104 + ], 105 + CaseBody::IfElse { 106 + check, 107 + if_body, 108 + else_body, 109 + .. 95 110 } => docvec![ 96 111 "if (", 97 112 break_("", "")
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__assert.snap
··· 11 11 const FILEPATH = "src/module.gleam"; 12 12 13 13 export function go(x) { 14 - if (x === 1) { 15 - 16 - } else { 14 + if (!(x === 1)) { 17 15 throw makeError( 18 16 "let_assert", 19 17 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__assert1.snap
··· 14 14 let $ = x[1]; 15 15 if ($ === 2) { 16 16 let $1 = x[0]; 17 - if ($1 === 1) { 18 - 19 - } else { 17 + if (!($1 === 1)) { 20 18 throw makeError( 21 19 "let_assert", 22 20 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__returning_literal_subject.snap
··· 12 12 13 13 export function go(x) { 14 14 let $ = x + 1; 15 - if ($ === 1) { 16 - 17 - } else { 15 + if (!($ === 1)) { 18 16 throw makeError( 19 17 "let_assert", 20 18 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assignments__tuple_matching.snap
··· 18 18 let $ = x[1]; 19 19 if ($ === 2) { 20 20 let $1 = x[0]; 21 - if ($1 === 1) { 22 - 23 - } else { 21 + if (!($1 === 1)) { 24 22 throw makeError( 25 23 "let_assert", 26 24 FILEPATH,
+2 -6
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__discard_sized.snap
··· 16 16 const FILEPATH = "src/module.gleam"; 17 17 18 18 export function go(x) { 19 - if (x.bitSize >= 16 && x.bitSize === 24) { 20 - 21 - } else { 19 + if (!(x.bitSize >= 16 && x.bitSize === 24)) { 22 20 throw makeError( 23 21 "let_assert", 24 22 FILEPATH, ··· 29 27 { value: x, start: 18, end: 46, pattern_start: 29, pattern_end: 42 } 30 28 ) 31 29 } 32 - if (x.bitSize >= 16 && x.bitSize === 24) { 33 - 34 - } else { 30 + if (!(x.bitSize >= 16 && x.bitSize === 24)) { 35 31 throw makeError( 36 32 "let_assert", 37 33 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__dynamic_size_pattern_with_unit.snap
··· 17 17 18 18 export function go(x) { 19 19 let size = 3; 20 - if ( 20 + if (!( 21 21 size >= 0 && 22 22 x.bitSize === size * 2 && 23 23 bitArraySliceToInt(x, 0, size * 2, true, false) === 1 24 - ) { 25 - 26 - } else { 24 + )) { 27 25 throw makeError( 28 26 "let_assert", 29 27 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__empty_match.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 0) { 19 - 20 - } else { 18 + if (!(x.bitSize === 0)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_literal_aligned_float.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize >= 8 && 20 20 x.bitSize >= 72 && 21 21 bitArraySliceToFloat(x, 8, 72, true) === 1.1 22 - ) { 23 - 24 - } else { 22 + )) { 25 23 throw makeError( 26 24 "let_assert", 27 25 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_literal_unaligned_float.snap
··· 17 17 18 18 export function go(x) { 19 19 let n = 1; 20 - if ( 20 + if (!( 21 21 n >= 0 && 22 22 x.bitSize >= n && 23 23 x.bitSize >= 64 + n && 24 24 bitArraySliceToFloat(x, n, n + 64, true) === 1.1 25 - ) { 26 - 27 - } else { 25 + )) { 28 26 throw makeError( 29 27 "let_assert", 30 28 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_signed_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 8 && x.byteAt(0) === 255) { 19 - 20 - } else { 18 + if (!(x.bitSize === 8 && x.byteAt(0) === 255)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_sized_big_endian_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 16 && x.byteAt(0) === 4 && x.byteAt(1) === 210) { 19 - 20 - } else { 18 + if (!(x.bitSize === 16 && x.byteAt(0) === 4 && x.byteAt(1) === 210)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_sized_big_endian_signed_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 16 && x.byteAt(0) === 4 && x.byteAt(1) === 210) { 19 - 20 - } else { 18 + if (!(x.bitSize === 16 && x.byteAt(0) === 4 && x.byteAt(1) === 210)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_sized_big_endian_unsigned_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 16 && x.byteAt(0) === 4 && x.byteAt(1) === 210) { 19 - 20 - } else { 18 + if (!(x.bitSize === 16 && x.byteAt(0) === 4 && x.byteAt(1) === 210)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_sized_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize >= 16 && 20 20 x.byteAt(0) === 4 && x.byteAt(1) === 210 && 21 21 x.bitSize === 24 && 22 22 x.byteAt(2) === 123 23 - ) { 24 - 25 - } else { 23 + )) { 26 24 throw makeError( 27 25 "let_assert", 28 26 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_sized_little_endian_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 16 && x.byteAt(0) === 210 && x.byteAt(1) === 4) { 19 - 20 - } else { 18 + if (!(x.bitSize === 16 && x.byteAt(0) === 210 && x.byteAt(1) === 4)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_sized_little_endian_signed_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 16 && x.byteAt(0) === 210 && x.byteAt(1) === 4) { 19 - 20 - } else { 18 + if (!(x.bitSize === 16 && x.byteAt(0) === 210 && x.byteAt(1) === 4)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_sized_little_endian_unsigned_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 16 && x.byteAt(0) === 210 && x.byteAt(1) === 4) { 19 - 20 - } else { 18 + if (!(x.bitSize === 16 && x.byteAt(0) === 210 && x.byteAt(1) === 4)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_sized_value_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 16 && x.byteAt(0) === 1 && x.byteAt(1) === 2) { 19 - 20 - } else { 18 + if (!(x.bitSize === 16 && x.byteAt(0) === 1 && x.byteAt(1) === 2)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_unsigned_constant_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x.bitSize === 8 && x.byteAt(0) === 254) { 19 - 20 - } else { 18 + if (!(x.bitSize === 8 && x.byteAt(0) === 254)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_utf8.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize === 80 && 20 20 x.byteAt(0) === 71 && 21 21 x.byteAt(1) === 108 && ··· 27 27 x.byteAt(7) === 159 && 28 28 x.byteAt(8) === 145 && 29 29 x.byteAt(9) === 141 30 - ) { 31 - 32 - } else { 30 + )) { 33 31 throw makeError( 34 32 "let_assert", 35 33 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__match_utf8_with_escape_chars.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize === 80 && 20 20 x.byteAt(0) === 34 && 21 21 x.byteAt(1) === 92 && ··· 27 27 x.byteAt(7) === 159 && 28 28 x.byteAt(8) === 152 && 29 29 x.byteAt(9) === 128 30 - ) { 31 - 32 - } else { 30 + )) { 33 31 throw makeError( 34 32 "let_assert", 35 33 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_match_utf16.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize >= 80 && 20 20 x.byteAt(0) === 0 && 21 21 x.byteAt(1) === 72 && ··· 28 28 x.byteAt(8) === 0 && 29 29 x.byteAt(9) === 111 && 30 30 (x.bitSize - 80) % 8 === 0 31 - ) { 32 - 33 - } else { 31 + )) { 34 32 throw makeError( 35 33 "let_assert", 36 34 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_match_utf16_little_endian.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize >= 80 && 20 20 x.byteAt(0) === 72 && 21 21 x.byteAt(1) === 0 && ··· 28 28 x.byteAt(8) === 111 && 29 29 x.byteAt(9) === 0 && 30 30 (x.bitSize - 80) % 8 === 0 31 - ) { 32 - 33 - } else { 31 + )) { 34 32 throw makeError( 35 33 "let_assert", 36 34 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_match_utf32.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize >= 160 && 20 20 x.byteAt(0) === 0 && 21 21 x.byteAt(1) === 0 && ··· 38 38 x.byteAt(18) === 0 && 39 39 x.byteAt(19) === 111 && 40 40 (x.bitSize - 160) % 8 === 0 41 - ) { 42 - 43 - } else { 41 + )) { 44 42 throw makeError( 45 43 "let_assert", 46 44 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_match_utf32_little_endian.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize >= 160 && 20 20 x.byteAt(0) === 72 && 21 21 x.byteAt(1) === 0 && ··· 38 38 x.byteAt(18) === 0 && 39 39 x.byteAt(19) === 0 && 40 40 (x.bitSize - 160) % 8 === 0 41 - ) { 42 - 43 - } else { 41 + )) { 44 42 throw makeError( 45 43 "let_assert", 46 44 FILEPATH,
+2 -4
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__pattern_with_unit.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if ( 18 + if (!( 19 19 x.bitSize >= 4 && 20 20 bitArraySliceToInt(x, 0, 4, true, false) === 1 && 21 21 x.bitSize === 16 && 22 22 bitArraySliceToInt(x, 4, 16, true, false) === 2 23 - ) { 24 - 25 - } else { 23 + )) { 26 24 throw makeError( 27 25 "let_assert", 28 26 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__tuple_bit_array.snap
··· 16 16 17 17 export function go(x) { 18 18 let $ = x[0]; 19 - if ($.bitSize === 0) { 20 - 21 - } else { 19 + if (!($.bitSize === 0)) { 22 20 throw makeError( 23 21 "let_assert", 24 22 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bit_arrays__tuple_multiple_bit_arrays.snap
··· 25 25 let $1 = x[1]; 26 26 if ($1.bitSize === 8 && $1.byteAt(0) === 1) { 27 27 let $2 = x[0]; 28 - if ($2.bitSize === 0) { 29 - 30 - } else { 28 + if (!($2.bitSize === 0)) { 31 29 throw makeError( 32 30 "let_assert", 33 31 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__blocks__let_assert_message_no_lifted.snap
··· 29 29 30 30 export function main() { 31 31 let $ = side_effects(new Ok(10)); 32 - if ($ instanceof Error) { 33 - 34 - } else { 32 + if (!($ instanceof Error)) { 35 33 throw makeError( 36 34 "let_assert", 37 35 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bools__assigning.snap
··· 17 17 const FILEPATH = "src/module.gleam"; 18 18 19 19 export function go(x, y) { 20 - if (x) { 21 - 22 - } else { 20 + if (!(x)) { 23 21 throw makeError( 24 22 "let_assert", 25 23 FILEPATH,
+2 -6
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__bools__shadowed_bools_and_nil.snap
··· 24 24 export class Nil extends $CustomType {} 25 25 26 26 export function go(x, y) { 27 - if (x instanceof True) { 28 - 29 - } else { 27 + if (!(x instanceof True)) { 30 28 throw makeError( 31 29 "let_assert", 32 30 FILEPATH, ··· 46 44 "Pattern match failed, no pattern matched the value.", 47 45 { value: x, start: 76, end: 96, pattern_start: 87, pattern_end: 92 } 48 46 ) 49 - if (y instanceof Nil) { 50 - 51 - } else { 47 + if (!(y instanceof Nil)) { 52 48 throw makeError( 53 49 "let_assert", 54 50 FILEPATH,
+1 -5
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__case__case_branches_guards_are_wrapped_in_parentheses.snap
··· 1 1 --- 2 2 source: compiler-core/src/javascript/tests/case.rs 3 - assertion_line: 243 4 3 expression: "\npub fn anything() -> a {\n case [] {\n [a] if False || True -> a\n _ -> anything()\n }\n}\n" 5 - snapshot_kind: text 6 4 --- 7 5 ----- SOURCE CODE 8 6 ··· 20 18 export function anything() { 21 19 while (true) { 22 20 let $ = toList([]); 23 - if ($ instanceof $Empty) { 24 - 25 - } else { 21 + if (!($ instanceof $Empty)) { 26 22 let $1 = $.tail; 27 23 if ($1 instanceof $Empty && false || true) { 28 24 let a = $.head;
+2 -6
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__lists__list_destructuring.snap
··· 19 19 const FILEPATH = "src/module.gleam"; 20 20 21 21 export function go(x, y) { 22 - if (x instanceof $Empty) { 23 - 24 - } else { 22 + if (!(x instanceof $Empty)) { 25 23 throw makeError( 26 24 "let_assert", 27 25 FILEPATH, ··· 87 85 let $2 = $.head; 88 86 if ($2 === 2) { 89 87 let $3 = x.head; 90 - if ($3 === 1) { 91 - 92 - } else { 88 + if (!($3 === 1)) { 93 89 throw makeError( 94 90 "let_assert", 95 91 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__int_patterns.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x === 4) { 19 - 20 - } else { 18 + if (!(x === 4)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__preceeding_zeros_float_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function main(x) { 18 - if (x === 9_179.1) { 19 - 20 - } else { 18 + if (!(x === 9_179.1)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__preceeding_zeros_int_pattern.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function main(x) { 18 - if (x === 9_179) { 19 - 20 - } else { 18 + if (!(x === 9_179)) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,
+1 -3
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__strings__string_patterns.snap
··· 15 15 const FILEPATH = "src/module.gleam"; 16 16 17 17 export function go(x) { 18 - if (x === "Hello") { 19 - 20 - } else { 18 + if (!(x === "Hello")) { 21 19 throw makeError( 22 20 "let_assert", 23 21 FILEPATH,