Skip to content

Commit

Permalink
Merge pull request #553 from unexpectedjs/fix/arrowFunctionInspect
Browse files Browse the repository at this point in the history
Fix inspection of single line arrow functions that have a linebreak right after the arrow
  • Loading branch information
papandreou committed Dec 31, 2018
2 parents 1248cb8 + 9158b17 commit 1f1bd59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ module.exports = function(expect) {
isWrappedInBraces = false;
body = matchBodyAndIndent[2];
const matchInitialNewline = openingBrace.match(/^\n( +)/);
if (matchInitialNewline) {
if (matchInitialNewline && /\n/.test(body)) {
// An arrow function whose body starts with a newline, as prettier likes to output, eg.:
// () =>
// foo(
Expand Down
13 changes: 13 additions & 0 deletions test/types/function-type.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ describe('function type', () => {
});
}

var implicitReturnArrowFunction;
try {
// eslint-disable-next-line no-new-func
implicitReturnArrowFunction = new Function('return a =>\n a')();
} catch (e) {}

if (implicitReturnArrowFunction) {
it('should render an implicit return arrow function a single line break after the arrow', () => {
// eslint-disable-next-line no-eval
expect(eval(`a =>\n a`), 'to inspect as', `a =>\n a`);
});
}

// We can't complete this test if the runtime doesn't support arrow functions:
var evilImplicitReturnMultilineArrowFunction;
try {
Expand Down

0 comments on commit 1f1bd59

Please sign in to comment.