@@ -5,14 +5,15 @@ import {
5
5
replaceSourceRange ,
6
6
} from 'ts-macro'
7
7
import { analyze } from '@typescript-eslint/scope-manager'
8
- // @ts -ignore
9
8
import { walk } from 'estree-walker'
10
- import { type IdentifierName , type Node , parseSync } from 'oxc-parser'
11
9
import {
12
10
collectRefs ,
11
+ getOxcParser ,
13
12
getReferences ,
13
+ getRequire ,
14
14
transformFunctionReturn ,
15
15
} from './core/utils'
16
+ import type { IdentifierName , Node } from 'oxc-parser'
16
17
17
18
const HELPER_PREFIX = '__MACROS_'
18
19
@@ -28,7 +29,7 @@ const plugin = createPlugin<{ ignore?: string[] } | undefined>(
28
29
const ignore = ( options ?. ignore || [ ] ) . map ( ( str ) => str . slice ( 1 ) )
29
30
return {
30
31
name : 'vue-reactivity-function' ,
31
- resolveVirtualCode ( { filePath , ast, source, codes } ) {
32
+ resolveVirtualCode ( { ast, source, codes } ) {
32
33
if ( ! ast . text . includes ( '$' ) ) return
33
34
try {
34
35
transformReactivityFunction ( {
@@ -45,6 +46,16 @@ const plugin = createPlugin<{ ignore?: string[] } | undefined>(
45
46
46
47
export default plugin
47
48
49
+ let parseSync : typeof import ( 'oxc-parser' ) . parseSync
50
+ if ( __BROWSER__ ) {
51
+ parseSync = await getOxcParser ( )
52
+ } else {
53
+ const require = getRequire ( )
54
+ if ( require ) {
55
+ parseSync = require ( 'oxc-parser' ) . parseSync
56
+ }
57
+ }
58
+
48
59
function transformReactivityFunction ( options : {
49
60
codes : Code [ ]
50
61
source ?: string
@@ -58,14 +69,14 @@ function transformReactivityFunction(options: {
58
69
const unrefs : IdentifierName [ ] = [ ]
59
70
const refs : Node [ ] = [ ]
60
71
let index = 0
61
- walk ( program , {
62
- leave ( node : Node , parent : Node ) {
72
+ walk < Node > ( program , {
73
+ leave ( node , parent ) {
63
74
// @ts -ignore
64
75
node . parent = parent
65
76
// @ts -ignore
66
77
node . range = [ node . start , node . end ]
67
78
} ,
68
- enter ( node : Node , parent : Node ) {
79
+ enter ( node , parent ) {
69
80
if ( node . type === 'TSNonNullExpression' ) {
70
81
node = node . expression
71
82
}
0 commit comments