* @function * @name astMemberExpressionUnroll * @desc Parses the abstract syntax tree for binary expression. * * Utility function for astCallExpression. * * @param {Object} ast - the AST object to parse * * @returns {String} the function namespace call, unrolled
(ast)
| 142 | * @returns {String} the function namespace call, unrolled |
| 143 | */ |
| 144 | astMemberExpressionUnroll(ast) { |
| 145 | if (ast.type === 'Identifier') { |
| 146 | return ast.name; |
| 147 | } else if (ast.type === 'ThisExpression') { |
| 148 | return 'this'; |
| 149 | } |
| 150 | |
| 151 | if (ast.type === 'MemberExpression') { |
| 152 | if (ast.object && ast.property) { |
| 153 | //babel sniffing |
| 154 | if (ast.object.hasOwnProperty('name') && ast.object.name !== 'Math') { |
| 155 | return this.astMemberExpressionUnroll(ast.property); |
| 156 | } |
| 157 | |
| 158 | return ( |
| 159 | this.astMemberExpressionUnroll(ast.object) + |
| 160 | '.' + |
| 161 | this.astMemberExpressionUnroll(ast.property) |
| 162 | ); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | //babel sniffing |
| 167 | if (ast.hasOwnProperty('expressions')) { |
| 168 | const firstExpression = ast.expressions[0]; |
| 169 | if (firstExpression.type === 'Literal' && firstExpression.value === 0 && ast.expressions.length === 2) { |
| 170 | return this.astMemberExpressionUnroll(ast.expressions[1]); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // Failure, unknown expression |
| 175 | throw this.astErrorOutput('Unknown astMemberExpressionUnroll', ast); |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @desc Parses the class function JS, and returns its Abstract Syntax Tree object. |
no test coverage detected