2024-10-08
IDE Update
- AI Codelens now supports
/generateand/fixcommands.
The /generate command provides a generic interface for generating code.

The /fix command reads the current function's error information and suggests fixes.

Language Updates
- Adjusted the precedence of infix expressions and
if,match,loop,while,for,trycontrol flow expressions. These control flow expressions can no longer directly appear in positions requiring infix expressions and now require an additional layer of parentheses when nested.
For example, the syntax for if and match is:
if <infix-expr> { <expression> } [else { <expression> }]
match <infix-expr> { <match-cases> }
Since if, match, loop, while, for, try are no longer considered infix expressions, code like if if expr {} {} is now invalid:
// invalid
if if cond {a} else {b} {v} else {d}
match match expr { ... } { ... }
let a = expr1 + expr2 + if a {b} else {c} + expr3
// valid
if (if cond {a} else {b}) {v} else {d}
match (match expr { ... }) { ... }
let a = expr1 + expr2 + (if a {b} else {c}) + expr3
-
JavaScript backend
- Arrays now compile to native JS arrays, making interaction with JS more convenient.
-
Standard Library API
- Added
concatandfrom_arrayfunctions to theStringpackage, deprecatingArray::join. - Added
rev_concat()to theimmut/listpackage. Buffertype now includeslengthandis_emptyfunctions.- Improved the
to_jsonfunction for theOptiontype.
- Added
-
Experimental Library API
x/fspackage now supports the Wasm, Wasm-gc, and JS backends, including the following APIs:write_string_to_file,write_bytes_to_fileread_file_to_string,read_file_to_bytespath_existsread_dircreate_diris_dir,is_fileremove_dir,remove_file
Build System Updates
-
moon test -pnow supports fuzzy matching. For example,moon test -p moonbitlang/core/builtincan be shortened tomoon test -p mcbormoon test -p builtin. -
In
moon.pkg.json, if thesourcefield is an empty string"", it is equivalent to".", representing the current directory.
Moondoc Update
- The documentation generator now supports package-level
READMEfiles. AnyREADME.mdin the same directory asmoon.pkg.jsonwill be displayed on the package’s documentation page.