to-string-tokens.js 560 B

1234567891011121314151617
  1. "use strict";
  2. var validFunction = require("../valid-function");
  3. var re1 = /^\s*function[\0-')-\uffff]*\(([\0-(*-\uffff]*)\)\s*\{([\0-\uffff]*)\}\s*$/
  4. , re2 = /^\s*\(?([\0-'*-\uffff]*)\)?\s*=>\s*(\{?[\0-\uffff]*\}?)\s*$/;
  5. module.exports = function () {
  6. var str = String(validFunction(this)), data = str.match(re1);
  7. if (!data) {
  8. data = str.match(re2);
  9. if (!data) throw new Error("Unrecognized string format");
  10. data[1] = data[1].trim();
  11. if (data[2][0] === "{") data[2] = data[2].trim().slice(1, -1);
  12. }
  13. return { args: data[1], body: data[2] };
  14. };