Handle react fragment in top level.

Fixes #229.
This commit is contained in:
강동윤 2019-02-18 18:08:40 +09:00
parent 1368a4a281
commit 59f6a6ffb6
2 changed files with 24 additions and 0 deletions

View File

@ -266,6 +266,14 @@ impl Fold<Expr> for Jsx {
// <div></div> => React.createElement('div', null);
self.jsx_elem_to_expr(el)
}
Expr::Paren(ParenExpr {
expr: box Expr::JSXFragment(frag),
..
})
| Expr::JSXFragment(frag) => {
// <></> => React.createElement(React.Fragment, null);
self.jsx_frag_to_expr(frag)
}
_ => expr,
}
}

View File

@ -1024,3 +1024,19 @@ var div = React.createElement(Component, Object.assign({}, props, {
}));
"#
);
test!(
::swc_ecma_parser::Syntax::Es(::swc_ecma_parser::EsConfig {
jsx: true,
..Default::default()
}),
|_| tr(Options {
use_builtins: true,
..Default::default()
},),
issue_229,
"const a = <>test</>
const b = <div>test</div>",
"const a = React.createElement(React.Fragment, null, 'test');
const b = React.createElement('div', null, 'test');"
);