forked from babel/babel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
retrievers.js
27 lines (25 loc) · 980 Bytes
/
retrievers.js
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
26
27
import * as t from "../lib";
import assert from "assert";
import { parse } from "babylon";
function getBody(program) {
return parse(program, {sourceType: "module"}).program.body;
}
describe("retrievers", function () {
describe("getBindingIdentifiers", function () {
it("variable declarations", function () {
const program = "var a = 1; let b = 2; const c = 3;";
const ids = t.getBindingIdentifiers(getBody(program));
assert.deepEqual(Object.keys(ids), ["a", "b", "c"]);
});
it("function declarations", function () {
const program = "var foo = 1; function bar() { var baz = 2; }";
const ids = t.getBindingIdentifiers(getBody(program));
assert.deepEqual(Object.keys(ids), ["bar", "foo"]);
});
it("export named declarations", function () {
const program = "export const foo = 'foo';";
const ids = t.getBindingIdentifiers(getBody(program));
assert.deepEqual(Object.keys(ids), ["foo"]);
});
});
});