Created
December 31, 2014 12:24
-
-
Save mateusvahl/45bfb3e10a84e34b0074 to your computer and use it in GitHub Desktop.
`@` alias to `this` 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
/** | |
Sweet.js version: 0.7.2 | |
`this` nickname `@` | |
Expected: | |
@ -> this | |
@something -> this.something | |
example: | |
function hello (tag) { | |
var element = @document.querySelectorAll(tag); | |
console.log(element, @); | |
Object.prototype.toString.call(@, 5); | |
return @; | |
} | |
*/ | |
macro @ { | |
rule { ; } => { this; } | |
rule { , } => { this, } | |
rule { $exp } => { this.$exp } | |
rule { } => { this } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To have support for
@[name]
syntax from CoffeeScript, a following rule can be added beforerule { $exp } => { this.$exp }
.Not sure entirely why last rule doesn't work in that particular case.