esutils
Advanced tools
Comparing version 1.1.2 to 1.1.3
@@ -112,2 +112,28 @@ /* | ||
function isProblematicIfStatement(node) { | ||
var current; | ||
if (node.type !== 'IfStatement') { | ||
return false; | ||
} | ||
if (node.alternate == null) { | ||
return false; | ||
} | ||
if (node.consequent.type === 'BlockStatement') { | ||
return false; | ||
} | ||
current = node.consequent; | ||
do { | ||
if (current.type === 'IfStatement') { | ||
if (!current.alternate) { | ||
return true; | ||
} | ||
} | ||
current = trailingStatement(current); | ||
} while (current); | ||
return false; | ||
} | ||
module.exports = { | ||
@@ -118,2 +144,3 @@ isExpression: isExpression, | ||
isSourceElement: isSourceElement, | ||
isProblematicIfStatement: isProblematicIfStatement, | ||
@@ -120,0 +147,0 @@ trailingStatement: trailingStatement |
@@ -6,3 +6,3 @@ { | ||
"main": "lib/utils.js", | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"engines": { | ||
@@ -9,0 +9,0 @@ "node": ">=0.10.0" |
@@ -38,2 +38,21 @@ ### esutils [![Build Status](https://secure.travis-ci.org/Constellation/esutils.svg)](http://travis-ci.org/Constellation/esutils) | ||
#### ast.isProblematicIfStatement(node) | ||
Returns true if `node` is a problematic IfStatement. If `node` is a problematic `IfStatement`, `node` cannot be represented as an one on one JavaScript code. | ||
```js | ||
{ | ||
type: 'IfStatement', | ||
consequent: { | ||
type: 'WithStatement', | ||
body: { | ||
type: 'IfStatement', | ||
consequent: {type: 'EmptyStatement'} | ||
} | ||
}, | ||
alternate: {type: 'EmptyStatement'} | ||
} | ||
``` | ||
The above node cannot be represented as a JavaScript code, since the top level `else` alternate belongs to an inner `IfStatement`. | ||
### code | ||
@@ -40,0 +59,0 @@ |
32974
385
170