# We usually do not check the actual JS output from the compiler, but since # JSX is not natively supported by Node, we do it in this case. test 'self closing', -> eqJS '''
''', '''
; ''' test 'self closing formatting', -> eqJS '''
''', '''
; ''' test 'self closing multiline', -> eqJS '''
''', '''
; ''' test 'regex attribute', -> eqJS '''
asds/} /> ''', '''
asds/} />; ''' test 'string attribute', -> eqJS '''
''', '''
; ''' test 'simple attribute', -> eqJS '''
''', '''
; ''' test 'assignment attribute', -> eqJS '''
''', ''' var y;
; ''' test 'object attribute', -> eqJS '''
''', '''
; ''' test 'attribute without value', -> eqJS '''
''', '''
; ''' test 'paired', -> eqJS '''
''', '''
; ''' test 'simple content', -> eqJS '''
Hello world
''', '''
Hello world
; ''' test 'content interpolation', -> eqJS '''
Hello {42}
''', '''
Hello {42}
; ''' test 'nested tag', -> eqJS '''
''', '''
; ''' test 'tag inside interpolation formatting', -> eqJS '''
Hello {}
''', '''
Hello
; ''' test 'tag inside interpolation, tags are callable', -> eqJS '''
Hello { x}
''', '''
Hello {(x)}
; ''' test 'tags inside interpolation, tags trigger implicit calls', -> eqJS '''
Hello {f }
''', '''
Hello {f()}
; ''' test 'regex in interpolation', -> eqJS '''
asds/}>
{/>asdsad ''', '''
asds/}>
{/>asdsad; ''' test 'interpolation in string attribute value', -> eqJS '''
''', '''
; ''' # Unlike in `coffee-react-transform`. test 'bare numbers not allowed', -> throws -> CoffeeScript.compile '
' test 'bare expressions not allowed', -> throws -> CoffeeScript.compile '
' test 'bare complex expressions not allowed', -> throws -> CoffeeScript.compile '
' test 'unescaped opening tag angle bracket disallowed', -> throws -> CoffeeScript.compile '<<' test 'space around equal sign', -> eqJS '''
''', '''
; ''' # The following tests were adopted from James Friend’s # [https://github.com/jsdf/coffee-react-transform](https://github.com/jsdf/coffee-react-transform). test 'ambiguous tag-like expression', -> throws -> CoffeeScript.compile 'x = a c' test 'ambiguous tag', -> eqJS ''' a c ''', ''' a( c ); ''' test 'escaped CoffeeScript attribute', -> eqJS ''' ''', ''' ; ''' test 'escaped CoffeeScript attribute over multiple lines', -> eqJS ''' ''', ''' ; ''' test 'multiple line escaped CoffeeScript with nested CSX', -> eqJS ''' { for n in a
a asf
  • { n+1 }
  • }
    ''', ''' var n; {(function() { var i, len, results; results = []; for (i = 0, len = a.length; i < len; i++) { n = a[i]; results.push(); } return results; })()}
    ; ''' test 'nested CSX within an attribute, with object attr value', -> eqJS ''' } /> ''', ''' } /> ; ''' test 'complex nesting', -> eqJS '''
    ''', '''
    ; ''' test 'multiline tag with nested CSX within an attribute', -> eqJS ''' } > blah blah blah ''', ''' var name; }> blah blah blah ; ''' test 'escaped CoffeeScript with nested object literals', -> eqJS ''' blah blah blah { {'a' : {}, 'asd': 'asd'} } ''', ''' blah blah blah {{ 'a': {}, 'asd': 'asd' }} ; ''' test 'multiline tag attributes with escaped CoffeeScript', -> eqJS ''' ''', ''' ; ''' test 'lots of attributes', -> eqJS ''' ''', ''' ; ''' # TODO: fix partially indented CSX # test 'multiline elements', -> # eqJS ''' #
    # test = /432/gm # this is a regex # 6 /432/gm # this is division # } # > #
    #
    #
    #
    #
    #
    #
    #
    #
    # ''', ''' # bla # ''' test 'complex regex', -> eqJS ''' /\\/\\/\\>\\// ''', ''' ; /\\/\\/\\>\\//; ''' test 'heregex', -> eqJS ''' test = /432/gm # this is a regex 6 /432/gm # this is division {test = //} this is a regex containing something which looks like a tag REGEX = /// ^ (/ (?! [\s=] ) # comment comment comment [^ [ / \n \\ ]* # comment comment (?: (?: \\[\s\S] # comment comment | \[ # comment comment [^ \] \n \\ ]* (?: \\[\s\S] [^ \] \n \\ ]* )* tag ] ) [^ [ / \n \\ ]* )* /) ([imgy]{0,4}) (?!\w) /// ''', ''' var REGEX, test; test = /432/gm; 6 / 432 / gm; {(test = //)} this is a regex containing something which looks like a tag ; ; REGEX = /^(\\/(?![s=])[^[\\/ ]*(?:(?:\\[sS]|[[^] ]*(?:\\[sS][^] ]*)*tag<\\/Tag>])[^[\\/ ]*)*\\/)([imgy]{0,4})(?!w)/; ; ''' test 'comment within CSX is not treated as comment', -> eqJS ''' # i am not a comment ''', ''' # i am not a comment ; ''' test 'comment at start of CSX escape', -> eqJS ''' {# i am a comment "i am a string" } ''', ''' {"i am a string"} ; ''' test 'CSX comment cannot be used inside interpolation', -> throws -> CoffeeScript.compile ''' {# i am a comment} ''' test 'comment syntax cannot be used inline', -> throws -> CoffeeScript.compile ''' {#comment inline} ''' test 'string within CSX is ignored', -> eqJS ''' "i am not a string" 'nor am i' ''', ''' "i am not a string" 'nor am i' ; ''' test 'special chars within CSX are ignored', -> eqJS """ a,/';][' a\''@$%^&˚¬∑˜˚∆å∂¬˚*()*&^%$>> '"''"'''\'\'m' i """, """ a,/';][' a''@$%^&˚¬∑˜˚∆å∂¬˚*()*&^%$>> '"''"'''''m' i ; """ test 'html entities (name, decimal, hex) within CSX', -> eqJS ''' &&&€ € €;; ''', ''' &&&€ € €;; ; ''' test 'tag with {{}}', -> eqJS ''' ''', ''' ; ''' test 'tag with namespace', -> eqJS ''' ''', ''' ; ''' test 'tag with lowercase namespace', -> eqJS ''' ''', ''' ; ''' test 'self closing tag with namespace', -> eqJS ''' ''', ''' ; ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'self closing tag with spread attribute', -> # eqJS ''' # # ''', ''' # React.createElement(Component, Object.assign({"a": (b)}, x , {"b": "c"})) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'complex spread attribute', -> # eqJS ''' # # ''', ''' # React.createElement(Component, Object.assign({}, x, {"a": (b)}, x , {"b": "c"}, $my_xtraCoolVar123 )) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'multiline spread attribute', -> # eqJS ''' # # # ''', ''' # React.createElement(Component, Object.assign({}, # x , {"a": (b)}, x , {"b": "c"}, z ) # ) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'multiline tag with spread attribute', -> # eqJS ''' # # # ''', ''' # React.createElement(Component, Object.assign({ \ # "z": "1" # }, x, { \ # "a": (b), \ # "b": "c" # }) # ) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'multiline tag with spread attribute first', -> # eqJS ''' # # # ''', ''' # React.createElement(Component, Object.assign({}, \ # x, { \ # "z": "1", \ # "a": (b), \ # "b": "c" # }) # ) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'complex multiline spread attribute', -> # eqJS ''' # #
    # # ''', ''' # React.createElement(Component, Object.assign({}, \ # y, {"a": (b)}, x , {"b": "c"}, z ), # React.createElement("div", {"code": (someFunc({a:{b:{}, C:'}'}}))}) # ) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'self closing spread attribute on single line', -> # eqJS ''' # # ''', ''' # React.createElement(Component, Object.assign({"a": "b", "c": "d"}, @props )) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'self closing spread attribute on new line', -> # eqJS ''' # # ''', ''' # React.createElement(Component, Object.assign({ \ # "a": "b", \ # "c": "d" # }, @props # )) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'self closing spread attribute on same line', -> # eqJS ''' # # ''', ''' # React.createElement(Component, Object.assign({ \ # "a": "b", \ # "c": "d" # }, @props )) # ''' # TODO: Uncomment the following test once destructured object spreads are supported. # test 'self closing spread attribute on next line', -> # eqJS ''' # # ''', ''' # React.createElement(Component, Object.assign({ \ # "a": "b", \ # "c": "d" # }, @props # )) # ''' test 'empty strings are not converted to true', -> eqJS ''' ''', ''' ; ''' test 'CoffeeScript @ syntax in tag name', -> throws -> CoffeeScript.compile ''' <@Component> ''' test 'hyphens in tag names', -> eqJS ''' {text} ''', ''' {text}; ''' test 'closing tags must be closed', -> throws -> CoffeeScript.compile ''' a = 3 div = 5 ok a
    div = 5 ok 3
    div = 5 ok (3)
    div = 5 a = [3] ok a[0]
    eqJS ''' a
    ''', ''' a
    ; ''' test 'tag inside CSX works following: number', -> eqJS ''' 3
    ''', ''' 3
    ; ''' test 'tag inside CSX works following: paren', -> eqJS ''' (3)
    ''', ''' (3)
    ; ''' test 'tag inside CSX works following: square bracket', -> eqJS ''' ]
    ''', ''' ]
    ; ''' test 'unspaced less than inside CSX works but is not encouraged', -> eqJS ''' a = 3 div = 5 html = {a ''', ''' var a, div, html; a = 3; div = 5; html = {a < div}; ''' test 'unspaced less than before CSX works but is not encouraged', -> eqJS ''' div = 5 res = 2
    ''', ''' var div, html, res; div = 5; res = 2 < div; html = ; ''' test 'unspaced less than after CSX works but is not encouraged', -> eqJS ''' div = 5 html = res = 2
    ; res = 2 < div; '''