From 393d8f143f78be66e15bbee86e39e3d94ce2258c Mon Sep 17 00:00:00 2001 From: zengyue ye Date: Wed, 23 Mar 2022 10:49:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20@jsxImportSource=20=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=E4=B8=8D=E6=8A=A5=E9=94=99=20(#1409)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc.js | 1 + jest.config.js | 2 +- packages/f2/jsx-dev-runtime.d.ts | 1 + packages/f2/jsx-dev-runtime.js | 2 ++ packages/f2/jsx-runtime.d.ts | 1 + packages/f2/src/jsx/jsx-automatic.ts | 4 +-- packages/f2/src/jsx/jsx-classic.d.ts | 15 -------- packages/f2/src/jsx/jsx-classic.js | 17 --------- packages/f2/src/jsx/jsx-classic.ts | 28 +++++++++++++++ packages/f2/src/jsx/jsx-namespace.d.ts | 47 ++++++++++++++++++++++++ packages/f2/src/jsx/jsx-runtime.ts | 2 +- packages/f2/src/jsx/types.d.ts | 49 +++----------------------- tsconfig.json | 3 +- 13 files changed, 90 insertions(+), 82 deletions(-) create mode 100644 packages/f2/jsx-dev-runtime.d.ts create mode 100644 packages/f2/jsx-dev-runtime.js delete mode 100644 packages/f2/src/jsx/jsx-classic.d.ts delete mode 100644 packages/f2/src/jsx/jsx-classic.js create mode 100644 packages/f2/src/jsx/jsx-classic.ts create mode 100644 packages/f2/src/jsx/jsx-namespace.d.ts diff --git a/.eslintrc.js b/.eslintrc.js index 50391a0e8..e0b103e89 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -27,6 +27,7 @@ module.exports = { 'no-case-declarations': 0, '@typescript-eslint/explicit-module-boundary-types': 0, '@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }], + '@typescript-eslint/no-namespace': 0, }, settings: { 'import/parsers': { diff --git a/jest.config.js b/jest.config.js index f0cf4a862..2d640bec1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,7 +1,7 @@ module.exports = { runner: 'jest-electron/runner', testEnvironment: 'jest-electron/environment', - preset: 'ts-jest/presets/js-with-ts', + preset: 'ts-jest', collectCoverage: false, collectCoverageFrom: ['packages/*/src/**/*.{ts,tsx,js}', '!**/node_modules/**'], modulePathIgnorePatterns: ['packages/*/dist'], diff --git a/packages/f2/jsx-dev-runtime.d.ts b/packages/f2/jsx-dev-runtime.d.ts new file mode 100644 index 000000000..8789aa8d6 --- /dev/null +++ b/packages/f2/jsx-dev-runtime.d.ts @@ -0,0 +1 @@ +export * from './jsx-runtime'; diff --git a/packages/f2/jsx-dev-runtime.js b/packages/f2/jsx-dev-runtime.js new file mode 100644 index 000000000..19d28ba21 --- /dev/null +++ b/packages/f2/jsx-dev-runtime.js @@ -0,0 +1,2 @@ +'use strict'; +module.exports = require('./jsx-runtime'); diff --git a/packages/f2/jsx-runtime.d.ts b/packages/f2/jsx-runtime.d.ts index 95d0043b2..6b106a6ef 100644 --- a/packages/f2/jsx-runtime.d.ts +++ b/packages/f2/jsx-runtime.d.ts @@ -1 +1,2 @@ export * from './es/jsx/jsx-runtime'; +export { JSX } from './es/jsx/jsx-namespace'; diff --git a/packages/f2/src/jsx/jsx-automatic.ts b/packages/f2/src/jsx/jsx-automatic.ts index 0751f4ee1..d6b374ea3 100644 --- a/packages/f2/src/jsx/jsx-automatic.ts +++ b/packages/f2/src/jsx/jsx-automatic.ts @@ -1,8 +1,8 @@ -import JSX from './types'; +import { JSX as JSXNamespace } from './jsx-namespace'; import { ElementType } from '../types'; // 实现jsx-automatic 入口 -export function jsx(type: ElementType, config, key?: string): JSX.Element { +export function jsx(type: ElementType, config, key?: string): JSXNamespace.Element { const { ref, ...props } = config || {}; return { key, diff --git a/packages/f2/src/jsx/jsx-classic.d.ts b/packages/f2/src/jsx/jsx-classic.d.ts deleted file mode 100644 index a34b0ce92..000000000 --- a/packages/f2/src/jsx/jsx-classic.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -/** - * ref: https://github.com/microsoft/TypeScript/pull/22207 - */ - -import GlobalJSX from './types'; - -export namespace jsx { - export namespace JSX { - export type Element = GlobalJSX.Element; - export type ElementClass = GlobalJSX.ElementClass; - export type IntrinsicElements = GlobalJSX.IntrinsicElements; - } -} - -export function jsx(): jsx.JSX.Element; diff --git a/packages/f2/src/jsx/jsx-classic.js b/packages/f2/src/jsx/jsx-classic.js deleted file mode 100644 index 911f42914..000000000 --- a/packages/f2/src/jsx/jsx-classic.js +++ /dev/null @@ -1,17 +0,0 @@ -// 实现jsx-classic 入口 -export function jsx(type, config, ...children) { - const { key, ref, ...props } = config || {}; - - // 保持和automatic模式一致 - if (children.length) { - props.children = children.length === 1 ? children[0] : children; - } - return { - key, - ref, - type, - props, - // 存储一些过程中的cache值 - _cache: {}, - }; -} diff --git a/packages/f2/src/jsx/jsx-classic.ts b/packages/f2/src/jsx/jsx-classic.ts new file mode 100644 index 000000000..9e9057705 --- /dev/null +++ b/packages/f2/src/jsx/jsx-classic.ts @@ -0,0 +1,28 @@ +import { JSX as JSXNamespace } from './jsx-namespace'; +import { ElementType } from '../types'; + +export namespace jsx { + export namespace JSX { + export type Element = JSXNamespace.Element; + export type ElementClass = JSXNamespace.ElementClass; + export type IntrinsicElements = JSXNamespace.IntrinsicElements; + } +} + +// 实现jsx-classic 入口 +export function jsx(type: ElementType, config, ...children): JSXNamespace.Element { + const { key, ref, ...props } = config || {}; + + // 保持和automatic模式一致 + if (children.length) { + props.children = children.length === 1 ? children[0] : children; + } + return { + key, + ref, + type, + props, + // 存储一些过程中的cache值 + _cache: {}, + }; +} diff --git a/packages/f2/src/jsx/jsx-namespace.d.ts b/packages/f2/src/jsx/jsx-namespace.d.ts new file mode 100644 index 000000000..cc74ffe46 --- /dev/null +++ b/packages/f2/src/jsx/jsx-namespace.d.ts @@ -0,0 +1,47 @@ +import { + Ref, + ElementType, + Props, + RectProps, + CircleProps, + LineProps, + PolygonProps, + PolylineProps, + ArcProps, + SectorProps, + TextProps, + CustomProps, + MarkerProps, + ImageProps, +} from '../types'; + +export namespace JSX { + export interface Element { + key: string; + ref?: Ref; + type: ElementType; + props: Props; + [key: string]: any; + } + + export interface ElementClass { + refs: {}; + props: Props; + render(): Element | null; + } + + export interface IntrinsicElements { + group: RectProps; + rect: RectProps; + circle: CircleProps; + line: LineProps; + polygon: PolygonProps; + polyline: PolylineProps; + arc: ArcProps; + sector: SectorProps; + text: TextProps; + custom: CustomProps; + marker: MarkerProps; + image: ImageProps; + } +} diff --git a/packages/f2/src/jsx/jsx-runtime.ts b/packages/f2/src/jsx/jsx-runtime.ts index e75cc49d2..fc448134c 100644 --- a/packages/f2/src/jsx/jsx-runtime.ts +++ b/packages/f2/src/jsx/jsx-runtime.ts @@ -1,4 +1,4 @@ import { jsx } from './jsx-automatic'; import Fragment from './fragment'; -export { Fragment, jsx, jsx as jsxs }; +export { Fragment, jsx, jsx as jsxs, jsx as jsxDEV }; diff --git a/packages/f2/src/jsx/types.d.ts b/packages/f2/src/jsx/types.d.ts index 4e79c0865..30e83e481 100644 --- a/packages/f2/src/jsx/types.d.ts +++ b/packages/f2/src/jsx/types.d.ts @@ -1,50 +1,11 @@ -import { - Ref, - ElementType, - Props, - RectProps, - CircleProps, - LineProps, - PolygonProps, - PolylineProps, - ArcProps, - SectorProps, - TextProps, - CustomProps, - MarkerProps, - ImageProps, -} from '../types'; +import { JSX as JSXNamespace } from './jsx-namespace'; +// 全局 declare global { namespace JSX { - interface Element { - key: string; - ref?: Ref; - type: ElementType; - props: Props; - // children: Element; - _cache?: any; - [key: string]: any; - } - interface ElementClass { - refs: {}; - props: Props; - render(): Element | null; - } - interface IntrinsicElements { - group: RectProps; - rect: RectProps; - circle: CircleProps; - line: LineProps; - polygon: PolygonProps; - polyline: PolylineProps; - arc: ArcProps; - sector: SectorProps; - text: TextProps; - custom: CustomProps; - marker: MarkerProps; - image: ImageProps; - } + export type Element = JSXNamespace.Element; + export type ElementClass = JSXNamespace.ElementClass; + export type IntrinsicElements = JSXNamespace.IntrinsicElements; } } diff --git a/tsconfig.json b/tsconfig.json index d0599b1fc..50ebc9b07 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,8 +9,7 @@ "moduleResolution": "node", "useDefineForClassFields": false, "resolveJsonModule": true, - "skipLibCheck": true, - "allowJs": true + "skipLibCheck": true }, "exclude": [ "scripts",