Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/parser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module.exports = class Parser
) or
@cjsxStart() or
@cjsxAttribute() or
@cjsxComment() or
@cjsxEscape() or
@cjsxUnescape() or
@cjsxEnd() or
Expand Down Expand Up @@ -207,6 +208,13 @@ module.exports = class Parser
"Invalid attribute #{input} in CJSX tag #{@peekActiveState(2).value}",
first_line: @chunkLine, first_column: @chunkColumn

cjsxComment: ->
match = @chunk.match(/^\{#(.*)\}/)

return 0 unless match
@addLeafNodeToActiveBranch ParseTreeLeafNode($.CJSX_COMMENT, match[1])
return match[0].length

cjsxEscape: ->
return 0 unless @chunk.charAt(0) is '{' and
@currentState() in [$.CJSX_EL, $.CJSX_ATTR_PAIR]
Expand Down
3 changes: 3 additions & 0 deletions src/serialiser.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ nodeSerialisers =
element = node.value
"#{@reactObject}.createElement(#{element}, #{joinList(serialisedChildren)})"

CJSX_COMMENT: (node) ->
""

CJSX_ESC: (node) ->
childrenSerialised = node.children
.map((child) => @serialiseNode child)
Expand Down
1 change: 1 addition & 0 deletions src/symbols.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports =
# they're just names for use in debugging
CJSX_START: 'CJSX_START'
CJSX_END: 'CJSX_END'
CJSX_COMMENT: 'CJSX_COMMENT'
CJSX_ESC_START: 'CJSX_ESC_START'
CJSX_ESC_END: 'CJSX_ESC_END'
CJSX_PRAGMA: 'CJSX_PRAGMA'
46 changes: 46 additions & 0 deletions test/output-testcases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,52 @@ React.createElement(Person, null, """
""")
##end

##desc
empty node is handled as expected
##input
<Person>
</Person>
##expected
React.createElement(Person, null
)
##end

##desc
cs comment at start of cjsx escape
##input
<Person>
{# i am a comment
"i am a string"
}
</Person>
##expected
React.createElement(Person, null,
(# i am a comment
"i am a string"
)
)
##end

##desc
cjsx comment is passed through
##input
<Person>
{# i am a comment}
</Person>
##expected
React.createElement(Person, null,

)
##end

##desc
comment syntax can be used inline
##input
<Person>{#comment inline}</Person>
##expected
React.createElement(Person, null, )
##end

##desc
string within cjsx is ignored by parser and escaped
##input
Expand Down