Skip to content

Commit c34a6aa

Browse files
committed
fixed comment, used toJS, added error tests, fixed error in identifier regex, fixed interpolation inside attributes value and added test
1 parent e2c3e95 commit c34a6aa

File tree

8 files changed

+595
-538
lines changed

8 files changed

+595
-538
lines changed

lib/coffeescript/grammar.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/lexer.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/nodes.js

+6-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/coffeescript/parser.js

+526-527
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lexer.coffee

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ exports.Lexer = class Lexer
4848
@seenExport = no # Used to recognize EXPORT FROM? AS? tokens.
4949
@importSpecifierList = no # Used to identify when in an IMPORT {...} FROM? ...
5050
@exportSpecifierList = no # Used to identify when in an EXPORT {...} FROM? ...
51-
@includesCSX = no # Used to optimize CSX checks
51+
@includesCSX = no # Used to optimize CSX checks.
5252

5353
@chunkLine =
5454
opts.line or 0 # The start line for the current @chunk.
@@ -715,7 +715,7 @@ exports.Lexer = class Lexer
715715
offsetInChunk += index
716716

717717
unless str[...closingDelimiter.length] is closingDelimiter
718-
@error "missing #{closingDelimiter}", length: closingDelimiter.length
718+
@error "missing #{closingDelimiter}", length: delimiter.length
719719

720720
[firstToken, ..., lastToken] = tokens
721721
firstToken[2].first_column -= delimiter.length
@@ -1065,7 +1065,7 @@ IDENTIFIER = /// ^
10651065
///
10661066

10671067
CSX_IDENTIFIER = /// ^
1068-
(?!\d<)
1068+
(?![\d<])
10691069
( (?: (?!\s)[\-\.$\w\x7f-\uffff] )+ ) # like `IDENTIFIER` but includes `-`, `.`s
10701070
( [^\S]* = (?!=) )? # Is this an attribute name?
10711071
///

src/nodes.coffee

+5
Original file line numberDiff line numberDiff line change
@@ -2839,6 +2839,11 @@ exports.StringWithInterpolations = class StringWithInterpolations extends Base
28392839
shouldCache: -> @body.shouldCache()
28402840

28412841
compileNode: (o) ->
2842+
if @csxAttribute
2843+
wrapped = new Parens new StringWithInterpolations @body
2844+
wrapped.csxAttribute = yes
2845+
return wrapped.compileNode o
2846+
28422847
# Assumes that `expr` is `Value` » `StringLiteral` or `Op`
28432848
expr = @body.unwrap()
28442849

test/csx.coffee

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# We usually do not check the actual JS output from the compiler, but since
22
# CSX is not readily supported by Node, we do it in this case
3-
eqCSX = (cs, js) ->
4-
eq CoffeeScript.compile(cs, {bare: true}), js + '\n'
3+
eqCSX = (cs, js) -> eq toJS(cs), js
54

65
test 'self closing', ->
76
eqCSX '''
@@ -120,6 +119,13 @@ test 'regex in interpolation', ->
120119
<div x={/>asds/}><div />{/>asdsad</}</div>;
121120
'''
122121

122+
test 'interpolation in string attribute value', ->
123+
eqCSX '''
124+
<div x="Hello #{world}" />
125+
''', '''
126+
<div x={`Hello ${world}`} />;
127+
'''
128+
123129
# Unlike in coffee-react-transform
124130
test 'bare numbers not allowed', ->
125131
throws -> CoffeeScript.compile '<div x=3 />'
@@ -130,7 +136,7 @@ test 'bare expressions not allowed', ->
130136
test 'bare complex expressions not allowed', ->
131137
throws -> CoffeeScript.compile '<div x=f(3) />'
132138

133-
test 'unescaped opening tag arrows disallowed', ->
139+
test 'unescaped opening tag angle bracket disallowed', ->
134140
throws -> CoffeeScript.compile '<Person><<</Person>'
135141

136142
test 'space around equal sign', ->
@@ -143,10 +149,10 @@ test 'space around equal sign', ->
143149
# The following tests were adopted from James Friend's
144150
# https://github.com/jsdf/coffee-react-transform
145151

146-
test 'ambigious tag-like expression', ->
152+
test 'ambiguous tag-like expression', ->
147153
throws -> CoffeeScript.compile 'x = a <b > c'
148154

149-
test 'ambigious tag', ->
155+
test 'ambiguous tag', ->
150156
eqCSX '''
151157
a <b > c </b>
152158
''', '''

test/error_messages.coffee

+40
Original file line numberDiff line numberDiff line change
@@ -1545,3 +1545,43 @@ test "#4248: Unicode code point escapes", ->
15451545
'\\u{a}\\u{1111110000}'
15461546
\ ^\^^^^^^^^^^^^^
15471547
'''
1548+
1549+
test "csx error: non-matching tag names", ->
1550+
assertErrorFormat '''
1551+
<div><span></div></span>
1552+
''',
1553+
'''
1554+
[stdin]:1:7: error: expected corresponding CSX closing tag for span
1555+
<div><span></div></span>
1556+
^^^^
1557+
'''
1558+
1559+
test "csx error: bare expressions not allowed", ->
1560+
assertErrorFormat '''
1561+
<div x=3 />
1562+
''',
1563+
'''
1564+
[stdin]:1:8: error: expected wrapped or quoted CSX attribute
1565+
<div x=3 />
1566+
^
1567+
'''
1568+
1569+
test "csx error: unescaped opening tag angle bracket disallowed", ->
1570+
assertErrorFormat '''
1571+
<Person><<</Person>
1572+
''',
1573+
'''
1574+
[stdin]:1:9: error: unexpected <<
1575+
<Person><<</Person>
1576+
^^
1577+
'''
1578+
1579+
test "csx error: ambiguous tag-like expression", ->
1580+
assertErrorFormat '''
1581+
x = a <b > c
1582+
''',
1583+
'''
1584+
[stdin]:1:10: error: missing </
1585+
x = a <b > c
1586+
^
1587+
'''

0 commit comments

Comments
 (0)