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:
Joe Haddad 2020-08-31 15:16:47 -04:00 committed by GitHub
parent ce6a7f1d98
commit 371e152cd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 1 deletions

View File

@ -437,7 +437,7 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
const location = path.node.loc;
if (!location) {
// the element was generated and doesn't have location information
return;
return path.scope.buildUndefinedNode();
}
if (!state.fileNameIdentifier) {

View File

@ -0,0 +1,6 @@
{
"plugins": [
"./plugin.js",
["transform-react-jsx-development", { "runtime": "automatic" }]
]
}

View File

@ -0,0 +1,6 @@
// empty
var _reactJsxDevRuntime = require("react/jsx-dev-runtime");
/*#__PURE__*/
_reactJsxDevRuntime.jsxDEV("div", {}, void 0, false, void 0, this)

View File

@ -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")),
[]
)
);
}
}
}
};
};