Skip to content

Commit

Permalink
Merge pull request #247 from guillaumebrunerie/jsx_fixes
Browse files Browse the repository at this point in the history
Various fixes for JSX support
  • Loading branch information
amaanq committed Jul 11, 2023
2 parents 3429d8c + b893426 commit a232b3a
Show file tree
Hide file tree
Showing 10 changed files with 266,916 additions and 265,804 deletions.
6 changes: 3 additions & 3 deletions common/corpus/declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ declare module Foo {

(ambient_declaration
(module
name: (nested_identifier (identifier) (identifier))
name: (nested_identifier (identifier) (property_identifier))
body: (statement_block
(export_statement
declaration: (variable_declaration (variable_declarator name: (identifier)))))))
Expand Down Expand Up @@ -320,7 +320,7 @@ import r = X.N;
---

(program
(import_alias (identifier) (nested_identifier (identifier) (identifier))))
(import_alias (identifier) (nested_identifier (identifier) (property_identifier))))

==================================
Import aliases in modules
Expand All @@ -334,7 +334,7 @@ module C {

(program
(module (identifier) (statement_block
(import_alias (identifier) (nested_identifier (identifier) (identifier))))))
(import_alias (identifier) (nested_identifier (identifier) (property_identifier))))))

==================================
Export import aliases
Expand Down
33 changes: 18 additions & 15 deletions common/define-grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ module.exports = function defineGrammar(dialect) {
if (dialect === 'typescript') {
choices.push($.type_assertion);
choices.push(...previous.members.filter(member =>
member.name !== '_jsx_element' && member.name !== 'jsx_fragment'
member.name !== '_jsx_element'
));
} else if (dialect === 'tsx') {
choices.push(...previous.members);
Expand All @@ -227,20 +227,24 @@ module.exports = function defineGrammar(dialect) {

_jsx_start_opening_element: $ => seq(
'<',
choice(
field('name', choice(
$._jsx_identifier,
$.jsx_namespace_name
)),
optional(
seq(
field('name', choice(
$.identifier,
$.nested_identifier
)),
field('type_arguments', optional($.type_arguments))
)
choice(
field('name', choice(
$._jsx_identifier,
$.jsx_namespace_name
)),
seq(
field('name', choice(
$.identifier,
$.nested_identifier
)),
field('type_arguments', optional($.type_arguments))
)
),
repeat(field('attribute', $._jsx_attribute)),
),
),
repeat(field('attribute', $._jsx_attribute))
),

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

export_specifier: ($, previous) => seq(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"main": "./bindings/node",
"devDependencies": {
"tree-sitter-cli": "^0.20.6",
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#d15843d"
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#f772967"
},
"scripts": {
"build": "npm run build-typescript && npm run build-tsx",
Expand Down
6 changes: 6 additions & 0 deletions tsx/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Type arguments in JSX

<Element<T>>hi</Element>;
<Element<T> />;
<>fragment</>;

---

Expand All @@ -16,4 +17,9 @@ Type arguments in JSX
(expression_statement
(jsx_self_closing_element
(identifier) (type_arguments (type_identifier))))
(expression_statement
(jsx_element
(jsx_opening_element)
(jsx_text)
(jsx_closing_element)))
)

0 comments on commit a232b3a

Please sign in to comment.