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

Configure Feed

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

Add RegExp as a nonstructural compatible object to structurallyCompatibleObjects in preludes.mjs.

+44 -23
+3
CHANGELOG.md
··· 8 8 - `Utf8Codepoint` has been renamed to `UtfCodepoint` in `prelude.d.mts`. 9 9 - Fixed a bug where `gleam deps list` would look in filesystem root instead of 10 10 the current directory. 11 + - Fixed a bug with the `isEqual` function in `prelude.js` where RegExps were 12 + being incorrectly structurally compared and being falsely reported as being 13 + equal. 11 14 12 15 ### Formatter 13 16
+7 -2
compiler-core/templates/prelude.mjs
··· 1 1 export class CustomType { 2 2 withFields(fields) { 3 3 let properties = Object.keys(this).map((label) => 4 - label in fields ? fields[label] : this[label] 4 + label in fields ? fields[label] : this[label], 5 5 ); 6 6 return new this.constructor(...properties); 7 7 } ··· 223 223 unequalBuffers(a, b) || 224 224 unequalArrays(a, b) || 225 225 unequalMaps(a, b) || 226 - unequalSets(a, b); 226 + unequalSets(a, b) || 227 + unequalRegExps(a, b); 227 228 if (unequal) return false; 228 229 229 230 const proto = Object.getPrototypeOf(a); ··· 276 277 return ( 277 278 a instanceof Set && (a.size != b.size || [...a].some((e) => !b.has(e))) 278 279 ); 280 + } 281 + 282 + function unequalRegExps(a, b) { 283 + return a instanceof RegExp && (a.source !== b.source || a.flags !== b.flags); 279 284 } 280 285 281 286 function isObject(a) {
+34 -21
test/javascript_prelude/main.mjs
··· 113 113 114 114 assertEqual( 115 115 new ExampleRecordImpl(undefined, 1, new Ok(2.1)), 116 - new ExampleRecordImpl(undefined, 1, new Ok(2.1)) 116 + new ExampleRecordImpl(undefined, 1, new Ok(2.1)), 117 117 ); 118 118 assertNotEqual( 119 119 new ExampleRecordImpl(undefined, 1, new Ok("2.1")), 120 - new ExampleRecordImpl(undefined, 1, new Ok(2.1)) 120 + new ExampleRecordImpl(undefined, 1, new Ok(2.1)), 121 121 ); 122 122 123 123 assertEqual(List.fromArray([]), List.fromArray([])); 124 124 assertEqual( 125 125 List.fromArray([1, 2, new Ok(1)]), 126 - List.fromArray([1, 2, new Ok(1)]) 126 + List.fromArray([1, 2, new Ok(1)]), 127 127 ); 128 128 assertNotEqual( 129 129 List.fromArray([1, 2, new Ok(1)]), 130 - List.fromArray([1, 2, new Ok(2)]) 130 + List.fromArray([1, 2, new Ok(2)]), 131 131 ); 132 132 assertNotEqual(List.fromArray([1, 2]), List.fromArray([1, 2, new Ok(2)])); 133 133 assertNotEqual(List.fromArray([1]), List.fromArray([])); ··· 136 136 assertEqual(new BitArray(new Uint8Array([])), new BitArray(new Uint8Array([]))); 137 137 assertEqual( 138 138 new BitArray(new Uint8Array([1, 2, 3])), 139 - new BitArray(new Uint8Array([1, 2, 3])) 139 + new BitArray(new Uint8Array([1, 2, 3])), 140 140 ); 141 141 assertNotEqual( 142 142 new BitArray(new Uint8Array([1, 2])), 143 - new BitArray(new Uint8Array([1, 2, 3])) 143 + new BitArray(new Uint8Array([1, 2, 3])), 144 144 ); 145 145 146 146 assertEqual(new UtfCodepoint(128013), new UtfCodepoint(128013)); ··· 152 152 153 153 assertEqual( 154 154 new BitArray(new Uint8Array([97, 98, 99])), 155 - toBitArray([stringBits("abc")]) 155 + toBitArray([stringBits("abc")]), 156 156 ); 157 157 158 158 assertEqual( 159 159 new BitArray(new Uint8Array([97])), 160 - toBitArray([codepointBits(new UtfCodepoint(97))]) 160 + toBitArray([codepointBits(new UtfCodepoint(97))]), 161 161 ); 162 162 163 163 assertEqual( 164 164 new BitArray(new Uint8Array([240, 159, 144, 141])), 165 - toBitArray([codepointBits(new UtfCodepoint(128013))]) 165 + toBitArray([codepointBits(new UtfCodepoint(128013))]), 166 166 ); 167 167 168 168 // toList ··· 207 207 assertEqual(fun, fun); 208 208 assertNotEqual( 209 209 () => 1, 210 - () => 1 210 + () => 1, 211 211 ); 212 212 213 213 // Maps are compared structurally ··· 219 219 ["a", 1], 220 220 ["b", 2], 221 221 ]), 222 - new Map([["a", 1]]) 222 + new Map([["a", 1]]), 223 223 ); 224 224 assertNotEqual( 225 225 new Map([["a", 1]]), 226 226 new Map([ 227 227 ["a", 1], 228 228 ["b", 2], 229 - ]) 229 + ]), 230 230 ); 231 231 assertNotEqual(new Map([["a", 1]]), new Map([["b", 1]])); 232 232 assertEqual( 233 233 new Map([["a", new Map([["a", []]])]]), 234 - new Map([["a", new Map([["a", []]])]]) 234 + new Map([["a", new Map([["a", []]])]]), 235 235 ); 236 236 237 237 // Sets are compared structurally ··· 243 243 assertNotEqual(new Set(["a", 1]), new Set(["a", 1, "b"])); 244 244 assertNotEqual( 245 245 new Set(["a", new Map([["a", []]])]), 246 - new Set(["a", new Map([["a", []]])]) 246 + new Set(["a", new Map([["a", []]])]), 247 247 ); 248 248 249 249 // WeakMaps are not equal unless they have reference equality ··· 256 256 assertEqual(weak_set, weak_set); 257 257 assertNotEqual(new WeakSet([map, set]), new WeakSet([map, set])); 258 258 259 + // RegExp are compared structurally 260 + let re = new RegExp("test", "g"); 261 + let re_literal = /test/g; 262 + assertEqual(re, re); 263 + assertEqual(re_literal, re_literal); 264 + assertEqual(re, re_literal); 265 + assertNotEqual(re, new RegExp("test", "i")); 266 + assertNotEqual(re, new RegExp("test")); 267 + assertNotEqual(re_literal, new RegExp("test", "i")); 268 + assertNotEqual(re_literal, /test/); 269 + assertNotEqual(re_literal, new RegExp("test", "i")); 270 + assertNotEqual(re, /test/i); 271 + 259 272 class ExampleA { 260 273 constructor(x) { 261 274 this.x = x; ··· 317 330 // custom equals throws, fallback to structural equality 318 331 assertEqual( 319 332 new HasCustomEqualsThatThrows(1, 1), 320 - new HasCustomEqualsThatThrows(1, 1) 333 + new HasCustomEqualsThatThrows(1, 1), 321 334 ); 322 335 assertNotEqual( 323 336 new HasCustomEqualsThatThrows(1, 1), 324 - new HasCustomEqualsThatThrows(1, 2) 337 + new HasCustomEqualsThatThrows(1, 2), 325 338 ); 326 339 // custom equals works, use it 327 340 assertEqual(new HasCustomEquals(1, 1), new HasCustomEquals(1, 1)); ··· 335 348 assertEqual(new BitArray(new Uint8Array([1, 2, 3])).byteAt(2), 3); 336 349 assertEqual( 337 350 new BitArray(new Uint8Array([63, 240, 0, 0, 0, 0, 0, 0])).floatAt(0), 338 - 1.0 351 + 1.0, 339 352 ); 340 353 assertEqual(new BitArray(new Uint8Array([1, 2, 3])).intFromSlice(0, 1), 1); 341 354 assertEqual(new BitArray(new Uint8Array([1, 2, 3])).intFromSlice(0, 2), 258); 342 355 assertEqual( 343 356 new BitArray(new Uint8Array([1, 2, 3])).sliceAfter(1), 344 - new BitArray(new Uint8Array([2, 3])) 357 + new BitArray(new Uint8Array([2, 3])), 345 358 ); 346 359 347 360 // Result.isOk ··· 425 438 426 439 assertEqual( 427 440 new ExampleRecordImpl(1, 2, 3).withFields({}), 428 - new ExampleRecordImpl(1, 2, 3) 441 + new ExampleRecordImpl(1, 2, 3), 429 442 ); 430 443 assertEqual( 431 444 new ExampleRecordImpl(1, 2, 3).withFields({ boop: 6, 0: 40 }), 432 - new ExampleRecordImpl(40, 2, 6) 445 + new ExampleRecordImpl(40, 2, 6), 433 446 ); 434 447 assertEqual( 435 448 new ExampleRecordImpl(1, 2, 3).withFields({ boop: 4, detail: 5, 0: 6 }), 436 - new ExampleRecordImpl(6, 5, 4) 449 + new ExampleRecordImpl(6, 5, 4), 437 450 ); 438 451 439 452 // Test BitArray can only be constructed from Uint8Array, not ArrayBuffer