a zip code crypto-currency system good for red ONLY

getFunctionExpression.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. module.exports = function(expr) {
  6. // <FunctionExpression>
  7. if(expr.type === "FunctionExpression" || expr.type === "ArrowFunctionExpression") {
  8. return {
  9. fn: expr,
  10. expressions: [],
  11. needThis: false
  12. };
  13. }
  14. // <FunctionExpression>.bind(<Expression>)
  15. if(expr.type === "CallExpression" &&
  16. expr.callee.type === "MemberExpression" &&
  17. expr.callee.object.type === "FunctionExpression" &&
  18. expr.callee.property.type === "Identifier" &&
  19. expr.callee.property.name === "bind" &&
  20. expr.arguments.length === 1) {
  21. return {
  22. fn: expr.callee.object,
  23. expressions: [expr.arguments[0]]
  24. };
  25. }
  26. // (function(_this) {return <FunctionExpression>})(this) (Coffeescript)
  27. if(expr.type === "CallExpression" &&
  28. expr.callee.type === "FunctionExpression" &&
  29. expr.callee.body.type === "BlockStatement" &&
  30. expr.arguments.length === 1 &&
  31. expr.arguments[0].type === "ThisExpression" &&
  32. expr.callee.body.body &&
  33. expr.callee.body.body.length === 1 &&
  34. expr.callee.body.body[0].type === "ReturnStatement" &&
  35. expr.callee.body.body[0].argument &&
  36. expr.callee.body.body[0].argument.type === "FunctionExpression") {
  37. return {
  38. fn: expr.callee.body.body[0].argument,
  39. expressions: [],
  40. needThis: true
  41. };
  42. }
  43. };