Skip to content

Commit a707073

Browse files
authored
fix jsx detection for vite/esbuild (#3113)
1 parent 1dbb52a commit a707073

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/plots/src/util/is-valid-element.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export const isValidElement = (jsxCode: string): boolean => {
2-
const basicReactPatterns = [/\breact\b/i, /\.jsx/, /children:\s*\[/, /\*#__PURE__\*/];
2+
const basicReactPatterns = [/\breact\b/i, /\.jsx/, /children:\s*\[/, /\*\s*[#@]__PURE__\s*\*/];
33
const createElementPattern = /(\w+)?\.createElement\(\s*(['"`])([^'"`]+)\2/g;
44

55
// G 元素集合

packages/plots/tests/util/is-valid-element-spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ const BUILD_ASSESTS_BIGFISH_DEV2 = `(event, { items })=>{
107107
columnNumber: 24
108108
}, this);
109109
}`
110+
const BUILD_ASSESTS_ESBUILD = `($, _, i) => /* @__PURE__ */ jsxDEV("div", { style: { height: 1, width: 30, background: "#aaa", margin: "0 20" } }, void 0, false, {
111+
fileName: "index.tsx",
112+
lineNumber: 12,
113+
columnNumber: 29
114+
}, this)`
110115

111116
describe('isValidElement', () => {
112117
it('ice build product', async () => {
@@ -125,6 +130,10 @@ describe('isValidElement', () => {
125130
expect(isValidElement(BUILD_ASSESTS_BIGFISH_DEV2)).toBeTruthy();
126131
});
127132

133+
it('build product with vite', async () => {
134+
expect(isValidElement(BUILD_ASSESTS_ESBUILD)).toBeTruthy();
135+
});
136+
128137
it('should return true for basic React patterns', () => {
129138
expect(isValidElement('import React from "react"')).toBeTruthy();
130139
expect(isValidElement('const children: []')).toBeTruthy();

0 commit comments

Comments
 (0)