Skip to content

Commit

Permalink
add more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 2, 2021
1 parent f2b2184 commit b53b1e7
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/babel-types/test/retrievers.js
Expand Up @@ -18,11 +18,59 @@ describe("retrievers", function () {
getBody("var foo = 1; function bar() { var baz = 2; }"),
["bar", "foo"],
],
[
"object methods",
getBody("({ a(b) { let c } })")[0].expression.properties[0],
["b"],
],
[
"class methods",
getBody("(class { a(b) { let c } })")[0].expression.body.body,
["b"],
],
[
"class private methods",
getBody("(class { #a(b) { let c } })")[0].expression.body.body,
["b"],
],
[
"export named declarations",
getBody("export const foo = 'foo';"),
["foo"],
],
[
"export default class declarations",
getBody("export default class foo {}"),
["foo"],
],
[
"export default referenced identifiers",
getBody("export default foo"),
[],
],
["export all declarations", getBody("export * from 'x'"), []],
[
"export all as namespace declarations",
getBody("export * as ns from 'x'"),
[], // exported bindings are not associated with declarations
],
[
"export namespace specifiers",
getBody("export * as ns from 'x'")[0].specifiers,
["ns"],
],
[
"object patterns",
getBody("const { a, b: { ...c } = { d } } = {}"),
["a", "c"],
],
[
"array patterns",
getBody("var [ a, ...{ b, ...c } ] = {}"),
["a", "b", "c"],
],
["update expression", getBody("++x")[0].expression, ["x"]],
["assignment expression", getBody("x ??= 1")[0].expression, ["x"]],
])("%s", (_, program, bindingNames) => {
const ids = t.getBindingIdentifiers(program);
expect(Object.keys(ids)).toEqual(bindingNames);
Expand Down

0 comments on commit b53b1e7

Please sign in to comment.