This is an archive of the discontinued LLVM Phabricator instance.

clang-format: [JS] Fix function formatting
Needs ReviewPublic

Authored by ono on Jun 18 2014, 4:07 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

We should consume function identifier only when we are in braced list.

This fixes bug introduced in r210887 that breaks function formatting with inner
functions.

Before:

function testa(a, b) { function innera(a, b) { return a; } } function
testb(a, b) { return b; }

After:

function testa(a, b) {
  function innera(a, b) { return a; }
}
function testb(a, b) { return b; }

Diff Detail

Event Timeline

ono updated this revision to Diff 10548.Jun 18 2014, 4:07 AM
ono retitled this revision from to clang-format: [JS] Fix function formatting.
ono updated this object.
ono edited the test plan for this revision. (Show Details)
ono added a reviewer: djasper.
ono added subscribers: ono, Unknown Object (MLST).
djasper edited edge metadata.Jun 18 2014, 4:13 AM

What is 71bd6fc3? Can you use subversion revisions?

What is the actual bug? We definitely need a test case as well..

ono updated this revision to Diff 10550.Jun 18 2014, 5:05 AM
ono edited edge metadata.

Added sample and proper SVN revision reference.

ono updated this revision to Diff 10551.Jun 18 2014, 5:08 AM

Remove spaces after Before/After headers, sample is in the commit log.

All your diffs are identical and I still don't see a subversion revision number.

ono updated this object.Jun 18 2014, 5:17 AM

Sorry somehow updating commit msg and uploading it here doesn't affect Summary at very top. So I had to edit it manually.

ono updated this revision to Diff 10584.Jun 18 2014, 11:57 AM
ono updated this object.

Added tests.

ono updated this object.Jun 18 2014, 11:57 AM

Based on the tests, I think this is (or at least might be) the wrong fix. For example, there can be function literals with names in other expression contexts, not just in braced lists, e.g.:

var variablename = function FunctionName(Argument List) { 
  // Function Body 
};

I'll ponder this some more and get back to you.

ono updated this revision to Diff 10883.Jun 26 2014, 5:09 AM

Assume it is regular function declaration if previous token for function keyword is right brace, semicolon or none.

That patch still seems like the wrong approach to me. Submitted alternative solution in r212038. Let me know if you have further problems with this.

ono added a comment.Jun 30 2014, 2:17 PM

Your change works great, thanks!

djasper resigned from this revision.Apr 12 2015, 1:20 AM
djasper removed a reviewer: djasper.