Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce JSX support #5668

Merged
merged 62 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
37a3b00
Implement jsx option
lukastaegert Mar 1, 2024
5fb5288
Add tests
lukastaegert Mar 2, 2024
eb86704
Pass jsx options to SWC
Martin-Idel Mar 2, 2024
72e9b57
Add JsxElement to ast-types
felixhuttmann Mar 2, 2024
9aa3d5c
Add JsxOpeningElement
AlexDroll Mar 2, 2024
407fc32
Add JSXElementChild -> JSXElement
tiptr Mar 2, 2024
907fd9a
Add JSXElementChild -> JSXText
tiptr Mar 2, 2024
eb4648a
WIP Add JsxAttribute
AlexDroll Mar 2, 2024
2baff98
Add JSXElementChild -> JSXExprContainer and JSXEmptyExpr
tiptr Mar 2, 2024
66ae8fd
Add JsxFragment
felixhuttmann Mar 2, 2024
0579ccf
Align AST types with official types and verify
lukastaegert Apr 28, 2024
d2f9b94
Sort converters into alphabetical order
lukastaegert Apr 28, 2024
da70cc5
Associate identifier with variable
lukastaegert Apr 29, 2024
5655718
Use correct JSX types
lukastaegert May 1, 2024
fcb49b2
Ensure React is included when JSX is used
lukastaegert May 1, 2024
63430c9
Rework JSX option and global variable handling for preserving
lukastaegert May 8, 2024
e7b75cd
Start work on transpilation support
lukastaegert May 9, 2024
0a978c3
Improve option and transpilation support
lukastaegert May 9, 2024
c49be1b
Handle missing jsx factory
lukastaegert May 10, 2024
bca5eab
Add additional tests and support expressions
lukastaegert May 11, 2024
79da44e
Handle JSXText
lukastaegert May 11, 2024
4e25b16
Support attributes transpilation
lukastaegert May 12, 2024
58a786b
Support fragments
lukastaegert May 12, 2024
2bbb572
Extract shared code from fragments
lukastaegert May 12, 2024
9680b65
Support JSXText in all possible positions
lukastaegert May 12, 2024
4fad480
Support all possible JSX attribute types
lukastaegert May 13, 2024
634ddd4
Support JSXMemberExpression
lukastaegert May 13, 2024
c240f3f
Support JSXSpreadChild
lukastaegert May 13, 2024
9eabdc6
Support JSXSpreadAttribute
lukastaegert May 14, 2024
b96aa33
Use correct span for empty expressions
lukastaegert May 21, 2024
22e9bf3
Improve formatting for macro names
lukastaegert Aug 2, 2024
387bb35
Move converters into separate files
lukastaegert Aug 2, 2024
d0d5082
Make everything except the parse function only crate public
lukastaegert Aug 2, 2024
8824ef5
use macros for JSX where possible
lukastaegert Aug 2, 2024
dbb3032
Initial jsx rendering logic for simple cases
lukastaegert Aug 2, 2024
f90dbf3
Split classic and automatic mode
lukastaegert Aug 2, 2024
15467f0
Handle jsx without children
lukastaegert Aug 2, 2024
6c8dd15
Handle jsx with children
lukastaegert Aug 2, 2024
3f208d5
Fix fragment rendering
lukastaegert Aug 3, 2024
be3c7fd
Prepare for fallback rendering
lukastaegert Aug 3, 2024
2979bf1
Reenable tests for now
lukastaegert Aug 3, 2024
eab8818
Update linting
lukastaegert Aug 19, 2024
20074d5
Improve JSX rendering and move to parent element
lukastaegert Aug 22, 2024
43aafdb
Align classic attribute rendering with automatic
lukastaegert Aug 23, 2024
88acff7
Refine classic mode rendering
lukastaegert Aug 31, 2024
e5bbe8d
Refine automatic mode rendering
lukastaegert Sep 1, 2024
6f33fe1
Fix automatic rendering
lukastaegert Sep 1, 2024
b9bfb43
Extract attribute rendering
lukastaegert Sep 2, 2024
dac38b0
Extract shared functionality
lukastaegert Sep 2, 2024
ed2ee43
Move initialize and include functionality to shared base element
lukastaegert Sep 6, 2024
59af083
Extract fragment opening rendering to JSXOpeningFragment
lukastaegert Sep 6, 2024
b335d59
Share rendering functionality with fragments
lukastaegert Sep 6, 2024
5ff0728
Deconflict closing elements
lukastaegert Sep 6, 2024
a10024b
Handle native elements
lukastaegert Sep 9, 2024
9e56a5a
Add additional checks
lukastaegert Sep 10, 2024
17eab3d
Ensure CLI supports presets
lukastaegert Sep 10, 2024
f139fef
Add JSX options to REPL
lukastaegert Sep 20, 2024
9be895b
Add documentation
lukastaegert Sep 20, 2024
6229600
Improve coverage
lukastaegert Oct 1, 2024
ef9bbc4
Fix local browser build
lukastaegert Oct 2, 2024
4b2e94b
Add jsx example
lukastaegert Oct 2, 2024
98f5c5a
Refine docs
lukastaegert Oct 2, 2024
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
Prev Previous commit
Next Next commit
Support JSXSpreadChild
  • Loading branch information
