Skip to content

Commit

Permalink
Add test for reference paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonLaster committed Feb 10, 2017
1 parent 4d411ef commit aebf24a
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/babel-traverse/test/scope.js
Expand Up @@ -14,6 +14,19 @@ function getPath(code) {
return path;
}

function getIdentifierPath(code) {
const ast = parse(code);
let nodePath;
traverse(ast, {
Identifier: function(path) {
nodePath = path;
_path.stop();
}
});

return nodePath;
}

describe("scope", function () {
describe("binding paths", function () {
it("function declaration id", function () {
Expand Down Expand Up @@ -60,5 +73,13 @@ describe("scope", function () {
_foo2: { }
`).scope.generateUid("foo"), "_foo3");
});

it("reference paths", function() {
var node = getIdentifierPath("function square(n) { return n * n}");
var referencePaths = node.context.scope.bindings.n.referencePaths;
assert.equal(referencePaths.length, 2)
assert.deepEqual(referencePaths[0].node.loc.start, { line: 1, column:28 });
assert.deepEqual(referencePaths[1].node.loc.start, { line: 1, column:32 });
})
});
});

0 comments on commit aebf24a

Please sign in to comment.