Nascent Personality Manifestation
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

babylon-ast-dependencies

1.0.2 • Public • Published

babylon-ast-dependencies

Inspects Babylon ASTs for dependency identifiers

Install

npm install --save babylon-ast-dependencies

Example

import * as babylon from 'babylon'
import babylonAstDependencies from 'babylon-ast-dependencies';
 
const ast = babylon.parse(
  `
    import foo from "foo";
    require('./bar')
    export * from './woz'
  `,
  {sourceType: 'module'}
);
 
const deps = babylonAstDependencies(ast);
 
console.log(deps.map(dep => dep.source);
// ['foo', './bar', 'woz']

Notes

Lists of objects are returned, where each object has the value of the identifier as a source prop. Rather than simply returning lists of strings, we use objects as it leaves open the potential for more contextual information to be provided in a backwards-compatible manner.

Keywords

none

install

npm i babylon-ast-dependencies

Downloadsweekly downloads

30

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability