diff options
author | 2022-03-07 00:29:50 -0800 | |
---|---|---|
committer | 2022-03-07 00:29:50 -0800 | |
commit | 50c8747c9769663b0d9485cc3dfa74f92fd7ffc3 (patch) | |
tree | 98fdc25635a45a264c7ebbb432dfbffd3f57276a | |
parent | 3598f0ed8a0af43a12f8f5259566e154713f3fce (diff) | |
download | bun-50c8747c9769663b0d9485cc3dfa74f92fd7ffc3.tar.gz bun-50c8747c9769663b0d9485cc3dfa74f92fd7ffc3.tar.zst bun-50c8747c9769663b0d9485cc3dfa74f92fd7ffc3.zip |
[JS Parser] Add optimization for JSX spread
-rw-r--r-- | src/js_parser/js_parser.zig | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/js_parser/js_parser.zig b/src/js_parser/js_parser.zig index afe429e9e..979cf7663 100644 --- a/src/js_parser/js_parser.zig +++ b/src/js_parser/js_parser.zig @@ -12095,6 +12095,17 @@ fn NewParser_( // Babel defines static jsx as children.len > 1 const is_static_jsx = e_.children.len > 1; + // Optimization: if the only non-child prop is a spread object + // we can just pass the object as the first argument + // this goes as deep as there are spreads + // <div {{...{...{...{...foo}}}}} /> + // -> + // <div {{...foo}} /> + // jsx("div", {...foo}) + while (props.items.len == 1 and props.items[0].kind == .spread and props.items[0].value.?.data == .e_object) { + props = props.items[0].value.?.data.e_object.properties.list(); + } + // if (p.options.jsx.development) { switch (e_.children.len) { 0 => {}, |