@@ -30,8 +30,9 @@ import {
30
30
KEEP_ALIVE ,
31
31
BASE_TRANSITION
32
32
} from './runtimeHelpers'
33
- import { isString , isFunction , isObject , hyphenate } from '@vue/shared'
33
+ import { isString , isObject , hyphenate } from '@vue/shared'
34
34
import { parse } from '@babel/parser'
35
+ import { walk } from 'estree-walker'
35
36
import { Node } from '@babel/types'
36
37
37
38
export const isBuiltInType = ( tag : string , expected : string ) : boolean =>
@@ -49,31 +50,16 @@ export function isCoreComponent(tag: string): symbol | void {
49
50
}
50
51
}
51
52
52
- // cache node requires
53
- // lazy require dependencies so that they don't end up in rollup's dep graph
54
- // and thus can be tree-shaken in browser builds.
55
- let _parse : typeof parse
56
- let _walk : any
57
-
58
- export function loadDep ( name : string ) {
59
- if ( ! __BROWSER__ && typeof process !== 'undefined' && isFunction ( require ) ) {
60
- return require ( name )
61
- } else {
62
- // This is only used when we are building a dev-only build of the compiler
63
- // which runs in the browser but also uses Node deps.
64
- return ( window as any ) . _deps [ name ]
65
- }
66
- }
67
-
68
53
export const parseJS : typeof parse = ( code , options ) => {
69
- assert (
70
- ! __BROWSER__ ,
71
- `Expression AST analysis can only be performed in non-browser builds.`
72
- )
73
- if ( ! _parse ) {
74
- _parse = loadDep ( '@babel/parser' ) . parse
54
+ if ( __BROWSER__ ) {
55
+ assert (
56
+ ! __BROWSER__ ,
57
+ `Expression AST analysis can only be performed in non-browser builds.`
58
+ )
59
+ return null as any
60
+ } else {
61
+ return parse ( code , options )
75
62
}
76
- return _parse ( code , options )
77
63
}
78
64
79
65
interface Walker {
@@ -82,12 +68,15 @@ interface Walker {
82
68
}
83
69
84
70
export const walkJS = ( ast : Node , walker : Walker ) => {
85
- assert (
86
- ! __BROWSER__ ,
87
- `Expression AST analysis can only be performed in non-browser builds.`
88
- )
89
- const walk = _walk || ( _walk = loadDep ( 'estree-walker' ) . walk )
90
- return walk ( ast , walker )
71
+ if ( __BROWSER__ ) {
72
+ assert (
73
+ ! __BROWSER__ ,
74
+ `Expression AST analysis can only be performed in non-browser builds.`
75
+ )
76
+ return null as any
77
+ } else {
78
+ return ( walk as any ) ( ast , walker )
79
+ }
91
80
}
92
81
93
82
const nonIdentifierRE = / ^ \d | [ ^ \$ \w ] /
0 commit comments