Skip to content

Instantly share code, notes, and snippets.

@weepy
Created March 30, 2010 09:19
Show Gist options
  • Save weepy/348943 to your computer and use it in GitHub Desktop.
Save weepy/348943 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)\n 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/)
line: @chunk.split("\n")[0]
@i: + line.length
[_using, object, methods...]: line.split " "
methods: methods.join("").replace(/^\s+|\s+$/g).split ","
@token 'EXTENSION', new UsingNode(object, methods)
true
cs: """
x: 1
using MyModule *
y: 2
using MyModule get, set
"""
js: CoffeeScript.compile cs, {no_wrap: on}
alert(js)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment