babel-is

verify ast node in babel plugin

Usage no npm install needed!

<script type="module">
  import babelIs from 'https://cdn.skypack.dev/babel-is';
</script>

README

babel-is

Installation

For npm users

npm i babel-is

For yarn users

yarn add babel-is

Usage

In your babel plugin

const is = require( 'babel-is' )

module.exports = function () {
  return {
    visitor: {
      VariableDeclaration( path ) {
        const selector = `FunctionDeclaration[id.name=foo] [kind=let]`

        if ( is( path, selector ) ) {
          // matches all `let` variable declarations in `foo` function
          // add your logic
          // ...
        }
      }
    }
  }
}

License

MIT