Releases: FlatLang/Flat
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
Statements as expressions #199
Control structure statements can now be used as expressions. The affected statements types include:
If statements
Returns
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'")
}
Assignments
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'")
}
Match statements
Returns
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'")
}
Assignments
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'")
}
Remove "new" keyword from constructor calls #408
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).
Example:
Previously constructors that were called like this:
new CliArg("--link", new Array(), minCount: 0, maxCount: 1)
can (and must) now be:
CliArg("--link", Array(), minCount: 0, maxCount: 1)
Add target runtimes #410
You can now use the [TargetRuntime]
annotation to
target specific runtimes for runtime specific code. For example,
[TargetRuntime browser]
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");
}
}
Handle primitive null assignments
Variables of a primitive type are now handled as reference types when they are assigned as null.
Handle inline local declaration assignments
The Flat compiler now adds metadata to local declarations and assignments so that the code generators can generate inline local declaration assignments.
General bug fixes #403
- Fixed some method calls with unambiguous argument names failing as ambiguous.
- Fixed null checks being added inside wrong scope for safe navigation operators in if statement condition.
- Fix redundant returns from being generated to transpiled code.
Full Changelog: v0.1.5...v0.1.6
v0.1.5
Full Changelog: v0.1.4...v0.1.5
v0.1.4
Full Changelog: v0.1.3...v0.1.4
v0.1.3
Full Changelog: v0.1.2...v0.1.3
v0.1.2
Full Changelog: v0.1.1...v0.1.2
v0.1.1
Full Changelog: v0.1.0...v0.1.1
v0.1.0
Update build.yml