Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,23 @@
return false;
}

function isExpressionES6(node) {
if (node == null) { return false; }
if (isExpression(node)) { return true; }
switch (node.type) {
case 'ArrowFunctionExpression':
case 'ClassExpression':
case 'TaggedTemplateExpression':
case 'YieldExpression':
// patterns may not belong here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, patterns are not expressions.

case 'AssignmentPattern':
case 'ArrayPattern':
case 'ObjectPattern':
return true;
}
return false;
}

function isIterationStatement(node) {
if (node == null) { return false; }
switch (node.type) {
Expand Down Expand Up @@ -87,6 +104,16 @@
return false;
}

function isStatementES6(node) {
if (node == null) { return false; }
if (isStatement(node)) { return true; }
switch (node.type) {
case 'ForOfStatement':
return true;
}
return false;
}

function isSourceElement(node) {
return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
}
Expand Down Expand Up @@ -133,7 +160,9 @@

module.exports = {
isExpression: isExpression,
isExpressionES6: isExpressionES6,
isStatement: isStatement,
isStatementES6: isStatementES6,
isIterationStatement: isIterationStatement,
isSourceElement: isSourceElement,
isProblematicIfStatement: isProblematicIfStatement,
Expand Down