You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
692 B
JavaScript
26 lines
692 B
JavaScript
7 years ago
|
var astw = require('../');
|
||
|
var test = require('tape');
|
||
|
var generate = require('escodegen').generate;
|
||
|
|
||
|
function unparse (s) {
|
||
|
return generate(s, { format: { compact: true } });
|
||
|
}
|
||
|
|
||
|
test('parent', function (t) {
|
||
|
t.plan(4);
|
||
|
|
||
|
var walk = astw('(' + function () {
|
||
|
var xs = [ 1, 2, 3 ];
|
||
|
fn(ys);
|
||
|
} + ')()');
|
||
|
|
||
|
walk(function (node) {
|
||
|
if (node.type === 'ArrayExpression') {
|
||
|
t.equal(node.parent.type, 'VariableDeclarator');
|
||
|
t.equal(unparse(node.parent), 'xs=[1,2,3]');
|
||
|
t.equal(node.parent.parent.type, 'VariableDeclaration');
|
||
|
t.equal(unparse(node.parent.parent), 'var xs=[1,2,3];');
|
||
|
}
|
||
|
});
|
||
|
});
|