Skip to content

Commit 599a834

Browse files
authored
Merge pull request #23 from react18-tools/fix-jsx-runtime-edge-cases
Fix-jsx-runtime-edge-cases
2 parents 5a747b8 + e5ea097 commit 599a834

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

lib/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# esbuild-plugin-react18
22

3+
## 0.2.1
4+
5+
### Patch Changes
6+
7+
- Handle edgecase where jsx import ends with ',' in place of ';'
8+
39
## 0.2.0
410

511
### Minor Changes

lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "esbuild-plugin-react18",
33
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
44
"private": false,
5-
"version": "0.2.0",
5+
"version": "0.2.1",
66
"description": "Unlock the Potential of React Server Components! Harness the power of an ESBuild plugin designed for crafting libraries compatible with RSC (React18 Server Components).",
77
"license": "MPL-2.0",
88
"main": "./dist/index.js",

lib/src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ function replaceBuild(buildReplacePattern: ReplacePattern, result: BuildResult)
125125

126126
const useClientRegExp = /^(["']use strict["'];)?["']use client["'];?/i;
127127
const useServerRegExp = /^(["']use strict["'];)?["']use server["'];?/i;
128-
const jsxImportRegExp = /(var |,)?[a-zA-Z_$][\w$]*=require\("react\/jsx-runtime"\);?/g;
128+
const jsxImportRegExp = /(var |,)?[a-zA-Z_$][\w$]*=require\("react\/jsx-runtime"\)[;,]?/g;
129129
const regExp2replace2GetVar0 = /(var |,)/;
130-
const regExp2replace2GetVar = /[=]require\(['"]react\/jsx-runtime['"]\);?/;
130+
const regExp2replace2GetVar = /[=]require\(['"]react\/jsx-runtime['"]\)[;,]?/;
131131

132132
function onEndCallBack(result: BuildResult, options: React18PluginOptions, write?: boolean) {
133133
/** remove empty file imports */
@@ -161,7 +161,9 @@ function onEndCallBack(result: BuildResult, options: React18PluginOptions, write
161161
.replace(regExp2replace2GetVar, "")
162162
.replace(regExp2replace2GetVar0, "");
163163
for (let index = 1; index < jsxMatches.length; index++) {
164-
txt = txt.replace(jsxMatches[index], "");
164+
const token = jsxMatches[index];
165+
const toReplace = /^,.*,$/.test(token) ? token.slice(1) : token;
166+
txt = txt.replace(toReplace, "");
165167
const v1 = jsxMatches[index]
166168
.replace(regExp2replace2GetVar, "")
167169
.replace(regExp2replace2GetVar0, "");

0 commit comments

Comments
 (0)