summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestJS.cpp
Commit message (Collapse)AuthorAgeFilesLines
* clang-format: [JS] Only special case top level object literalDaniel Jasper2015-06-101-0/+4
| | | | | | | | | | | | | | | | | | | | | | assignments as enums. Top level object literals are treated as enums, and their k/v pairs are put on separate lines: X.Y = { A: 1, B: 2 }; However assignments within blocks should not be affected: function x() { y = {a:1, b:2}; } This change fixes the second case. Patch by Martin Probst. llvm-svn: 239462
* clang-format: [JS] Let fat arrows have 'Assignment' precedence.Daniel Jasper2015-06-051-1/+8
| | | | | | | | | | | | | | | | | This is a more correct representation than using "Equality" introduced in r238942 which was a quick fix to solve an actual regression. According to the typescript spec, arrows behave like "low-precedence" assignments. Before: var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) && aaaaaaaaaaaaaaaaaaaaa(bbbbbbb)); After: var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) && aaaaaaaaaaaaaaaaaaaaa(bbbbbbb)); llvm-svn: 239137
* clang-format: [JS] Let fat arrows have 'Equality' precedence.Daniel Jasper2015-06-031-0/+6
| | | | | | | | | | | | | | | | | | | | | | | This fixes a regression in literal formatting: Before: aaaaaaaaaaaaa = { aaaaaaaaaaaaaaaaaaaaaaaaaaaa: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) => aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, }; After: var aaaaaaaaaaaaaaaaaaaa = { aaaaaaaaaaaaaaaaaaaaaaaaaaaa: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) => aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, }; Also apply no-else-after-return policy. llvm-svn: 238942
* clang-format: [JS] More aggressively keep array literals on one line.Daniel Jasper2015-06-031-4/+3
| | | | | | | | | | | | | | Before: var aaaaa: List<SomeThing> = [ new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB() ]; After: var aaaaa: List<SomeThing> = [new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB()]; llvm-svn: 238909
* clang-format: [JS] Fix bug in type colon detection.Daniel Jasper2015-06-031-0/+9
| | | | | | | | | | | | | Before, this couldn't be formatted at all: class X { subs = { 'b': { 'c': 1, }, }; } llvm-svn: 238907
* clang-format: [JS] Always add space after fat arrow.Daniel Jasper2015-06-021-0/+1
| | | | | | | | | | Before: return () =>[]; After: return () => []; llvm-svn: 238875
* clang-format: [JS] Array literal detection fix #4.Daniel Jasper2015-06-021-0/+5
| | | | llvm-svn: 238873
* clang-format: Don't try to detect C++ lambdas in other languages.Daniel Jasper2015-06-021-0/+2
| | | | llvm-svn: 238845
* clang-format: [JS] Fix incorrect line length calculation.Daniel Jasper2015-06-021-1/+2
| | | | llvm-svn: 238841
* clang-format: [JS] Array literal detection fix #3.Daniel Jasper2015-06-021-0/+3
| | | | llvm-svn: 238839
* clang-format: [JS] Fix another regression when detecting array literals.Daniel Jasper2015-06-021-0/+5
| | | | llvm-svn: 238835
* clang-format: [JS] Fix regression of detecting array literals.Daniel Jasper2015-06-021-0/+5
| | | | llvm-svn: 238832
* clang-format: [JS] Making arrow function wrapping more consistent.Daniel Jasper2015-06-011-1/+16
| | | | | | | | | | | | | | | | | | | | | | Before: someFunction(() => { doSomething(); // break }) .doSomethingElse( // break ); After: someFunction(() => { doSomething(); // break }) .doSomethingElse( // break ); This is still bad, but at least it is consistent with what we do for other function literals. Added corresponding tests. llvm-svn: 238736
* clang-format: [JS] Fix line breaks in computed property names.Daniel Jasper2015-05-311-0/+3
| | | | | | | | | | | | | | | | | | | Before: let foo = { [someLongKeyHere]: 1, someOtherLongKeyHere: 2, [keyLongEnoughToWrap]: 3, lastLongKey: 4 }; After: let foo = { [someLongKeyHere]: 1, someOtherLongKeyHere: 2, [keyLongEnoughToWrap]: 3, lastLongKey: 4 }; llvm-svn: 238671
* clang-format: [JS] Support ES6 computed property names.Daniel Jasper2015-05-291-0/+5
| | | | | | | | | | | | | | | | Before: var x = { [a]: 1, b: 2 }; After: var x = { [a]: 1, b: 2 }; llvm-svn: 238544
* clang-format: Lower binding strengths created by the [] created by ObjCDaniel Jasper2015-05-281-0/+7
| | | | | | | | | | | | | | | | | | method expressions and array literals. They should not bind stronger than regular parentheses or the braces of braced lists. Specific test case in JavaScript: Before: var aaaaa: List< SomeThing> = [new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB()]; After: var aaaaa: List<SomeThing> = [ new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB() ]; llvm-svn: 238400
* clang-format: [JS] Fix incorrect detection of ternary expressions.Daniel Jasper2015-05-271-0/+7
| | | | | | | | | | | | | A definintion like this could not be formatted at all: constructor({aa}: { aa?: string, aaaaaaaa?: string, aaaaaaaaaaaaaaa?: boolean, aaaaaa?: List<string> }) { } llvm-svn: 238291
* clang-format: [JS] Support ES6 spread operator.Daniel Jasper2015-05-261-0/+4
| | | | | | | | | | | | | | Specifically, don't add a space before it. Before: someFunction(... a); var x = [1, 2, ... a]; After: someFunction(...a); var x = [1, 2, ...a]; llvm-svn: 238183
* clang-format: [JS] Better support for fat arrows.Manuel Klimek2015-05-211-1/+24
| | | | | | | | | | | | Assigns a token type (TT_JsFatArrow) to => tokens, and uses that to more easily recognize and format fat arrow functions. Improves function parsing to better recognize formal parameter lists and return type declarations. Recognizes arrow functions and parse function bodies as child blocks. Patch by Martin Probst. llvm-svn: 237895
* clang-format: [JS] Parse exported functions as free-standing.Daniel Jasper2015-05-111-0/+6
| | | | | | | | | | | | | Before: export function foo() {} export function bar() {} After: export function foo() { } export function bar() { } llvm-svn: 236978
* clang-format: [JS] Avoid bad line-warp around "function".Daniel Jasper2015-05-081-0/+6
| | | | | | | | | | | | | | | | | | | | Before: someLooooooooongFunction( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, function( aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) { // code }); After: someLooooooooongFunction( aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, function(aaaaaaaaaaaaaaaaaaaaaaaaaaaaa) { // code }); llvm-svn: 236813
* clang-format: [JS] Fix regex literal detection.Daniel Jasper2015-05-081-0/+1
| | | | | | | | | | Before: var regex = /= / ; After: var regex = /=/; llvm-svn: 236811
* clang-format: [JS] support optional methods.Daniel Jasper2015-05-051-0/+4
| | | | | | | | | | | | | | | Optional methods use ? tokens like this: interface X { y?(): z; } It seems easiest to detect and disambiguate these from ternary expressions by checking if the code is in a declaration context. Turns out that that didn't quite work properly for interfaces in Java and JS, and for JS file root contexts. Patch by Martin Probst, thank you. llvm-svn: 236488
* clang-format: [JS] Do not collapse short interfaces.Daniel Jasper2015-05-051-0/+6
| | | | | | Patch by Martin Probst. llvm-svn: 236485
* clang-format: [JS] Fix calculation of template string width.Daniel Jasper2015-05-021-0/+6
| | | | | | | | | | OriginalColumn might not be set, so fall back to Location and SourceMgr in case it is missing. Also initialize end column in case the token is multi line, but it's the ` token itself that starts the multi line. Patch by Martin Probst, thank you! llvm-svn: 236383
* clang-format: [JS] Fix templated parameter default values.Daniel Jasper2015-05-021-0/+2
| | | | | | | | | | Parameters can have templated types and default values (= ...), which is another location in which a template closer should be followed by whitespace. Patch by Martin Probst, thank you. llvm-svn: 236382
* clang-format: [JS] handle comments in template strings.Daniel Jasper2015-04-161-0/+27
| | | | | | Patch by Martin Probst. Thank you. llvm-svn: 235078
* clang-format: [JS] Support index signature types.Daniel Jasper2015-04-131-0/+4
| | | | | | Patch by Martin Probst. llvm-svn: 234754
* clang-format: [JS] support optionality markers in JS types.Daniel Jasper2015-04-131-0/+8
| | | | | | Patch by Martin Probst. Thank you. llvm-svn: 234753
* clang-format: [JS] Allow periods and commata in class declarations.Daniel Jasper2015-04-131-0/+1
| | | | | | Patch by Martin Probst. Thank you. llvm-svn: 234752
* clang-format: Improve nested block formatting.Daniel Jasper2015-04-071-4/+3
| | | | | | | | | | | | | | | | | | Before: functionA(functionB({ int i; int j; }), aaaa, bbbb, cccc); After: functionA(functionB({ int i; int j; }), aaaa, bbbb, cccc); llvm-svn: 234304
* clang-format: [JS] Understand object literals with only methods.Daniel Jasper2015-04-041-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | Before: let theObject = {someMethodName() { doTheThing(); doTheOtherThing(); }, someOtherMethodName() { doSomething(); doSomethingElse(); }}; After: let theObject = { someMethodName() { doTheThing(); doTheOtherThing(); }, someOtherMethodName() { doSomething(); doSomethingElse(); } }; llvm-svn: 234091
* clang-format: [JS] Support getters, setters and methods in object literals.Daniel Jasper2015-03-311-0/+21
| | | | llvm-svn: 233698
* clang-format: [JS] Fix comment formatting in goog.scopes.Daniel Jasper2015-03-301-0/+5
| | | | | | | | | | | | | | | | | | Before: goog.scope(function() { // test var x = 0; // test }); After: goog.scope(function() { // test var x = 0; // test }); llvm-svn: 233530
* clang-format: [JS] support cast syntax and type arguments.Daniel Jasper2015-03-151-0/+12
| | | | | | | | | Casts in TS syntax (foo = <type>bar;) should not be followed by whitespace. Patch by Martin Probst. Thank you. llvm-svn: 232321
* clang-format: [JS] more precisely detect enums.Daniel Jasper2015-03-151-5/+8
| | | | | | | | | | | | The current enum detection is overly aggressive. As NestingLevel only applies per line (?) it classifies many if not most object literals as enum declarations and adds superfluous line breaks into them. This change narrows the heuristic by requiring an assignment just before the open brace and requiring the line to start with an identifier. Patch by Martin Probst. Thank you. llvm-svn: 232320
* clang-format: [js] Support template strings.Daniel Jasper2015-02-201-0/+41
| | | | | | | | | Merge template strings (marked by backticks ``). Do not format any contents of template strings. Patch by Martin Probst. Thank you. llvm-svn: 230011
* clang-format: [js] Support ES6 module exports.Daniel Jasper2015-02-191-1/+22
| | | | | | Patch by Martin Probst, thank you! llvm-svn: 229865
* clang-format: [js] Support ES6 module imports.Daniel Jasper2015-02-191-0/+26
| | | | | | Patch by Martin Probst. llvm-svn: 229863
* clang-format: [js] Do not fall through for JS structural elements.Daniel Jasper2015-02-191-0/+2
| | | | | | Patch by Martin Probst. Thank you. llvm-svn: 229862
* clang-format: [JS] support AtScript style annotations for JS.Daniel Jasper2015-02-181-0/+13
| | | | | | | | Based on Java annotation support and style. Patch by Martin Probst. llvm-svn: 229703
* clang-format: [JS] Support classes.Daniel Jasper2015-02-181-0/+10
| | | | | | | | | | This adds support for JavaScript class definitions (again following TypeScript & AtScript style). This only required support for visibility modifiers in JS, everything else was already working. Patch by Martin Probst, thank you. llvm-svn: 229701
* clang-format: [JS] Support type annotations.Daniel Jasper2015-02-181-0/+10
| | | | | | | | | | This patch adds support for type annotations that follow TypeScript's, Flow's, and AtScript's syntax style. Patch by Martin Probst, thank you. Review: http://reviews.llvm.org/D7721 llvm-svn: 229700
* clang-format: Fix incorrect calculation of token lenghts.Daniel Jasper2014-12-171-0/+2
| | | | | | This led, e.g. to break JavaScript regex literals too early. llvm-svn: 224419
* clang-format: Revamp nested block formatting.Daniel Jasper2014-12-121-4/+28
| | | | | | | | | | | | | | | | | | | | | | This fixed llvm.org/PR21804 and hopefully a few other strange cases. Before: if (blah_blah(whatever, whatever, [] { doo_dah(); doo_dah(); })) { } } After: if (blah_blah(whatever, whatever, [] { doo_dah(); doo_dah(); })) { } } llvm-svn: 224112
* clang-format: [JS] Don't put top-level dict literals on a single line.Daniel Jasper2014-12-041-9/+12
| | | | | | | These are often used for enums which apparently are easier to read if formatted with one element per line. llvm-svn: 223367
* clang-format: [JS] Contract fewer functions to a single line.Daniel Jasper2014-11-271-0/+5
| | | | | | | | | | | | | Before: var someVariable = function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); }; After: var someVariable = function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); }; llvm-svn: 222893
* clang-format: [JS] Try not to break in container literals.Daniel Jasper2014-11-271-0/+5
| | | | | | | | | | | | | | | | | Before: var obj = { fooooooooo: function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); } }; After: var obj = { fooooooooo: function(x) { return x.zIsTooLongForOneLineWithTheDeclarationLine(); } }; llvm-svn: 222892
* clang-format: [JS] new and delete are valid function names.Daniel Jasper2014-11-271-0/+2
| | | | | | | | | | | | Before: someObject.new (); someObject.delete (); After: someObject.new(); someObject.delete(); llvm-svn: 222890
* clang-format: [JS] Make Closure module detection more narrow.Daniel Jasper2014-11-271-0/+5
| | | | | | | | | | | Before: var MyLongClassName = goog.module.get('my.long.module.name.followedBy.MyLongClassName'); After: var MyLongClassName = goog.module.get('my.long.module.name.followedBy.MyLongClassName'); llvm-svn: 222888
OpenPOWER on IntegriCloud