From eb516b36dd4d744d3b3acc68d2ebcc82abaaa3be Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 27 Dec 2024 15:10:34 -0700 Subject: [PATCH 1/5] feat(richtext-lexical): multiline string support for objects in MDX parser --- packages/richtext-lexical/package.json | 2 +- .../src/utilities/jsx/declare.d.ts | 4 ++ .../jsx/extractPropsFromJSXPropsString.ts | 10 ++--- .../src/utilities/jsx/jsx.spec.ts | 19 +++++++- pnpm-lock.yaml | 45 ++++++++++--------- 5 files changed, 52 insertions(+), 28 deletions(-) create mode 100644 packages/richtext-lexical/src/utilities/jsx/declare.d.ts diff --git a/packages/richtext-lexical/package.json b/packages/richtext-lexical/package.json index bf8cab427f..1baf0c8ef5 100644 --- a/packages/richtext-lexical/package.json +++ b/packages/richtext-lexical/package.json @@ -362,7 +362,7 @@ "bson-objectid": "2.0.4", "dequal": "2.0.3", "escape-html": "1.0.3", - "json5": "^2.2.3", + "jsox": "1.2.121", "lexical": "0.20.0", "mdast-util-from-markdown": "2.0.2", "mdast-util-mdx-jsx": "3.1.3", diff --git a/packages/richtext-lexical/src/utilities/jsx/declare.d.ts b/packages/richtext-lexical/src/utilities/jsx/declare.d.ts new file mode 100644 index 0000000000..583496ee10 --- /dev/null +++ b/packages/richtext-lexical/src/utilities/jsx/declare.d.ts @@ -0,0 +1,4 @@ +declare module 'jsox' { + const JSOX: any + export default JSOX +} diff --git a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts index bdf8544b50..5a09970a50 100644 --- a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts +++ b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts @@ -1,6 +1,6 @@ -import JSON5Import from 'json5' +import JSOXImport from 'jsox' -const JSON5 = ('default' in JSON5Import ? JSON5Import.default : JSON5Import) as typeof JSON5Import +const JSOX = 'default' in JSOXImport ? JSOXImport.default : JSOXImport /** * Turns a JSX props string into an object. @@ -82,7 +82,7 @@ function handleArray(propsString: string, startIndex: number): { newIndex: numbe i++ } - return { newIndex: i, value: JSON5.parse(`[${value}]`) } + return { newIndex: i, value: JSOX.parse(`[${value}]`) } } function handleQuotedString( @@ -120,10 +120,10 @@ function handleObject(propsString: string, startIndex: number): { newIndex: numb function parseObject(objString: string): Record { if (objString[0] !== '{') { - return JSON5.parse(objString) + return JSOX.parse(objString) } - const result = JSON5.parse(objString.replace(/(\w+):/g, '"$1":')) + const result = JSOX.parse(objString.replace(/(\w+):/g, '"$1":')) return result } diff --git a/packages/richtext-lexical/src/utilities/jsx/jsx.spec.ts b/packages/richtext-lexical/src/utilities/jsx/jsx.spec.ts index 6d635e013a..6dec5b7f69 100644 --- a/packages/richtext-lexical/src/utilities/jsx/jsx.spec.ts +++ b/packages/richtext-lexical/src/utilities/jsx/jsx.spec.ts @@ -118,13 +118,30 @@ describe('jsx', () => { }, { // Test if unquoted property keys in objects within arrays are supprted. This is - // supported through the more lenient json5 parser, instead of using JSON.parse() + // supported through the more lenient JSOX parser, instead of using JSON.parse() input: 'key={[1, 2, { hello: "there" }]}', inputFromOutput: 'key={[1, 2, { "hello": "there" }]}', output: { key: [1, 2, { hello: 'there' }], }, }, + { + // Test if ` strings work + input: `key={[1, 2, { hello: \`there\` }]}`, + inputFromOutput: 'key={[1, 2, { "hello": "there" }]}', + output: { + key: [1, 2, { hello: 'there' }], + }, + }, + { + // Test if multiline ` strings work + input: `key={[1, 2, { hello: \`Hello +there\` }]}`, + inputFromOutput: 'key={[1, 2, { "hello": "Hello\\nthere" }]}', + output: { + key: [1, 2, { hello: 'Hello\nthere' }], + }, + }, ] for (const { input, output } of INPUT_AND_OUTPUT) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4b9622df64..10a1cdaff3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -45,7 +45,7 @@ importers: version: 1.48.1 '@sentry/nextjs': specifier: ^8.33.1 - version: 8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.3(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(babel-plugin-react-compiler@19.0.0-beta-df7b47d-20241124)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)) + version: 8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.3(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))) '@sentry/node': specifier: ^8.33.1 version: 8.37.1 @@ -964,7 +964,7 @@ importers: version: link:../payload ts-jest: specifier: ^29.1.0 - version: 29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(esbuild@0.19.12)(jest@29.7.0(@types/node@22.5.4)(babel-plugin-macros@3.1.0))(typescript@5.7.2) + version: 29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(jest@29.7.0(@types/node@22.5.4)(babel-plugin-macros@3.1.0))(typescript@5.7.2) packages/plugin-cloud-storage: dependencies: @@ -1087,7 +1087,7 @@ importers: dependencies: '@sentry/nextjs': specifier: ^8.33.1 - version: 8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.4(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)) + version: 8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.4(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))) '@sentry/types': specifier: ^8.33.1 version: 8.37.1 @@ -1244,9 +1244,9 @@ importers: escape-html: specifier: 1.0.3 version: 1.0.3 - json5: - specifier: ^2.2.3 - version: 2.2.3 + jsox: + specifier: 1.2.121 + version: 1.2.121 lexical: specifier: 0.20.0 version: 0.20.0 @@ -1711,7 +1711,7 @@ importers: version: link:../packages/ui '@sentry/nextjs': specifier: ^8.33.1 - version: 8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.3(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(babel-plugin-react-compiler@19.0.0-beta-df7b47d-20241124)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)) + version: 8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.3(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))) '@sentry/react': specifier: ^7.77.0 version: 7.119.2(react@19.0.0) @@ -7796,6 +7796,10 @@ packages: jsonfile@6.1.0: resolution: {integrity: sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==} + jsox@1.2.121: + resolution: {integrity: sha512-9Ag50tKhpTwS6r5wh3MJSAvpSof0UBr39Pto8OnzFT32Z/pAbxAsKHzyvsyMEHVslELvHyO/4/jaQELHk8wDcw==} + hasBin: true + jsx-ast-utils@3.3.5: resolution: {integrity: sha512-ZZow9HBI5O6EPgSJLUb8n2NKgmVWTwCvHGwFuJlMjvLFqlGG6pjirPhtdsseaLZjSibD8eegzmYpUZwoIlj2cQ==} engines: {node: '>=4.0'} @@ -7857,7 +7861,6 @@ packages: libsql@0.4.7: resolution: {integrity: sha512-T9eIRCs6b0J1SHKYIvD8+KCJMcWZ900iZyxdnSCdqxN12Z1ijzT+jY5nrk72Jw4B0HGzms2NgpryArlJqvc3Lw==} - cpu: [x64, arm64, wasm32] os: [darwin, linux, win32] lie@3.1.1: @@ -13688,7 +13691,7 @@ snapshots: '@sentry/utils': 7.119.2 localforage: 1.10.0 - '@sentry/nextjs@8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.3(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(babel-plugin-react-compiler@19.0.0-beta-df7b47d-20241124)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12))': + '@sentry/nextjs@8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.3(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13)))': dependencies: '@opentelemetry/api': 1.9.0 '@opentelemetry/instrumentation-http': 0.53.0(@opentelemetry/api@1.9.0) @@ -13702,7 +13705,7 @@ snapshots: '@sentry/types': 8.37.1 '@sentry/utils': 8.37.1 '@sentry/vercel-edge': 8.37.1 - '@sentry/webpack-plugin': 2.22.6(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)) + '@sentry/webpack-plugin': 2.22.6(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))) chalk: 3.0.0 next: 15.0.3(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(babel-plugin-react-compiler@19.0.0-beta-df7b47d-20241124)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4) resolve: 1.22.8 @@ -13717,7 +13720,7 @@ snapshots: - supports-color - webpack - '@sentry/nextjs@8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.4(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12))': + '@sentry/nextjs@8.37.1(@opentelemetry/core@1.27.0(@opentelemetry/api@1.9.0))(@opentelemetry/instrumentation@0.54.2(@opentelemetry/api@1.9.0))(@opentelemetry/sdk-trace-base@1.27.0(@opentelemetry/api@1.9.0))(next@15.0.4(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4))(react@19.0.0)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13)))': dependencies: '@opentelemetry/api': 1.9.0 '@opentelemetry/instrumentation-http': 0.53.0(@opentelemetry/api@1.9.0) @@ -13731,7 +13734,7 @@ snapshots: '@sentry/types': 8.37.1 '@sentry/utils': 8.37.1 '@sentry/vercel-edge': 8.37.1 - '@sentry/webpack-plugin': 2.22.6(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)) + '@sentry/webpack-plugin': 2.22.6(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))) chalk: 3.0.0 next: 15.0.4(@babel/core@7.26.0)(@opentelemetry/api@1.9.0)(@playwright/test@1.48.1)(babel-plugin-macros@3.1.0)(react-dom@19.0.0(react@19.0.0))(react@19.0.0)(sass@1.77.4) resolve: 1.22.8 @@ -13841,12 +13844,12 @@ snapshots: '@sentry/types': 8.37.1 '@sentry/utils': 8.37.1 - '@sentry/webpack-plugin@2.22.6(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12))': + '@sentry/webpack-plugin@2.22.6(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13)))': dependencies: '@sentry/bundler-plugin-core': 2.22.6 unplugin: 1.0.1 uuid: 9.0.0 - webpack: 5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12) + webpack: 5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13)) transitivePeerDependencies: - encoding - supports-color @@ -17812,6 +17815,8 @@ snapshots: optionalDependencies: graceful-fs: 4.2.11 + jsox@1.2.121: {} + jsx-ast-utils@3.3.5: dependencies: array-includes: 3.1.8 @@ -19895,17 +19900,16 @@ snapshots: ansi-escapes: 4.3.2 supports-hyperlinks: 2.3.0 - terser-webpack-plugin@5.3.10(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)): + terser-webpack-plugin@5.3.10(@swc/core@1.9.3(@swc/helpers@0.5.13))(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))): dependencies: '@jridgewell/trace-mapping': 0.3.25 jest-worker: 27.5.1 schema-utils: 3.3.0 serialize-javascript: 6.0.2 terser: 5.36.0 - webpack: 5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12) + webpack: 5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13)) optionalDependencies: '@swc/core': 1.9.3(@swc/helpers@0.5.13) - esbuild: 0.19.12 terser@5.36.0: dependencies: @@ -20001,7 +20005,7 @@ snapshots: optionalDependencies: typescript: 5.7.2 - ts-jest@29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(esbuild@0.19.12)(jest@29.7.0(@types/node@22.5.4)(babel-plugin-macros@3.1.0))(typescript@5.7.2): + ts-jest@29.2.5(@babel/core@7.26.0)(@jest/transform@29.7.0)(@jest/types@29.6.3)(babel-jest@29.7.0(@babel/core@7.26.0))(jest@29.7.0(@types/node@22.5.4)(babel-plugin-macros@3.1.0))(typescript@5.7.2): dependencies: bs-logger: 0.2.6 ejs: 3.1.10 @@ -20019,7 +20023,6 @@ snapshots: '@jest/transform': 29.7.0 '@jest/types': 29.6.3 babel-jest: 29.7.0(@babel/core@7.26.0) - esbuild: 0.19.12 ts-pattern@5.5.0: {} @@ -20321,7 +20324,7 @@ snapshots: webpack-virtual-modules@0.5.0: {} - webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12): + webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13)): dependencies: '@types/eslint-scope': 3.7.7 '@types/estree': 1.0.6 @@ -20343,7 +20346,7 @@ snapshots: neo-async: 2.6.2 schema-utils: 3.3.0 tapable: 2.2.1 - terser-webpack-plugin: 5.3.10(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))(esbuild@0.19.12)) + terser-webpack-plugin: 5.3.10(@swc/core@1.9.3(@swc/helpers@0.5.13))(webpack@5.96.1(@swc/core@1.9.3(@swc/helpers@0.5.13))) watchpack: 2.4.2 webpack-sources: 3.2.3 transitivePeerDependencies: From 6d7b3c8a3888b2f5522a06578c8ff32b8e62bdb2 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 27 Dec 2024 15:22:08 -0700 Subject: [PATCH 2/5] fix dumb CJS mess --- .../src/utilities/jsx/extractPropsFromJSXPropsString.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts index 5a09970a50..6c6442d178 100644 --- a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts +++ b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts @@ -1,6 +1,4 @@ -import JSOXImport from 'jsox' - -const JSOX = 'default' in JSOXImport ? JSOXImport.default : JSOXImport +import * as JSOX from 'jsox' /** * Turns a JSX props string into an object. @@ -82,6 +80,7 @@ function handleArray(propsString: string, startIndex: number): { newIndex: numbe i++ } + // @ts-expect-error return { newIndex: i, value: JSOX.parse(`[${value}]`) } } @@ -120,9 +119,11 @@ function handleObject(propsString: string, startIndex: number): { newIndex: numb function parseObject(objString: string): Record { if (objString[0] !== '{') { + // @ts-expect-error return JSOX.parse(objString) } + // @ts-expect-error const result = JSOX.parse(objString.replace(/(\w+):/g, '"$1":')) return result From 9e1da25ad99efc769a3675f2a93b94eda1f8b34b Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 27 Dec 2024 15:34:51 -0700 Subject: [PATCH 3/5] fix import --- .../src/utilities/jsx/extractPropsFromJSXPropsString.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts index 6c6442d178..09d971896e 100644 --- a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts +++ b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts @@ -1,4 +1,6 @@ -import * as JSOX from 'jsox' +import * as _JSOX from 'jsox' + +const JSOX = 'default' in _JSOX ? _JSOX.default : _JSOX /** * Turns a JSX props string into an object. From 44c7114a54574d5f0be53336ca61ba90b742aea0 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 27 Dec 2024 15:36:09 -0700 Subject: [PATCH 4/5] again --- .../src/utilities/jsx/extractPropsFromJSXPropsString.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts index 09d971896e..cb241beb78 100644 --- a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts +++ b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts @@ -82,7 +82,6 @@ function handleArray(propsString: string, startIndex: number): { newIndex: numbe i++ } - // @ts-expect-error return { newIndex: i, value: JSOX.parse(`[${value}]`) } } @@ -121,11 +120,9 @@ function handleObject(propsString: string, startIndex: number): { newIndex: numb function parseObject(objString: string): Record { if (objString[0] !== '{') { - // @ts-expect-error return JSOX.parse(objString) } - // @ts-expect-error const result = JSOX.parse(objString.replace(/(\w+):/g, '"$1":')) return result From 05755479ff4f6dbe49d8b2a4560ccc9cc3e959de Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 27 Dec 2024 15:45:11 -0700 Subject: [PATCH 5/5] may the lords of JS allow this --- packages/richtext-lexical/src/utilities/jsx/declare.d.ts | 3 +-- .../src/utilities/jsx/extractPropsFromJSXPropsString.ts | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/richtext-lexical/src/utilities/jsx/declare.d.ts b/packages/richtext-lexical/src/utilities/jsx/declare.d.ts index 583496ee10..22bafe400c 100644 --- a/packages/richtext-lexical/src/utilities/jsx/declare.d.ts +++ b/packages/richtext-lexical/src/utilities/jsx/declare.d.ts @@ -1,4 +1,3 @@ declare module 'jsox' { - const JSOX: any - export default JSOX + export const JSOX: any } diff --git a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts index cb241beb78..42a90c26e7 100644 --- a/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts +++ b/packages/richtext-lexical/src/utilities/jsx/extractPropsFromJSXPropsString.ts @@ -1,6 +1,4 @@ -import * as _JSOX from 'jsox' - -const JSOX = 'default' in _JSOX ? _JSOX.default : _JSOX +import { JSOX } from 'jsox' /** * Turns a JSX props string into an object.