Skip to content

Commit

Permalink
fix: @jsxImportSource 模式不报错 (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Mar 23, 2022
1 parent a6e1276 commit 393d8f1
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 82 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -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'],
Expand Down
1 change: 1 addition & 0 deletions packages/f2/jsx-dev-runtime.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './jsx-runtime';
2 changes: 2 additions & 0 deletions packages/f2/jsx-dev-runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
module.exports = require('./jsx-runtime');
1 change: 1 addition & 0 deletions packages/f2/jsx-runtime.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './es/jsx/jsx-runtime';
export { JSX } from './es/jsx/jsx-namespace';
4 changes: 2 additions & 2 deletions packages/f2/src/jsx/jsx-automatic.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
15 changes: 0 additions & 15 deletions packages/f2/src/jsx/jsx-classic.d.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/f2/src/jsx/jsx-classic.js

This file was deleted.

28 changes: 28 additions & 0 deletions packages/f2/src/jsx/jsx-classic.ts
Original file line number Diff line number Diff line change
@@ -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: {},
};
}
47 changes: 47 additions & 0 deletions packages/f2/src/jsx/jsx-namespace.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 1 addition & 1 deletion packages/f2/src/jsx/jsx-runtime.ts
Original file line number Diff line number Diff line change
@@ -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 };
49 changes: 5 additions & 44 deletions packages/f2/src/jsx/types.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"moduleResolution": "node",
"useDefineForClassFields": false,
"resolveJsonModule": true,
"skipLibCheck": true,
"allowJs": true
"skipLibCheck": true
},
"exclude": [
"scripts",
Expand Down

0 comments on commit 393d8f1

Please sign in to comment.