Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

noop support for ArrowFunctionExpression #488

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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