Skip to content

Commit bff7115

Browse files
committed
fix: use typescript-eslint instead of babel
1 parent 95afe2b commit bff7115

File tree

13 files changed

+1001
-577
lines changed

13 files changed

+1001
-577
lines changed

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export default sxzz({
44
rules: {
55
'unused-imports/no-unused-vars': 'off',
66
'unused-imports/no-unused-imports': 'off',
7+
'import/no-default-export': 'off',
78
},
89
})

package.json

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,26 @@
5252
"require": "./dist/volar.cjs",
5353
"import": "./dist/volar.js"
5454
},
55+
"./raw": {
56+
"require": "./dist/raw.cjs",
57+
"import": "./dist/raw.js"
58+
},
59+
"./rolldown": {
60+
"require": "./dist/rolldown.cjs",
61+
"import": "./dist/rolldown.js"
62+
},
63+
"./rspack": {
64+
"require": "./dist/rspack.cjs",
65+
"import": "./dist/rspack.js"
66+
},
67+
"./nuxt": {
68+
"require": "./dist/nuxt.cjs",
69+
"import": "./dist/nuxt.js"
70+
},
71+
"./astro": {
72+
"require": "./dist/astro.cjs",
73+
"import": "./dist/astro.js"
74+
},
5575
"./*": "./*"
5676
},
5777
"typesVersions": {
@@ -76,9 +96,9 @@
7696
"prepublishOnly": "pnpm run build"
7797
},
7898
"dependencies": {
79-
"@babel/parser": "^7.27.0",
80-
"@babel/plugin-transform-typescript": "^7.27.0",
81-
"@babel/traverse": "^7.27.0",
99+
"@nuxt/kit": "^3.16.2",
100+
"@typescript-eslint/scope-manager": "^8.30.1",
101+
"@typescript-eslint/typescript-estree": "^8.30.1",
82102
"@vue-macros/common": "3.0.0-beta.8",
83103
"ts-macro": "^0.1.25",
84104
"unplugin": "^2.3.2"
@@ -89,6 +109,7 @@
89109
"@sxzz/prettier-config": "^2.0.2",
90110
"@types/babel__traverse": "^7.20.7",
91111
"@types/node": "^20.14.11",
112+
"@typescript-eslint/types": "^8.30.1",
92113
"@vue-macros/reactivity-transform": "^0.4.6",
93114
"@vue-macros/test-utils": "^1.4.0",
94115
"bumpp": "^9.4.1",

pnpm-lock.yaml

Lines changed: 368 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/astro.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import unplugin from '.'
2+
import type { Options } from './core/options'
3+
4+
export default (options: Options) => ({
5+
name: 'unplugin-vue-reactivity-function',
6+
hooks: {
7+
'astro:config:setup': (astro: any) => {
8+
astro.config.vite.plugins ||= []
9+
astro.config.vite.plugins.push(unplugin.vite(options))
10+
},
11+
},
12+
})

src/core/utils.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import type { Reference, Scope } from '@typescript-eslint/scope-manager'
2+
import type { TSESTree } from '@typescript-eslint/typescript-estree'
3+
4+
export function getReferences(
5+
scope: Scope,
6+
id: TSESTree.Identifier,
7+
): Reference[] {
8+
return scope.childScopes.reduce(
9+
(acc, scope) => (acc.push(...getReferences(scope, id)), acc),
10+
scope.references.filter(
11+
(ref) => ref.identifier !== id && ref.resolved?.identifiers.includes(id),
12+
),
13+
)
14+
}
15+
16+
export function getMemberExpression(node: TSESTree.Node) {
17+
if (!node.parent) return node
18+
if (
19+
node.parent.type === 'MemberExpression' ||
20+
node.parent.type === 'ChainExpression' ||
21+
(node.parent.type === 'CallExpression' && node.parent?.callee === node)
22+
) {
23+
return getMemberExpression(node.parent)
24+
}
25+
return node
26+
}
27+
28+
export function transformArguments(
29+
argument: TSESTree.Node,
30+
refs: TSESTree.Node[],
31+
) {
32+
if (
33+
[
34+
'Identifier',
35+
'CallExpression',
36+
'MemberExpression',
37+
'ChainExpression',
38+
'TSInstantiationExpression',
39+
].includes(argument.type)
40+
) {
41+
refs.push(argument)
42+
} else if (
43+
argument.type === 'FunctionExpression' ||
44+
argument.type === 'ArrowFunctionExpression'
45+
) {
46+
transformFunctionReturn(argument, refs)
47+
} else if (argument.type === 'ArrayExpression') {
48+
argument.elements.forEach((arg) => {
49+
transformArguments(arg!, refs)
50+
})
51+
} else if (argument.type === 'ObjectExpression') {
52+
argument.properties.forEach((prop) => {
53+
if (prop.type === 'Property') {
54+
transformArguments(prop.value, refs)
55+
}
56+
})
57+
}
58+
}
59+
60+
export function transformFunctionReturn(
61+
node: TSESTree.Node,
62+
refs: TSESTree.Node[],
63+
) {
64+
if (
65+
node.type === 'FunctionDeclaration' ||
66+
node.type === 'FunctionExpression' ||
67+
node.type === 'ArrowFunctionExpression'
68+
) {
69+
if (node.body.type !== 'BlockStatement') {
70+
transformArguments(node.body, refs)
71+
} else {
72+
node.body.body?.forEach((statement) => {
73+
if (statement.type === 'ReturnStatement' && statement.argument) {
74+
transformArguments(statement.argument, refs)
75+
}
76+
})
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)