summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTestJS.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* clang-format: [JS] Correctly format JavaScript imports with long module pathsMartin Probst2017-07-181-0/+11
| | | | | | | | | | | | | | | | | | | | | | | Currently the `UnwrappedLineParser` fails to correctly unwrap JavaScript imports where the module path is not on the same line as the `from` keyword. For example: import {A} from 'some/path/longer/than/column/limit/module.js';``` This causes issues when in the middle a list of imports because the formatter thinks it has reached the end of the imports, and therefore will not sort any imports lower in the list. The formatter will, however, split the `from` keyword and the module path if the path exceeds the column limit, which triggers the issue the next time the file is formatted. Patch originally by Jared Neil - thanks! Differential Revision: https://reviews.llvm.org/D34920 llvm-svn: 308306
* clang-format: [JS] do not wrap after "readonly".Martin Probst2017-07-071-0/+8
| | | | | | | | | | | | | | Summary: Breaks after "readonly" trigger automatic semicolon insertion in field declarations. Reviewers: krasimir, djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D35112 llvm-svn: 307394
* clang-format: [JS] space between pseudo keywords and template literals.Martin Probst2017-07-041-0/+1
| | | | | | | | | | | | | | | | | | | | Summary: Before: yield`foo`; After: yield `foo`; This reinstates commit 71d3b5cd91 / r307023 and fixes the logic by introducing an explicit table of JavaScript pseudo keywords. Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D34953 llvm-svn: 307087
* Revert "clang-format: [JS] space between pseudo keywords and template literals."Martin Probst2017-07-031-1/+0
| | | | | | This reverts commit 71d3b5cd916106005ef23467e3f6c7fbca7bc499. llvm-svn: 307034
* clang-format: [JS] space between pseudo keywords and template literals.Martin Probst2017-07-031-0/+1
| | | | | | | | | | | | | | | | | Summary: Before: yield`foo`; After: yield `foo`; Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D34938 llvm-svn: 307023
* clang-format: [JS] recognize exported type definitions.Martin Probst2017-06-071-0/+6
| | | | | | | | | | Summary: Support "export type T = {...};", in addition to just "type T = {...};". Reviewers: klimek Differential Revision: https://reviews.llvm.org/D33980 llvm-svn: 304904
* clang-format: [JS] Correctly Indent Nested JavaScript Literals.Martin Probst2017-06-061-0/+39
| | | | | | | | | | | | | | | | | Nested literals are sometimes only indented by 2 spaces, instead of respecting the IndentWidth option. There are existing unit tests (FormatTestJS.ArrayLiterals) that only pass because the style used to test them uses an IndentWidth of 2. This change removes the magic 2 and always uses the IndentWidth. I've added 6 tests. The first 4 of these tests fail before this change, while the last 2 already pass, but were added just to make sure it the change works with all types of braces. Patch originally by Jared Neil, thanks! Differential Revision: https://reviews.llvm.org/D33857 llvm-svn: 304791
* clang-format: [JS] improve calculateBraceType heuristicMartin Probst2017-05-311-3/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: calculateBraceTypes decides for braced init for empty brace pairs ({}). In context of a function declaration, this incorrectly classifies empty function or method bodies as braced inits, leading to missing wraps: class C { foo() {}[bar]() {} } Where code should have wrapped after "}", before "[". This change adds another piece of contextual information in that braces following closing parentheses must always be the opening braces of function blocks. This fixes brace detection for methods immediately followed by brackets (computed property declarations), but also curlies. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33714 llvm-svn: 304290
* clang-format: [JS] fix indenting bound functions.Martin Probst2017-05-291-0/+5
| | | | | | | | | | | | | | | | Summary: The previous fix to force build style wrapping if the previous token is a closing parenthesis broke a peculiar pattern where users parenthesize the function declaration in a bind call: fn((function() { ... }).bind(this)); This restores the previous behaviour by reverting that change, but narrowing the special case for unindenting closing parentheses to those followed by semicolons and opening braces, i.e. immediate calls and function declarations. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D33640 llvm-svn: 304135
* clang-format: [JS] avoid line breaks before unindented r_parens.Martin Probst2017-05-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The change that enabled wrapping at the previous scope's indentation had unintended side-effects in that clang-format would prefer to wrap closing parentheses to the next line if it avoided a wrap on the next line (assuming very narrow lines): fooObject .someCall(barbazbam) .then(bam); Would get formatted as: fooObject.someCall(barbazbam ).then(bam); Because the ')' is now indented at the parent level (fooObject). Normally formatting a builder pattern style call sequence like that is outlawed in clang-format anyway. However for JavaScript this is special cased to support trailing .bind calls. This change disallows this special case when following a closing ')' to avoid the problem. Included are some random comment fixes. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33399 llvm-svn: 303557
* clang-format: [JS] for await, and fix a crash with for loops.Martin Probst2017-05-181-3/+2
| | | | | | | | | | | | | | Summary: The syntax is actually `for await (const x of y)` (d'oh). This also fixes a crash for `for` tokens not followed by additional tokens. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D33329 llvm-svn: 303382
* clang-format: [JS] for async loops.Martin Probst2017-05-151-0/+9
| | | | | | | | | | | | | | | Summary: JavaScript supports asynchronous loop iteration in async functions: for async (const x of y) ... Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D33193 llvm-svn: 303106
* JavaScript allows parameter lists to include trailing commas:Martin Probst2017-05-151-2/+26
| | | | | | | | | | | | | | | | | | | myFunction(param1, param2,); For symmetry with other parenthesized lists ([...], {...}), clang-format should wrap parenthesized lists one-per-line if they contain a trailing comma: myFunction( param1, param2, ); This is particularly useful in function declarations or calls with many arguments, e.g. commonly in constructors. Differential Revision: https://reviews.llvm.org/D33023 llvm-svn: 303049
* clang-format: [JS] fix non-null assertion operator recognition.Martin Probst2017-05-151-0/+1
| | | | | | | | | | | | | | | | | Summary: `getIdentifierInfo()` includes all keywords, whereas non-null assertion operators should only be recognized after non-keywords or pseudo keywords. Ideally this should list all tokens that clang-format recognizes as a keyword, but that are pseudo or no keywords in JS. For the time being, just recognize the specific bits users ran into (`namespace` in this case). Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33182 llvm-svn: 303038
* clang-format: [JS] support non-null assertions after all identifiers.Martin Probst2017-05-121-0/+1
| | | | | | | | | | | | | | | | | Summary: Previously: x = namespace !; Now: x = namespace!; Reviewers: djasper Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33113 llvm-svn: 302893
* clang-format: refine calculating brace types.Martin Probst2017-05-101-0/+10
| | | | | | | | | | | | | | | | | | Summary: For C++ code, opening parenthesis following a } indicate a braced init. For JavaScript and other languages, this is an invalid syntactical construct, unless the closing parenthesis belongs to a function - in which situation its a BK_Block. This fixes indenting IIFEs following top level functions: function foo() {} (function() { codeHere(); }()); clang-format used to collapse these lines together. Subscribers: klimek Differential Revision: https://reviews.llvm.org/D33006 llvm-svn: 302658
* clang-format: [JS] Don't indent JavaScript IIFEs.Martin Probst2017-05-091-0/+19
| | | | | | | | | | | | | | | | Because IIFEs[1] are often used like an anonymous namespace around large sections of JavaScript code, it's useful not to indent to them (which effectively reduces the column limit by the indent amount needlessly). It's also common for developers to wrap these around entire files or libraries. When adopting clang-format, changing the indent entire file can reduce the usefulness of the blame annotations. Patch by danbeam, thanks! Differential Revision: https://reviews.llvm.org/D32989 llvm-svn: 302580
* clang-format: [JS] keep triple slash directives intact.Martin Probst2017-05-091-0/+1
| | | | | | | | | | | | | | | | | | | Summary: TypeScript uses triple slash directives of the form: /// <reference path="..."/> For various non-source instructions that should not be wrapped. Reference: https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32997 llvm-svn: 302523
* clang-format: [JS] exponentiation operatorMartin Probst2017-05-041-0/+6
| | | | | | | | | | | | Summary: While its precedence should be higher than multiplicative, LLVM does not have a level for that, so for the time being just treat it as multiplicative. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32864 llvm-svn: 302156
* clang-format: [JS] parse async function declarations.Martin Probst2017-04-271-0/+17
| | | | | | | | | | | | | | | | | | | | | | | Summary: Previously, clang-format would accidentally parse an async function declaration as a function expression, and thus not insert an unwrapped line for async functions, causing subsequent functions to run into the function: async function f() { x(); } function g() { ... With this change, async functions get parsed as top level function declarations and get their own unwrapped line context. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32590 llvm-svn: 301538
* clang-format: [JS/Java] ignore Objective-C constructs in JS & Java.Martin Probst2017-04-261-0/+3
| | | | | | | | | | | | | | | | | | | | | | | Summary: Java and JavaScript support annotations and decorators, respectively, that use a leading "@" token. clang-format currently detects this as an Objective-C construct and applies special formatting, for example no whitespace around "=" operators. This change disables the distinction for Java and JavaScript, which leads to normal formatting of single line annotated and initialized properties. Before: class X { @foo() bar=false; } After: class X { @foo() bar = false; } Reviewers: djasper, bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32532 llvm-svn: 301399
* clang-format: [JS] prevent wraps before class members.Martin Probst2017-04-261-0/+19
| | | | | | | | | | | | Summary: In JavaScript/TypeScript, class member definitions that use modifiers can be subject to Automatic Semicolon Insertion (ASI). For example, "class X { get \n foo }" defines a property called "get" and a property called "foo", both with no type annotation. This change prevents wrapping after the modifier keywords (visibility modifiers, static, get and set) to prevent accidental ASI. Reviewers: djasper, bkramer Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D32531 llvm-svn: 301397
* [clang-format] Replace IncompleteFormat by a struct with LineKrasimir Georgiev2017-04-211-3/+3
| | | | | | | | | | | | | | Summary: This patch replaces the boolean IncompleteFormat that is used to notify the client if an unrecoverable syntax error occurred by a struct that also contains a line number. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D32298 llvm-svn: 300985
* clang-format: [JS] fix whitespace around "of" operator.Martin Probst2017-04-051-0/+2
| | | | | | | | | | | | | | | | | | | Summary: Previously: import {of } from 'x'; of (null); Now: import {of} from 'x'; of(null); Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D31698 llvm-svn: 299533
* clang-format: [JavaScript] Ignore QT keywords.Daniel Jasper2017-03-311-0/+2
| | | | llvm-svn: 299204
* clang-format: [JS] do not wrap @see tags.Martin Probst2017-03-131-0/+7
| | | | | | | | | | | | | | | Summary: @see is special among JSDoc tags in that it is commonly followed by URLs. The JSDoc spec suggests that users should wrap URLs in an additional {@link url...} tag (@see http://usejsdoc.org/tags-see.html), but this is very commonly violated, with @see being followed by a "naked" URL. This change special cases all JSDoc lines that contain an @see not to be wrapped to account for that. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D30883 llvm-svn: 297607
* clang-format: [JS] allow breaking after non-null assertions.Martin Probst2017-03-131-0/+6
| | | | | | | | | | | | | | | | Summary: Previously clang-format would not break after any !. However in TypeScript, ! can be used as a post fix operator for non-nullability: x.foo()!.bar()!; With this change, clang-format will wrap after the ! if it is likely a post-fix non null operator. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D30705 llvm-svn: 297606
* clang-format: [JS] do not wrap after interface and type.Martin Probst2017-03-131-0/+14
| | | | | | | | | | | | | | | | | | | | | Summary: `interface` and `type` are pseudo keywords and cause automatic semicolon insertion when followed by a line break: interface // gets parsed as a long variable access to "interface" VeryLongInterfaceName { } With this change, clang-format not longer wraps after `interface` or `type`. Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30874 llvm-svn: 297605
* [clang-format] Enable comment reflowing in multiline comments containing pragmasKrasimir Georgiev2017-03-081-1/+21
| | | | | | | | | | | | | | | | | Summary: This patch enables comment reflowing of lines not matching the comment pragma regex in multiline comments containing comment pragma lines. Previously, these comments were dumped without being reindented to the result. Reviewers: djasper, mprobst Reviewed By: mprobst Subscribers: klimek, mprobst, cfe-commits Differential Revision: https://reviews.llvm.org/D30697 llvm-svn: 297261
* clang-format: [JS] Properly format object literals with shorthands.Daniel Jasper2017-03-011-0/+5
| | | | | | | | | | | | | | | | | Before: return { a, b: 'b', c, }; After: return { a, b: 'b', c, }; llvm-svn: 296664
* clang-format: [JS/TS] Properly understand cast expressions.Daniel Jasper2017-03-011-0/+3
| | | | | | | | | | Many things were wrong: - We didn't always allow wrapping after "as", which can be necessary. - We used to Undestand the identifier after "as" as a start of a name. - We didn't properly parse the structure of the expression with "as" having the precedence of relational operators llvm-svn: 296659
* Blacklist arbitrary @\\w+ JSDoc tags from wrapping.Martin Probst2017-02-281-0/+24
| | | | | | | | | | | | | | | | | | | | Summary: Also limits the blacklisting to only apply when the tag is actually followed by a parameter in curly braces. /** @mods {long.type.must.not.wrap} */ vs /** @const this is a long description that may wrap. */ Reviewers: djasper Subscribers: klimek, krasimir, cfe-commits Differential Revision: https://reviews.llvm.org/D30452 llvm-svn: 296467
* clang-format: [JS] whitespace after async in arrow functions.Martin Probst2017-02-271-0/+2
| | | | | | | | | | | | | | | | | | | Summary: Async arrow functions should be marked with a whitespace after the async keyword, before the parameter list: x = async () => foo(); Before: x = async() => foo(); This makes it easier to tell apart an async arrow function from a call to a function called async. Reviewers: bkramer Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D30399 llvm-svn: 296330
* clang-format: [JS] Improve line-wrapping behavior of template strings.Daniel Jasper2017-02-201-36/+20
| | | | | | | | Specifically, similar to other blocks, clang-format now wraps both after "${" and before the corresponding "}", if the contained expression spans multiple lines. llvm-svn: 295663
* clang-format: [JS/TS] Improve detection for array subscripts in types.Daniel Jasper2017-02-201-0/+3
| | | | | | | | | | | | Before: var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[ ]).someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); After: var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[]) .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); llvm-svn: 295658
* clang-format: [JS] correcly format object literal methods.Martin Probst2017-02-071-0/+12
| | | | | | | | | | | | | | | | | | | | | Summary: In JavaScript, object literals can contain methods: var x = { a() { return 1; }, }; Previously, clang-format always parsed nested {} inside a braced list as further braced lists. Special case this logic for JavaScript to try parsing as a braced list, but fall back to parsing as a child block. Reviewers: djasper Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D29656 llvm-svn: 294315
* clang-format: [JS] exclaim preceding regex literals.Martin Probst2017-02-071-0/+1
| | | | | | | | | | | | | | | | | | | | Summary: Regex detection would incorrectly classify a trailing `!` operator (nullability cast) followed by a `/` as the start of a regular expression literal. This fixes code such as: var foo = x()! / 10; Which would previously parse a regexp all the way to the end of the source file (or next `/`). Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29634 llvm-svn: 294304
* clang-format: [JS] handle parenthesized class expressions.Martin Probst2017-02-071-0/+4
| | | | | | | | | | | | | | | | | | | | Summary: In JavaScript, classes are expressions, so they can appear e.g. in argument lists. var C = foo(class { bar() { return 1; } }; Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29635 llvm-svn: 294302
* clang-format: [JS] Fix bugs in parsing and aligning template strings.Daniel Jasper2017-02-031-0/+4
| | | | llvm-svn: 294009
* clang-format: [JS] Indent expressions in ${} relative to their surroundingDaniel Jasper2017-01-311-0/+57
| | | | | | | | | | | | | | | | | | | | This only affects expressions inside ${} scopes of template strings. Here, we want to indent relative to the surrounding template string and not the surrounding expression. Otherwise, this can create quite a mess. Before: var f = ` aaaaaaaaaaaaaaaaaa: ${someFunction( aaaaa + // bbbb)}`; After: var f = ` aaaaaaaaaaaaaaaaaa: ${someFunction( aaaaa + // bbbb)}`; llvm-svn: 293636
* clang-format: [JS] Properly set scopes inside template strings.Daniel Jasper2017-01-311-0/+7
| | | | | | | | | | | | | Before: var f = `aaaaaaaaaaaaa:${aaaaaaa .aaaaa} aaaaaaaa aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`; After: var f = `aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa aaaaaaaaaaaaa:${aaaaaaa.aaaaa} aaaaaaaa`; llvm-svn: 293622
* clang-format: [JS] Fix incorrect line break in template strings.Daniel Jasper2017-01-311-0/+4
| | | | | | | | | | | Before: var f = `aaaa ${a ? 'a' : 'b' }`; After: var f = `aaaa ${a ? 'a' : 'b'}`; llvm-svn: 293618
* clang-format: [JavaScript] Undo r291974 for JavaScript.Daniel Jasper2017-01-301-0/+10
| | | | | | | | | | | | | | | | | | | | | This had significant negative consequences and I don't have a good solution for it yet. Before: var string = [ 'aaaaaa', 'bbbbbb', ] .join('+'); After: var string = [ 'aaaaaa', 'bbbbbb', ].join('+'); llvm-svn: 293465
* clang-format: [JS] do not format MPEG transport streams.Martin Probst2017-01-271-0/+9
| | | | | | | | | | | | | | | Summary: The MPEG transport stream file format also uses ".ts" as its file extension. This change detects its specific framing format (0x47 every 189 bytes) and simply ignores MPEG TS files. Reviewers: djasper, sammccall Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D29186 llvm-svn: 293270
* clang-format: [JS] revert over-eager ASI check.Martin Probst2017-01-161-4/+22
| | | | | | | | | | | | Summary: Change r291428 introduced ASI detection after closing curly braces. That would generally be correct, however this breaks indentation for structural statements. What happens is that CompoundStatementIndenter increases indentation for the current line, then after reading ASI creates a new line (with the increased line level), and only after the structural parser sees e.g. the if/then/else branch closed, line level is reduced. That leads to the new line started by ASI having a level too high. Reviewers: djasper Subscribers: sammccall, cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D28763 llvm-svn: 292099
* clang-format: [JS] fix broken test.Martin Probst2017-01-091-1/+3
| | | | llvm-svn: 291429
* clang-format: [JS] ASI after importsMartin Probst2017-01-091-0/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Automatic semicolon insertion should break import and export statements: Before, this would format on one line: // Note: no semi after 'x' below! import {x} from 'x' export function foo() {} Into: import {x} from 'x' export function foo() {} With this change, the statements get separated. This also improves automatic semicolon insertion to consider closing braces preceding declarations and statements. Reviewers: klimek Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28465 llvm-svn: 291428
* TypoJoerg Sonnenberger2017-01-051-2/+2
| | | | llvm-svn: 291148
* clang-format: [JS] avoid indent after ambient function declarations.Martin Probst2017-01-041-0/+10
| | | | | | | | | | | | | | | | | | | | | Summary: Before: declare function foo(); let x = 1; After: declare function foo(); let x = 1; The problem was that clang-format would unconditionally try to parse a child block, even though ambient function declarations do not have a body (similar to forward declarations). Reviewers: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D28246 llvm-svn: 290959
* clang-format: [JS] Properly format dict literals that skip labels.Daniel Jasper2016-11-291-0/+7
| | | | llvm-svn: 288121
OpenPOWER on IntegriCloud