2 Copyright (C) 2013 Yusuke Suzuki <utatane.tea@gmail.com>
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in the
11 documentation and/or other materials provided with the distribution.
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
14 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
17 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 function isExpression(node) {
29 if (node == null) { return false; }
31 case 'ArrayExpression':
32 case 'AssignmentExpression':
33 case 'BinaryExpression':
34 case 'CallExpression':
35 case 'ConditionalExpression':
36 case 'FunctionExpression':
39 case 'LogicalExpression':
40 case 'MemberExpression':
42 case 'ObjectExpression':
43 case 'SequenceExpression':
44 case 'ThisExpression':
45 case 'UnaryExpression':
46 case 'UpdateExpression':
52 function isIterationStatement(node) {
53 if (node == null) { return false; }
55 case 'DoWhileStatement':
56 case 'ForInStatement':
58 case 'WhileStatement':
64 function isStatement(node) {
65 if (node == null) { return false; }
67 case 'BlockStatement':
68 case 'BreakStatement':
69 case 'ContinueStatement':
70 case 'DebuggerStatement':
71 case 'DoWhileStatement':
72 case 'EmptyStatement':
73 case 'ExpressionStatement':
74 case 'ForInStatement':
77 case 'LabeledStatement':
78 case 'ReturnStatement':
79 case 'SwitchStatement':
80 case 'ThrowStatement':
82 case 'VariableDeclaration':
83 case 'WhileStatement':
90 function isSourceElement(node) {
91 return isStatement(node) || node != null && node.type === 'FunctionDeclaration';
94 function trailingStatement(node) {
97 if (node.alternate != null) {
98 return node.alternate;
100 return node.consequent;
102 case 'LabeledStatement':
104 case 'ForInStatement':
105 case 'WhileStatement':
106 case 'WithStatement':
112 function isProblematicIfStatement(node) {
115 if (node.type !== 'IfStatement') {
118 if (node.alternate == null) {
121 current = node.consequent;
123 if (current.type === 'IfStatement') {
124 if (current.alternate == null) {
128 current = trailingStatement(current);
135 isExpression: isExpression,
136 isStatement: isStatement,
137 isIterationStatement: isIterationStatement,
138 isSourceElement: isSourceElement,
139 isProblematicIfStatement: isProblematicIfStatement,
141 trailingStatement: trailingStatement
144 /* vim: set sw=4 ts=4 et tw=80 : */