Skip to content

Instantly share code, notes, and snippets.

@matehat
Forked from weepy/gist:348943
Created March 30, 2010 12:01
Show Gist options
  • Save matehat/349042 to your computer and use it in GitHub Desktop.
Save matehat/349042 to your computer and use it in GitHub Desktop.
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