* @desc Parses the abstract syntax tree for *call* expression * @param {Object} ast - the AST object to parse * @param {Array} retArr - return array string * @returns {Array} the append retArr
(ast, retArr)
| 1318 | * @returns {Array} the append retArr |
| 1319 | */ |
| 1320 | astCallExpression(ast, retArr) { |
| 1321 | if (!ast.callee) { |
| 1322 | throw this.astErrorOutput('Unknown CallExpression', ast); |
| 1323 | } |
| 1324 | |
| 1325 | let functionName = null; |
| 1326 | const isMathFunction = this.isAstMathFunction(ast); |
| 1327 | |
| 1328 | // Its a math operator or this.something(), remove the prefix |
| 1329 | if (isMathFunction || (ast.callee.object && ast.callee.object.type === 'ThisExpression')) { |
| 1330 | functionName = ast.callee.property.name; |
| 1331 | } |
| 1332 | // Issue #212, BABEL! |
| 1333 | else if (ast.callee.type === 'SequenceExpression' && ast.callee.expressions[0].type === 'Literal' && !isNaN(ast.callee.expressions[0].raw)) { |
| 1334 | functionName = ast.callee.expressions[1].property.name; |
| 1335 | } else { |
| 1336 | functionName = ast.callee.name; |
| 1337 | } |
| 1338 | |
| 1339 | if (!functionName) { |
| 1340 | throw this.astErrorOutput(`Unhandled function, couldn't find name`, ast); |
| 1341 | } |
| 1342 | |
| 1343 | // if this if grows to more than one, lets use a switch |
| 1344 | switch (functionName) { |
| 1345 | case 'pow': |
| 1346 | functionName = '_pow'; |
| 1347 | break; |
| 1348 | case 'round': |
| 1349 | functionName = '_round'; |
| 1350 | break; |
| 1351 | } |
| 1352 | |
| 1353 | // Register the function into the called registry |
| 1354 | if (this.calledFunctions.indexOf(functionName) < 0) { |
| 1355 | this.calledFunctions.push(functionName); |
| 1356 | } |
| 1357 | |
| 1358 | if (functionName === 'random' && this.plugins && this.plugins.length > 0) { |
| 1359 | for (let i = 0; i < this.plugins.length; i++) { |
| 1360 | const plugin = this.plugins[i]; |
| 1361 | if (plugin.functionMatch === 'Math.random()' && plugin.functionReplace) { |
| 1362 | retArr.push(plugin.functionReplace); |
| 1363 | return retArr; |
| 1364 | } |
| 1365 | } |
| 1366 | } |
| 1367 | |
| 1368 | // track the function was called |
| 1369 | if (this.onFunctionCall) { |
| 1370 | this.onFunctionCall(this.name, functionName, ast.arguments); |
| 1371 | } |
| 1372 | |
| 1373 | // Call the function |
| 1374 | retArr.push(functionName); |
| 1375 | |
| 1376 | // Open arguments space |
| 1377 | retArr.push('('); |
no test coverage detected