How to use the getOuterBindingIdentifiers function from @babel/types

Find comprehensive JavaScript @babel/types.getOuterBindingIdentifiers code examples handpicked from public code repositorys.

@babel/types.getOuterBindingIdentifiers is a function provided by the Babel types library that returns an object representing the identifiers that are declared in a given AST node.

233
234
235
236
237
238
239
240
241
242
243
244
function getBindingIdentifiers(duplicates) {
  return t.getBindingIdentifiers(this.node, duplicates);
}


function getOuterBindingIdentifiers(duplicates) {
  return t.getOuterBindingIdentifiers(this.node, duplicates);
}


function getBindingIdentifierPaths(duplicates = false, outerOnly = false) {
  const path = this;
fork icon0
star icon0
watch icon1

+ 11 other calls in file

How does @babel/types.getOuterBindingIdentifiers work?

@babel/types.getOuterBindingIdentifiers is a function provided by the Babel types library that returns an object representing the identifiers that are declared in a given AST node. When you call @babel/types.getOuterBindingIdentifiers, you provide an AST node as input. The function traverses the input node and any child nodes, returning an object that represents all of the identifiers that are declared in the node. The returned object has keys that represent each unique identifier declared in the node, and the values of these keys are true. This allows for simple checking of whether a given identifier is declared within a node. By providing a way to easily access the identifiers declared within an AST node, @babel/types.getOuterBindingIdentifiers is a useful tool for working with Babel's abstract syntax tree and for analyzing and transforming JavaScript code.

Ai Example

1
2
3
4
5
6
7
8
9
10
const fs = require("fs");
const { parse } = require("@babel/parser");
const t = require("@babel/types");

const code = fs.readFileSync("./example.js");
const ast = parse(code, { sourceType: "module" });

const identifiers = t.getOuterBindingIdentifiers(ast);

console.log(identifiers);

In this example, the fs module is used to read the contents of a JavaScript file into a variable called code. The @babel/parser module is used to parse the code into an AST, and @babel/types.getOuterBindingIdentifiers is called with the AST as input. The resulting identifiers object contains keys that represent each unique identifier declared in the JavaScript file, and the values of these keys are true. By examining the keys of this object, you can determine which variables, functions, and classes are declared in the file. Note that this example assumes that the JavaScript file is written in ECMAScript modules format, as indicated by the sourceType: 'module' option passed to parse(). If the file is not an ES module, this option should be omitted.

Other functions in @babel/types

Sorted by popularity

function icon

@babel/types.identifier is the most popular function in @babel/types (20936 examples)