Fix getBindingIdentifiers in babel-types (#5068)
* Added getBindingIdentifier tests * Added failing test for getBindingIdentifiers * Fix babel-types getBindingIdentifiers
This commit is contained in:
@@ -29,8 +29,8 @@ export function getBindingIdentifiers(
|
||||
}
|
||||
|
||||
if (t.isExportDeclaration(id)) {
|
||||
if (t.isDeclaration(node.declaration)) {
|
||||
search.push(node.declaration);
|
||||
if (t.isDeclaration(id.declaration)) {
|
||||
search.push(id.declaration);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
27
packages/babel-types/test/retrievers.js
Normal file
27
packages/babel-types/test/retrievers.js
Normal file
@@ -0,0 +1,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"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user