我在哪里可以查看所有eslint ast节点类型?

时间:2016-09-23 16:14:54

标签: abstract-syntax-tree eslint

有许多节点类型需要检测,即:

  • VariableDeclarator
  • FunctionExpression
  • MemberExpression
  • AssignmentExpression

eslint网站解释了规则,但没有提供所有可用的节点类型检测。

我找到了一个检测IfStatement的教程示例,但这并没有拿起我的if语句,所以想知道我是否有语法错误。

4 个答案:

答案 0 :(得分:4)

除了您找到的ESTree文档外,我还建议:https://astexplorer.net/

它会显示您粘贴的代码的AST,并且还会突出显示每个节点在您点击/悬停它们时对应的代码部分。

在编写规则,找出边缘情况时,或者一般来说,理解给定代码片段的AST是什么样的,这是非常宝贵的。试一试!

答案 1 :(得分:1)

没关系。我的if语句不起作用的原因是因为我在测试的代码中没有if语句。

关于所有ast节点类型的引用我也发现了 - https://github.com/estree/estree/blob/master/es5.md

答案 2 :(得分:0)

答案 3 :(得分:0)

我相信这就是你想要的

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' ]