MoonBit Update
IDE Update
- AI Codelens now supports
/generate
and/fix
commands.
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
,try
control 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
concat
andfrom_array
functions to theString
package, deprecatingArray::join
. - Added
rev_concat()
to theimmut/list
package. Buffer
type now includeslength
andis_empty
functions.- Improved the
to_json
function for theOption
type.
- Added
-
Experimental Library API
x/fs
package now supports the Wasm, Wasm-gc, and JS backends, including the following APIs:write_string_to_file
,write_bytes_to_file
read_file_to_string
,read_file_to_bytes
path_exists
read_dir
create_dir
is_dir
,is_file
remove_dir
,remove_file
Build System Updates
-
moon test -p
now supports fuzzy matching. For example,moon test -p moonbitlang/core/builtin
can be shortened tomoon test -p mcb
ormoon test -p builtin
. -
In
moon.pkg.json
, if thesource
field is an empty string""
, it is equivalent to"."
, representing the current directory.
Moondoc Update
- The documentation generator now supports package-level
README
files. AnyREADME.md
in the same directory asmoon.pkg.json
will be displayed on the package’s documentation page.