* @param {Object} [options] * @param {token} [options.loneArg] The argument to the function in cases * where it was defined using the * single-argument shorthand. * @param {bool} [options.parsedOpening] Whether the opening
(options)
| 21773 | * @returns {{ arity: number, params: Array.<string>}} |
| 21774 | */ |
| 21775 | function functionparams(options) { |
| 21776 | var next; |
| 21777 | var paramsIds = []; |
| 21778 | var ident; |
| 21779 | var tokens = []; |
| 21780 | var t; |
| 21781 | var pastDefault = false; |
| 21782 | var pastRest = false; |
| 21783 | var arity = 0; |
| 21784 | var loneArg = options && options.loneArg; |
| 21785 | |
| 21786 | if (loneArg && loneArg.identifier === true) { |
| 21787 | state.funct["(scope)"].addParam(loneArg.value, loneArg); |
| 21788 | return { arity: 1, params: [ loneArg.value ] }; |
| 21789 | } |
| 21790 | |
| 21791 | next = state.tokens.next; |
| 21792 | |
| 21793 | if (!options || !options.parsedOpening) { |
| 21794 | advance("("); |
| 21795 | } |
| 21796 | |
| 21797 | if (state.tokens.next.id === ")") { |
| 21798 | advance(")"); |
| 21799 | return; |
| 21800 | } |
| 21801 | |
| 21802 | function addParam(addParamArgs) { |
| 21803 | state.funct["(scope)"].addParam.apply(state.funct["(scope)"], addParamArgs); |
| 21804 | } |
| 21805 | |
| 21806 | for (;;) { |
| 21807 | arity++; |
| 21808 | // are added to the param scope |
| 21809 | var currentParams = []; |
| 21810 | |
| 21811 | if (_.contains(["{", "["], state.tokens.next.id)) { |
| 21812 | tokens = destructuringPattern(); |
| 21813 | for (t in tokens) { |
| 21814 | t = tokens[t]; |
| 21815 | if (t.id) { |
| 21816 | paramsIds.push(t.id); |
| 21817 | currentParams.push([t.id, t.token]); |
| 21818 | } |
| 21819 | } |
| 21820 | } else { |
| 21821 | if (checkPunctuator(state.tokens.next, "...")) pastRest = true; |
| 21822 | ident = identifier(true); |
| 21823 | if (ident) { |
| 21824 | paramsIds.push(ident); |
| 21825 | currentParams.push([ident, state.tokens.curr]); |
| 21826 | } else { |
| 21827 | // Skip invalid parameter. |
| 21828 | while (!checkPunctuators(state.tokens.next, [",", ")"])) advance(); |
| 21829 | } |
| 21830 | } |
| 21831 | |
| 21832 | // It is valid to have a regular argument after a default argument |
no test coverage detected