Skip to content

Commit 768fb3e

Browse files
committed
refactor: improve types
1 parent 86ba932 commit 768fb3e

6 files changed

Lines changed: 18 additions & 16 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"test": "vitest",
77
"lint": "eslint --cache .",
88
"format": "prettier --write .",
9-
"typecheck": "tsc --noEmit",
9+
"typecheck": "tsc",
1010
"release": "bumpp -r"
1111
},
1212
"license": "MIT",

packages/babel-plugin-jsx/index.html

Lines changed: 0 additions & 2 deletions
This file was deleted.

packages/babel-plugin-jsx/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ const hasJSX = (parentPath: NodePath<t.Program>) => {
3131

3232
const JSX_ANNOTATION_REGEX = /\*?\s*@jsx\s+([^\s]+)/;
3333

34-
export default ({ types }: typeof BabelCore) => ({
34+
export default ({ types }: typeof BabelCore): BabelCore.PluginObj<State> => ({
3535
name: 'babel-plugin-jsx',
3636
inherits: syntaxJsx,
3737
visitor: {
3838
...transformVueJSX,
3939
...sugarFragment,
4040
Program: {
41-
enter(path: NodePath<t.Program>, state: State) {
41+
enter(path, state) {
4242
if (hasJSX(path)) {
4343
const importNames = [
4444
'createVNode',
@@ -168,7 +168,7 @@ export default ({ types }: typeof BabelCore) => ({
168168
}
169169
}
170170
},
171-
exit(path: NodePath<t.Program>) {
171+
exit(path) {
172172
const body = path.get('body') as NodePath[];
173173
const specifiersMap = new Map<string, t.ImportSpecifier>();
174174

packages/babel-plugin-jsx/src/sugar-fragment.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as t from '@babel/types';
2-
import { type NodePath } from '@babel/traverse';
2+
import { type NodePath, type Visitor } from '@babel/traverse';
33
import type { State } from './interface';
44
import { FRAGMENT, createIdentifier } from './utils';
55

66
const transformFragment = (
7-
path: NodePath<t.JSXElement>,
7+
path: NodePath<t.JSXFragment>,
88
Fragment: t.JSXIdentifier | t.JSXMemberExpression
99
) => {
1010
const children = path.get('children') || [];
@@ -16,9 +16,9 @@ const transformFragment = (
1616
);
1717
};
1818

19-
export default {
19+
const visitor: Visitor<State> = {
2020
JSXFragment: {
21-
enter(path: NodePath<t.JSXElement>, state: State) {
21+
enter(path, state) {
2222
const fragmentCallee = createIdentifier(state, FRAGMENT);
2323
path.replaceWith(
2424
transformFragment(
@@ -34,3 +34,5 @@ export default {
3434
},
3535
},
3636
};
37+
38+
export default visitor;

packages/babel-plugin-jsx/src/transform-vue-jsx.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as t from '@babel/types';
2-
import { type NodePath } from '@babel/traverse';
2+
import { type NodePath, type Visitor } from '@babel/traverse';
33
// @ts-expect-error
44
import { addDefault } from '@babel/helper-module-imports';
55
import {
@@ -559,10 +559,12 @@ const transformJSXElement = (
559559
]);
560560
};
561561

562-
export default {
562+
const visitor: Visitor<State> = {
563563
JSXElement: {
564-
exit(path: NodePath<t.JSXElement>, state: State) {
564+
exit(path, state) {
565565
path.replaceWith(transformJSXElement(path, state));
566566
},
567567
},
568568
};
569+
570+
export default visitor;

tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"compilerOptions": {
3-
"sourceMap": true,
43
"target": "ESNext",
54
"module": "ESNext",
65
"lib": ["ES2015", "DOM", "DOM.Iterable"],
@@ -10,13 +9,14 @@
109
"noUnusedLocals": true,
1110
"resolveJsonModule": true,
1211
"esModuleInterop": true,
13-
"removeComments": false,
1412
"jsx": "preserve",
1513
"types": ["vitest/globals"],
1614
"skipLibCheck": true,
1715
"paths": {
1816
"@vue/babel-plugin-jsx": ["./packages/babel-plugin-jsx/src"]
19-
}
17+
},
18+
"noEmit": true,
19+
"incremental": true
2020
},
2121
"include": ["packages/*/src", "packages/*/test"]
2222
}

0 commit comments

Comments
 (0)