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:
Nicolò Ribaudo 2020-03-20 22:29:50 +01:00 committed by GitHub
parent bb6a1580d2
commit 87b2781046
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 2 deletions

View File

@ -53,16 +53,20 @@ export default declare((api, options) => {
let pragma = PRAGMA_DEFAULT;
let pragmaFrag = PRAGMA_FRAG_DEFAULT;
let pragmaSet = !!options.pragma;
let pragmaFragSet = !!options.pragma;
if (file.ast.comments) {
for (const comment of (file.ast.comments: Array<Object>)) {
const jsxMatches = JSX_ANNOTATION_REGEX.exec(comment.value);
if (jsxMatches) {
pragma = jsxMatches[1];
pragmaSet = true;
}
const jsxFragMatches = JSX_FRAG_ANNOTATION_REGEX.exec(comment.value);
if (jsxFragMatches) {
pragmaFrag = jsxFragMatches[1];
pragmaFragSet = true;
}
}
}
@ -70,8 +74,8 @@ export default declare((api, options) => {
state.set("jsxIdentifier", createIdentifierParser(pragma));
state.set("jsxFragIdentifier", createIdentifierParser(pragmaFrag));
state.set("usedFragment", false);
state.set("pragmaSet", pragma !== DEFAULT.pragma);
state.set("pragmaFragSet", pragmaFrag !== DEFAULT.pragmaFrag);
state.set("pragmaSet", pragmaSet);
state.set("pragmaFragSet", pragmaFragSet);
},
exit(path, state) {
if (

View File

@ -0,0 +1,3 @@
/* @jsxFrag React.Fragment */
/* @jsx h */
<>Test</>;

View File

@ -0,0 +1,5 @@
{
"plugins": [
"transform-react-jsx"
]
}

View File

@ -0,0 +1,4 @@
/* @jsxFrag React.Fragment */
/* @jsx h */
h(React.Fragment, null, "Test");

View File

@ -0,0 +1,2 @@
import React from 'react';
const D = <></>;

View File

@ -0,0 +1,4 @@
{
"presets": [
["react", { "pragma": "__jsx" }]]
}

View File

@ -0,0 +1,3 @@
import React from 'react';
const D = __jsx(React.Fragment, null);