@@ -170,6 +170,62 @@ describe('VariableDeclarators', function() {
170
170
171
171
expect ( identifiers . length ) . toBe ( 1 ) ;
172
172
} ) ;
173
+
174
+ describe ( 'parsing with bablylon' , function ( ) {
175
+ it ( 'does not rename object property' , function ( ) {
176
+ nodes = [
177
+ recast . parse ( 'var foo = 42; var obj = { foo: null };' , {
178
+ parser : getParser ( 'babylon' ) ,
179
+ } ) . program
180
+ ] ;
181
+ Collection
182
+ . fromNodes ( nodes )
183
+ . findVariableDeclarators ( 'foo' ) . renameTo ( 'newFoo' ) ;
184
+
185
+ expect (
186
+ Collection . fromNodes ( nodes ) . find ( types . Identifier , { name : 'newFoo' } ) . length
187
+ ) . toBe ( 1 ) ;
188
+ expect (
189
+ Collection . fromNodes ( nodes ) . find ( types . Identifier , { name : 'foo' } ) . length
190
+ ) . toBe ( 1 ) ;
191
+ } )
192
+
193
+ it ( 'does not rename object method' , function ( ) {
194
+ nodes = [
195
+ recast . parse ( 'var foo = 42; var obj = { foo() {} };' , {
196
+ parser : getParser ( 'babylon' ) ,
197
+ } ) . program
198
+ ] ;
199
+ Collection
200
+ . fromNodes ( nodes )
201
+ . findVariableDeclarators ( 'foo' ) . renameTo ( 'newFoo' ) ;
202
+
203
+ expect (
204
+ Collection . fromNodes ( nodes ) . find ( types . Identifier , { name : 'newFoo' } ) . length
205
+ ) . toBe ( 1 ) ;
206
+ expect (
207
+ Collection . fromNodes ( nodes ) . find ( types . Identifier , { name : 'foo' } ) . length
208
+ ) . toBe ( 1 ) ;
209
+ } )
210
+
211
+ it ( 'does not rename class method' , function ( ) {
212
+ nodes = [
213
+ recast . parse ( 'var foo = 42; class A { foo() {} }' , {
214
+ parser : getParser ( 'babylon' ) ,
215
+ } ) . program
216
+ ] ;
217
+ Collection
218
+ . fromNodes ( nodes )
219
+ . findVariableDeclarators ( 'foo' ) . renameTo ( 'newFoo' ) ;
220
+
221
+ expect (
222
+ Collection . fromNodes ( nodes ) . find ( types . Identifier , { name : 'newFoo' } ) . length
223
+ ) . toBe ( 1 ) ;
224
+ expect (
225
+ Collection . fromNodes ( nodes ) . find ( types . Identifier , { name : 'foo' } ) . length
226
+ ) . toBe ( 1 ) ;
227
+ } )
228
+ } ) ;
173
229
} ) ;
174
230
175
231
} ) ;
0 commit comments