Setup JSX runtime even if the file doesn't contain JSX (#12479)

This commit is contained in:
Nicolò Ribaudo
2020-12-10 19:27:22 +01:00
committed by GitHub
parent e5b2680756
commit bf417186bf
9 changed files with 158 additions and 130 deletions

View File

@@ -0,0 +1 @@
const foo = 2;

View File

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

View File

@@ -0,0 +1 @@
const foo = /*#__PURE__*/undefined.jsx("p", {});

View File

@@ -0,0 +1,13 @@
module.exports = ({ types: t }) => ({
visitor: {
NumericLiteral(path) {
path.replaceWith(
t.jsxElement(
t.jsxOpeningElement(t.jsxIdentifier("p"), []),
t.jsxClosingElement(t.jsxIdentifier("p")),
[]
)
);
}
}
});

View File

@@ -0,0 +1 @@
const foo = 2;

View File

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

View File

@@ -0,0 +1 @@
const foo = /*#__PURE__*/React.createElement("p", null);

View File

@@ -0,0 +1,13 @@
module.exports = ({ types: t }) => ({
visitor: {
NumericLiteral(path) {
path.replaceWith(
t.jsxElement(
t.jsxOpeningElement(t.jsxIdentifier("p"), []),
t.jsxClosingElement(t.jsxIdentifier("p")),
[]
)
);
}
}
});