filbert icon indicating copy to clipboard operation
filbert copied to clipboard

Is there a way to check the types of nodes? (similar to @babel/types)

Open preston-willis opened this issue 4 years ago • 3 comments

I'm looking for a way to check node types, and the docs weren't clear if there were any built-in boolean type eval functions

I'm looking for something like this:

import {
  isDeclaration,
  isExpressionStatement,
  isThisExpression,
  isMemberExpression,
  isVariableDeclarator,
  isClassDeclaration,
  isClassExpression,
  isLiteral,
  isFunctionExpression,
  isFunctionDeclaration,
  isProperty,
  isClassProperty,
  isObjectExpression,
  isObjectMethod,
  isClassMethod,
  isTemplateLiteral,
  isFunction as isBabelFunction
} from '@babel/types'

preston-willis avatar May 18 '20 17:05 preston-willis

Thanks for all your help! sorry if this is a stupid question or does not belong here.

preston-willis avatar May 18 '20 17:05 preston-willis

The AST filbert uses is pretty similar to the one babel uses, so you might be able to use that very library.

basicer avatar May 20 '20 07:05 basicer

Short answer is no, there aren't built-in functions for this. But, the node.type property looks like it matches pretty closely to most of the babel types at first glance. Hope that or using babel library directly gets you further along!

differentmatt avatar May 22 '20 04:05 differentmatt