@@ -5,14 +5,15 @@ import {
55 replaceSourceRange ,
66} from 'ts-macro'
77import { analyze } from '@typescript-eslint/scope-manager'
8- // @ts -ignore
98import { walk } from 'estree-walker'
10- import { type IdentifierName , type Node , parseSync } from 'oxc-parser'
119import {
1210 collectRefs ,
11+ getOxcParser ,
1312 getReferences ,
13+ getRequire ,
1414 transformFunctionReturn ,
1515} from './core/utils'
16+ import type { IdentifierName , Node } from 'oxc-parser'
1617
1718const HELPER_PREFIX = '__MACROS_'
1819
@@ -28,7 +29,7 @@ const plugin = createPlugin<{ ignore?: string[] } | undefined>(
2829 const ignore = ( options ?. ignore || [ ] ) . map ( ( str ) => str . slice ( 1 ) )
2930 return {
3031 name : 'vue-reactivity-function' ,
31- resolveVirtualCode ( { filePath , ast, source, codes } ) {
32+ resolveVirtualCode ( { ast, source, codes } ) {
3233 if ( ! ast . text . includes ( '$' ) ) return
3334 try {
3435 transformReactivityFunction ( {
@@ -45,6 +46,16 @@ const plugin = createPlugin<{ ignore?: string[] } | undefined>(
4546
4647export default plugin
4748
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+
4859function transformReactivityFunction ( options : {
4960 codes : Code [ ]
5061 source ?: string
@@ -58,14 +69,14 @@ function transformReactivityFunction(options: {
5869 const unrefs : IdentifierName [ ] = [ ]
5970 const refs : Node [ ] = [ ]
6071 let index = 0
61- walk ( program , {
62- leave ( node : Node , parent : Node ) {
72+ walk < Node > ( program , {
73+ leave ( node , parent ) {
6374 // @ts -ignore
6475 node . parent = parent
6576 // @ts -ignore
6677 node . range = [ node . start , node . end ]
6778 } ,
68- enter ( node : Node , parent : Node ) {
79+ enter ( node , parent ) {
6980 if ( node . type === 'TSNonNullExpression' ) {
7081 node = node . expression
7182 }
0 commit comments