AST: "CSX" -> "JSX" (#5188)

* updated grammar

* restore JSXIdentifier::astType()
This commit is contained in:
Julian Rosse
2019-03-31 15:13:05 -04:00
committed by Geoffrey Booth
parent 0c2d3673d3
commit 28a1a1d304
14 changed files with 299 additions and 331 deletions

View File

@@ -200,7 +200,7 @@ test "AST as expected for IdentifierLiteral node", ->
type: 'Identifier'
name: 'id'
test "AST as expected for CSXTag node", ->
test "AST as expected for JSXTag node", ->
testExpression '<CSXY />',
type: 'JSXElement'
openingElement:

View File

@@ -2241,7 +2241,7 @@ test "AST location data as expected for Existence node", ->
line: 1
column: 7
test "AST location data as expected for CSXTag node", ->
test "AST location data as expected for JSXTag node", ->
testAstLocationData '<CSXY />',
type: 'JSXElement'
openingElement:

View File

@@ -725,7 +725,7 @@ test "Block comment in an interpolated string", ->
eqJS '"a#{### Comment ###}b"', '`a${/* Comment */""}b`;'
eqJS '"a#{### 1 ###}b#{### 2 ###}c"', '`a${/* 1 */""}b${/* 2 */""}c`;'
test "#4629: Block comment in CSX interpolation", ->
test "#4629: Block comment in JSX interpolation", ->
eqJS '<div>{### Comment ###}</div>', '<div>{/* Comment */}</div>;'
eqJS '''
<div>

View File

@@ -1589,17 +1589,17 @@ test "#4248: Unicode code point escapes", ->
\ ^\^^^^^^^^^^^^^
'''
test "CSX error: non-matching tag names", ->
test "JSX error: non-matching tag names", ->
assertErrorFormat '''
<div><span></div></span>
''',
'''
[stdin]:1:7: error: expected corresponding CSX closing tag for span
[stdin]:1:7: error: expected corresponding JSX closing tag for span
<div><span></div></span>
^^^^
'''
test "CSX error: bare expressions not allowed", ->
test "JSX error: bare expressions not allowed", ->
assertErrorFormat '''
<div x=3 />
''',
@@ -1609,7 +1609,7 @@ test "CSX error: bare expressions not allowed", ->
^
'''
test "CSX error: unescaped opening tag angle bracket disallowed", ->
test "JSX error: unescaped opening tag angle bracket disallowed", ->
assertErrorFormat '''
<Person><<</Person>
''',
@@ -1619,7 +1619,7 @@ test "CSX error: unescaped opening tag angle bracket disallowed", ->
^^
'''
test "CSX error: ambiguous tag-like expression", ->
test "JSX error: ambiguous tag-like expression", ->
assertErrorFormat '''
x = a <b > c
''',
@@ -1629,51 +1629,51 @@ test "CSX error: ambiguous tag-like expression", ->
^
'''
test 'CSX error: invalid attributes', ->
test 'JSX error: invalid attributes', ->
assertErrorFormatAst '''
<div a="b" {props} />
''', '''
[stdin]:1:12: error: Unexpected token. Allowed CSX attributes are: id="val", src={source}, {props...} or attribute.
[stdin]:1:12: error: Unexpected token. Allowed JSX attributes are: id="val", src={source}, {props...} or attribute.
<div a="b" {props} />
^^^^^^^
'''
assertErrorFormatAst '''
<div a={b} {a:{b}} />
''', '''
[stdin]:1:12: error: Unexpected token. Allowed CSX attributes are: id="val", src={source}, {props...} or attribute.
[stdin]:1:12: error: Unexpected token. Allowed JSX attributes are: id="val", src={source}, {props...} or attribute.
<div a={b} {a:{b}} />
^^^^^^^
'''
assertErrorFormatAst '''
<div {"#{a}"} />
''', '''
[stdin]:1:6: error: Unexpected token. Allowed CSX attributes are: id="val", src={source}, {props...} or attribute.
[stdin]:1:6: error: Unexpected token. Allowed JSX attributes are: id="val", src={source}, {props...} or attribute.
<div {"#{a}"} />
^^^^^^^^
'''
assertErrorFormatAst '''
<div props... />
''', '''
[stdin]:1:11: error: Unexpected token. Allowed CSX attributes are: id="val", src={source}, {props...} or attribute.
[stdin]:1:11: error: Unexpected token. Allowed JSX attributes are: id="val", src={source}, {props...} or attribute.
<div props... />
^^^
'''
assertErrorFormatAst '''
<div {a:"b", props..., c:d()} />
''', '''
[stdin]:1:6: error: Unexpected token. Allowed CSX attributes are: id="val", src={source}, {props...} or attribute.
[stdin]:1:6: error: Unexpected token. Allowed JSX attributes are: id="val", src={source}, {props...} or attribute.
<div {a:"b", props..., c:d()} />
^^^^^^^^^^^^^^^^^^^^^^^^
'''
assertErrorFormatAst '''
<div {props..., a, b} />
''', '''
[stdin]:1:6: error: Unexpected token. Allowed CSX attributes are: id="val", src={source}, {props...} or attribute.
[stdin]:1:6: error: Unexpected token. Allowed JSX attributes are: id="val", src={source}, {props...} or attribute.
<div {props..., a, b} />
^^^^^^^^^^^^^^^^
'''
test '#5034: CSX error: Adjacent JSX elements must be wrapped in an enclosing tag', ->
test '#5034: JSX error: Adjacent JSX elements must be wrapped in an enclosing tag', ->
assertErrorFormat '''
render = -> (
<Row>a</Row>

View File

@@ -184,7 +184,7 @@ test 'escaped CoffeeScript attribute over multiple lines', ->
<Person name={test() ? 'yes' : 'no'} />;
'''
test 'multiple line escaped CoffeeScript with nested CSX', ->
test 'multiple line escaped CoffeeScript with nested JSX', ->
eqJS '''
<Person name={
if test()
@@ -222,7 +222,7 @@ test 'multiple line escaped CoffeeScript with nested CSX', ->
</Person>;
'''
test 'nested CSX within an attribute, with object attr value', ->
test 'nested JSX within an attribute, with object attr value', ->
eqJS '''
<Company>
<Person name={<NameComponent attr3={ {'a': {}, b: '{'} } />} />
@@ -248,7 +248,7 @@ test 'complex nesting', ->
})} />;
'''
test 'multiline tag with nested CSX within an attribute', ->
test 'multiline tag with nested JSX within an attribute', ->
eqJS '''
<Person
name={
@@ -299,7 +299,7 @@ test 'lots of attributes', ->
<Person eyes={2} friends={getFriends()} popular="yes" active={isActive() ? 'active' : 'inactive'} data-attr='works' checked check={me_out} />;
'''
# TODO: fix partially indented CSX
# TODO: fix partially indented JSX
# test 'multiline elements', ->
# eqJS '''
# <div something={
@@ -378,7 +378,7 @@ test 'heregex', ->
<Person />;
'''
test 'comment within CSX is not treated as comment', ->
test 'comment within JSX is not treated as comment', ->
eqJS '''
<Person>
# i am not a comment
@@ -389,7 +389,7 @@ test 'comment within CSX is not treated as comment', ->
</Person>;
'''
test 'comment at start of CSX escape', ->
test 'comment at start of JSX escape', ->
eqJS '''
<Person>
{# i am a comment
@@ -403,7 +403,7 @@ test 'comment at start of CSX escape', ->
</Person>;
'''
test 'comment at end of CSX escape', ->
test 'comment at end of JSX escape', ->
eqJS '''
<Person>
{"i am a string"
@@ -418,7 +418,7 @@ test 'comment at end of CSX escape', ->
</Person>;
'''
test 'CSX comment cannot be used inside interpolation', ->
test 'JSX comment cannot be used inside interpolation', ->
throws -> CoffeeScript.compile '''
<Person>
{# i am a comment}
@@ -430,21 +430,21 @@ test 'comment syntax cannot be used inline', ->
<Person>{#comment inline}</Person>
'''
test 'string within CSX is ignored', ->
test 'string within JSX is ignored', ->
eqJS '''
<Person> "i am not a string" 'nor am i' </Person>
''', '''
<Person> "i am not a string" 'nor am i' </Person>;
'''
test 'special chars within CSX are ignored', ->
test 'special chars within JSX are ignored', ->
eqJS """
<Person> a,/';][' a\''@$%^&˚¬˜˚å¬˚*()*&^%$>> '"''"'''\'\'m' i </Person>
""", """
<Person> a,/';][' a''@$%^&˚¬˜˚å¬˚*()*&^%$>> '"''"'''''m' i </Person>;
"""
test 'html entities (name, decimal, hex) within CSX', ->
test 'html entities (name, decimal, hex) within JSX', ->
eqJS '''
<Person> &&&&euro; &#8364; &#x20AC;;; </Person>
''', '''
@@ -619,55 +619,55 @@ test 'closing tags must be closed', ->
<a></a
'''
# Tests for allowing less than operator without spaces when ther is no CSX
# Tests for allowing less than operator without spaces when ther is no JSX
test 'unspaced less than without CSX: identifier', ->
test 'unspaced less than without JSX: identifier', ->
a = 3
div = 5
ok a<div
test 'unspaced less than without CSX: number', ->
test 'unspaced less than without JSX: number', ->
div = 5
ok 3<div
test 'unspaced less than without CSX: paren', ->
test 'unspaced less than without JSX: paren', ->
div = 5
ok (3)<div
test 'unspaced less than without CSX: index', ->
test 'unspaced less than without JSX: index', ->
div = 5
a = [3]
ok a[0]<div
test 'tag inside CSX works following: identifier', ->
test 'tag inside JSX works following: identifier', ->
eqJS '''
<span>a<div /></span>
''', '''
<span>a<div /></span>;
'''
test 'tag inside CSX works following: number', ->
test 'tag inside JSX works following: number', ->
eqJS '''
<span>3<div /></span>
''', '''
<span>3<div /></span>;
'''
test 'tag inside CSX works following: paren', ->
test 'tag inside JSX works following: paren', ->
eqJS '''
<span>(3)<div /></span>
''', '''
<span>(3)<div /></span>;
'''
test 'tag inside CSX works following: square bracket', ->
test 'tag inside JSX works following: square bracket', ->
eqJS '''
<span>]<div /></span>
''', '''
<span>]<div /></span>;
'''
test 'unspaced less than inside CSX works but is not encouraged', ->
test 'unspaced less than inside JSX works but is not encouraged', ->
eqJS '''
a = 3
div = 5
@@ -682,7 +682,7 @@ test 'unspaced less than inside CSX works but is not encouraged', ->
html = <span>{a < div}</span>;
'''
test 'unspaced less than before CSX works but is not encouraged', ->
test 'unspaced less than before JSX works but is not encouraged', ->
eqJS '''
div = 5
res = 2<div
@@ -697,7 +697,7 @@ test 'unspaced less than before CSX works but is not encouraged', ->
html = <span />;
'''
test 'unspaced less than after CSX works but is not encouraged', ->
test 'unspaced less than after JSX works but is not encouraged', ->
eqJS '''
div = 5
html = <span />
@@ -712,7 +712,7 @@ test 'unspaced less than after CSX works but is not encouraged', ->
res = 2 < div;
'''
test '#4686: comments inside interpolations that also contain CSX tags', ->
test '#4686: comments inside interpolations that also contain JSX tags', ->
eqJS '''
<div>
{
@@ -727,7 +727,7 @@ test '#4686: comments inside interpolations that also contain CSX tags', ->
</div>;
'''
test '#4686: comments inside interpolations that also contain CSX attributes', ->
test '#4686: comments inside interpolations that also contain JSX attributes', ->
eqJS '''
<div>
<div anAttr={
@@ -742,7 +742,7 @@ test '#4686: comments inside interpolations that also contain CSX attributes', -
</div>;
'''
test '#5086: comments inside CSX tags but outside interpolations', ->
test '#5086: comments inside JSX tags but outside interpolations', ->
eqJS '''
<div>
<div ###comment### attribute={value} />
@@ -753,7 +753,7 @@ test '#5086: comments inside CSX tags but outside interpolations', ->
</div>;
'''
test '#5086: comments inside CSX attributes but outside interpolations', ->
test '#5086: comments inside JSX attributes but outside interpolations', ->
eqJS '''
<div>
<div attribute={###attr comment### value} />
@@ -764,7 +764,7 @@ test '#5086: comments inside CSX attributes but outside interpolations', ->
</div>;
'''
test '#5086: comments inside nested CSX tags and attributes but outside interpolations', ->
test '#5086: comments inside nested JSX tags and attributes but outside interpolations', ->
eqJS '''
<div>
<div>