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

Configure Feed

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

implement suggested `negate_expression`. fix unneeded parens.

+29 -8
+24 -3
compiler-core/src/javascript/expression.rs
··· 1100 1100 .group() 1101 1101 } 1102 1102 1103 + fn negate_bool_expression(&mut self, value: &'a TypedExpr) -> Document<'a> { 1104 + match value { 1105 + TypedExpr::BinOp { 1106 + name, left, right, .. 1107 + } => match name { 1108 + BinOp::And => self.print_bin_op(left, right, "||"), 1109 + BinOp::Or => self.print_bin_op(left, right, "&&"), 1110 + BinOp::Eq => self.equal(left, right, false), 1111 + BinOp::NotEq => self.equal(left, right, true), 1112 + BinOp::LtInt | BinOp::LtFloat => self.print_bin_op(left, right, ">="), 1113 + BinOp::LtEqInt | BinOp::LtEqFloat => self.print_bin_op(left, right, ">"), 1114 + BinOp::GtInt | BinOp::GtFloat => self.print_bin_op(left, right, "<="), 1115 + BinOp::GtEqInt | BinOp::GtEqFloat => self.print_bin_op(left, right, "<"), 1116 + _ => unreachable!("type checking should make this impossible"), 1117 + }, 1118 + TypedExpr::NegateBool { value, .. } => self.expression(value), 1119 + _ => docvec!["!", self.expression(value)], 1120 + } 1121 + } 1122 + 1103 1123 /// In Gleam, the `&&` operator is short-circuiting, meaning that we can't 1104 1124 /// pre-evaluate both sides of it, and use them in the exception that is 1105 1125 /// thrown. ··· 1171 1191 let left_value = 1172 1192 self.not_in_tail_position(Some(Ordering::Loose), |this| this.wrap_expression(left)); 1173 1193 1174 - let right_value = 1175 - self.not_in_tail_position(Some(Ordering::Strict), |this| this.wrap_expression(right)); 1194 + let right_value = self.not_in_tail_position(Some(Ordering::Strict), |this| { 1195 + this.negate_bool_expression(right) 1196 + }); 1176 1197 1177 1198 let right_check = docvec![ 1178 1199 line(), 1179 1200 "if (", 1180 - docvec!["!(", right_value, ")"].nest(INDENT), 1201 + right_value.nest(INDENT), 1181 1202 ") {", 1182 1203 docvec![ 1183 1204 line(),
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assert__assert_binary_operator_with_side_effects.snap
··· 26 26 27 27 export function go(x) { 28 28 if (true) { 29 - if (!(wibble(1, 4))) { 29 + if (!wibble(1, 4)) { 30 30 throw makeError( 31 31 "assert", 32 32 FILEPATH,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assert__assert_binary_operator_with_side_effects2.snap
··· 26 26 27 27 export function go(x) { 28 28 if (wibble(5, 5)) { 29 - if (!(wibble(4, 6))) { 29 + if (!wibble(4, 6)) { 30 30 throw makeError( 31 31 "assert", 32 32 FILEPATH,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assert__assert_with_logical_and_binary_rhs_1.snap
··· 16 16 17 17 export function main() { 18 18 if (true) { 19 - if (!(3 < 4)) { 19 + if (3 >= 4) { 20 20 throw makeError( 21 21 "assert", 22 22 FILEPATH,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assert__assert_with_logical_and_binary_rhs_2.snap
··· 16 16 17 17 export function main() { 18 18 if (true) { 19 - if (!("foo" === "foo")) { 19 + if ("foo" !== "foo") { 20 20 throw makeError( 21 21 "assert", 22 22 FILEPATH,
+1 -1
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assert__assert_with_logical_and_binary_rhs_3.snap
··· 16 16 17 17 export function main() { 18 18 if (true) { 19 - if (!("foo" !== "bar")) { 19 + if ("foo" === "bar") { 20 20 throw makeError( 21 21 "assert", 22 22 FILEPATH,