This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Annotations can only occur immediately before a variable, a function declaration or an assignment | |
``` | |
@Component('position') | |
module.exports = function (x, y) { | |
return {x: x || 0, y: y || 0}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
`a?()` | |
Call its operand only if it is defined and a `function`, returns `undefined` otherwise | |
`a?.b` or `a?['b']` | |
Access a property on its operand only if it is defined and not `null` nor `undefined`, returns `undefined` otherwise |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
``` | |
var foo = { | |
lazy computed() { | |
return []; | |
} | |
}; | |
``` | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
``` | |
var foo = { | |
bound method() { | |
return this; | |
} | |
}; | |
var method = foo.method; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Immediately invoke a block with scopped variables | |
``` | |
do (foo = 'bar') { | |
... | |
} | |
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro statement { | |
rule { return $expression:expr } => { $expression; continue } | |
rule { $expression:expr ... } | |
} | |
macro inline_forEach { | |
rule { ($list:expr, function ($value:ident, $index:ident, $ref:ident) { | |
$body:statement ... | |
}, $context:expr) } => { | |
(function ($ref) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro inline_map { | |
rule { ($list:expr, function ($value:ident, $index:ident, $ref:ident) { | |
$return:expression | |
}, $context:expr) } => { | |
(function ($ref) { | |
var length = $ref.length, res = new Array(length); | |
for (var $index = 0; $index < length; $index += 1) { | |
var $value = $ref[$index]; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro inline_indexOf { | |
rule { ($list:expr, $needle:expr) } => { | |
(function (ref, needle) { | |
var length = ref.length; | |
for (var i = 0; i < length; i += 1) { | |
if (ref[i] === needle) return i; | |
} | |
return -1; | |
}($list, $needle)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro inline_lastIndexOf { | |
rule { ($list:expr, $needle:expr) } => { | |
(function (ref, needle) { | |
for (var i = ref.length - 1; i > -1; i -= 1) { | |
if (ref[i] === needle) return i; | |
} | |
return -1; | |
}($list, $needle)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let keys = macro { | |
rule infix { Object. | () } => { Object.keys() } | |
rule infix { Object. | ($object:expr) } => { | |
(function (object) { | |
if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) { | |
throw new TypeError('Object.keys called on non-object'); | |
} | |
var keys = [], proto = object.__proto__; |