Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "esbuild-plugin-react18",
"author": "Mayank Kumar Chaudhari <https://mayank-chaudhari.vercel.app>",
"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",
Expand Down
8 changes: 5 additions & 3 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 = /^,.*,$/.test(token) ? token.slice(1) : token;
txt = txt.replace(toReplace, "");
const v1 = jsxMatches[index]
.replace(regExp2replace2GetVar, "")
.replace(regExp2replace2GetVar0, "");
Expand Down