Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't consider
??
operator LogicExpression as a boolean
value node (
#986) Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
- Loading branch information
1 parent
ff1cd2e
commit dc7f79b
Showing
5 changed files
with
25 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
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
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,17 @@ | ||
'use strict'; | ||
|
||
/** | ||
Check if the given node is a true logical expression or not. | ||
The three binary expressions logical-or (`||`), logical-and (`&&`), and coalesce (`??`) are known as `ShortCircuitExpression`, but ESTree represents these by the `LogicalExpression` node type. This function rejects coalesce expressions of `LogicalExpression` node type. | ||
@param {Node} node - The node to check. | ||
@returns {boolean} `true` if the node is `&&` or `||`. | ||
@see https://tc39.es/ecma262/#prod-ShortCircuitExpression | ||
*/ | ||
const isLogicalExpression = node => | ||
node && | ||
node.type === 'LogicalExpression' && | ||
(node.operator === '&&' || node.operator === '||'); | ||
|
||
module.exports = isLogicalExpression; |
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
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