summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestJS.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: [JS] Optionally re-quote string literals.Daniel Jasper2016-03-021-2/+33
| | | | | | | | | | | | | | | | | | | | | Turns "foo" into 'foo' (or vice versa, depending on configuration). This makes it more convenient to follow the Google JavaScript style guide: https://google.github.io/styleguide/javascriptguide.xml?showone=Strings#Strings This functionality is behind the option "JavaScriptQuotes", which can be: * "leave" (no re-quoting) * "single" (change to single quotes) * "double" (change to double quotes) This also changes single quoted JavaScript string literals to be treated as tok::string_literal, not tok::char_literal, which fixes two unrelated tests. Patch by Martin Probst. Thank you. llvm-svn: 262534
* clang-format: [JS] Support quoted object literal keys.Daniel Jasper2016-03-011-0/+7
| | | | | | | | | | | | | | | | | Before: var x = { a: a, b: b, 'c': c, }; After: var x = { a: a, b: b, 'c': c, }; llvm-svn: 262291
* clang-format: [JS] treat forwardDeclare as an import/export statement.Daniel Jasper2016-02-221-0/+2
| | | | | | Patch by Martin Probst. Thank you. llvm-svn: 261528
* clang-format: [JS] Support for (.. of ..) loops.Daniel Jasper2016-02-111-0/+3
| | | | | | | | | | Before: for (var i of[2, 3]) {} After: for (var i of [2, 3]) {} llvm-svn: 260518
* clang-format: [JS] Don't count shortened object literals as blocks.Daniel Jasper2016-02-071-0/+5
| | | | | | | | | | | | | | | Before: f({a}, () => { g(); // }); After: f({a}, () => { g(); // }); llvm-svn: 260060
* clang-format: [JS/TypeScript] Support "enum" as an optional property name, too.Daniel Jasper2016-02-031-0/+1
| | | | | | | | | | | Before: enum?: string []; After: enum?: string[]; llvm-svn: 259628
* clang-format: [JS] Treat "in" as a proper operator.Daniel Jasper2016-02-011-0/+11
| | | | llvm-svn: 259350
* clang-format: [JS] Fix incorrect line break leading to semicolon insertion.Daniel Jasper2016-01-141-0/+4
| | | | | | | | | | | | | | | | clang-format only works for JavaScript code, if all the semicolons are present anyway, so this linebreak can never be desired. Before (with appropriate statement lengths or column limit): return [ aaa ]; After: return [ aaaa ]; llvm-svn: 257741
* clang-format: [ObjC+JS] Allow bin-packing of array literals.Daniel Jasper2016-01-131-9/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After reading the style guides again, they don't actually say how to pack or not pack array literals. Based on some user reports, array initializers can unnecessarily get quite long if they contain many small elements. Array literals with trailing commas are still formatted one per line so that users have a way to opt out of the packing. Before: var array = [ aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa ]; After: var array = [ aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa, aaaaaa ]; llvm-svn: 257615
* clang-format: [JS] Support exporting abstract classes.Daniel Jasper2016-01-121-0/+1
| | | | | | | | | | | Before: export abstract class X {y: number;} (and all sorts of other havoc in more complicated cases). After: export abstract class X { y: number; } llvm-svn: 257451
* clang-format: [JS] Teach clang-format about "export interface".Daniel Jasper2016-01-111-0/+4
| | | | llvm-svn: 257406
* clang-format: [JS] Improve line-flow when calling functions on array literals.Daniel Jasper2016-01-111-0/+6
| | | | | | | | | | | | | | | | | | | Before: return [ aaaaaaaaaaaaaaaaaaaaaa ].aaaaaaa(function() { // }) .bbbbbb(); After: return [aaaaaaaaaaaaaaaaaaaaaa] .aaaaaaa(function() { // }) .bbbbbb(); llvm-svn: 257324
* clang-format: Fix the counting of leading whitespace in tok::unknown tokensDaniel Jasper2016-01-091-0/+3
| | | | | | | | Previously, all whitespace characters would increase the starting column, which doesn't make sense. This fixes a problem, e.g. with the length calculation in JS template strings. llvm-svn: 257267
* clang-format: [JS] Support semicolons in TypeScript's TypeMemberLists.Daniel Jasper2016-01-091-0/+8
| | | | | | | | | | | | | | Before: var x: { a: string; b: number; } = {}; After: var x: {a: string; b: number;} = {}; llvm-svn: 257255
* clang-format: [JS] Prefer wrapping before the TypeScript return typeDaniel Jasper2016-01-081-0/+3
| | | | | | | | | | | | | | over wrapping before parameters. Before: function someFunc( args: string[]): {longReturnValue: string[]} {} After: function someFunc(args: string[]): {longReturnValue: string[]} {} llvm-svn: 257162
* clang-format: [JS] Add some Closure Compiler JSDoc tags to the defaultDaniel Jasper2016-01-081-0/+10
| | | | | | Google configuration so that they aren't line-wrapped. llvm-svn: 257159
* clang-format: [JS] Support more ES6 classes.Daniel Jasper2016-01-081-0/+6
| | | | | | | | | | | | | | | Before: foo = class { constructor() {} } ; After: foo = class { constructor() {} }; llvm-svn: 257154
* clang-format: Fix corner case in one-per-line formatting.Daniel Jasper2016-01-071-0/+5
| | | | | | | | | | | | | | | | | | | Before (example is JS, but also applies to C++): return [ aaaa() .bbbbbbbb('A'), aaaa().bbbbbbbb('B'), aaaa().bbbbbbbb('C'), ]; After: return [ aaaa().bbbbbbbb('A'), aaaa().bbbbbbbb('B'), aaaa().bbbbbbbb('C'), ]; llvm-svn: 257079
* clang-format: [JS] Support more ES6 imports.Daniel Jasper2016-01-071-0/+1
| | | | | | | | | | | Before: import a, {X, Y} from 'some/module.js'; After: import a, {X, Y} from 'some/module.js'; llvm-svn: 257038
* clang-format: [JS] Support more ES6 default exports.Daniel Jasper2016-01-041-0/+1
| | | | llvm-svn: 256759
* clang-format: [JS] Support ES6 exports of array literals.Daniel Jasper2016-01-041-0/+5
| | | | | | | | | | | | | | | | Before: export default[aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb]; export default[]; After: export default [ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ]; export default []; llvm-svn: 256758
* clang-format: [JS] Improve empty array literal detection.Daniel Jasper2016-01-041-0/+2
| | | | | | | | | | | | | | | Previously, the [] in the following example were recognized as an array subscript leading to weird indentation. Before: var aaaa = aaaaa || // wrap []; After: var aaaa = aaaaa || // wrap []; llvm-svn: 256753
* clang-format: [JS] Support TypeScript 1.6 user defined type guards.Daniel Jasper2015-12-301-0/+8
| | | | | | | | | | | | | | | | Before: function foo(check: Object): check is{foo: string, bar: string, baz: string, foobar: string} { return 'bar' in check; } After: function foo(check: Object): check is {foo: string, bar: string, baz: string, foobar: string} { return 'bar' in check; } llvm-svn: 256631
* clang-format: [JS/TypeScript] Support "enum" as property name.Daniel Jasper2015-12-291-0/+1
| | | | | | | | | | | Before: enum: string []; After: enum: string[]; llvm-svn: 256546
* clang-format: [JS] Support arrays of object-type literals.Daniel Jasper2015-12-221-0/+5
| | | | | | | | | | | | | | | Before: interface I { o: {} []; } After: interface I { o: {}[]; } llvm-svn: 256247
* clang-format: [JS] Conservatively introduce column layout for JS arrayDaniel Jasper2015-12-221-0/+11
| | | | | | | | initializers. For now, only use it for 20 items or more. Otherwise, clang-format formats these one-per-line and thus increases the vertical code size a lot. llvm-svn: 256246
* clang-format: [JS] "operator" is not a keyword in Java/JavaScript.Daniel Jasper2015-12-221-0/+5
| | | | llvm-svn: 256245
* clang-format: [JS] Change Google-style default for aligning operands.Daniel Jasper2015-12-211-8/+8
| | | | | | The style guide allows both, but apparently, this is the more dominant use. llvm-svn: 256154
* clang-format: [JS] Make AllowShortFunctionsOnASingle line value "Empty"Daniel Jasper2015-11-201-0/+6
| | | | | | work properly. llvm-svn: 253674
* clang-format: [JS] Properly add a space after "in" in for loops.Daniel Jasper2015-11-201-0/+5
| | | | llvm-svn: 253672
* clang-format: [JS] struct and union aren't keywords / reserved words.Daniel Jasper2015-11-201-0/+2
| | | | llvm-svn: 253671
* clang-format: [JS] Add goog.setTestOnly to the list of stuff thatDaniel Jasper2015-10-291-0/+2
| | | | | | is import-statement-like and shouldn't be wrapped. llvm-svn: 251643
* clang-format: Add an additional value to AlignAfterOpenBracket: AlwaysBreak.Daniel Jasper2015-10-271-49/+63
| | | | | | | | | | | | | | | | | | | | Summary: If this option is set, clang-format will always insert a line wrap, e.g. before the first parameter of a function call unless all parameters fit on the same line. This obviates the need to make a decision on the alignment itself. Use this style for Google's JavaScript style and add some minor tweaks to correctly handle nested blocks etc. with it. Don't use this option for for/while loops. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D14104 llvm-svn: 251405
* clang-format: [JS] Handle string literals spanning character classes.Daniel Jasper2015-10-181-0/+10
| | | | | | | | | | | | | | | If a RegExp contains a character group with a quote (/["]/), the trailing end of it is first tokenized as a string literal, which leads to the merging code seeing an unbalanced bracket. This change parses regex literals from the left hand side. That simplifies the parsing code and also allows correctly handling escapes and character classes, hopefully correctly parsing all regex literals. Patch by Martin Probst, thank you. Review: http://reviews.llvm.org/D13765 llvm-svn: 250648
* clang-format: [JS] handle character classes in regexes.Daniel Jasper2015-10-121-0/+6
| | | | | | | | | Slashes in regular expressions do not need to be escaped and do not terminate the regular expression even without a preceding backslash. Patch by Martin Probst. Thank you. llvm-svn: 250009
* clang-format: [JS] Support pseudo-keywordsDaniel Jasper2015-09-281-0/+13
| | | | | | | | | JavaScript allows keywords to appear in IdenfierName positions, e.g. fields, or object literal members, but not as plain identifiers. Patch by Martin Probst. Thank you! llvm-svn: 248714
* clang-format: [JS] handle let (ES6)Daniel Jasper2015-09-281-0/+2
| | | | | | Patch by Martin Probst. Thank you! llvm-svn: 248713
* clang-format: [JS] Assign proper penalties when breaking a type annotationDaniel Jasper2015-07-101-0/+4
| | | | | | | | | | | | | | | | Before: class Test { aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {} } After: class Test { aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {} } llvm-svn: 241908
* clang-format: [JS] Properly reset parse state after parsing interface.Daniel Jasper2015-07-061-0/+4
| | | | llvm-svn: 241446
* clang-format: [JS] Prevent confusing TypeScript parameters wraps.Daniel Jasper2015-07-061-0/+3
| | | | | | | | | | | | | Before: aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {} After: aaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {} llvm-svn: 241444
* clang-format: [JS] Allow line breaks after TypeScript type colons.Daniel Jasper2015-07-031-0/+2
| | | | llvm-svn: 241339
* clang-format: [JS] Treat regex literals like string literals.Daniel Jasper2015-07-021-0/+4
| | | | | | | Using the token type "unknown" can interfere badly with WhitespaceManager's way of handling multiline comments. llvm-svn: 241273
* clang-format: [JS] Skip comments when applying the regex-literal heuristicDaniel Jasper2015-07-021-0/+2
| | | | llvm-svn: 241264
* clang-format: [JS] Fix bug in regex literal parsing.Daniel Jasper2015-07-021-0/+1
| | | | | | The lexer wasn't properly reset leading to unexpected deletions. llvm-svn: 241262
* clang-format: [JS] Support regex literals at the start of a file.Daniel Jasper2015-07-021-0/+1
| | | | llvm-svn: 241259
* clang-format: [JS] Fix character counting in template strings.Daniel Jasper2015-07-021-7/+7
| | | | | | | Some counts were off, we don't need to take the leading newlines of the first ` into account and some tests were just wrong. llvm-svn: 241257
* clang-format: [JS] Support regex literals containing quotes (' and ").Daniel Jasper2015-06-241-0/+6
| | | | llvm-svn: 240548
* Revert r240270 ("Fixed/added namespace ending comments using clang-tidy").Alexander Kornienko2015-06-221-1/+1
| | | | llvm-svn: 240353
* Fixed/added namespace ending comments using clang-tidy. NFCAlexander Kornienko2015-06-221-1/+1
| | | | | | | | | | | | The patch is generated using this command: $ tools/extra/clang-tidy/tool/run-clang-tidy.py -fix \ -checks=-*,llvm-namespace-comment -header-filter='llvm/.*|clang/.*' \ work/llvm/tools/clang To reduce churn, not touching namespaces spanning less than 10 lines. llvm-svn: 240270
* clang-format: [JS] Add a special case for indenting function literals.Daniel Jasper2015-06-181-0/+4
| | | | | | | | | | | | | | | | | | | | Before: var func = function() { doSomething(); }; After: var func = function() { doSomething(); }; This is a very narrow special case which fixes most of the discrepency with what our users do. In the long run, we should try to come up with a more generic fix for indenting these. llvm-svn: 240014
OpenPOWER on IntegriCloud