Skip to content

Commit

Permalink
feat: add support for hypenated props in JSX
Browse files Browse the repository at this point in the history
  • Loading branch information
kollhof committed Jul 1, 2021
1 parent 9c28c6e commit 3f2949c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/lang/jsx/init.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ describe 'JSX', fn:
to_match_snapshot


it 'parses hyphenated attr: <Foobar spam_ham="ni" />', fn:
expect
parse_expr '<Foobar spam-ham="ni" />'
to_match_snapshot


it "parses self closing elem with str attr: <Foobar spam='ni' />", fn:
expect
parse_expr "<Foobar spam='ni' />"
Expand Down
8 changes: 8 additions & 0 deletions src/lang/jsx/init.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ jsx:elem (1:0-3:6) div
"\\n"
`;
exports[`JSX parses hyphenated attr: <Foobar spam_ham="ni" /> 1`] = `
jsx:elem (1:0-1:24) Foobar
jsx:attr (1:8-1:21)
ident (1:8-1:16) spam_ham
string " (1:17-1:21)
'ni'
`;
exports[`JSX parses self closing elem with expr attr: <Foobar spam={ni} /> 1`] = `
jsx:elem (1:0-1:20) Foobar
jsx:attr (1:8-1:17)
Expand Down
2 changes: 1 addition & 1 deletion src/lexer/tokens.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jsx_elem_lex = rx'
|(?<empty>\b_\b)

|(?<number>[0-9][\._a-fA-Fxobe+0-9-]*)
|(?<ident>[_$\p{L}][_$\p{L}\p{N}]*)
|(?<ident>[_$\p{L}][-_$\p{L}\p{N}]*)

|(?<spread>\.\.\.)
|(?<member>\.)
Expand Down
8 changes: 8 additions & 0 deletions src/lexer/tokens.test.fnk
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ describe 'JSX tokenizer', fn:
to_match_snapshot


it 'tokenizes hyphenated attr', fn:
expect
foo '
<Foobar spam-ham />
'
to_match_snapshot


it 'tokenizes expr-attr', fn:
expect
foo '
Expand Down
19 changes: 19 additions & 0 deletions src/lexer/tokens.test.fnk.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ end (51-51) (7:0-7:0)
\\"\\""
`;
exports[`JSX tokenizer tokenizes hyphenated attr 1`] = `
"jsx-elem-start (0-1) (1:0-1:1)
\\"<\\"
ident (1-7) (1:1-1:7)
\\"Foobar\\"
ignorable (7-8) (1:7-1:8)
\\" \\"
ident (8-16) (1:8-1:16)
\\"spam_ham\\"
ignorable (16-17) (1:16-1:17)
\\" \\"
jsx-elem-close (17-19) (1:17-1:19)
\\"/>\\"
ignorable (19-20) (1:19-2:0)
\\"\\\\n\\"
end (20-20) (2:0-2:0)
\\"\\""
`;
exports[`JSX tokenizer tokenizes jsx 1`] = `
"jsx-elem-start (0-1) (1:0-1:1)
\\"<\\"
Expand Down

0 comments on commit 3f2949c

Please sign in to comment.