Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80555 views
1
var astw = require('../');
2
var test = require('tape');
3
var generate = require('escodegen').generate;
4
5
function unparse (s) {
6
return generate(s, { format: { compact: true } });
7
}
8
9
test('parent', function (t) {
10
t.plan(4);
11
12
var walk = astw('(' + function () {
13
var xs = [ 1, 2, 3 ];
14
fn(ys);
15
} + ')()');
16
17
walk(function (node) {
18
if (node.type === 'ArrayExpression') {
19
t.equal(node.parent.type, 'VariableDeclarator');
20
t.equal(unparse(node.parent), 'xs=[1,2,3]');
21
t.equal(node.parent.parent.type, 'VariableDeclaration');
22
t.equal(unparse(node.parent.parent), 'var xs=[1,2,3];');
23
}
24
});
25
});
26
27