react / wstein / node_modules / browserify / node_modules / module-deps / node_modules / detective / node_modules / escodegen / node_modules / esutils / lib / ast.js
80621 views/*1Copyright (C) 2013 Yusuke Suzuki <[email protected]>23Redistribution and use in source and binary forms, with or without4modification, are permitted provided that the following conditions are met:56* Redistributions of source code must retain the above copyright7notice, this list of conditions and the following disclaimer.8* Redistributions in binary form must reproduce the above copyright9notice, this list of conditions and the following disclaimer in the10documentation and/or other materials provided with the distribution.1112THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'13AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY16DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES17(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;18LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND19ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT20(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF21THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.22*/2324(function () {25'use strict';2627function isExpression(node) {28if (node == null) { return false; }29switch (node.type) {30case 'ArrayExpression':31case 'AssignmentExpression':32case 'BinaryExpression':33case 'CallExpression':34case 'ConditionalExpression':35case 'FunctionExpression':36case 'Identifier':37case 'Literal':38case 'LogicalExpression':39case 'MemberExpression':40case 'NewExpression':41case 'ObjectExpression':42case 'SequenceExpression':43case 'ThisExpression':44case 'UnaryExpression':45case 'UpdateExpression':46return true;47}48return false;49}5051function isIterationStatement(node) {52if (node == null) { return false; }53switch (node.type) {54case 'DoWhileStatement':55case 'ForInStatement':56case 'ForStatement':57case 'WhileStatement':58return true;59}60return false;61}6263function isStatement(node) {64if (node == null) { return false; }65switch (node.type) {66case 'BlockStatement':67case 'BreakStatement':68case 'ContinueStatement':69case 'DebuggerStatement':70case 'DoWhileStatement':71case 'EmptyStatement':72case 'ExpressionStatement':73case 'ForInStatement':74case 'ForStatement':75case 'IfStatement':76case 'LabeledStatement':77case 'ReturnStatement':78case 'SwitchStatement':79case 'ThrowStatement':80case 'TryStatement':81case 'VariableDeclaration':82case 'WhileStatement':83case 'WithStatement':84return true;85}86return false;87}8889function isSourceElement(node) {90return isStatement(node) || node != null && node.type === 'FunctionDeclaration';91}9293function trailingStatement(node) {94switch (node.type) {95case 'IfStatement':96if (node.alternate != null) {97return node.alternate;98}99return node.consequent;100101case 'LabeledStatement':102case 'ForStatement':103case 'ForInStatement':104case 'WhileStatement':105case 'WithStatement':106return node.body;107}108return null;109}110111function isProblematicIfStatement(node) {112var current;113114if (node.type !== 'IfStatement') {115return false;116}117if (node.alternate == null) {118return false;119}120current = node.consequent;121do {122if (current.type === 'IfStatement') {123if (current.alternate == null) {124return true;125}126}127current = trailingStatement(current);128} while (current);129130return false;131}132133module.exports = {134isExpression: isExpression,135isStatement: isStatement,136isIterationStatement: isIterationStatement,137isSourceElement: isSourceElement,138isProblematicIfStatement: isProblematicIfStatement,139140trailingStatement: trailingStatement141};142}());143/* vim: set sw=4 ts=4 et tw=80 : */144145146