Skip to content

Commit

Permalink
noop support for ArrowFunctionExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
Langdon Oliver committed Jun 2, 2017
1 parent 72e4d95 commit ef52228
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lib/hooks/ArrowFunctionExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ function shouldHandleParams(node) {
}

function shouldIndentBody(node, opts) {
// we don't want to indent the body twice if ObjectExpression or
// ArrayExpression or CallExpression
return node.body.type === 'BlockStatement' || !opts[node.body.type];
var bodyFirstNonEmpty = tk.findNextNonEmpty(node.body.startToken);

if (bodyFirstNonEmpty.value === '}') {
// noop
limit.after(node.body.startToken, 0);
return false;
} else {
// we don't want to indent the body twice if ObjectExpression or
// ArrayExpression or CallExpression
return node.body.type === 'BlockStatement' || !opts[node.body.type];
}
}
7 changes: 7 additions & 0 deletions test/compare/default/arrow_function_expression-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ arr.map(d =>
{return d * 2;});
arr.map( ( e , f , g) => e * f - g );

// noop (#487)
const f1 = () => {};
const f2 = ( ) => { };
const f3 = ( ) => {

};

// default params (#285)
let defaultParams = (x, y = 1, z = 2 ) => {
return x + y + z;
Expand Down
5 changes: 5 additions & 0 deletions test/compare/default/arrow_function_expression-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ arr.map(d => {
});
arr.map((e, f, g) => e * f - g);

// noop (#487)
const f1 = () => {};
const f2 = () => {};
const f3 = () => {};

// default params (#285)
let defaultParams = (x, y = 1, z = 2) => {
return x + y + z;
Expand Down

0 comments on commit ef52228

Please sign in to comment.