在哪里可以查看所有 eslint ast 节点类型?
Where can I view all the eslint ast node types?
需要检测的节点类型很多,即:
- 变量声明符
- 函数表达式
- 成员表达式
- 赋值表达式
eslint 网站解释了规则,但没有提供所有可用的节点类型检测。
我找到了一个检测 IfStatement 的教程示例,但这并没有提取我的 if 语句,所以想知道我是否有语法错误。
没关系。我的 if 语句不起作用的原因是我在测试的代码中没有 if 语句。
关于对所有 ast 节点类型的引用,我也发现了 -
https://github.com/estree/estree/blob/master/es5.md
除了您找到的 ESTree 文档外,我还推荐:https://astexplorer.net/
它向您显示您粘贴的代码的 AST,并在您 click/hover 上方突出显示每个节点对应的代码部分。
在编写规则、找出边缘情况时,或者在一般情况下,对于理解给定代码片段的 AST 是什么样子,它的价值是无可估量的。试试吧!
更新的列表(例如,包括 ArrowFunctionExpression
)在 https://github.com/benjamn/ast-types/blob/master/gen/namedTypes.ts . https://github.com/benjamn/ast-types/blob/master/gen/kinds.ts and https://github.com/benjamn/ast-types/blob/master/def/es6.ts 也很有趣,也可能有帮助。
我相信这就是你想要的
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' ]
需要检测的节点类型很多,即:
- 变量声明符
- 函数表达式
- 成员表达式
- 赋值表达式
eslint 网站解释了规则,但没有提供所有可用的节点类型检测。
我找到了一个检测 IfStatement 的教程示例,但这并没有提取我的 if 语句,所以想知道我是否有语法错误。
没关系。我的 if 语句不起作用的原因是我在测试的代码中没有 if 语句。
关于对所有 ast 节点类型的引用,我也发现了 - https://github.com/estree/estree/blob/master/es5.md
除了您找到的 ESTree 文档外,我还推荐:https://astexplorer.net/
它向您显示您粘贴的代码的 AST,并在您 click/hover 上方突出显示每个节点对应的代码部分。
在编写规则、找出边缘情况时,或者在一般情况下,对于理解给定代码片段的 AST 是什么样子,它的价值是无可估量的。试试吧!
更新的列表(例如,包括 ArrowFunctionExpression
)在 https://github.com/benjamn/ast-types/blob/master/gen/namedTypes.ts . https://github.com/benjamn/ast-types/blob/master/gen/kinds.ts and https://github.com/benjamn/ast-types/blob/master/def/es6.ts 也很有趣,也可能有帮助。
我相信这就是你想要的
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' ]