Consider jsxFrag as set when it's set to the default value (#11295)
* Consider jsxFrag as set when it's set to the default value * Test #11294
This commit is contained in:
parent
bb6a1580d2
commit
87b2781046
@ -53,16 +53,20 @@ export default declare((api, options) => {
|
|||||||
|
|
||||||
let pragma = PRAGMA_DEFAULT;
|
let pragma = PRAGMA_DEFAULT;
|
||||||
let pragmaFrag = PRAGMA_FRAG_DEFAULT;
|
let pragmaFrag = PRAGMA_FRAG_DEFAULT;
|
||||||
|
let pragmaSet = !!options.pragma;
|
||||||
|
let pragmaFragSet = !!options.pragma;
|
||||||
|
|
||||||
if (file.ast.comments) {
|
if (file.ast.comments) {
|
||||||
for (const comment of (file.ast.comments: Array<Object>)) {
|
for (const comment of (file.ast.comments: Array<Object>)) {
|
||||||
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
|
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
|
||||||
if (jsxMatches) {
|
if (jsxMatches) {
|
||||||
pragma = jsxMatches[1];
|
pragma = jsxMatches[1];
|
||||||
|
pragmaSet = true;
|
||||||
}
|
}
|
||||||
const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec(comment.value);
|
const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec(comment.value);
|
||||||
if (jsxFragMatches) {
|
if (jsxFragMatches) {
|
||||||
pragmaFrag = jsxFragMatches[1];
|
pragmaFrag = jsxFragMatches[1];
|
||||||
|
pragmaFragSet = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,8 +74,8 @@ export default declare((api, options) => {
|
|||||||
state.set("jsxIdentifier", createIdentifierParser(pragma));
|
state.set("jsxIdentifier", createIdentifierParser(pragma));
|
||||||
state.set("jsxFragIdentifier", createIdentifierParser(pragmaFrag));
|
state.set("jsxFragIdentifier", createIdentifierParser(pragmaFrag));
|
||||||
state.set("usedFragment", false);
|
state.set("usedFragment", false);
|
||||||
state.set("pragmaSet", pragma !== DEFAULT.pragma);
|
state.set("pragmaSet", pragmaSet);
|
||||||
state.set("pragmaFragSet", pragmaFrag !== DEFAULT.pragmaFrag);
|
state.set("pragmaFragSet", pragmaFragSet);
|
||||||
},
|
},
|
||||||
exit(path, state) {
|
exit(path, state) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
/* @jsxFrag React.Fragment */
|
||||||
|
/* @jsx h */
|
||||||
|
<>Test</>;
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"transform-react-jsx"
|
||||||
|
]
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
/* @jsxFrag React.Fragment */
|
||||||
|
|
||||||
|
/* @jsx h */
|
||||||
|
h(React.Fragment, null, "Test");
|
||||||
2
packages/babel-preset-react/test/fixtures/regression/11294/input.mjs
vendored
Normal file
2
packages/babel-preset-react/test/fixtures/regression/11294/input.mjs
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import React from 'react';
|
||||||
|
const D = <></>;
|
||||||
4
packages/babel-preset-react/test/fixtures/regression/11294/options.json
vendored
Normal file
4
packages/babel-preset-react/test/fixtures/regression/11294/options.json
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["react", { "pragma": "__jsx" }]]
|
||||||
|
}
|
||||||
3
packages/babel-preset-react/test/fixtures/regression/11294/output.mjs
vendored
Normal file
3
packages/babel-preset-react/test/fixtures/regression/11294/output.mjs
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
const D = __jsx(React.Fragment, null);
|
||||||
Loading…
x
Reference in New Issue
Block a user