differentmatt / filbert

JavaScript parser of Python
Other
133 stars 27 forks source link

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

Open preston-willis opened 4 years ago

preston-willis commented 4 years ago

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 commented 4 years ago

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

basicer commented 4 years ago

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

differentmatt commented 4 years ago

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!