Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit ca7358f

Browse files
test: add nested case for nested declarators #25
1 parent 1563df7 commit ca7358f

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

test/test.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,124 @@ describe( 'rollup-pluginutils', function () {
306306
assert.ok(scope.contains('b'));
307307
});
308308

309+
it('adds nested declarators from a deconstructed declaration', function() {
310+
var ast = {
311+
"type": "Program",
312+
"start": 0,
313+
"end": 40,
314+
"body": [{
315+
"type": "VariableDeclaration",
316+
"start": 0,
317+
"end": 40,
318+
"declarations": [{
319+
"type": "VariableDeclarator",
320+
"start": 4,
321+
"end": 39,
322+
"id": {
323+
"type": "ObjectPattern",
324+
"start": 4,
325+
"end": 19,
326+
"properties": [{
327+
"type": "Property",
328+
"start": 6,
329+
"end": 17,
330+
"method": false,
331+
"shorthand": false,
332+
"computed": false,
333+
"key": {
334+
"type": "Identifier",
335+
"start": 6,
336+
"end": 7,
337+
"name": "a"
338+
},
339+
"value": {
340+
"type": "ObjectPattern",
341+
"start": 9,
342+
"end": 17,
343+
"properties": [{
344+
"type": "Property",
345+
"start": 11,
346+
"end": 15,
347+
"method": false,
348+
"shorthand": false,
349+
"computed": false,
350+
"key": {
351+
"type": "Identifier",
352+
"start": 11,
353+
"end": 12,
354+
"name": "b"
355+
},
356+
"value": {
357+
"type": "Identifier",
358+
"start": 14,
359+
"end": 15,
360+
"name": "c"
361+
},
362+
"kind": "init"
363+
}]
364+
},
365+
"kind": "init"
366+
}]
367+
},
368+
"init": {
369+
"type": "ObjectExpression",
370+
"start": 22,
371+
"end": 39,
372+
"properties": [{
373+
"type": "Property",
374+
"start": 24,
375+
"end": 37,
376+
"method": false,
377+
"shorthand": false,
378+
"computed": false,
379+
"key": {
380+
"type": "Identifier",
381+
"start": 24,
382+
"end": 25,
383+
"name": "a"
384+
},
385+
"value": {
386+
"type": "ObjectExpression",
387+
"start": 27,
388+
"end": 37,
389+
"properties": [{
390+
"type": "Property",
391+
"start": 29,
392+
"end": 35,
393+
"method": false,
394+
"shorthand": false,
395+
"computed": false,
396+
"key": {
397+
"type": "Identifier",
398+
"start": 29,
399+
"end": 30,
400+
"name": "b"
401+
},
402+
"value": {
403+
"type": "Literal",
404+
"start": 32,
405+
"end": 35,
406+
"value": "b",
407+
"raw": "'b'"
408+
},
409+
"kind": "init"
410+
}]
411+
},
412+
"kind": "init"
413+
}]
414+
}
415+
}],
416+
"kind": "let"
417+
}],
418+
"sourceType": "module"
419+
};
420+
421+
var scope = attachScopes(ast, 'scope');
422+
assert.ok(!scope.contains('a'));
423+
assert.ok(!scope.contains('b'));
424+
assert.ok(scope.contains('c'));
425+
});
426+
309427
// TODO more tests
310428
});
311429

0 commit comments

Comments
 (0)