Skip to content

rtsao/babel-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-utils

getImportDeclarationVisitor(packageName, handler)

Creates as visitor that calls a handler callback for each import declaration that matches the supplied package.

visitNamedImports(importPath, moduleName, hander)

Given an import path declaration node, calls a handler callback for each reference to the supplied named modules.

Suppose we want to transform usages of foo from some-package.

import {foo as bar} from "some-package";

bar({});
const visitor = getImportDeclarationVisitor("some-package", path => {
  visitNamedImports(path, "foo", paths => {
    paths.forEach(path => {
      // ...
    });
  });
});

resolveToValue(path)

Takes an identifier path and recursively traverses the scope (through variable declarations) until it finds a non-variable declaration.

const foo = {foo: "foo"};
const bar = foo;
const baz = bar;

someFunction(baz);

Suppose we want to transform the argument of someFunction. resolveToValue will yield the object expression (assigned to foo) given the identifier node path passed to someFunction.

About

Unofficial Babel plugin utilities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published