Skip to content

Commit

Permalink
fix(jsx): do not throw on generated element in development mode (#12017)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Timer and JLHwung committed Aug 31, 2020
1 parent ce6a7f1 commit 371e152
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
Expand Up @@ -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) {
Expand Down
@@ -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")),
[]
)
);
}
}
}
};
};

0 comments on commit 371e152

Please sign in to comment.