Fix JSX pragma anywhere in comment (#14012)

* Fix JSX pragma anywhere in comment

* jsx regex patterns support jsx docs

* removed extra spaces from regex patterns
This commit is contained in:
Sneh Khatri 2021-12-02 21:05:44 +05:30 committed by GitHub
parent 36a5ac4145
commit 029cd15bd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 4 deletions

View File

@ -31,11 +31,12 @@ const DEFAULT = {
pragmaFrag: "React.Fragment", pragmaFrag: "React.Fragment",
}; };
const JSX_SOURCE_ANNOTATION_REGEX = /\*?\s*@jsxImportSource\s+([^\s]+)/; const JSX_SOURCE_ANNOTATION_REGEX =
const JSX_RUNTIME_ANNOTATION_REGEX = /\*?\s*@jsxRuntime\s+([^\s]+)/; /^\s*\*?\s*@jsxImportSource\s+([^\s]+)\s*$/m;
const JSX_RUNTIME_ANNOTATION_REGEX = /^\s*\*?\s*@jsxRuntime\s+([^\s]+)\s*$/m;
const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/; const JSX_ANNOTATION_REGEX = /^\s*\*?\s*@jsx\s+([^\s]+)\s*$/m;
const JSX_FRAG_ANNOTATION_REGEX = /\*?\s*@jsxFrag\s+([^\s]+)/; const JSX_FRAG_ANNOTATION_REGEX = /^\s*\*?\s*@jsxFrag\s+([^\s]+)\s*$/m;
const get = (pass: PluginPass, name: string) => const get = (pass: PluginPass, name: string) =>
pass.get(`@babel/plugin-react-jsx/${name}`); pass.get(`@babel/plugin-react-jsx/${name}`);

View File

@ -0,0 +1,5 @@
/**
* @jsx jsx
*/
<foo />

View File

@ -0,0 +1,4 @@
/**
* @jsx jsx
*/
jsx("foo", null);

View File

@ -0,0 +1,2 @@
// Make sure not to use a jsx pragma here (like "@jsx Something"), we need this to be React.createElement!
<blah/>

View File

@ -0,0 +1,4 @@
// Make sure not to use a jsx pragma here (like "@jsx Something"), we need this to be React.createElement!
/*#__PURE__*/
React.createElement("blah", null);