From 5780dc034e5ec6d827d430a1c81277aedf170579 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Sun, 19 May 2024 20:35:26 +0530 Subject: [PATCH 1/4] Handle edgecase where jsx import ends with ',' in place of ';' --- lib/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/index.ts b/lib/src/index.ts index 452de0bf..553889d5 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -125,9 +125,9 @@ function replaceBuild(buildReplacePattern: ReplacePattern, result: BuildResult) const useClientRegExp = /^(["']use strict["'];)?["']use client["'];?/i; const useServerRegExp = /^(["']use strict["'];)?["']use server["'];?/i; -const jsxImportRegExp = /(var |,)?[a-zA-Z_$][\w$]*=require\("react\/jsx-runtime"\);?/g; +const jsxImportRegExp = /(var |,)?[a-zA-Z_$][\w$]*=require\("react\/jsx-runtime"\)[;,]?/g; const regExp2replace2GetVar0 = /(var |,)/; -const regExp2replace2GetVar = /[=]require\(['"]react\/jsx-runtime['"]\);?/; +const regExp2replace2GetVar = /[=]require\(['"]react\/jsx-runtime['"]\)[;,]?/; function onEndCallBack(result: BuildResult, options: React18PluginOptions, write?: boolean) { /** remove empty file imports */ From ec15c4be6a66f0ccce4b83a4ae3384368d60af75 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Sun, 19 May 2024 20:38:31 +0530 Subject: [PATCH 2/4] Changelog --- lib/CHANGELOG.md | 6 ++++++ lib/package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/CHANGELOG.md b/lib/CHANGELOG.md index 0d1b7499..da40007c 100644 --- a/lib/CHANGELOG.md +++ b/lib/CHANGELOG.md @@ -1,5 +1,11 @@ # esbuild-plugin-react18 +## 0.2.1 + +### Patch Changes + +- Handle edgecase where jsx import ends with ',' in place of ';' + ## 0.2.0 ### Minor Changes diff --git a/lib/package.json b/lib/package.json index 0c9bba53..2b6f5642 100644 --- a/lib/package.json +++ b/lib/package.json @@ -2,7 +2,7 @@ "name": "esbuild-plugin-react18", "author": "Mayank Kumar Chaudhari ", "private": false, - "version": "0.2.0", + "version": "0.2.1", "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).", "license": "MPL-2.0", "main": "./dist/index.js", From 789a6cf2fe7d6f42d043dbb976c9442c28c3c303 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Sun, 19 May 2024 20:45:45 +0530 Subject: [PATCH 3/4] fix start as well as end with ',' --- lib/src/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/src/index.ts b/lib/src/index.ts index 553889d5..60cbeab3 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -161,7 +161,9 @@ function onEndCallBack(result: BuildResult, options: React18PluginOptions, write .replace(regExp2replace2GetVar, "") .replace(regExp2replace2GetVar0, ""); for (let index = 1; index < jsxMatches.length; index++) { - txt = txt.replace(jsxMatches[index], ""); + const token = jsxMatches[index]; + const toReplace = token.match(/^,.*,$/) ? token.slice(1) : token; + txt = txt.replace(toReplace, ""); const v1 = jsxMatches[index] .replace(regExp2replace2GetVar, "") .replace(regExp2replace2GetVar0, ""); From e5ea097e49b6dc6f2ff540fe053bab667d534bc9 Mon Sep 17 00:00:00 2001 From: Mayank Kumar Chaudhari Date: Sun, 19 May 2024 20:51:23 +0530 Subject: [PATCH 4/4] Fix deepsource --- lib/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/index.ts b/lib/src/index.ts index 60cbeab3..0df2ccf2 100644 --- a/lib/src/index.ts +++ b/lib/src/index.ts @@ -162,7 +162,7 @@ function onEndCallBack(result: BuildResult, options: React18PluginOptions, write .replace(regExp2replace2GetVar0, ""); for (let index = 1; index < jsxMatches.length; index++) { const token = jsxMatches[index]; - const toReplace = token.match(/^,.*,$/) ? token.slice(1) : token; + const toReplace = /^,.*,$/.test(token) ? token.slice(1) : token; txt = txt.replace(toReplace, ""); const v1 = jsxMatches[index] .replace(regExp2replace2GetVar, "")