* @param {Object} [options] * @param {token} [options.name] The identifier belonging to the function (if * any) * @param {boolean} [options.statement] The statement that triggered creation * of the current function. *
(options)
| 21975 | * the body of member functions. |
| 21976 | */ |
| 21977 | function doFunction(options) { |
| 21978 | var f, token, name, statement, classExprBinding, isGenerator, isArrow, ignoreLoopFunc; |
| 21979 | var oldOption = state.option; |
| 21980 | var oldIgnored = state.ignored; |
| 21981 | |
| 21982 | if (options) { |
| 21983 | name = options.name; |
| 21984 | statement = options.statement; |
| 21985 | classExprBinding = options.classExprBinding; |
| 21986 | isGenerator = options.type === "generator"; |
| 21987 | isArrow = options.type === "arrow"; |
| 21988 | ignoreLoopFunc = options.ignoreLoopFunc; |
| 21989 | } |
| 21990 | |
| 21991 | state.option = Object.create(state.option); |
| 21992 | state.ignored = Object.create(state.ignored); |
| 21993 | |
| 21994 | state.funct = functor(name || state.nameStack.infer(), state.tokens.next, { |
| 21995 | "(statement)": statement, |
| 21996 | "(context)": state.funct, |
| 21997 | "(arrow)": isArrow, |
| 21998 | "(generator)": isGenerator |
| 21999 | }); |
| 22000 | |
| 22001 | f = state.funct; |
| 22002 | token = state.tokens.curr; |
| 22003 | token.funct = state.funct; |
| 22004 | |
| 22005 | functions.push(state.funct); |
| 22006 | |
| 22007 | // So that the function is available to itself and referencing itself is not |
| 22008 | // seen as a closure, add the function name to a new scope, but do not |
| 22009 | // test for unused (unused: false) |
| 22010 | // it is a new block scope so that params can override it, it can be block scoped |
| 22011 | // but declarations inside the function don't cause already declared error |
| 22012 | state.funct["(scope)"].stack("functionouter"); |
| 22013 | var internallyAccessibleName = name || classExprBinding; |
| 22014 | if (internallyAccessibleName) { |
| 22015 | state.funct["(scope)"].block.add(internallyAccessibleName, |
| 22016 | classExprBinding ? "class" : "function", state.tokens.curr, false); |
| 22017 | } |
| 22018 | |
| 22019 | // create the param scope (params added in functionparams) |
| 22020 | state.funct["(scope)"].stack("functionparams"); |
| 22021 | |
| 22022 | var paramsInfo = functionparams(options); |
| 22023 | |
| 22024 | if (paramsInfo) { |
| 22025 | state.funct["(params)"] = paramsInfo.params; |
| 22026 | state.funct["(metrics)"].arity = paramsInfo.arity; |
| 22027 | state.funct["(metrics)"].verifyMaxParametersPerFunction(); |
| 22028 | } else { |
| 22029 | state.funct["(metrics)"].arity = 0; |
| 22030 | } |
| 22031 | |
| 22032 | if (isArrow) { |
| 22033 | if (!state.inES6(true)) { |
| 22034 | warning("W119", state.tokens.curr, "arrow function syntax (=>)", "6"); |