Setup JSX runtime even if the file doesn't contain JSX (#12479)
This commit is contained in:
parent
e5b2680756
commit
bf417186bf
@ -138,7 +138,6 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
|
||||
|
||||
Program: {
|
||||
enter(path, state) {
|
||||
if (hasJSX(path)) {
|
||||
const { file } = state;
|
||||
let runtime = RUNTIME_DEFAULT;
|
||||
|
||||
@ -268,7 +267,6 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
|
||||
if (options.development) {
|
||||
path.traverse(injectMetaPropertiesVisitor, state);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// TODO (Babel 8): Decide if this should be removed or brought back.
|
||||
@ -353,18 +351,6 @@ You can set \`throwIfNamespace: false\` to bypass this warning.`,
|
||||
return imports;
|
||||
}
|
||||
|
||||
function hasJSX(parentPath) {
|
||||
let fileHasJSX = false;
|
||||
parentPath.traverse({
|
||||
"JSXElement|JSXFragment"(path) {
|
||||
fileHasJSX = true;
|
||||
path.stop();
|
||||
},
|
||||
});
|
||||
|
||||
return fileHasJSX;
|
||||
}
|
||||
|
||||
function getSource(source, importName) {
|
||||
switch (importName) {
|
||||
case "Fragment":
|
||||
|
||||
@ -0,0 +1 @@
|
||||
const foo = 2;
|
||||
@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
["transform-react-jsx", { "runtime": "automatic" }],
|
||||
"./plugin.js"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
const foo = /*#__PURE__*/undefined.jsx("p", {});
|
||||
@ -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")),
|
||||
[]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -0,0 +1 @@
|
||||
const foo = 2;
|
||||
@ -0,0 +1,6 @@
|
||||
{
|
||||
"plugins": [
|
||||
["transform-react-jsx", { "runtime": "classic" }],
|
||||
"./plugin.js"
|
||||
]
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
const foo = /*#__PURE__*/React.createElement("p", null);
|
||||
13
packages/babel-plugin-transform-react-jsx/test/fixtures/regression/issue-12478-classic/plugin.js
vendored
Normal file
13
packages/babel-plugin-transform-react-jsx/test/fixtures/regression/issue-12478-classic/plugin.js
vendored
Normal 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")),
|
||||
[]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user