-
-
Save effection/5276656 to your computer and use it in GitHub Desktop.
Better class macro in Sweet.js
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 class { | |
case $className { constructor $constParam $constBody $rest ... } => { | |
function $className $constParam $constBody | |
class $className { $rest ... } | |
} | |
case $className { private_function $pMethodName $pMethodParam $pMethodBody $rest ...} => { | |
function $pMethodName $pMethodParam $pMethodBody | |
class $className { $rest ... } | |
} | |
case $className { $($methodName $methodParam $methodBody) ... } => { | |
$($className.prorotype.$methodName = function $methodName $methodParam $methodBody;) ... | |
} | |
} | |
class Person { | |
constructor(name) { | |
this.name = name; | |
} | |
private_function myMethod() { console.log('private'); } | |
private_function otherPrivate() { console.log('private'); } | |
say(msg) { | |
console.log(this.name + " says: " + msg); | |
} | |
other(foo) { | |
console.log("other method"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment