From 75db27e5d4fc86cf8aba27a5392f96d5afbd0eb6 Mon Sep 17 00:00:00 2001 From: Homyee King Date: Fri, 8 Nov 2024 09:52:09 +0800 Subject: [PATCH] fix: should re-export createElement for backwards compatibility (#7002) * fix: should re-export createElement for backwards compatibility * feat: createElement * chore: swc helpers * chore: swc-helpers --- packages/jsx-runtime/package.json | 3 ++- packages/jsx-runtime/src/createElement.ts | 5 +++++ packages/jsx-runtime/src/index.ts | 1 + pnpm-lock.yaml | 21 +++++++++++++++------ 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 packages/jsx-runtime/src/createElement.ts diff --git a/packages/jsx-runtime/package.json b/packages/jsx-runtime/package.json index 45cd547e3b..33807b5f70 100644 --- a/packages/jsx-runtime/package.json +++ b/packages/jsx-runtime/package.json @@ -34,7 +34,8 @@ "jsx-runtime" ], "dependencies": { - "style-unit": "^3.0.4" + "style-unit": "^3.0.4", + "@swc/helpers": "^0.5.13" }, "devDependencies": { "@ice/pkg": "^1.5.0", diff --git a/packages/jsx-runtime/src/createElement.ts b/packages/jsx-runtime/src/createElement.ts new file mode 100644 index 0000000000..c3c36a56c9 --- /dev/null +++ b/packages/jsx-runtime/src/createElement.ts @@ -0,0 +1,5 @@ +import { createElement as reactCreateElement } from 'react'; +import { hijackElementProps } from './style.js'; +export function createElement(type: any, props: any, ...children: any[]) { + return reactCreateElement(type, hijackElementProps(props), ...children); +} diff --git a/packages/jsx-runtime/src/index.ts b/packages/jsx-runtime/src/index.ts index ef3801e929..7f3a8be528 100644 --- a/packages/jsx-runtime/src/index.ts +++ b/packages/jsx-runtime/src/index.ts @@ -1 +1,2 @@ export * from './prod.js'; +export { createElement } from './createElement.js'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 303b44a454..bacf9a3dc2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1813,6 +1813,9 @@ importers: packages/jsx-runtime: dependencies: + '@swc/helpers': + specifier: ^0.5.13 + version: 0.5.13 style-unit: specifier: ^3.0.4 version: 3.0.5 @@ -8569,6 +8572,12 @@ packages: dependencies: tslib: 2.5.0 + /@swc/helpers@0.5.13: + resolution: {integrity: sha512-UoKGxQ3r5kYI9dALKJapMmuK+1zWM/H17Z1+iwnNmzcJRnfFuevZs375TA5rW31pu4BS4NoSy1fRsexDXfWn5w==} + dependencies: + tslib: 2.5.0 + dev: false + /@swc/types@0.1.4: resolution: {integrity: sha512-z/G02d+59gyyUb7KYhKi9jOhicek6QD2oMaotUyG+lUkybpXoV49dY9bj7Ah5Q+y7knK2jU67UTX9FyfGzaxQg==} @@ -22045,6 +22054,7 @@ packages: serialize-javascript: 6.0.1 terser: 5.16.5 webpack: 5.88.2(@swc/core@1.3.80)(esbuild@0.17.16) + dev: true /terser-webpack-plugin@5.3.7(esbuild@0.17.16)(webpack@5.86.0): resolution: {integrity: sha512-AfKwIktyP7Cu50xNjXF/6Qb5lBNzYaWpU6YfoX3uZicTx0zTy0stDDCsvjDapKsSDvOeWo5MEq4TmdBy2cNoHw==} @@ -22094,7 +22104,6 @@ packages: serialize-javascript: 6.0.1 terser: 5.16.5 webpack: 5.88.2(esbuild@0.17.16) - dev: true /terser-webpack-plugin@5.3.7(webpack@5.88.2): resolution: {integrity: sha512-AfKwIktyP7Cu50xNjXF/6Qb5lBNzYaWpU6YfoX3uZicTx0zTy0stDDCsvjDapKsSDvOeWo5MEq4TmdBy2cNoHw==} @@ -23299,7 +23308,7 @@ packages: mime-types: 2.1.35 range-parser: 1.2.1 schema-utils: 4.0.0 - webpack: 5.88.2(@swc/core@1.3.80)(esbuild@0.17.16) + webpack: 5.88.2(esbuild@0.17.16) /webpack-dev-middleware@6.0.2(webpack@5.88.2): resolution: {integrity: sha512-iOddiJzPcQC6lwOIu60vscbGWth8PCRcWRCwoQcTQf9RMoOWBHg5EyzpGdtSmGMrSPd5vHEfFXmVErQEmkRngQ==} @@ -23315,7 +23324,7 @@ packages: mime-types: 2.1.35 range-parser: 1.2.1 schema-utils: 4.0.0 - webpack: 5.88.2(@swc/core@1.3.80)(esbuild@0.17.16) + webpack: 5.88.2(esbuild@0.17.16) dev: true /webpack-dev-server@4.13.1(webpack@5.88.2): @@ -23359,7 +23368,7 @@ packages: serve-index: 1.9.1 sockjs: 0.3.24 spdy: 4.0.2 - webpack: 5.88.2(@swc/core@1.3.80)(esbuild@0.17.16) + webpack: 5.88.2(esbuild@0.17.16) webpack-dev-middleware: 5.3.4(webpack@5.88.2) ws: 8.13.0 transitivePeerDependencies: @@ -23512,7 +23521,7 @@ packages: serve-index: 1.9.1 sockjs: 0.3.24 spdy: 4.0.2 - webpack: 5.88.2(@swc/core@1.3.80)(esbuild@0.17.16) + webpack: 5.88.2(esbuild@0.17.16) webpack-dev-middleware: 5.3.4(webpack@5.88.2) ws: 8.13.0 transitivePeerDependencies: @@ -23661,6 +23670,7 @@ packages: - '@swc/core' - esbuild - uglify-js + dev: true /webpack@5.88.2(esbuild@0.17.16): resolution: {integrity: sha512-JmcgNZ1iKj+aiR0OvTYtWQqJwq37Pf683dY9bVORwVbUrDhLhdn/PlO2sHsFHPkj7sHNQF3JwaAkp49V+Sq1tQ==} @@ -23700,7 +23710,6 @@ packages: - '@swc/core' - esbuild - uglify-js - dev: true /webpackbar@5.0.2(webpack@5.88.2): resolution: {integrity: sha512-BmFJo7veBDgQzfWXl/wwYXr/VFus0614qZ8i9znqcl9fnEdiVkdbi0TedLQ6xAK92HZHDJ0QmyQ0fmuZPAgCYQ==}