Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up[transform-react-jsx] Add useSpread option to transform JSX #10572
Conversation
This comment has been minimized.
This comment has been minimized.
Can you also add a test where the spread isn't the first property? |
@@ -172,6 +172,14 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`, | |||
let _props = []; | |||
const objs = []; | |||
|
|||
const useSpread = file.opts.useSpread || false; |
This comment has been minimized.
This comment has been minimized.
nicolo-ribaudo
Oct 18, 2019
Member
I don't like that this accepts 0
, but let's keep it as-is for consistency with the other options of this file
We should revisit it in Babel 8.
This comment has been minimized.
This comment has been minimized.
JLHwung
Oct 18, 2019
Contributor
IMO, we could begin on useSpread
now because it is a new option. useBuiltins: 0
is strange enough and it does not justify that you can even use useSpread: 0
.
I think when return attribs.map(convertAttribute) because And we may teach |
@@ -172,6 +172,14 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`, | |||
let _props = []; | |||
const objs = []; | |||
|
|||
const useSpread = file.opts.useSpread || false; |
This comment has been minimized.
This comment has been minimized.
JLHwung
Oct 18, 2019
•
Contributor
I think we should also add useSpread
to preset-react
, too.
Another thought is that may be we should give a warning (or even error) when both useBuiltIns
and useSpread
are true
because useSpread
precedes useBuiltIns
.
); | ||
} | ||
|
||
const useBuiltIns = setDefaultValue(file.opts.useBuiltIns, false); |
This comment has been minimized.
This comment has been minimized.
nicolo-ribaudo
Oct 25, 2019
Member
While this makes 100% sense, it is a breaking change (for example, if you pass 0
) and we should defer it to Babel 8.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@@ -172,7 +180,15 @@ You can turn on the 'throwIfNamespace' flag to bypass this warning.`, | |||
let _props = []; | |||
const objs = []; | |||
|
|||
const useBuiltIns = file.opts.useBuiltIns || false; | |||
const useSpread = setDefaultValue(file.opts.useSpread, false); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Hey @JLHwung , do you mean to add a condition before if (useSpread) {
const props = attribs.map(convertAttribute);
return t.objectExpression(props);
} |
This comment has been minimized.
This comment has been minimized.
@ivandevp correct, I missed the |
This comment has been minimized.
This comment has been minimized.
I've made the requested changes guys, let me know if you think we can do any other enhancement. |
This comment has been minimized.
This comment has been minimized.
@ivandevp Could you add |
This comment has been minimized.
This comment has been minimized.
Sure @JLHwung! I forgot that one |
This comment has been minimized.
This comment has been minimized.
Hey @JLHwung ! I've tried to follow the |
The CI failure is unrelated |
Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
A new `useSpread` option was added in Babel 7.7.0 (babel/babel#10572): https://babeljs.io/docs/en/babel-preset-react#usespread Enabling this means that the JSX-> JS conversion will use an inline object with spread elements (for code that spreads props), rather than Babel's extend helper or `Object.assign`. `@babel/env` will still transpile these down if required for the target browsers (the only reason `useSpread` is not already enabled by default is that for the upstream project this is a breaking change, since they cannot assume that users of `babel-preset-react` are always using it alongside `@babel/env`, even though most likely are).
A new `useSpread` option was added in Babel 7.7.0 (babel/babel#10572): https://babeljs.io/docs/en/babel-preset-react#usespread Enabling this means that the JSX-> JS conversion will use an inline object with spread elements (for code that spreads props), rather than Babel's extend helper or `Object.assign`. `@babel/env` will still transpile these down if required for the target browsers (the only reason `useSpread` is not already enabled by default is that for the upstream project this is a breaking change, since they cannot assume that users of `babel-preset-react` are always using it alongside `@babel/env`, even though most likely are).
ivandevp commentedOct 18, 2019
•
edited