Created
May 13, 2014 06:23
-
-
Save aaronpowell/6f8b72be982bfdcc7293 to your computer and use it in GitHub Desktop.
Type annotations and checking with Sweet.js
This file contains 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
macroclass typedef { | |
pattern { $x:ident : $type:ident } | |
pattern { $x:ident : $type:lit } | |
} | |
let function = macro { | |
rule { $name ($params:typedef ...) { $body ... } } => { | |
function $name ($params$x ...) { | |
$(if (typeof $params$x !== typeof $params$type) { | |
throw new Error('Found type ' + (typeof $params$x) + ' but expected ' + typeof $params$type); | |
}) ... | |
$body ... | |
} | |
} | |
} | |
function foo (a : 0) { | |
console.log(a); | |
} | |
foo(1); | |
foo('a'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment