summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestJS.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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
* clang-format: [JS] Support Closure's module statements.Daniel Jasper2014-11-231-0/+11
| | | | | | | These are like import statements and should not be line-wrapped. Minor restructuring of the handling of other import statements. llvm-svn: 222637
* Revert "clang-format: [js] Updates to Google's JavaScript style."Daniel Jasper2014-11-051-15/+18
| | | | | | | | This reverts commit eefd2eaad43c5c2b17953ae7ed1e72b28e696f7b. Apparently, this change was a bit premature. llvm-svn: 221365
* clang-format: [js] Updates to Google's JavaScript style.Daniel Jasper2014-10-311-18/+15
| | | | | | The style guide is changing.. llvm-svn: 220977
* clang-format: [JS] Support more regex literals.Daniel Jasper2014-10-291-0/+4
| | | | | | | | | | Previously a regex-literal containing "/*" would through clang-format off, e.g.: var regex = /\/*$/; Would lead to none of the following code to be formatted. llvm-svn: 220860
* clang-format: [JS] Support AllowShortFunctionsOnASingleLine.Daniel Jasper2014-09-301-3/+65
| | | | | | | | | Specifically, this also counts for stuff like (with style "inline"): var x = function() { return 1; }; llvm-svn: 218689
* clang-format: [JS] Improve formatting of function literals in chainsDaniel Jasper2014-09-291-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | Before: getSomeLongPromise(.....) .then( function(value) { body(); body(); }) .thenCatch(function(error) { body(); body(); }); After: getSomeLongPromise(.....) .then(function(value) { body(); body(); }) .thenCatch(function(error) { body(); body(); }); llvm-svn: 218595
* clang-format: [JS] add space before operator 'in'.Daniel Jasper2014-09-191-0/+1
| | | | | | | | | | Before: return ('aaa')in bbbb; After: return ('aaa') in bbbb; llvm-svn: 218119
* clang-format: [JS] Support regex literals with trailing escaped slash.Daniel Jasper2014-09-091-0/+2
| | | | | | | | | | | | | | | | | | Before: var regex = / a\//; int i; After: var regex = /a\//; int i; This required pushing the Lexer into its wrapper class and generating a new one in this specific case. Otherwise, the sequence get lexed as a //-comment. This is hacky, but I don't know a better way (short of supporting regex literals in the Lexer). Pushing the Lexer down seems to make all the call sites simpler. llvm-svn: 217444
* clang-format: [JS] Format embedded function literals more efficently.Daniel Jasper2014-09-051-8/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: return { a: a, link: function() { f(); // }, link: function() { f(); // } }; After: return { a: a, link: function() { f(); // }, link: function() { f(); // } }; llvm-svn: 217238
* clang-format: [JS] JavaScript does not have the */&/&& madness.Daniel Jasper2014-09-051-0/+4
| | | | | | | | | | | | | Before: e&& e.SomeFunction(); After: e && e.SomeFunction(); Yeah, this might be useful for C++, too, but it is not such a frequent pattern there (plus the fix is much harder). llvm-svn: 217237
* clang-format: [JS] Better support for empty function literals.Daniel Jasper2014-09-051-0/+1
| | | | | | | | | | Before: SomeFunction(function(){}); After: SomeFunction(function() {}); llvm-svn: 217236
* clang-format: [JS] Fix indentation in dict literals.Daniel Jasper2014-09-051-0/+5
| | | | | | | | | | | | | | | | | | Before: return { 'finish': // a }; After: return { 'finish': // a }; llvm-svn: 217235
* clang-format: [JS] Support alternative operator names as identifiers.Daniel Jasper2014-09-041-0/+4
| | | | | | | | | | Before: not. and . or . not_eq = 1; After: not.and.or.not_eq = 1; llvm-svn: 217179
* clang-format: [JS] Supprot "catch" as function name.Daniel Jasper2014-09-041-0/+3
| | | | | | | | | | Before: someObject.catch (); After: someObject.catch(); llvm-svn: 217158
* clang-format: [JS] Support comments in dict literals.Daniel Jasper2014-09-041-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | Before: var stuff = { // comment for update update : false, // comment for update modules : false, // comment for update tasks : false }; After: var stuff = { // comment for update update : false, // comment for update modules : false, // comment for update tasks : false }; llvm-svn: 217157
* clang-format: [JS] support free-standing functions again.Daniel Jasper2014-06-301-0/+11
| | | | | | | | | | | | | | | | | | | | | | | This worked initially but was broken by r210887. Before: function outer1(a, b) { function inner1(a, b) { return a; } inner1(a, b); } function outer2(a, b) { function inner2(a, b) { return a; } inner2(a, b); } After: function outer1(a, b) { function inner1(a, b) { return a; } inner1(a, b); } function outer2(a, b) { function inner2(a, b) { return a; } inner2(a, b); } Thanks to Adam Strzelecki for working on this. llvm-svn: 212038
* clang-format: [JS] Understand named function literals.Daniel Jasper2014-06-131-1/+8
| | | | | | | | | | | | | | | | | | | Before: return {a: function SomeFunction(){// ... return 1; } } ; After: return { a: function SomeFunction() { // ... return 1; } }; llvm-svn: 210887
* clang-format: [JS] Treat dict literals similar to objc method exprs.Daniel Jasper2014-06-101-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before: return { link: function() { f(); // } }; return { a: a, link: function() { f(); // } } After: return { link: function() { f(); // } }; return { a: a, link: function() { f(); // } }; llvm-svn: 210537
* clang-format: Fix incorrect indentation.Daniel Jasper2014-06-061-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | Before (JavaScript example, but can extend to other languages): return { a: 'E', b: function() { return function() { f(); // This is wrong. }; } }; After: return { a: 'E', b: function() { return function() { f(); // This is better. }; } }; llvm-svn: 210334
* clang-format: Refactor indentation behavior for multiple nested blocks.Daniel Jasper2014-06-031-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a few oddities when formatting multiple nested JavaScript blocks, e.g.: Before: promise.then( function success() { doFoo(); doBar(); }, [], function error() { doFoo(); doBaz(); }); promise.then([], function success() { doFoo(); doBar(); }, function error() { doFoo(); doBaz(); }); After: promise.then( function success() { doFoo(); doBar(); }, [], function error() { doFoo(); doBaz(); }); promise.then([], function success() { doFoo(); doBar(); }, function error() { doFoo(); doBaz(); }); llvm-svn: 210097
* clang-format: [JS] Understand line breaks in concatenated strings.Daniel Jasper2014-05-221-0/+5
| | | | | | | | | | | | | | Before: var literal = 'hello ' + 'world'; After: var literal = 'hello ' + 'world'; There is no reason to concatenated two string literals with a '+' unless the line break is intended. llvm-svn: 209413
* clang-format: Correctly calculate line lenghts for nest blocks.Daniel Jasper2014-05-221-0/+7
| | | | | | | | | | | | | | | If simple (one-statement) blocks can be inlined, the length needs to be calculated correctly. Before (in JavaScript but this also affects lambdas, etc.): var x = { valueOf: function() { return 1; } }; After: var x = {valueOf: function() { return 1; }}; llvm-svn: 209410
* clang-format: Fix corner case working around one-per-line dict literals.Daniel Jasper2014-05-211-0/+5
| | | | | | | | | | | | | | | Before: var object_literal_with_long_name = { a: 'aaaaaaaaaaaaaaaaaa', b: 'bbbbbbbbbbbbbbbbbb' }; After: var object_literal_with_long_name = { a: 'aaaaaaaaaaaaaaaaaa', b: 'bbbbbbbbbbbbbbbbbb' }; llvm-svn: 209296
* clang-format: [JS] Support different function literal style.Daniel Jasper2014-05-211-0/+12
| | | | | | | | | | | | | | | | | Before: goog.array.forEach(array, function() { doSomething(); doSomething(); }, this); After: goog.array.forEach(array, function() { doSomething(); doSomething(); }, this); llvm-svn: 209291
* clang-format: [JS] Understand top-level function literals properly.Daniel Jasper2014-05-201-1/+5
| | | | llvm-svn: 209205
* clang-format: [JS] Support ES6 destructuring assignments.Daniel Jasper2014-05-191-0/+5
| | | | | | | | | | Before: var[a, b, c] = [1, 2, 3]; After: var [a, b, c] = [1, 2, 3]; llvm-svn: 209113
* clang-format: [JS] Support for EC6 arrow functions.Daniel Jasper2014-05-191-0/+2
| | | | | | | | | | Before: var b = a.map((x) = > x + 1); After: var b = a.map((x) => x + 1); llvm-svn: 209112
* clang-format: [JS] Basic support for escape sequences in regex literals.Daniel Jasper2014-05-121-0/+3
| | | | | | | | | | Before: var regex = /\\/ g; // This isn't even recognized as regex. After: var regex = /\\/g; // It now is. llvm-svn: 208539
* clang-format: [JS] Fix spacing in dict literals.Daniel Jasper2014-05-091-0/+1
| | | | | | | | | | Before: someVariable = {'a':[{}]}; After: someVariable = {'a': [{}]}; llvm-svn: 208403
* clang-format: Initial support for try-catch.Daniel Jasper2014-05-081-0/+10
| | | | | | | | | | Most of this patch was created by Alexander Rojas in http://reviews.llvm.org/D2555 Thank you! Synced and addressed review comments. llvm-svn: 208302
* clang-format: [JS] support closures in container literals.Daniel Jasper2014-05-081-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | Before: return {body: {setAttribute: function(key, val) {this[key] = val; } , getAttribute : function(key) { return this[key]; } , style : { direction: '' } } } ; After: return { body: { setAttribute: function(key, val) { this[key] = val; }, getAttribute: function(key) { return this[key]; }, style: {direction: ''} } }; llvm-svn: 208292
* clang-format: [JS] Support regex literals after 'return'.Daniel Jasper2014-05-081-0/+2
| | | | llvm-svn: 208285
* clang-format: [JS] Initial support for regex literals.Daniel Jasper2014-05-081-0/+70
| | | | llvm-svn: 208281
* clang-format: Be slightly more aggressive on single-line functions.Daniel Jasper2014-05-071-0/+5
| | | | | | | | | | | | | | So that JS functions can also be merged into a single line. Before: var func = function() { return 1; }; After: var func = function() { return 1; }; llvm-svn: 208176
OpenPOWER on IntegriCloud