Where can I view all the eslint ast node types?
Asked Answered
A

4

18

There are many node types to detect, ie:

  • VariableDeclarator
  • FunctionExpression
  • MemberExpression
  • AssignmentExpression

The eslint website explains the rules but doesn't provide all of the available node type detections.

I found a tutorial example detecting IfStatement but this is not picking up my if statement, so wondering if I have a syntax error.

Apparent answered 23/9, 2016 at 16:14 Comment(0)
A
2

It's ok. The reason my ifstatement wasn't working was because i didn't have an if statement in the code I was testing.

Regarding the reference to all the ast node types I found that too - https://github.com/estree/estree/blob/master/es5.md

Apparent answered 23/9, 2016 at 16:33 Comment(0)
W
19

Besides the ESTree documentation that you found, I would recommend: https://astexplorer.net/

It shows you the AST for the code you paste in and also highlights which part of the code each node corresponds to as you click/hover over them.

It's invaluable when writing a rule, figuring out edge cases, or in general, for understanding how the AST of a given snippet of code looks like. Give it a try!

Whomp answered 23/9, 2016 at 20:53 Comment(0)
C
5

A more up to date list (e.g., that includes ArrowFunctionExpression) is at https://github.com/benjamn/ast-types/blob/master/src/gen/namedTypes.ts . https://github.com/benjamn/ast-types/blob/master/src/gen/kinds.ts and https://github.com/benjamn/ast-types/blob/master/src/def/es6.ts are also interesting and may be helpful as well.

Chilblain answered 8/5, 2019 at 14:4 Comment(2)
All links dead...Yirinec
The links are now updatedChilblain
A
2

It's ok. The reason my ifstatement wasn't working was because i didn't have an if statement in the code I was testing.

Regarding the reference to all the ast node types I found that too - https://github.com/estree/estree/blob/master/es5.md

Apparent answered 23/9, 2016 at 16:33 Comment(0)
S
0

I belive this is what you want

AssignmentExpression: [ 'left', 'right' ],
    AssignmentPattern: [ 'left', 'right' ],
    ArrayExpression: [ 'elements' ],
    ArrayPattern: [ 'elements' ],
    ArrowFunctionExpression: [ 'params', 'body' ],
    AwaitExpression: [ 'argument' ],
    BlockStatement: [ 'body' ],
    BinaryExpression: [ 'left', 'right' ],
    BreakStatement: [ 'label' ],
    CallExpression: [ 'callee', 'arguments' ],
    CatchClause: [ 'param', 'body' ],
    ClassBody: [ 'body' ],
    ClassDeclaration: [ 'id', 'superClass', 'body' ],
    ClassExpression: [ 'id', 'superClass', 'body' ],
    ConditionalExpression: [ 'test', 'consequent', 'alternate' ],
    ContinueStatement: [ 'label' ],
    DebuggerStatement: [],
    DoWhileStatement: [ 'body', 'test' ],
    EmptyStatement: [],
    ExportAllDeclaration: [ 'source' ],
    ExportDefaultDeclaration: [ 'declaration' ],
    ExportNamedDeclaration: [ 'declaration', 'specifiers', 'source' ],
    ExportSpecifier: [ 'exported', 'local' ],
    ExpressionStatement: [ 'expression' ],
    ExperimentalRestProperty: [ 'argument' ],
    ExperimentalSpreadProperty: [ 'argument' ],
    ForStatement: [ 'init', 'test', 'update', 'body' ],
    ForInStatement: [ 'left', 'right', 'body' ],
    ForOfStatement: [ 'left', 'right', 'body' ],
    FunctionDeclaration: [ 'id', 'params', 'body' ],
    FunctionExpression: [ 'id', 'params', 'body' ],
    Identifier: [],
    IfStatement: [ 'test', 'consequent', 'alternate' ],
    ImportDeclaration: [ 'specifiers', 'source' ],
    ImportDefaultSpecifier: [ 'local' ],
    ImportExpression: [ 'source' ],
    ImportNamespaceSpecifier: [ 'local' ],
    ImportSpecifier: [ 'imported', 'local' ],
    JSXAttribute: [ 'name', 'value' ],
    JSXClosingElement: [ 'name' ],
    JSXElement: [ 'openingElement', 'children', 'closingElement' ],
    JSXEmptyExpression: [],
    JSXExpressionContainer: [ 'expression' ],
    JSXIdentifier: [],
    JSXMemberExpression: [ 'object', 'property' ],
    JSXNamespacedName: [ 'namespace', 'name' ],
    JSXOpeningElement: [ 'name', 'attributes' ],
    JSXSpreadAttribute: [ 'argument' ],
    JSXText: [],
    JSXFragment: [ 'openingFragment', 'children', 'closingFragment' ],
    Literal: [],
    LabeledStatement: [ 'label', 'body' ],
    LogicalExpression: [ 'left', 'right' ],
    MemberExpression: [ 'object', 'property' ],
    MetaProperty: [ 'meta', 'property' ],
    MethodDefinition: [ 'key', 'value' ],
    NewExpression: [ 'callee', 'arguments' ],
    ObjectExpression: [ 'properties' ],
    ObjectPattern: [ 'properties' ],
    Program: [ 'body' ],
    Property: [ 'key', 'value' ],
    RestElement: [ 'argument' ],
    ReturnStatement: [ 'argument' ],
    SequenceExpression: [ 'expressions' ],
    SpreadElement: [ 'argument' ],
    Super: [],
    SwitchStatement: [ 'discriminant', 'cases' ],
    SwitchCase: [ 'test', 'consequent' ],
    TaggedTemplateExpression: [ 'tag', 'quasi' ],
    TemplateElement: [],
    TemplateLiteral: [ 'quasis', 'expressions' ],
    ThisExpression: [],
    ThrowStatement: [ 'argument' ],
    TryStatement: [ 'block', 'handler', 'finalizer' ],
    UnaryExpression: [ 'argument' ],
    UpdateExpression: [ 'argument' ],
    VariableDeclaration: [ 'declarations' ],
    VariableDeclarator: [ 'id', 'init' ],
    WhileStatement: [ 'test', 'body' ],
    WithStatement: [ 'object', 'body' ],
    YieldExpression: [ 'argument' ]
Selfknowledge answered 19/6, 2020 at 10:39 Comment(1)
Please provide more information for further detail.Fielder

© 2022 - 2024 — McMap. All rights reserved.