forked from jamesshore/lets_code_javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparent.js
More file actions
25 lines (21 loc) · 692 Bytes
/
parent.js
File metadata and controls
25 lines (21 loc) · 692 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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];');
}
});
});