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:
parent
a4bd8dc623
commit
6ccf196b61
1 changed files with 26 additions and 2 deletions
|
@ -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('');"
|
||||
|
||||
|
||||
# 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: []
|
||||
|
||||
|
|
Loading…
Reference in a new issue