⭐️ A friendly language for building type-safe, scalable systems!
337

Configure Feed

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

Fix JS bug with pipes and `assert`

authored by

GearsDatapacks and committed by
Louis Pilfold
(May 31, 2025, 1:17 PM +0100) 3cd57081 5095a156

+75 -2
+8
CHANGELOG.md
··· 1 1 # Changelog 2 2 3 + ## Unreleased 4 + 5 + ### Bug fixes 6 + 7 + - Fixed a bug where using a pipe operator on the right-hand side of an `assert` 8 + statement would generate invalid code on the JavaScript target. 9 + ([Surya Rose](https://github.com/GearsDatapacks)) 10 + 3 11 ## v1.11.0-rc2 - 2025-05-29 4 12 5 13 ### Compiler
+4 -2
compiler-core/src/javascript/expression.rs
··· 1012 1012 _ => {} 1013 1013 } 1014 1014 1015 - let left_document = self.assign_to_variable(left)?; 1016 - let right_document = self.not_in_tail_position(Some(Ordering::Strict), |this| { 1015 + let left_document = self.not_in_tail_position(Some(Ordering::Loose), |this| { 1016 + this.assign_to_variable(left) 1017 + })?; 1018 + let right_document = self.not_in_tail_position(Some(Ordering::Loose), |this| { 1017 1019 this.assign_to_variable(right) 1018 1020 })?; 1019 1021
+14
compiler-core/src/javascript/tests/assert.rs
··· 173 173 "# 174 174 ); 175 175 } 176 + 177 + // https://github.com/gleam-lang/gleam/issues/4643 178 + #[test] 179 + fn assert_with_pipe_on_right() { 180 + assert_js!( 181 + " 182 + fn add(a, b) { a + b } 183 + 184 + pub fn main() { 185 + assert 3 == 1 |> add(2) 186 + } 187 + " 188 + ); 189 + }
+49
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__assert__assert_with_pipe_on_right.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/assert.rs 3 + expression: "\nfn add(a, b) { a + b }\n\npub fn main() {\n assert 3 == 1 |> add(2)\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + fn add(a, b) { a + b } 8 + 9 + pub fn main() { 10 + assert 3 == 1 |> add(2) 11 + } 12 + 13 + 14 + ----- COMPILED JAVASCRIPT 15 + import { makeError } from "../gleam.mjs"; 16 + 17 + const FILEPATH = "src/module.gleam"; 18 + 19 + function add(a, b) { 20 + return a + b; 21 + } 22 + 23 + export function main() { 24 + let _block; 25 + let $ = 3; 26 + let _pipe = 1; 27 + _block = add(_pipe, 2); 28 + let $1 = _block; 29 + if (!($ === $1)) { 30 + throw makeError( 31 + "assert", 32 + FILEPATH, 33 + "my/mod", 34 + 5, 35 + "main", 36 + "Assertion failed.", 37 + { 38 + kind: "binary_operator", 39 + operator: "==", 40 + left: { kind: "literal", value: $, start: 50, end: 51 }, 41 + right: { kind: "expression", value: $1, start: 55, end: 66 }, 42 + start: 43, 43 + end: 66, 44 + expression_start: 50 45 + } 46 + ) 47 + } 48 + return undefined; 49 + }