@@ -29,6 +29,8 @@ export function transform(source, opts) {
29
29
30
30
const srcAst = parse ( source ) ;
31
31
32
+ // TBD: add import() ?
33
+
32
34
const names = 'Infinity,undefined,NaN,isFinite,isNaN,' +
33
35
'parseFloat,parseInt,decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
34
36
'Math,Number,Date,Array,Object,Boolean,String,RegExp,Map,Set,JSON,Intl,' +
@@ -87,7 +89,7 @@ export function transform(source, opts) {
87
89
! hash [ identifier . node . name ] &&
88
90
89
91
// not already in scope
90
- ! identifier . scope . hasBinding ( identifier . node . name )
92
+ ! identifier . scope . hasBinding ( identifier . node . name , false /* noGlobals */ ) // noGlobals false mean include globals (Array, Date, ...) and contextVariables (arguments, ... )
91
93
92
94
) {
93
95
@@ -96,6 +98,7 @@ export function transform(source, opts) {
96
98
}
97
99
98
100
101
+ // TBD: check https://github.com/yyx990803/buble/commit/af5d322e6925d65ee6cc7fcaadbe25a4151bfcdd
99
102
100
103
const withStatementVisitor = {
101
104
Identifier ( path ) {
@@ -107,21 +110,37 @@ export function transform(source, opts) {
107
110
// then use:
108
111
path . node . name = '_vm.' + path . node . name ;
109
112
}
110
- }
113
+ } ,
114
+ WithStatement ( path ) {
115
+
116
+ // let handle this by the parent traverse
117
+ path . skip ( ) ;
118
+ } ,
111
119
} ;
112
120
113
121
traverse ( srcAst , {
114
122
115
123
// babel withstatement https://babeljs.io/docs/en/babel-types#withstatement
116
124
// see yyx990803/buble WithStatement.js : https://github.com/yyx990803/buble/blob/master/src/program/types/WithStatement.js
117
125
118
- WithStatement ( path ) {
126
+ WithStatement : {
127
+ enter ( path ) {
128
+
129
+ path . traverse ( withStatementVisitor ) ;
130
+ } ,
131
+ exit ( path ) {
119
132
120
- path . traverse ( withStatementVisitor ) ;
133
+ const parentWithStatement = path . findParent ( e => e . isWithStatement ( ) ) ;
134
+ if ( parentWithStatement === null ) {
121
135
122
- const left = parse ( 'var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h' ) ;
123
- path . replaceWithMultiple ( [ ...left . program . body , ...path . node . body . body ] ) ;
136
+ const left = parse ( 'var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h' ) ;
137
+ path . replaceWithMultiple ( [ ...left . program . body , ...path . node . body . body ] ) ;
138
+ } else {
124
139
140
+ // just remove with statement
141
+ path . replaceWithMultiple ( path . node . body . body ) ;
142
+ }
143
+ }
125
144
}
126
145
127
146
} ) ;
0 commit comments