V0.1.6 RELEASE NOTES- Aug 19, 2022 | SHARE PAGE |
DOWNLOAD BETA v0.1.6
NOTABLE CHANGES
tl;dr:
- Statements as expressions
- Remove "new" keyword from constructor calls
- Add target runtimes
- Handle primitive null assignments
- Handle inline local declaration assignments
- Bug fixes
Control structure statements can now be used as expressions. The affected statements types include:
Previously returns would need to be written as such:
if (file.isDirectory || file.isSymbolicLink) {
return location + "/flat.json"
} else if (file.isFile) {
return file.location
} else {
throw InvalidFlatJsonException("Invalid flat.json location '#file.location'")
}
Now they can be written as such:
return if (file.isDirectory || file.isSymbolicLink) {
location + "/flat.json"
} else if (file.isFile) {
file.location
} else {
throw InvalidFlatJsonException("Invalid flat.json location '#file.location'")
}
Previously variable assignments would need to be written as such:
var String result
if (file.isDirectory || file.isSymbolicLink) {
result = location + "/flat.json"
} else if (file.isFile) {
result = file.location
} else {
throw InvalidFlatJsonException("Invalid flat.json location '#file.location'")
}
Now they can be written as such:
let result = if (file.isDirectory || file.isSymbolicLink) {
location + "/flat.json"
} else if (file.isFile) {
file.location
} else {
throw InvalidFlatJsonException("Invalid flat.json location '#file.location'")
}
Previously returns would need to be written as such:
match (package) {
"main" => return mainSource
"test" => return testSource
default => throw InvalidCommandException("Invalid installation package '#package'")
}
Now they can be written as such:
return match (package) {
"main" => mainSource
"test" => testSource
default => throw InvalidCommandException("Invalid installation package '#package'")
}
Previously variable assignments would need to be written as such:
var Package result
match (package) {
"main" => result = mainSource
"test" => result = testSource
default => throw InvalidCommandException("Invalid installation package '#package'")
}
Now they can be written as such:
let result = match (package) {
"main" => mainSource
"test" => testSource
default => throw InvalidCommandException("Invalid installation package '#package'")
}
The new
keyword is no longer necessary (or allowed)
when calling a constructor. It is redundant and adds extra characters, and does not add
any extra clarity as long as basic naming conventions are followed. The change does not
apply to array initializations (array initializations still require the
new
keyword).
You can now use the [
annotation to
target specific runtimes for runtime specific code. For example,
][
can be used to only compile
browser specific code. An example use case of this is if you want to handle logging
differently depending on the runtime. In node you may want to use
]process.stdout
instead of console.log
for messages:
[TargetRuntime browser]
logMessage(String message) {
external js {
console.log(#{message.chars.data});
}
}
[TargetRuntime not browser]
logMessage(String message) {
external js {
process.stdout.write(#{message.chars.data} + "\n");
}
}