-
Notifications
You must be signed in to change notification settings - Fork 3
Home
Enable latest ES features for LiveScript.
- Module
import
to this
at top scope is compiled to module import instead, importing to other variables or at inner scope is unchanged. import name
was compiled to import$(this, name)
, but this doesn't make sense when using modules, since this
points to undefined
at top scope.
import name, name1, name2: alias
import module: {name0, name1: alias1}
import name from "name";
import name1 from "name1";
import alias from "name2";
import { name0, name1 as alias1 } from "module";
export
compiles to ES module export
, the result works like the original when converted to common js module.
The only exception is exporting named object literals, this compiles to export from
instead.
export {name0, name1}
export default: name, alias: name
export external: {selected, alias1: another}
export { name0, name1 };
export { name as default, name as alias };
export { selected, another as alias1 } from "external";
- Destructing assignment and parameters
Array/object destructing is converted to its ES equivalent.
[a, b: {c: [d, e: f: g]}] = h
let a, d, g;
[a, {
b: {
c: [d, {
e: {
f: g
}
}]
}
}] = h;
Function parameters, default values and splats are also converted to modern version:
function repack [a, [b=2]] ...c
[a, ...c, b]
function repack([a, [b = 2]], ...c) {
return [a, ...c, b];
}
-
async
/await
An async function is a function uses await.
--harmony
flag should be passed to node 7 to enable this feature.
->
data = await <| await fetch \https://api.github.com/gists/public .json!
(async function () {
let data;
return data = await (await fetch("https://api.github.com/gists/public")).json();
});
- External helpers
Helper functions are replaced with builtin functions.
a <<< b
Object.assign(a, b)
- Statement completion value
Result of statements and automatic return are converted to do
expression, no need to use temporary variables.
function a b, c
d = if b then 0
if c
d
else
1
function a(b, c) {
let d;
d = do {
if (b) {
0;
}
};
return do {
if (c) {
d;
} else {
1;
}
};
}
- Block scope
- Arrow Functions