Skip to content

Commit a232b3a

Browse files
authored
Merge pull request #247 from guillaumebrunerie/jsx_fixes
Various fixes for JSX support
2 parents 3429d8c + b893426 commit a232b3a

File tree

10 files changed

+266916
-265804
lines changed

10 files changed

+266916
-265804
lines changed

common/corpus/declarations.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ declare module Foo {
125125

126126
(ambient_declaration
127127
(module
128-
name: (nested_identifier (identifier) (identifier))
128+
name: (nested_identifier (identifier) (property_identifier))
129129
body: (statement_block
130130
(export_statement
131131
declaration: (variable_declaration (variable_declarator name: (identifier)))))))
@@ -320,7 +320,7 @@ import r = X.N;
320320
---
321321

322322
(program
323-
(import_alias (identifier) (nested_identifier (identifier) (identifier))))
323+
(import_alias (identifier) (nested_identifier (identifier) (property_identifier))))
324324

325325
==================================
326326
Import aliases in modules
@@ -334,7 +334,7 @@ module C {
334334

335335
(program
336336
(module (identifier) (statement_block
337-
(import_alias (identifier) (nested_identifier (identifier) (identifier))))))
337+
(import_alias (identifier) (nested_identifier (identifier) (property_identifier))))))
338338

339339
==================================
340340
Export import aliases

common/define-grammar.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ module.exports = function defineGrammar(dialect) {
214214
if (dialect === 'typescript') {
215215
choices.push($.type_assertion);
216216
choices.push(...previous.members.filter(member =>
217-
member.name !== '_jsx_element' && member.name !== 'jsx_fragment'
217+
member.name !== '_jsx_element'
218218
));
219219
} else if (dialect === 'tsx') {
220220
choices.push(...previous.members);
@@ -227,20 +227,24 @@ module.exports = function defineGrammar(dialect) {
227227

228228
_jsx_start_opening_element: $ => seq(
229229
'<',
230-
choice(
231-
field('name', choice(
232-
$._jsx_identifier,
233-
$.jsx_namespace_name
234-
)),
230+
optional(
235231
seq(
236-
field('name', choice(
237-
$.identifier,
238-
$.nested_identifier
239-
)),
240-
field('type_arguments', optional($.type_arguments))
241-
)
232+
choice(
233+
field('name', choice(
234+
$._jsx_identifier,
235+
$.jsx_namespace_name
236+
)),
237+
seq(
238+
field('name', choice(
239+
$.identifier,
240+
$.nested_identifier
241+
)),
242+
field('type_arguments', optional($.type_arguments))
243+
)
244+
),
245+
repeat(field('attribute', $._jsx_attribute)),
246+
),
242247
),
243-
repeat(field('attribute', $._jsx_attribute))
244248
),
245249

246250
// This rule is only referenced by expression when the dialect is 'tsx'
@@ -252,8 +256,7 @@ module.exports = function defineGrammar(dialect) {
252256
// tsx only. See jsx_opening_element.
253257
jsx_self_closing_element: $ => prec.dynamic(-1, seq(
254258
$._jsx_start_opening_element,
255-
'/',
256-
'>'
259+
'/>'
257260
)),
258261

259262
export_specifier: ($, previous) => seq(

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"main": "./bindings/node",
2020
"devDependencies": {
2121
"tree-sitter-cli": "^0.20.6",
22-
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#d15843d"
22+
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#f772967"
2323
},
2424
"scripts": {
2525
"build": "npm run build-typescript && npm run build-tsx",

tsx/corpus/expressions.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Type arguments in JSX
44

55
<Element<T>>hi</Element>;
66
<Element<T> />;
7+
<>fragment</>;
78

89
---
910

@@ -16,4 +17,9 @@ Type arguments in JSX
1617
(expression_statement
1718
(jsx_self_closing_element
1819
(identifier) (type_arguments (type_identifier))))
20+
(expression_statement
21+
(jsx_element
22+
(jsx_opening_element)
23+
(jsx_text)
24+
(jsx_closing_element)))
1925
)

0 commit comments

Comments
 (0)