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

Fix JavaScript object equality

Closes https://github.com/gleam-lang/gleam/issues/4699

Changed files
+23 -2
compiler-core
src
templates
test
javascript_prelude
+4
CHANGELOG.md
··· 291 291 bit array segment on the JavaScript target. 292 292 ([Surya Rose](https://github.com/GearsDatapacks)) 293 293 294 + - Fixed a bug where `==` and `!=` would return incorrect output for some 295 + JavaScript objects. 296 + ([Louis Pilfold](https://github.com/lpil)) 297 + 294 298 ## v1.11.1 - 2025-06-05 295 299 296 300 ### Compiler
+1 -1
compiler-core/src/javascript.rs
··· 717 717 } 718 718 } 719 719 720 - fn jsdoc_comment<'a>(documentation: &'a EcoString, publicity: Publicity) -> Document<'a> { 720 + fn jsdoc_comment(documentation: &EcoString, publicity: Publicity) -> Document<'_> { 721 721 let doc_lines = documentation 722 722 .trim_end() 723 723 .split('\n')
+4 -1
compiler-core/templates/prelude.mjs
··· 1494 1494 } 1495 1495 1496 1496 let [keys, get] = getters(a); 1497 - for (let k of keys(a)) { 1497 + const ka = keys(a); 1498 + const kb = keys(b); 1499 + if (ka.length !== kb.length) return false; 1500 + for (let k of ka) { 1498 1501 values.push(get(a, k), get(b, k)); 1499 1502 } 1500 1503 }
+14
test/javascript_prelude/main.mjs
··· 422 422 new Map([["a", new Map([["a", []]])]]), 423 423 ); 424 424 425 + assertNotEqual(new Map([]), new Map([["b", 1]])); 426 + 425 427 // Sets are compared structurally 426 428 let set = new Set(["a", 1]); 427 429 assertEqual(set, set); ··· 531 533 // custom equals defined on object instead of prototype, don't use it 532 534 assertEqual(hasEqualsField, { ...hasEqualsField }); 533 535 assertNotEqual(hasEqualsField, hasEqualsField2); 536 + 537 + // Objects 538 + assertEqual({ a: 1 }, { a: 1 }); 539 + assertEqual({ a: 1, b: 2 }, { b: 2, a: 1 }); 540 + 541 + assertEqual({ a: {} }, { a: {} }); 542 + assertEqual({ a: 1, b: { c: 3 } }, { a: 1, b: { c: 3 } }); 543 + 544 + assertNotEqual({ a: 1 }, {}); 545 + assertNotEqual({ a: 1, b: 2 }, { b: 2 }); 546 + assertNotEqual({}, { a: 1 }); 547 + assertNotEqual({ b: 2 }, { a: 1, b: 2 }); 534 548 535 549 // BitArray 536 550