lukastaegert committed Oct 2, 2024
commit c240f3f763f796cc421ecd799e53cf19d5070947
29 changes: 22 additions & 7 deletions rust/parse_ast/src/convert_ast/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use swc_ecma_ast::{
ExprOrSpread, ForHead, ImportSpecifier, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXAttrValue,
JSXClosingElement, JSXClosingFragment, JSXElement, JSXElementChild, JSXElementName, JSXEmptyExpr,
JSXExpr, JSXExprContainer, JSXFragment, JSXMemberExpr, JSXNamespacedName, JSXObject,
JSXOpeningElement, JSXOpeningFragment, JSXText, Lit, ModuleDecl, ModuleExportName, ModuleItem,
NamedExport, ObjectPatProp, OptChainBase, ParenExpr, Pat, Program, PropName, PropOrSpread,
SimpleAssignTarget, Stmt, VarDeclOrExpr,
JSXOpeningElement, JSXOpeningFragment, JSXSpreadChild, JSXText, Lit, ModuleDecl,
ModuleExportName, ModuleItem, NamedExport, ObjectPatProp, OptChainBase, ParenExpr, Pat, Program,
PropName, PropOrSpread, SimpleAssignTarget, Stmt, VarDeclOrExpr,
};

use crate::ast_nodes::call_expression::StoredCallee;
Expand All @@ -26,13 +26,14 @@ use crate::convert_ast::converter::ast_constants::{
JSX_NAMESPACED_NAME_NAME_OFFSET, JSX_NAMESPACED_NAME_NAMESPACE_OFFSET,
JSX_NAMESPACED_NAME_RESERVED_BYTES, JSX_OPENING_ELEMENT_ATTRIBUTES_OFFSET,
JSX_OPENING_ELEMENT_NAME_OFFSET, JSX_OPENING_ELEMENT_RESERVED_BYTES,
JSX_OPENING_FRAGMENT_RESERVED_BYTES, JSX_TEXT_RAW_OFFSET, JSX_TEXT_RESERVED_BYTES,
JSX_OPENING_FRAGMENT_RESERVED_BYTES, JSX_SPREAD_CHILD_EXPRESSION_OFFSET,
JSX_SPREAD_CHILD_RESERVED_BYTES, JSX_TEXT_RAW_OFFSET, JSX_TEXT_RESERVED_BYTES,
JSX_TEXT_VALUE_OFFSET, TYPE_CLASS_EXPRESSION, TYPE_FUNCTION_DECLARATION,
TYPE_FUNCTION_EXPRESSION, TYPE_JSX_ATTRIBUTE, TYPE_JSX_CLOSING_ELEMENT,
TYPE_JSX_CLOSING_FRAGMENT, TYPE_JSX_ELEMENT, TYPE_JSX_EMPTY_EXPRESSION,
TYPE_JSX_EXPRESSION_CONTAINER, TYPE_JSX_FRAGMENT, TYPE_JSX_IDENTIFIER,
TYPE_JSX_MEMBER_EXPRESSION, TYPE_JSX_NAMESPACED_NAME, TYPE_JSX_OPENING_ELEMENT,
TYPE_JSX_OPENING_FRAGMENT, TYPE_JSX_TEXT,
TYPE_JSX_OPENING_FRAGMENT, TYPE_JSX_SPREAD_CHILD, TYPE_JSX_TEXT,
};
use crate::convert_ast::converter::string_constants::{
STRING_NOSIDEEFFECTS, STRING_PURE, STRING_SOURCEMAP,
Expand Down Expand Up @@ -479,8 +480,8 @@ impl<'a> AstConverter<'a> {
JSXElementChild::JSXExprContainer(jsx_expr_container) => {
self.convert_jsx_expression_container(jsx_expr_container);
}
JSXElementChild::JSXSpreadChild(_jsx_spread_child) => {
unimplemented!("JSXElementChild::JSXSpreadChild")
JSXElementChild::JSXSpreadChild(jsx_spread_child) => {
self.convert_jsx_spread_child(jsx_spread_child);
}
JSXElementChild::JSXFragment(jsx_fragment) => {
self.convert_jsx_fragment(jsx_fragment);
Expand Down Expand Up @@ -983,6 +984,20 @@ impl<'a> AstConverter<'a> {
self.add_end(end_position, &jsxopening_fragment.span);
}

fn convert_jsx_spread_child(&mut self, jsx_spread_child: &JSXSpreadChild) {
let end_position = self.add_type_and_start(
&TYPE_JSX_SPREAD_CHILD,
&jsx_spread_child.span,
JSX_SPREAD_CHILD_RESERVED_BYTES,
false,
);
// expression
self.update_reference_position(end_position + JSX_SPREAD_CHILD_EXPRESSION_OFFSET);
self.convert_expression(&jsx_spread_child.expr);
// end
self.add_end(end_position, &jsx_spread_child.span);
}

fn convert_jsx_text(&mut self, jsx_text: &JSXText) {
let end_position = self.add_type_and_start(
&TYPE_JSX_TEXT,
Expand Down
34 changes: 19 additions & 15 deletions rust/parse_ast/src/convert_ast/converter/ast_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ pub const TYPE_JSX_MEMBER_EXPRESSION: [u8; 4] = 50u32.to_ne_bytes();
pub const TYPE_JSX_NAMESPACED_NAME: [u8; 4] = 51u32.to_ne_bytes();
pub const TYPE_JSX_OPENING_ELEMENT: [u8; 4] = 52u32.to_ne_bytes();
pub const TYPE_JSX_OPENING_FRAGMENT: [u8; 4] = 53u32.to_ne_bytes();
pub const TYPE_JSX_TEXT: [u8; 4] = 54u32.to_ne_bytes();
pub const TYPE_LOGICAL_EXPRESSION: [u8; 4] = 62u32.to_ne_bytes();
pub const TYPE_MEMBER_EXPRESSION: [u8; 4] = 63u32.to_ne_bytes();
pub const TYPE_META_PROPERTY: [u8; 4] = 64u32.to_ne_bytes();
pub const TYPE_METHOD_DEFINITION: [u8; 4] = 65u32.to_ne_bytes();
pub const TYPE_NEW_EXPRESSION: [u8; 4] = 66u32.to_ne_bytes();
pub const TYPE_PROGRAM: [u8; 4] = 70u32.to_ne_bytes();
pub const TYPE_PROPERTY: [u8; 4] = 71u32.to_ne_bytes();
pub const TYPE_PROPERTY_DEFINITION: [u8; 4] = 72u32.to_ne_bytes();
pub const TYPE_REST_ELEMENT: [u8; 4] = 73u32.to_ne_bytes();
pub const TYPE_SPREAD_ELEMENT: [u8; 4] = 76u32.to_ne_bytes();
pub const TYPE_TEMPLATE_LITERAL: [u8; 4] = 83u32.to_ne_bytes();
pub const TYPE_TRY_STATEMENT: [u8; 4] = 86u32.to_ne_bytes();
pub const TYPE_VARIABLE_DECLARATION: [u8; 4] = 89u32.to_ne_bytes();
pub const TYPE_VARIABLE_DECLARATOR: [u8; 4] = 90u32.to_ne_bytes();
pub const TYPE_JSX_SPREAD_CHILD: [u8; 4] = 54u32.to_ne_bytes();
pub const TYPE_JSX_TEXT: [u8; 4] = 55u32.to_ne_bytes();
pub const TYPE_LOGICAL_EXPRESSION: [u8; 4] = 63u32.to_ne_bytes();
pub const TYPE_MEMBER_EXPRESSION: [u8; 4] = 64u32.to_ne_bytes();
pub const TYPE_META_PROPERTY: [u8; 4] = 65u32.to_ne_bytes();
pub const TYPE_METHOD_DEFINITION: [u8; 4] = 66u32.to_ne_bytes();
pub const TYPE_NEW_EXPRESSION: [u8; 4] = 67u32.to_ne_bytes();
pub const TYPE_PROGRAM: [u8; 4] = 71u32.to_ne_bytes();
pub const TYPE_PROPERTY: [u8; 4] = 72u32.to_ne_bytes();
pub const TYPE_PROPERTY_DEFINITION: [u8; 4] = 73u32.to_ne_bytes();
pub const TYPE_REST_ELEMENT: [u8; 4] = 74u32.to_ne_bytes();
pub const TYPE_SPREAD_ELEMENT: [u8; 4] = 77u32.to_ne_bytes();
pub const TYPE_TEMPLATE_LITERAL: [u8; 4] = 84u32.to_ne_bytes();
pub const TYPE_TRY_STATEMENT: [u8; 4] = 87u32.to_ne_bytes();
pub const TYPE_VARIABLE_DECLARATION: [u8; 4] = 90u32.to_ne_bytes();
pub const TYPE_VARIABLE_DECLARATOR: [u8; 4] = 91u32.to_ne_bytes();

pub const PANIC_ERROR_RESERVED_BYTES: usize = 8;
pub const PANIC_ERROR_MESSAGE_OFFSET: usize = 4;
Expand Down Expand Up @@ -179,6 +180,9 @@ pub const JSX_OPENING_ELEMENT_ATTRIBUTES_OFFSET: usize = 12;

pub const JSX_OPENING_FRAGMENT_RESERVED_BYTES: usize = 4;

pub const JSX_SPREAD_CHILD_RESERVED_BYTES: usize = 8;
pub const JSX_SPREAD_CHILD_EXPRESSION_OFFSET: usize = 4;

pub const JSX_TEXT_RESERVED_BYTES: usize = 12;
pub const JSX_TEXT_VALUE_OFFSET: usize = 4;
pub const JSX_TEXT_RAW_OFFSET: usize = 8;
Expand Down
48 changes: 24 additions & 24 deletions rust/parse_ast/src/convert_ast/converter/ast_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ macro_rules! store_import_specifier {
macro_rules! store_labeled_statement {
($self:expr, span => $span:expr, label => [$label_value:expr, $label_converter:ident], body => [$body_value:expr, $body_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&55u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&56u32.to_ne_bytes(), &$span, 12, false);
// label
$self.update_reference_position(end_position + 4);
$self.$label_converter(&$label_value);
Expand All @@ -335,7 +335,7 @@ macro_rules! store_labeled_statement {
macro_rules! store_literal_big_int {
($self:expr, span => $span:expr, bigint => $bigint_value:expr, raw => $raw_value:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&56u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&57u32.to_ne_bytes(), &$span, 12, false);
// bigint
$self.convert_string($bigint_value, end_position + 4);
// raw
Expand All @@ -350,7 +350,7 @@ macro_rules! store_literal_boolean {
($self:expr, span => $span:expr, value => $value_value:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(
&57u32.to_ne_bytes(),
&58u32.to_ne_bytes(),
&$span,
8,
false,
Expand All @@ -366,7 +366,7 @@ macro_rules! store_literal_boolean {
macro_rules! store_literal_null {
($self:expr, span => $span:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&58u32.to_ne_bytes(), &$span, 4, false);
let end_position = $self.add_type_and_start(&59u32.to_ne_bytes(), &$span, 4, false);
// end
$self.add_end(end_position, &$span);
};
Expand All @@ -376,7 +376,7 @@ macro_rules! store_literal_null {
macro_rules! store_literal_number {
($self:expr, span => $span:expr, raw => $raw_value:expr, value => $value_value:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&59u32.to_ne_bytes(), &$span, 16, false);
let end_position = $self.add_type_and_start(&60u32.to_ne_bytes(), &$span, 16, false);
// raw
if let Some(value) = $raw_value.as_ref() {
$self.convert_string(value, end_position + 4);
Expand All @@ -393,7 +393,7 @@ macro_rules! store_literal_number {
macro_rules! store_literal_reg_exp {
($self:expr, span => $span:expr, flags => $flags_value:expr, pattern => $pattern_value:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&60u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&61u32.to_ne_bytes(), &$span, 12, false);
// flags
$self.convert_string($flags_value, end_position + 4);
// pattern
Expand All @@ -407,7 +407,7 @@ macro_rules! store_literal_reg_exp {
macro_rules! store_literal_string {
($self:expr, span => $span:expr, value => $value_value:expr, raw => $raw_value:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&61u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&62u32.to_ne_bytes(), &$span, 12, false);
// value
$self.convert_string($value_value, end_position + 4);
// raw
Expand All @@ -423,7 +423,7 @@ macro_rules! store_literal_string {
macro_rules! store_object_expression {
($self:expr, span => $span:expr, properties => [$properties_value:expr, $properties_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&67u32.to_ne_bytes(), &$span, 8, false);
let end_position = $self.add_type_and_start(&68u32.to_ne_bytes(), &$span, 8, false);
// properties
$self.convert_item_list(
&$properties_value,
Expand All @@ -442,7 +442,7 @@ macro_rules! store_object_expression {
macro_rules! store_object_pattern {
($self:expr, span => $span:expr, properties => [$properties_value:expr, $properties_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&68u32.to_ne_bytes(), &$span, 8, false);
let end_position = $self.add_type_and_start(&69u32.to_ne_bytes(), &$span, 8, false);
// properties
$self.convert_item_list(
&$properties_value,
Expand All @@ -461,7 +461,7 @@ macro_rules! store_object_pattern {
macro_rules! store_private_identifier {
($self:expr, span => $span:expr, name => $name_value:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&69u32.to_ne_bytes(), &$span, 8, false);
let end_position = $self.add_type_and_start(&70u32.to_ne_bytes(), &$span, 8, false);
// name
$self.convert_string($name_value, end_position + 4);
// end
Expand All @@ -473,7 +473,7 @@ macro_rules! store_private_identifier {
macro_rules! store_return_statement {
($self:expr, span => $span:expr, argument => [$argument_value:expr, $argument_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&74u32.to_ne_bytes(), &$span, 8, false);
let end_position = $self.add_type_and_start(&75u32.to_ne_bytes(), &$span, 8, false);
// argument
if let Some(value) = $argument_value.as_ref() {
$self.update_reference_position(end_position + 4);
Expand All @@ -488,7 +488,7 @@ macro_rules! store_return_statement {
macro_rules! store_sequence_expression {
($self:expr, span => $span:expr, expressions => [$expressions_value:expr, $expressions_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&75u32.to_ne_bytes(), &$span, 8, false);
let end_position = $self.add_type_and_start(&76u32.to_ne_bytes(), &$span, 8, false);
// expressions
$self.convert_item_list(
&$expressions_value,
Expand All @@ -507,7 +507,7 @@ macro_rules! store_sequence_expression {
macro_rules! store_static_block {
($self:expr, span => $span:expr, body => [$body_value:expr, $body_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&77u32.to_ne_bytes(), &$span, 8, false);
let end_position = $self.add_type_and_start(&78u32.to_ne_bytes(), &$span, 8, false);
// body
$self.convert_item_list(&$body_value, end_position + 4, |ast_converter, node| {
ast_converter.$body_converter(node);
Expand All @@ -522,7 +522,7 @@ macro_rules! store_static_block {
macro_rules! store_super_element {
($self:expr, span => $span:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&78u32.to_ne_bytes(), &$span, 4, false);
let end_position = $self.add_type_and_start(&79u32.to_ne_bytes(), &$span, 4, false);
// end
$self.add_end(end_position, &$span);
};
Expand All @@ -532,7 +532,7 @@ macro_rules! store_super_element {
macro_rules! store_switch_case {
($self:expr, span => $span:expr, test => [$test_value:expr, $test_converter:ident], consequent => [$consequent_value:expr, $consequent_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&79u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&80u32.to_ne_bytes(), &$span, 12, false);
// test
if let Some(value) = $test_value.as_ref() {
$self.update_reference_position(end_position + 4);
Expand All @@ -556,7 +556,7 @@ macro_rules! store_switch_case {
macro_rules! store_switch_statement {
($self:expr, span => $span:expr, discriminant => [$discriminant_value:expr, $discriminant_converter:ident], cases => [$cases_value:expr, $cases_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&80u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&81u32.to_ne_bytes(), &$span, 12, false);
// discriminant
$self.update_reference_position(end_position + 4);
$self.$discriminant_converter(&$discriminant_value);
Expand All @@ -574,7 +574,7 @@ macro_rules! store_switch_statement {
macro_rules! store_tagged_template_expression {
($self:expr, span => $span:expr, tag => [$tag_value:expr, $tag_converter:ident], quasi => [$quasi_value:expr, $quasi_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&81u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&82u32.to_ne_bytes(), &$span, 12, false);
// tag
$self.update_reference_position(end_position + 4);
$self.$tag_converter(&$tag_value);
Expand All @@ -591,7 +591,7 @@ macro_rules! store_template_element {
($self:expr, span => $span:expr, tail => $tail_value:expr, cooked => $cooked_value:expr, raw => $raw_value:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(
&82u32.to_ne_bytes(),
&83u32.to_ne_bytes(),
&$span,
16,
false,
Expand All @@ -613,7 +613,7 @@ macro_rules! store_template_element {
macro_rules! store_this_expression {
($self:expr, span => $span:expr) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&84u32.to_ne_bytes(), &$span, 4, false);
let end_position = $self.add_type_and_start(&85u32.to_ne_bytes(), &$span, 4, false);
// end
$self.add_end(end_position, &$span);
};
Expand All @@ -623,7 +623,7 @@ macro_rules! store_this_expression {
macro_rules! store_throw_statement {
($self:expr, span => $span:expr, argument => [$argument_value:expr, $argument_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&85u32.to_ne_bytes(), &$span, 8, false);
let end_position = $self.add_type_and_start(&86u32.to_ne_bytes(), &$span, 8, false);
// argument
$self.update_reference_position(end_position + 4);
$self.$argument_converter(&$argument_value);
Expand All @@ -636,7 +636,7 @@ macro_rules! store_throw_statement {
macro_rules! store_unary_expression {
($self:expr, span => $span:expr, operator => $operator_value:expr, argument => [$argument_value:expr, $argument_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&87u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&88u32.to_ne_bytes(), &$span, 12, false);
// operator
let operator_position = end_position + 4;
$self.buffer[operator_position..operator_position + 4].copy_from_slice($operator_value);
Expand All @@ -653,7 +653,7 @@ macro_rules! store_update_expression {
($self:expr, span => $span:expr, prefix => $prefix_value:expr, operator => $operator_value:expr, argument => [$argument_value:expr, $argument_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(
&88u32.to_ne_bytes(),
&89u32.to_ne_bytes(),
&$span,
16,
false,
Expand All @@ -675,7 +675,7 @@ macro_rules! store_update_expression {
macro_rules! store_while_statement {
($self:expr, span => $span:expr, test => [$test_value:expr, $test_converter:ident], body => [$body_value:expr, $body_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(&91u32.to_ne_bytes(), &$span, 12, false);
let end_position = $self.add_type_and_start(&92u32.to_ne_bytes(), &$span, 12, false);
// test
$self.update_reference_position(end_position + 4);
$self.$test_converter(&$test_value);
Expand All @@ -692,7 +692,7 @@ macro_rules! store_yield_expression {
($self:expr, span => $span:expr, delegate => $delegate_value:expr, argument => [$argument_value:expr, $argument_converter:ident]) => {
let _: &mut AstConverter = $self;
let end_position = $self.add_type_and_start(
&92u32.to_ne_bytes(),
&93u32.to_ne_bytes(),
&$span,
12,
false,
Expand Down
5 changes: 5 additions & 0 deletions scripts/ast-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ export const AST_NODES = {
estreeType: 'any',
useMacro: false
},
JSXSpreadChild: {
estreeType: 'any',
fields: [['expression', 'Node']],
useMacro: false
},
JSXText: {
estreeType: 'any',
fields: [
Expand Down
7 changes: 7 additions & 0 deletions src/ast/bufferParsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import JSXMemberExpression from './nodes/JSXMemberExpression';
import JSXNamespacedName from './nodes/JSXNamespacedName';
import JSXOpeningElement from './nodes/JSXOpeningElement';
import JSXOpeningFragment from './nodes/JSXOpeningFragment';
import JSXSpreadChild from './nodes/JSXSpreadChild';
import JSXText from './nodes/JSXText';
import LabeledStatement from './nodes/LabeledStatement';
import Literal from './nodes/Literal';
Expand Down Expand Up @@ -166,6 +167,7 @@ const nodeTypeStrings = [
'JSXNamespacedName',
'JSXOpeningElement',
'JSXOpeningFragment',
'JSXSpreadChild',
'JSXText',
'LabeledStatement',
'Literal',
Expand Down Expand Up @@ -262,6 +264,7 @@ const nodeConstructors: (typeof NodeBase)[] = [
JSXNamespacedName,
JSXOpeningElement,
JSXOpeningFragment,
JSXSpreadChild,
JSXText,
LabeledStatement,
Literal,
Expand Down Expand Up @@ -658,6 +661,10 @@ const bufferParsers: ((node: any, position: number, buffer: AstBuffer) => void)[
node.attributes = [];
node.selfClosing = false;
},
function jsxSpreadChild(node: JSXSpreadChild, position, buffer) {
const { scope } = node;
node.expression = convertNode(node, scope, buffer[position], buffer);
},
function jsxText(node: JSXText, position, buffer) {
node.value = buffer.convertString(buffer[position]);
node.raw = buffer.convertString(buffer[position + 1]);
Expand Down
1 change: 1 addition & 0 deletions src/ast/childNodeKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const childNodeKeys: Record<string, string[]> = {
JSXNamespacedName: ['namespace', 'name'],
JSXOpeningElement: ['name', 'attributes'],
JSXOpeningFragment: [],
JSXSpreadChild: ['expression'],
JSXText: [],
LabeledStatement: ['label', 'body'],
Literal: [],
Expand Down
4 changes: 3 additions & 1 deletion src/ast/nodes/JSXClosingElement.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type JSXIdentifier from './JSXIdentifier';
import type JSXMemberExpression from './JSXMemberExpression';
import type JSXNamespacedName from './JSXNamespacedName';
import type * as NodeType from './NodeType';
import JSXClosingBase from './shared/JSXClosingBase';

export default class JSXClosingElement extends JSXClosingBase {
type!: NodeType.tJSXClosingElement;
name!: JSXIdentifier /* TODO | JSXMemberExpression | JSXNamespacedName */;
name!: JSXIdentifier | JSXMemberExpression | JSXNamespacedName;
}
Loading