有许多节点类型需要检测,即:
eslint网站解释了规则,但没有提供所有可用的节点类型检测。
我找到了一个检测IfStatement的教程示例,但这并没有拿起我的if语句,所以想知道我是否有语法错误。
答案 0 :(得分:4)
除了您找到的ESTree文档外,我还建议:https://astexplorer.net/
它会显示您粘贴的代码的AST,并且还会突出显示每个节点在您点击/悬停它们时对应的代码部分。
在编写规则,找出边缘情况时,或者一般来说,理解给定代码片段的AST是什么样的,这是非常宝贵的。试一试!
答案 1 :(得分:1)
没关系。我的if语句不起作用的原因是因为我在测试的代码中没有if语句。
关于所有ast节点类型的引用我也发现了 - https://github.com/estree/estree/blob/master/es5.md
答案 2 :(得分:0)
位于https://github.com/benjamn/ast-types/blob/master/gen/namedTypes.ts的最新列表(例如,包含ArrowFunctionExpression
)。 https://github.com/benjamn/ast-types/blob/master/gen/kinds.ts和https://github.com/benjamn/ast-types/blob/master/def/es6.ts也很有趣,也可能会有所帮助。
答案 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' ]