-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
throw-new-error
: Fix an edge case (#1390)
- Loading branch information
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
rules/utils/should-add-parentheses-to-new-expression-callee.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
// Copied from /~https://github.com/eslint/eslint/blob/aa87329d919f569404ca573b439934552006572f/lib/rules/no-extra-parens.js#L448 | ||
/** | ||
Check if a member expression contains a call expression. | ||
@param {ASTNode} node - The `MemberExpression` node to evaluate. | ||
@returns {boolean} true if found, false if not. | ||
*/ | ||
function doesMemberExpressionContainCallExpression(node) { | ||
let currentNode = node.object; | ||
let currentNodeType = node.object.type; | ||
|
||
while (currentNodeType === 'MemberExpression') { | ||
currentNode = currentNode.object; | ||
currentNodeType = currentNode.type; | ||
} | ||
|
||
return currentNodeType === 'CallExpression'; | ||
} | ||
|
||
/** | ||
Check if parentheses should be added to a `node` when it's used as `callee` of `NewExpression`. | ||
@param {Node} node - The AST node to check. | ||
@returns {boolean} | ||
*/ | ||
function shouldAddParenthesesToNewExpressionCallee(node) { | ||
return node.type === 'MemberExpression' && doesMemberExpressionContainCallExpression(node); | ||
} | ||
|
||
module.exports = shouldAddParenthesesToNewExpressionCallee; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters