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

Configure Feed

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

Fix bug with js numbers

+89
+4
CHANGELOG.md
··· 8 8 unqualified import even if it was already imported. 9 9 ([Surya Rose](https://github.com/GearsDatapacks)) 10 10 11 + - Fixed a bug where numbers starting with `0x_`, `0o_` and `0b_` would cause 12 + a syntax error when compiling to JavaScript. 13 + ([Surya Rose](https://github.com/GearsDatapacks)) 14 + 11 15 ## v1.10.0-rc1 - 2025-04-05 12 16 13 17 ### Compiler
+4
compiler-core/src/javascript/expression.rs
··· 1461 1461 value 1462 1462 }; 1463 1463 1464 + // If the number starts with `0x_`, `0b_` or `0o_`, that is valid Gleam syntax 1465 + // but not valid JavaScript syntax, so we remove the `_` here. 1466 + let value = value.trim_start_matches('_'); 1467 + 1464 1468 let value = value.trim_start_matches('0'); 1465 1469 if value.is_empty() { 1466 1470 out.push('0');
+36
compiler-core/src/javascript/tests/numbers.rs
··· 313 313 "# 314 314 ); 315 315 } 316 + 317 + // https://github.com/gleam-lang/gleam/issues/4459 318 + #[test] 319 + fn underscore_after_hexadecimal_prefix() { 320 + assert_js!( 321 + " 322 + pub fn main() { 323 + 0x_12_34 324 + } 325 + " 326 + ); 327 + } 328 + 329 + // https://github.com/gleam-lang/gleam/issues/4459 330 + #[test] 331 + fn underscore_after_octal_prefix() { 332 + assert_js!( 333 + " 334 + pub fn main() { 335 + 0o_12_34 336 + } 337 + " 338 + ); 339 + } 340 + 341 + // https://github.com/gleam-lang/gleam/issues/4459 342 + #[test] 343 + fn underscore_after_binary_prefix() { 344 + assert_js!( 345 + " 346 + pub fn main() { 347 + 0b_10_01 348 + } 349 + " 350 + ); 351 + }
+15
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__underscore_after_binary_prefix.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/numbers.rs 3 + expression: "\npub fn main() {\n 0b_10_01\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn main() { 8 + 0b_10_01 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + export function main() { 14 + return 0b10_01; 15 + }
+15
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__underscore_after_hexadecimal_prefix.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/numbers.rs 3 + expression: "\npub fn main() {\n 0x_12_34\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn main() { 8 + 0x_12_34 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + export function main() { 14 + return 0x12_34; 15 + }
+15
compiler-core/src/javascript/tests/snapshots/gleam_core__javascript__tests__numbers__underscore_after_octal_prefix.snap
··· 1 + --- 2 + source: compiler-core/src/javascript/tests/numbers.rs 3 + expression: "\npub fn main() {\n 0o_12_34\n}\n" 4 + --- 5 + ----- SOURCE CODE 6 + 7 + pub fn main() { 8 + 0o_12_34 9 + } 10 + 11 + 12 + ----- COMPILED JAVASCRIPT 13 + export function main() { 14 + return 0o12_34; 15 + }