1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

adding another language extension test, with %w{} style ruby word array literals

This commit is contained in:
Jeremy Ashkenas 2010-03-15 21:47:40 -07:00
parent a4bd8dc623
commit 6ccf196b61

View file

@ -27,8 +27,32 @@ CoffeeScript.extend ->
true
# Compile with the extension.
js: CoffeeScript.compile('return --tobesplit--', {no_wrap: on})
js: CoffeeScript.compile 'return --tobesplit--', {no_wrap: on}
ok js is "return 'tobesplit'.split('');"
Lexer.extensions: []
# Let's try a different extension, for Ruby-style array literals.
class WordArrayNode extends BaseNode
type: 'WordArray'
constructor: (words) ->
@words: words
compile_node: (o) ->
strings = ("\"$word\"" for word in @words).join ', '
"[$strings]"
CoffeeScript.extend ->
return false unless words: @chunk.match(/^%w\{(.*)\}/)
@i += words[0].length
@token 'EXTENSION', new WordArrayNode(words[1].split(/\s+/))
true
js: CoffeeScript.compile 'puts %w{one two three}', {no_wrap: on}
ok js is 'puts(["one", "two", "three"]);'
Lexer.extensions: []