fix(jsx): do not throw on generated element in development mode (#12017)
* Fix `jsxDEV` for generated elements * Throw invariant error * Add test * test: revise test layout * fix: node 6 does not support trailing comma * Use undefined node Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
This commit is contained in:
parent
ce6a7f1d98
commit
371e152cd2
@ -437,7 +437,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
|
|||||||
const location = path.node.loc;
|
const location = path.node.loc;
|
||||||
if (!location) {
|
if (!location) {
|
||||||
// the element was generated and doesn't have location information
|
// the element was generated and doesn't have location information
|
||||||
return;
|
return path.scope.buildUndefinedNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.fileNameIdentifier) {
|
if (!state.fileNameIdentifier) {
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
// empty
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"./plugin.js",
|
||||||
|
["transform-react-jsx-development", { "runtime": "automatic" }]
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
// empty
|
||||||
|
|
||||||
|
var _reactJsxDevRuntime = require("react/jsx-dev-runtime");
|
||||||
|
|
||||||
|
/*#__PURE__*/
|
||||||
|
_reactJsxDevRuntime.jsxDEV("div", {}, void 0, false, void 0, this)
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
module.exports = function ({ types: t }) {
|
||||||
|
return {
|
||||||
|
visitor: {
|
||||||
|
Program: {
|
||||||
|
enter(path) {
|
||||||
|
path.pushContainer(
|
||||||
|
"body",
|
||||||
|
t.JSXElement(
|
||||||
|
t.JSXOpeningElement(t.JSXIdentifier("div"), [], false),
|
||||||
|
t.JSXClosingElement(t.JSXIdentifier("div")),
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user