swc: JSX parsing panics when using the spread operator
Describe the bug
Using the spread operator in a JSX block causes a panic (at least in Deno).
Input code
const A = () => {
return <div>{...[]}</div>;
};
Expected behavior
The code to be emitted without a panic and something like:
"use strict";
const A = () => {
return React.createElement("div", null, []);
};
Actual behaviour
❯ RUST_BACKTRACE=1 deno bundle --no-check spread.tsx
Bundle file:///Users/kitsonk/github/deploy_dg/spread.tsx
thread 'main' panicked at 'cannot access a scoped thread local variable without calling `set` first', /Users/kitsonk/.cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:168:9
stack backtrace:
0: std::panicking::begin_panic
1: swc_ecma_transforms_react::jsx::Jsx<C>::jsx_elem_child_to_expr
2: core::iter::traits::iterator::Iterator::find_map::check::{{closure}}
3: <core::iter::adapters::chain::Chain<A,B> as core::iter::traits::iterator::Iterator>::next
4: <alloc::vec::Vec<T,A> as alloc::vec::spec_extend::SpecExtend<T,I>>::spec_extend
5: swc_ecma_transforms_react::jsx::Jsx<C>::jsx_elem_to_expr
6: <swc_ecma_transforms_react::jsx::Jsx<C> as swc_ecma_visit::VisitMut>::visit_mut_expr
7: swc_ecma_visit::visit_mut_stmts
8: <swc_ecma_transforms_react::jsx::Jsx<C> as swc_ecma_visit::VisitMut>::visit_mut_expr
9: swc_ecma_visit::visit_mut_var_declarators
10: <swc_visit::Optional<V> as swc_ecma_visit::Fold>::fold_module
11: swc_bundler::bundler::load::<impl swc_bundler::bundler::Bundler<L,R>>::load_transformed
12: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::next
13: deno::module_graph::Graph::emit_bundle
14: deno::bundle_module_graph
15: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
16: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
17: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
18: deno::main
Version
swc_common = “0.11.4” swc_ecmascript = “0.46.0”
Additional context
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 8
- Comments: 17 (12 by maintainers)
Commits related to this issue
- Add a test for #2037 — committed to kdy1/swc by kdy1 3 years ago
- fix(es/react): Allow spread children (#6505) **Related issue:** - Closes https://github.com/swc-project/swc/issues/2037. — committed to swc-project/swc by kdy1 2 years ago
I’ll do so, as I prefer behavior of tsc of it of babel.