3 // Important: Params is a "virtual" node type, not part of the AST spec.
4 // this hook is actually called by FunctionDeclaration and FunctionExpression
5 // hooks. It's mainly a way to share the common logic between both hooks.
7 var _ws = require('rocambole-whitespace');
8 var _tk = require('rocambole-token');
9 var _limit = require('../limit');
12 exports.format = function Params(node) {
13 var params = node.params;
14 var defaults = node.defaults;
15 var opening = node.startToken.value === '(' ?
17 _tk.findNext(node.startToken, '(');
18 var closing = _tk.findPrev(node.body.startToken, ')');
21 _ws.limitBefore(_tk.findNextNonEmpty(opening), 'ParameterList');
22 params.forEach(function(param, i) {
23 // if only one param or last one there are no commas to look for
24 if (i === params.length - 1) return;
26 _ws.limit(_tk.findNext(param.startToken, ','), 'ParameterComma');
28 defaults.forEach(function(init) {
30 _limit.around(_tk.findPrev(init.startToken, '='), 'ParameterDefault');
33 _ws.limitAfter(_tk.findPrevNonEmpty(closing), 'ParameterList');
35 _limit.after(opening, 0);
39 exports.getIndentEdges = function(node, opts) {
40 var params = node.params;
41 if (params.length && opts.ParameterList) {
42 // get/set on ObjectEpression affect drastically the FunctionExpression
43 // structure so we need to handle it differently
44 var start = node.parent.type === 'Property' ?
45 node.parent.startToken :
48 // we check if start is equal to "(" because of arrow functions
49 startToken: start.value === '(' ? start : _tk.findNext(start, '('),
50 endToken: _tk.findPrev(node.body.startToken, ')'),
51 level: opts.ParameterList