-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/react): Allow spread children (#6505)
**Related issue:** - Closes #2037.
- Loading branch information
Showing
18 changed files
with
242 additions
and
119 deletions.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
crates/swc/tests/fixture/issues-2xxx/2037/case1/output/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
var A = function() { | ||
return /*#__PURE__*/ React.createElement("div", null); | ||
return /*#__PURE__*/ React.createElement.apply(React, [ | ||
"div", | ||
null | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 19 additions & 6 deletions
25
crates/swc/tests/tsc-references/tsxSpreadChildren.1.normal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
//// [tsxSpreadChildren.tsx] | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 22 | {...todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>)} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
import _extends from "@swc/helpers/src/_extends.mjs"; | ||
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs"; | ||
function Todo(prop) { | ||
return /*#__PURE__*/ React.createElement("div", null, prop.key.toString() + prop.todo); | ||
} | ||
function TodoList(param) { | ||
var todos = param.todos; | ||
return /*#__PURE__*/ React.createElement.apply(React, [ | ||
"div", | ||
null | ||
].concat(_to_consumable_array(todos.map(function(todo) { | ||
return /*#__PURE__*/ React.createElement(Todo, { | ||
key: todo.id, | ||
todo: todo.todo | ||
}); | ||
})))); | ||
} | ||
var x; | ||
/*#__PURE__*/ React.createElement(TodoList, _extends({}, x)); |
10 changes: 4 additions & 6 deletions
10
crates/swc/tests/tsc-references/tsxSpreadChildren.2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
//// [tsxSpreadChildren.tsx] | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 22 | {...todos.map(todo => <Todo key={todo.id} todo={todo.todo}/>)} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
var x; | ||
import _extends from "@swc/helpers/src/_extends.mjs"; | ||
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs"; | ||
_extends({}, x); |
31 changes: 19 additions & 12 deletions
31
crates/swc/tests/tsc-references/tsxSpreadChildrenInvalidType(target=es2015).1.normal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,20 @@ | ||
//// [tsxSpreadChildrenInvalidType.tsx] | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 21 | {...<Todo key={todos[0].id} todo={todos[0].todo} />} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 27 | {...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
import _extends from "@swc/helpers/src/_extends.mjs"; | ||
function Todo(prop) { | ||
return /*#__PURE__*/ React.createElement("div", null, prop.key.toString() + prop.todo); | ||
} | ||
function TodoList({ todos }) { | ||
return /*#__PURE__*/ React.createElement("div", null, .../*#__PURE__*/ React.createElement(Todo, { | ||
key: todos[0].id, | ||
todo: todos[0].todo | ||
})); | ||
} | ||
function TodoListNoError({ todos }) { | ||
// any is not checked | ||
return /*#__PURE__*/ React.createElement("div", null, .../*#__PURE__*/ React.createElement(Todo, { | ||
key: todos[0].id, | ||
todo: todos[0].todo | ||
})); | ||
} | ||
let x; | ||
/*#__PURE__*/ React.createElement(TodoList, _extends({}, x)); |
15 changes: 3 additions & 12 deletions
15
crates/swc/tests/tsc-references/tsxSpreadChildrenInvalidType(target=es2015).2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,4 @@ | ||
//// [tsxSpreadChildrenInvalidType.tsx] | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 21 | {...<Todo key={todos[0].id} todo={todos[0].todo} />} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 27 | {...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
let x; | ||
import _extends from "@swc/helpers/src/_extends.mjs"; | ||
_extends({}, x); |
40 changes: 28 additions & 12 deletions
40
crates/swc/tests/tsc-references/tsxSpreadChildrenInvalidType(target=es5).1.normal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
//// [tsxSpreadChildrenInvalidType.tsx] | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 21 | {...<Todo key={todos[0].id} todo={todos[0].todo} />} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 27 | {...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
import _extends from "@swc/helpers/src/_extends.mjs"; | ||
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs"; | ||
function Todo(prop) { | ||
return /*#__PURE__*/ React.createElement("div", null, prop.key.toString() + prop.todo); | ||
} | ||
function TodoList(param) { | ||
var todos = param.todos; | ||
return /*#__PURE__*/ React.createElement.apply(React, [ | ||
"div", | ||
null | ||
].concat(_to_consumable_array(/*#__PURE__*/ React.createElement(Todo, { | ||
key: todos[0].id, | ||
todo: todos[0].todo | ||
})))); | ||
} | ||
function TodoListNoError(param) { | ||
var todos = param.todos; | ||
// any is not checked | ||
return /*#__PURE__*/ React.createElement.apply(React, [ | ||
"div", | ||
null | ||
].concat(_to_consumable_array(/*#__PURE__*/ React.createElement(Todo, { | ||
key: todos[0].id, | ||
todo: todos[0].todo | ||
})))); | ||
} | ||
var x; | ||
/*#__PURE__*/ React.createElement(TodoList, _extends({}, x)); |
16 changes: 4 additions & 12 deletions
16
crates/swc/tests/tsc-references/tsxSpreadChildrenInvalidType(target=es5).2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,5 @@ | ||
//// [tsxSpreadChildrenInvalidType.tsx] | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 21 | {...<Todo key={todos[0].id} todo={todos[0].todo} />} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
//! | ||
//! x Spread children are not supported in React. | ||
//! ,---- | ||
//! 27 | {...(<Todo key={todos[0].id} todo={todos[0].todo} /> as any)} | ||
//! : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
//! `---- | ||
var x; | ||
import _extends from "@swc/helpers/src/_extends.mjs"; | ||
import _to_consumable_array from "@swc/helpers/src/_to_consumable_array.mjs"; | ||
_extends({}, x); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-2037/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const A = () => { | ||
return <div>{...[]}</div>; | ||
}; |
3 changes: 3 additions & 0 deletions
3
crates/swc_ecma_transforms_react/tests/jsx/fixture/issue-2037/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const A = ()=>{ | ||
return /*#__PURE__*/ React.createElement("div", null, ...[]); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...sforms_react/tests/jsx/fixture/react-automatic/should-disallow-spread-children/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/*#__PURE__*/ React.createElement("div", null); | ||
/*#__PURE__*/ React.createElement("div", null, ...children); |
6 changes: 0 additions & 6 deletions
6
...rms_react/tests/jsx/fixture/react-automatic/should-disallow-spread-children/output.stderr
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
..._ecma_transforms_react/tests/jsx/fixture/react/should-disallow-spread-children/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
/*#__PURE__*/ React.createElement("div", null); | ||
/*#__PURE__*/ React.createElement("div", null, ...children); |
6 changes: 0 additions & 6 deletions
6
...ma_transforms_react/tests/jsx/fixture/react/should-disallow-spread-children/output.stderr
This file was deleted.
Oops, something went wrong.
90aa6c8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/bugs-1
343725
ns/iter (± 35985
)339249
ns/iter (± 19114
)1.01
es/full/minify/libraries/antd
1920780678
ns/iter (± 19446273
)1926569394
ns/iter (± 34703410
)1.00
es/full/minify/libraries/d3
453425285
ns/iter (± 13467547
)435442912
ns/iter (± 7649321
)1.04
es/full/minify/libraries/echarts
1673549682
ns/iter (± 35740117
)1624471008
ns/iter (± 28803665
)1.03
es/full/minify/libraries/jquery
106195557
ns/iter (± 3979181
)102257399
ns/iter (± 8813358
)1.04
es/full/minify/libraries/lodash
119116099
ns/iter (± 3980688
)130135274
ns/iter (± 4286135
)0.92
es/full/minify/libraries/moment
61056574
ns/iter (± 1940331
)63941126
ns/iter (± 3293122
)0.95
es/full/minify/libraries/react
20392111
ns/iter (± 768066
)21328940
ns/iter (± 1355804
)0.96
es/full/minify/libraries/terser
325606279
ns/iter (± 5716295
)325367259
ns/iter (± 28015923
)1.00
es/full/minify/libraries/three
565290116
ns/iter (± 14133209
)578632415
ns/iter (± 18338390
)0.98
es/full/minify/libraries/typescript
3386248125
ns/iter (± 37649841
)3437266357
ns/iter (± 47791599
)0.99
es/full/minify/libraries/victory
840360756
ns/iter (± 12367009
)856744228
ns/iter (± 28800418
)0.98
es/full/minify/libraries/vue
161071945
ns/iter (± 13825072
)158569815
ns/iter (± 7575003
)1.02
es/full/codegen/es3
33640
ns/iter (± 1652
)34035
ns/iter (± 1014
)0.99
es/full/codegen/es5
33423
ns/iter (± 2292
)34007
ns/iter (± 807
)0.98
es/full/codegen/es2015
33578
ns/iter (± 1310
)34081
ns/iter (± 957
)0.99
es/full/codegen/es2016
33452
ns/iter (± 2461
)34016
ns/iter (± 674
)0.98
es/full/codegen/es2017
33385
ns/iter (± 1658
)33999
ns/iter (± 743
)0.98
es/full/codegen/es2018
33207
ns/iter (± 1268
)34008
ns/iter (± 715
)0.98
es/full/codegen/es2019
33349
ns/iter (± 843
)34020
ns/iter (± 1942
)0.98
es/full/codegen/es2020
32879
ns/iter (± 7416
)33906
ns/iter (± 842
)0.97
es/full/all/es3
191712687
ns/iter (± 6938640
)200541905
ns/iter (± 8865910
)0.96
es/full/all/es5
180181303
ns/iter (± 6780544
)187712132
ns/iter (± 7367374
)0.96
es/full/all/es2015
145227350
ns/iter (± 4693508
)147288770
ns/iter (± 6736358
)0.99
es/full/all/es2016
142588261
ns/iter (± 4052083
)145597155
ns/iter (± 5191199
)0.98
es/full/all/es2017
146923796
ns/iter (± 6740560
)145379414
ns/iter (± 5165232
)1.01
es/full/all/es2018
140361734
ns/iter (± 3504576
)144724573
ns/iter (± 9131420
)0.97
es/full/all/es2019
139163534
ns/iter (± 3577505
)142600788
ns/iter (± 7385079
)0.98
es/full/all/es2020
136694510
ns/iter (± 4134678
)136994947
ns/iter (± 6100882
)1.00
es/full/parser
708445
ns/iter (± 26460
)717720
ns/iter (± 50162
)0.99
es/full/base/fixer
26395
ns/iter (± 1192
)26456
ns/iter (± 818
)1.00
es/full/base/resolver_and_hygiene
92861
ns/iter (± 3734
)92926
ns/iter (± 3163
)1.00
serialization of ast node
204
ns/iter (± 8
)205
ns/iter (± 1
)1.00
serialization of serde
217
ns/iter (± 6
)212
ns/iter (± 4
)1.02
This comment was automatically generated by workflow using github-action-benchmark.