-
-
Save matehat/349042 to your computer and use it in GitHub Desktop.
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
class UsingNode extends BaseNode | |
type: 'Using' | |
constructor: (object, methods) -> | |
@object: object | |
@methods: methods | |
compile_node: (o) -> | |
if @methods[0] == "*" | |
"for(var p in $@object) eval('var ' + p + '=' + $@object[p])" | |
else | |
assigns: "$prop=${@object}.$prop" for prop in @methods | |
"var ${assigns.join(", ")}" | |
CoffeeScript.extend -> | |
return false unless @chunk.match(/^using/) | |
@i: + @chunk.length | |
chunks: @chunk.split " " | |
chunks.shift() | |
object: chunks.shift() | |
methods: chunks.join("").replace(/^\s+|\s+$/g).split "," | |
@token 'EXTENSION', new UsingNode(object, methods) | |
true | |
js: CoffeeScript.compile 'using MyModule *', {no_wrap: on} | |
ok js is "for(var p in MyModule) eval('var ' + p + '=' + MyModule[p]);" | |
js: CoffeeScript.compile 'using MyModule get, set, del', {no_wrap: on} | |
ok js is "var get=MyModule.get, set=MyModule.set, del=MyModule.del;" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment