2.1.1 • Published 6 years ago

babel-utils v2.1.1

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

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.

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago