| 5155 | } |
| 5156 | } |
| 5157 | function doFunction(options) { |
| 5158 | var f, name, statement, classExprBinding, isGenerator, isArrow; |
| 5159 | var oldOption = state.option; |
| 5160 | var oldIgnored = state.ignored; |
| 5161 | var oldScope = scope; |
| 5162 | |
| 5163 | if (options) { |
| 5164 | name = options.name; |
| 5165 | statement = options.statement; |
| 5166 | classExprBinding = options.classExprBinding; |
| 5167 | isGenerator = options.type === "generator"; |
| 5168 | isArrow = options.type === "arrow"; |
| 5169 | } |
| 5170 | |
| 5171 | state.option = Object.create(state.option); |
| 5172 | state.ignored = Object.create(state.ignored); |
| 5173 | scope = Object.create(scope); |
| 5174 | |
| 5175 | funct = functor(name || state.nameStack.infer(), state.tokens.next, scope, { |
| 5176 | "(statement)": statement, |
| 5177 | "(context)": funct, |
| 5178 | "(generator)": isGenerator |
| 5179 | }); |
| 5180 | |
| 5181 | f = funct; |
| 5182 | state.tokens.curr.funct = funct; |
| 5183 | |
| 5184 | functions.push(funct); |
| 5185 | |
| 5186 | if (name) { |
| 5187 | addlabel(name, { type: "function" }); |
| 5188 | } |
| 5189 | |
| 5190 | if (classExprBinding) { |
| 5191 | addlabel(classExprBinding, { type: "function" }); |
| 5192 | } |
| 5193 | |
| 5194 | funct["(params)"] = functionparams(options); |
| 5195 | funct["(metrics)"].verifyMaxParametersPerFunction(funct["(params)"]); |
| 5196 | |
| 5197 | if (isArrow) { |
| 5198 | if (!state.option.esnext) { |
| 5199 | warning("W119", state.tokens.curr, "arrow function syntax (=>)"); |
| 5200 | } |
| 5201 | |
| 5202 | if (!options.loneArg) { |
| 5203 | advance("=>"); |
| 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | block(false, true, true, isArrow); |
| 5208 | |
| 5209 | if (!state.option.noyield && isGenerator && |
| 5210 | funct["(generator)"] !== "yielded") { |
| 5211 | warning("W124", state.tokens.curr); |
| 5212 | } |
| 5213 | |
| 5214 | funct["(metrics)"].verifyMaxStatementsPerFunction(); |