swc_ecma_transforms_react/jsx/
static_check.rs

1use swc_ecma_ast::*;
2
3/// We want to use React.createElement, even in the case of
4/// jsx, for <div {...props} key={key} /> to distinguish it
5/// from <div key={key} {...props} />. This is an intermediary
6/// step while we deprecate key spread from props. Afterwards,
7/// we will stop using createElement in the transform.
8pub(super) fn should_use_create_element(attrs: &[JSXAttrOrSpread]) -> bool {
9    let mut seen_prop_spread = false;
10    for attr in attrs {
11        if seen_prop_spread
12            && match attr {
13                JSXAttrOrSpread::JSXAttr(attr) => match &attr.name {
14                    JSXAttrName::Ident(i) => i.sym == "key",
15                    JSXAttrName::JSXNamespacedName(_) => false,
16                    #[cfg(swc_ast_unknown)]
17                    _ => panic!("unable to access unknown nodes"),
18                },
19                _ => false,
20            }
21        {
22            return true;
23        }
24
25        if let JSXAttrOrSpread::SpreadElement(_) = attr {
26            seen_prop_spread = true;
27        }
28    }
29
30    false
31}