Skip to content

Commit 029cd15

Browse files
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
1 parent 36a5ac4 commit 029cd15

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

packages/babel-plugin-transform-react-jsx/src/create-plugin.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ const DEFAULT = {
3131
pragmaFrag: "React.Fragment",
3232
};
3333

34-
const JSX_SOURCE_ANNOTATION_REGEX = /\*?\s*@jsxImportSource\s+([^\s]+)/;
35-
const JSX_RUNTIME_ANNOTATION_REGEX = /\*?\s*@jsxRuntime\s+([^\s]+)/;
34+
const JSX_SOURCE_ANNOTATION_REGEX =
35+
/^\s*\*?\s*@jsxImportSource\s+([^\s]+)\s*$/m;
36+
const JSX_RUNTIME_ANNOTATION_REGEX = /^\s*\*?\s*@jsxRuntime\s+([^\s]+)\s*$/m;
3637

37-
const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;
38-
const JSX_FRAG_ANNOTATION_REGEX = /\*?\s*@jsxFrag\s+([^\s]+)/;
38+
const JSX_ANNOTATION_REGEX = /^\s*\*?\s*@jsx\s+([^\s]+)\s*$/m;
39+
const JSX_FRAG_ANNOTATION_REGEX = /^\s*\*?\s*@jsxFrag\s+([^\s]+)\s*$/m;
3940

4041
const get = (pass: PluginPass, name: string) =>
4142
pass.get(`@babel/plugin-react-jsx/${name}`);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/**
2+
* @jsx jsx
3+
*/
4+
5+
<foo />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* @jsx jsx
3+
*/
4+
jsx("foo", null);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Make sure not to use a jsx pragma here (like "@jsx Something"), we need this to be React.createElement!
2+
<blah/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Make sure not to use a jsx pragma here (like "@jsx Something"), we need this to be React.createElement!
2+
3+
/*#__PURE__*/
4+
React.createElement("blah", null);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy