diff --git a/.eslintrc.yml b/.eslintrc.yml index 255da117716a..52280121c79e 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -3,24 +3,24 @@ env: es6: true node: true extends: -- eslint:recommended -- plugin:react/recommended -- plugin:prettier/recommended + - eslint:recommended + - plugin:react/recommended + - plugin:prettier/recommended plugins: -- import + - import rules: curly: error import/no-extraneous-dependencies: - - error - - devDependencies: ["tests*/**", "scripts/**"] + - error + - devDependencies: ["tests*/**", "scripts/**"] no-else-return: error no-inner-declarations: error no-unneeded-ternary: error no-useless-return: error no-var: error one-var: - - error - - never + - error + - never prefer-arrow-callback: error prefer-const: error react/display-name: off @@ -29,6 +29,6 @@ rules: strict: error symbol-description: error yoda: - - error - - never - - exceptRange: true + - error + - never + - exceptRange: true diff --git a/.ignore b/.ignore index bacdd589fbc6..a6920dce0114 100644 --- a/.ignore +++ b/.ignore @@ -1,3 +1,2 @@ website/static/lib dist - diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 229fc486b5c6..34e0a3a00d2e 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -44,9 +44,243 @@ const link = http://example.com; --> -#### TypeScript: Print comment following a JSX element with generic ([#6209] by [@duailibe]) +#### API: add resolveConfig option to getFileInfo() ([#6666] by [@kaicataldo]) -Previous versions would not print this comment, this has been fixed in this version. +Add a `resolveConfig: boolean` option to `prettier.getFileInfo()` that, when set to `true`, will resolve the configuration for the given file path. This allows consumers to take any overridden parsers into account. + +#### JavaScript: add support for PartialApplication ([#6397] by [@JounQin]) + +Previous versions would not be able to format this syntax, this has been fixed in this version. + + +```js +const addOne = add(1, ?); // apply from the left +addOne(2); // 3 + +const addTen = add(?, 10); // apply from the right +addTen(2); // 12 + +// with pipeline +let newScore = player.score + |> add(7, ?) + |> clamp(0, 100, ?); // shallow stack, the pipe to `clamp` is the same frame as the pipe to `add`. + +// Output (Prettier stable) +SyntaxError: Unexpected token (1:23) +> 1 | const addOne = add(1, ?); // apply from the left + | ^ + 2 | addOne(2); // 3 + 3 | + 4 | const addTen = add(?, 10); // apply from the right + +// Output (Prettier master) +const addOne = add(1, ?); // apply from the left +addOne(2); // 3 + +const addTen = add(?, 10); // apply from the right +addTen(2); // 12 + +// with pipeline +let newScore = player.score |> add(7, ?) |> clamp(0, 100, ?); // shallow stack, the pipe to \`clamp\` is the same frame as the pipe to \`add\`. +``` + +#### JavaScript: More readable parentheses for new-call ([#6412] by [@bakkot]) + + +```js +// Input +var a = new (x().y)(); +var a = new (x().y.z)(); +var a = new (x().y().z)(); + +// Output (Prettier stable) +var a = new (x()).y(); +var a = new (x()).y.z(); +var a = new (x().y()).z(); + +// Output (Prettier master) +var a = new (x().y)(); +var a = new (x().y.z)(); +var a = new (x().y().z)(); +``` + +#### MDX: Text following JSX was trimmed incorrectly ([#6340] by [@JounQin]) + + +```md + +# Heading + + test test + 123 + + + + test test +123 + + + + test test + 123 +``` + +#### TypeScript/Flow: Fix indentation for union types inside tuples ([#6381] by [@squidfunk], [#6605] by [@thorn0]) + + +```ts +// Input +type A = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type C = [ + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] +] + +// Output (Prettier stable) +type A = [ + + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +]; + +type B = [ + + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +]; + +type C = [ + + | [ + + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ] + | [ + + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ] +]; + +// Output (Prettier master) +type A = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +]; + +type B = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +]; + +type C = [ + | [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ] + | [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ] +]; +``` + +#### MDX: Adjacent JSX elements should be allowed ([#6332] by [@JounQin]) + + +```jsx +// Input + + test test +123 + +// Output (Prettier stable) +SyntaxError: Unexpected token (3:9) + 1 | + 2 | test test +> 3 | 123 + | ^ + +// Output (Prettier master) + + test test +123 + + +// Input + + test test + + + test test +123 + +// Output (Prettier stable) +SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...? (4:1) + 2 | test test + 3 | +> 4 | + | ^ + 5 | test test + 6 | 123 + +// Output (Prettier master) + + test test + + + test test +123 +``` + +#### TypeScript: Comments after JSX element names with type arguments were lost ([#6209] by [@duailibe]) ```ts @@ -74,7 +308,7 @@ const comp = ( ); ``` -### Handlebars: Avoid adding unwanted line breaks between text and mustaches ([#6186] by [@gavinjoyce]) +#### Handlebars: Avoid adding unwanted line breaks between text and mustaches ([#6186] by [@gavinjoyce]) Previously, Prettier added line breaks between text and mustaches which resulted in unwanted whitespace in rendered output. @@ -104,7 +338,7 @@ Previously, Prettier added line breaks between text and mustaches which resulted

``` -### Handlebars: Improve comment formatting ([#6206] by [@gavinjoyce]) +#### Handlebars: Improve comment formatting ([#6206] by [@gavinjoyce]) Previously, Prettier would sometimes ignore whitespace when formatting comments. @@ -146,9 +380,25 @@ Previously, Prettier would sometimes ignore whitespace when formatting comments. ``` -#### JavaScript: Keep unary expressions parentheses with comments ([#6217] by [@sosukesuzuki]) +#### JavaScript: Update ?? precedence to match stage 3 proposal ([#6404] by [@vjeux]) -Previously, Prettier removes parentheses enclose unary expressions. This change modify to keep it when the expression has comments. +We've updated Prettier's support for the nullish coalescing operator to match a spec update that no longer allows it to immediately contain, or be contained within an `&&` or `||` operation. + + +```js +// Input +(foo ?? baz) || baz; + +// Output (Prettier stable) +foo ?? baz || baz; + +// Output (Prettier master) +(foo ?? baz) || baz; +``` + +Please note, as we update our parsers with versions that support this spec update, code without the parenthesis will throw a parse error. + +#### JavaScript: Keep parentheses with comments in unary expressions ([#6217] by [@sosukesuzuki]) ```ts @@ -173,9 +423,58 @@ foo; ); ``` -### Handlebars: Improve comment formatting ([#6234] by [@gavinjoyce]) +#### Javascript: Use function literals in arguments to detect function composition ([#6033] by [@brainkim]) -Previously, Prettier would incorrectly decode HTML entiites. +Previously, we used a set of hard-coded names related to functional programming +(`compose`, `flow`, `pipe`, etc.) to detect function composition and chaining +patterns in code. This was done so that Prettier would not put code like the +following call to `pipe` on the same line even if it fit within the allotted +column budget: + + +```js +source$ + .pipe( + filter(x => x % 2 === 0), + map(x => x + x), + scan((acc, x) => acc + x, 0), + ) + .subscribe(x => console.log(x)); +``` + +However, this heuristic caused people to complain because of false positives +where calls to functions or methods matching the hard-coded names would always +be split on multiple lines, even if the calls did not contain function +arguments (https://github.com/prettier/prettier/issues/5769, +https://github.com/prettier/prettier/issues/5969). For many, this blanket +decision to split functions based on name was both surprising and sub-optimal. + +We now use a refined heuristic which uses the presence of function literals to +detect function composition. This heuristic preserves the line-splitting +behavior above and eliminates many if not all of the false positives caused by +the older heuristic. + +We encourage prettier users to try out the new heuristic and provide feedback. + + +```js +// Input +eventStore.update(id, _.flow(updater, incrementVersion)); + +// Output (Prettier stable) +eventStore.update( + id, + _.flow( + updater, + incrementVersion + ) +); + +// Output (Prettier master) +eventStore.update(id, _.flow(updater, incrementVersion)); +``` + +#### Handlebars: Preserve HTML entities ([#6234] by [@gavinjoyce]) ```hbs @@ -197,8 +496,6 @@ Previously, Prettier would incorrectly decode HTML entiites. #### JavaScript: Stop moving comments inside tagged template literals ([#6236] by [@sosukesuzuki]) -Previously, Prettier would move comments after the tag inside the template literal. This version fixes this problem. - ```js // Input @@ -216,9 +513,10 @@ foo // comment `; ``` -#### JavaScript: Fix moving comments in function calls like `useEffect` second argument ([#6270] by [@sosukesuzuki]) +#### TypeScript/Flow: Fix moving comments in function calls like `useEffect` ([#6270] by [@sosukesuzuki]) -This fixes a bug that was affecting function calls that have a arrow function as first argument and an array expression as second argument, such as the common React's `useEffect`. A comment in its own line before the second argument would be moved to the line above. +This fixes a bug that was affecting function calls with an arrow function as the first argument and an array expression as the second argument, e.g. React's `useEffect`. +If a comment was placed on the line before the second argument, Prettier would move it to the line above and corrupt the indentation. The bug was only present when using the Flow and TypeScript parsers. @@ -230,18 +528,14 @@ useEffect( console.log("some code", props.foo); }, - // We need to disable the eslint warning here, - // because of some complicated reason. - // eslint-disable line react-hooks/exhaustive-deps + // eslint-disable-line react-hooks/exhaustive-deps [] ); // Output (Prettier stable) useEffect(() => { console.log("some code", props.foo); -}, // We need to disable the eslint warning here, -// because of some complicated reason. -// eslint-disable line react-hooks/exhaustive-deps +}, // eslint-disable-line react-hooks/exhaustive-deps []); // Output (Prettier master) @@ -250,9 +544,7 @@ useEffect( console.log("some code", props.foo); }, - // We need to disable the eslint warning here, - // because of some complicated reason. - // eslint-disable line react-hooks/exhaustive-deps + // eslint-disable-line react-hooks/exhaustive-deps [] ); ``` @@ -261,6 +553,540 @@ useEffect( This version updates the TypeScript parser to correctly handle JSX text with double slashes (`//`). In previous versions, this would cause Prettier to crash. +#### HTML, Vue: Don't wrap `template` elements on lines shorter than `printWidth` ([#6284] by [@sosukesuzuki]) + +Previously, even if the line length was shorter than `printWidth`, Prettier would break the line with a `template` element. + + +```html +// Input + + +// Output (Prettier stable) + + +// Output (Prettier master) + +``` + +#### JavaScript: Fix breaks indentation and idempotency when an arrow function that args include object pattern is passed to a function as parameter. ([#6301] & [#6382] by [@sosukesuzuki]) + +Previously, Prettier indented code strangely when an arrow function whose parameters included an object pattern was passed to a function call as an argument. Also, it broke idempotence. Please see [#6294](https://github.com/prettier/prettier/issues/6294) for details. + + +```js +// Input +foo( + ({ + a, + + b + }) => {} +); + +// Output (Prettier stable) +foo(({ a, + b }) => {}); + +// Output (Prettier master) +foo( + ({ + a, + + b + }) => {} +); +``` + +#### TypeScript: Put a closing parenthesis onto a new line after union types ([#6307] by [@sosukesuzuki]) + + +```ts +// Input +const foo = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +// Prettier (stable) +const foo = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined)[]; + +// Prettier (master) +const foo = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; +``` + +#### HTML: Script tags are now treated as blocks for the purposes of formatting ([#6423] by [@thorn0]) + +Previously, in the [whitespace-sensitive mode](https://prettier.io/docs/en/options.html#html-whitespace-sensitivity), they were formatted as if they were inline. + + +```html + + + + + + + + + +``` + +#### TypeScript: Correctly format long one-line mapped types in one pass ([#6420] by [@sosukesuzuki]) + +Previously, when Prettier formatted long one-line mapped types, it would break the line but didn’t add a semicolon until you ran Prettier again, which means Prettier’s idempotence rule was broken. Now, Prettier adds the semicolon in the first run. + + +```ts +// Input +type FooBar = { [P in keyof T]: T[P] extends Something ? Something : T[P] } + +// Prettier (stable) +type FooBar = { + [P in keyof T]: T[P] extends Something ? Something : T[P] +}; + +// Prettier (master) +type FooBar = { + [P in keyof T]: T[P] extends Something ? Something : T[P]; +}; +``` + +#### JavaScript: Fix formatting of object destructuring with parameter decorators ([#6411] by [@sosukesuzuki]) + +Previously, Prettier formatted decorators for destructured parameters in a weird way. Now, parameter decorators are placed just above the parameter they belong to. + + +```js +// Input +class Class { + method( + @decorator + { foo } + ) {} +} + +// Prettier (stable) +class Class { + method(@decorator + { + foo + }) {} +} + +// Prettier (master) +class Class { + method( + @decorator + { foo } + ) {} +} +``` + +#### JavaScript: Handle empty object patterns with type annotations in function parameters ([#6438] by [@bakkot]) + + +```js +// Input +const f = ({}: MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongType) => {}; +function g({}: Foo) {} + +// Output (Prettier stable) +const f = ({ + , +}: MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongType) => {}; +function g({ }: Foo) {} + +// Output (Prettier master) +const f = ({}: MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongType) => {}; +function g({}: Foo) {} +``` + +#### JavaScript: Put a closing parenthesis onto a new line after binary expressions within function calls ([#6441] by [@sosukesuzuki]) + + +```js +// Input +( + aaaaaaaaaaaaaaaaaaaaaaaaa && + bbbbbbbbbbbbbbbbbbbbbbbbb && + ccccccccccccccccccccccccc && + ddddddddddddddddddddddddd && + eeeeeeeeeeeeeeeeeeeeeeeee +)(); + +// Prettier (stable) +(aaaaaaaaaaaaaaaaaaaaaaaaa && + bbbbbbbbbbbbbbbbbbbbbbbbb && + ccccccccccccccccccccccccc && + ddddddddddddddddddddddddd && + eeeeeeeeeeeeeeeeeeeeeeeee)(); + +// Prettier (master) +( + aaaaaaaaaaaaaaaaaaaaaaaaa && + bbbbbbbbbbbbbbbbbbbbbbbbb && + ccccccccccccccccccccccccc && + ddddddddddddddddddddddddd && + eeeeeeeeeeeeeeeeeeeeeeeee +)(); +``` + +#### JavaScript: Fix formatting of long named exports ([#6446] by [@sosukesuzuki]) + +Now, Prettier formats them the same way it formats named imports. + + +```js +// Input +export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo"; + +// Prettier (stable) +export { + fooooooooooooooooooooooooooooooooooooooooooooooooo +} from "fooooooooooooooooooooooooooooo"; + +// Prettier (master) +export { fooooooooooooooooooooooooooooooooooooooooooooooooo } from "fooooooooooooooooooooooooooooo"; +``` + +#### JavaScript: Fix bad formatting for multi-line optional chaining with comment ([#6506] by [@sosukesuzuki]) + + +```js +// Input +return a + .b() + .c() + // Comment + ?.d() + +// Prettier (stable) +return a + .b() + .c() + ?.// Comment + d(); + +// Prettier (master) +return ( + a + .b() + .c() + // Comment + ?.d() +); +``` + +#### JavaScript: Fix inconsistent indentation in switch statement ([#6514] by [@sosukesuzuki]) + + +```js +// Input +switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName) { +} + +switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) { +} + +// Prettier (stable) +switch ( + $veryLongAndVeryVerboseVariableName && + $anotherVeryLongAndVeryVerboseVariableName +) { +} + +switch ( + $longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName +) { +} + +// Prettier (master) +switch ( + $veryLongAndVeryVerboseVariableName && + $anotherVeryLongAndVeryVerboseVariableName +) { +} + +switch ( + $longButSlightlyShorterVariableName && + $anotherSlightlyShorterVariableName +) { +} +``` + +#### TypeScript: Keep type parameters inline for type annotations in variable declarations ([#6467] by [@sosukesuzuki]) + + +```ts +// Input +const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); + +// Prettier (stable) +const fooooooooooooooo: SomeThing< + boolean +> = looooooooooooooooooooooooooooooongNameFunc(); + +// Prettier (master) +const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); +``` + +#### Handlebars: Fix `--single-quote` option on HTML attributes ([#6377] by [@dcyriller]) + +Previously, the flag was not applied on HTML attributes. + + +```hbs +// Input +
+ +// Prettier (stable with the option --single-quote) +
+ +// Prettier (master with the option --single-quote) +
+``` + +#### TypeScript: Sometimes double parentheses around types were removed incorrectly ([#6604] by [@sosukesuzuki]) + + +```ts +// Input +type A = 0 extends ((1 extends 2 ? 3 : 4)) ? 5 : 6; +type B = ((0 extends 1 ? 2 : 3)) extends 4 ? 5 : 6; +type C = ((number | string))["toString"]; +type D = ((keyof T1))["foo"]; + +// Prettier (stable) +type A = 0 extends 1 extends 2 ? 3 : 4 ? 5 : 6; +type B = 0 extends 1 ? 2 : 3 extends 4 ? 5 : 6; +type C = number | string["toString"]; +type D = keyof T1["foo"]; + +// Prettier (master) +type A = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6; +type B = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6; +type C = (number | string)["toString"]; +type D = (keyof T1)["foo"]; +``` + +#### JavaScript: Support formatting code with V8 intrinsics ([#6496] by [@rreverser]) + + +```js +// Input +function doSmth() { + %DebugPrint + ( + foo ) + } + +// Prettier (stable) +SyntaxError: Unexpected token (2:13) + 1 | function doSmth() { +> 2 | %DebugPrint + | ^ + +// Prettier (master) +function doSmth() { + %DebugPrint(foo); +} +``` + +#### TypeScript: Sometimes removing parentheses around JSX made the code unparseable ([#6640] by [@sosukesuzuki]) + + +```tsx +// Input +().toString(); + +// Prettier (stable) +.toString(): + +// Prettier (master) +().toString(); +``` + +#### JavaScript: Object destructuring in method parameters always broke into multiple lines ([#6646] by [@ericsakmar]) + + +```js +// Input +const obj = { + func(id, { blog: { title } }) { + return id + title; + }, +}; + +class A { + func(id, { blog: { title } }) { + return id + title; + } + #func(id, { blog: { title } }) { + return id + title; + } +} + +// Prettier (stable) +const obj = { + func( + id, + { + blog: { title } + } + ) { + return id + title; + } +}; + +class A { + func( + id, + { + blog: { title } + } + ) { + return id + title; + } + #func( + id, + { + blog: { title } + } + ) { + return id + title; + } +} + +// Prettier (master) +const obj = { + func(id, { blog: { title } }) { + return id + title; + }, +}; + +class A { + func(id, { blog: { title } }) { + return id + title; + } + #func(id, { blog: { title } }) { + return id + title; + } +} +``` + +#### TypeScript: Fix optional computed methods ([#6673] by [@thorn0]) + + +```ts +// Input +class A { + protected [s]?() {} +} + +// Output (Prettier stable) +class A { + protected [s?]() {} +} + +// Output (Prettier master) +class A { + protected [s]?() {} +} +``` + +#### Angular: Put a closing parenthesis onto a new line after ternaries passed to pipes ([#5682] by [@selvazhagan]) + + +```html + +{{ (isCustomDiscount ? 'DISCOUNTS__DISCOUNT_TRAINING_HEADER__CUSTOM_DISCOUNT' : 'DISCOUNTS__DISCOUNT_TRAINING_HEADER__DISCOUNT') | translate }} + + +{{ + (isCustomDiscount + ? "DISCOUNTS__DISCOUNT_TRAINING_HEADER__CUSTOM_DISCOUNT" + : "DISCOUNTS__DISCOUNT_TRAINING_HEADER__DISCOUNT") | translate +}} + + +{{ + (isCustomDiscount + ? "DISCOUNTS__DISCOUNT_TRAINING_HEADER__CUSTOM_DISCOUNT" + : "DISCOUNTS__DISCOUNT_TRAINING_HEADER__DISCOUNT" + ) | translate +}} +``` + +#### Handlebars: Fix handling of whitespace and line breaks ([#6354] by [@chadian]) + +This fixes a variety of whitespace and line break usecases within handlebars and Glimmer templates. + + +```hbs +// Input +{{name}} + +Some sentence with {{dynamic}} expressions. + + + +sometimes{{nogaps}}areimportant +{{name}} is your name + +// Output (Prettier stable) + +{{name}} +Some sentence with +{{dynamic}} +expressions. + + + +sometimes +{{nogaps}} +areimportant + +{{name}} +is your name + +// Output (Prettier master) +{{name}} + +Some sentence with {{dynamic}} expressions. + + + +sometimes{{nogaps}}areimportant + +{{name}} is your name +``` + +[#5910]: https://github.com/prettier/prettier/pull/5910 +[#6033]: https://github.com/prettier/prettier/pull/6033 [#6186]: https://github.com/prettier/prettier/pull/6186 [#6206]: https://github.com/prettier/prettier/pull/6206 [#6209]: https://github.com/prettier/prettier/pull/6209 @@ -268,7 +1094,45 @@ This version updates the TypeScript parser to correctly handle JSX text with dou [#6234]: https://github.com/prettier/prettier/pull/6234 [#6236]: https://github.com/prettier/prettier/pull/6236 [#6270]: https://github.com/prettier/prettier/pull/6270 +[#6284]: https://github.com/prettier/prettier/pull/6284 [#6289]: https://github.com/prettier/prettier/pull/6289 +[#6301]: https://github.com/prettier/prettier/pull/6301 +[#6307]: https://github.com/prettier/prettier/pull/6307 +[#6332]: https://github.com/prettier/prettier/pull/6332 +[#6340]: https://github.com/prettier/prettier/pull/6340 +[#6377]: https://github.com/prettier/prettier/pull/6377 +[#6381]: https://github.com/prettier/prettier/pull/6381 +[#6397]: https://github.com/prettier/prettier/pull/6397 +[#6404]: https://github.com/prettier/prettier/pull/6404 +[#6411]: https://github.com/prettier/prettier/pull/6411 +[#6412]: https://github.com/prettier/prettier/pull/6412 +[#6420]: https://github.com/prettier/prettier/pull/6420 +[#6423]: https://github.com/prettier/prettier/pull/6423 +[#6438]: https://github.com/prettier/prettier/pull/6411 +[#6441]: https://github.com/prettier/prettier/pull/6441 +[#6446]: https://github.com/prettier/prettier/pull/6446 +[#6467]: https://github.com/prettier/prettier/pull/6467 +[#6496]: https://github.com/prettier/prettier/pull/6496 +[#6506]: https://github.com/prettier/prettier/pull/6506 +[#6514]: https://github.com/prettier/prettier/pull/6514 +[#6604]: https://github.com/prettier/prettier/pull/6604 +[#6605]: https://github.com/prettier/prettier/pull/6605 +[#6640]: https://github.com/prettier/prettier/pull/6640 +[#6646]: https://github.com/prettier/prettier/pull/6646 +[#6673]: https://github.com/prettier/prettier/pull/6673 +[#6382]: https://github.com/prettier/prettier/pull/6382 +[@brainkim]: https://github.com/brainkim [@duailibe]: https://github.com/duailibe [@gavinjoyce]: https://github.com/gavinjoyce [@sosukesuzuki]: https://github.com/sosukesuzuki +[@g-harel]: https://github.com/g-harel +[@jounqin]: https://github.com/JounQin +[@bakkot]: https://gibhub.com/bakkot +[@thorn0]: https://github.com/thorn0 +[@dcyriller]: https://github.com/dcyriller +[@rreverser]: https://github.com/RReverser +[@ericsakmar]: https://github.com/ericsakmar +[@squidfunk]: https://github.com/squidfunk +[@vjeux]: https://github.com/vjeux +[@selvazhagan]: https://github.com/selvazhagan +[@chadian]: https://github.com/chadian diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 90f8c9a639a9..d29de631f92d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ Here's what you need to know about the tests: - You can run `AST_COMPARE=1 jest` for a more robust test run. That formats each file, re-parses it, and compares the new AST with the original one and makes sure they are semantically equivalent. - Each test folder has a `jsfmt.spec.js` that runs the tests. For JavaScript files, generally you can just put `run_spec(__dirname, ["babel", "flow", "typescript"]);` there. This will verify that the output using each parser is the same. You can also pass options as the third argument, like this: `run_spec(__dirname, ["babel"], { trailingComma: "es5" });` - `tests/flow/` contains the Flow test suite, and is not supposed to be edited by hand. To update it, clone the Flow repo next to the Prettier repo and run: `node scripts/sync-flow-tests.js ../flow/tests/`. -- If you would like to debug prettier locally, you can either debug it in node or the browser. The easiest way to debug it in the browser is to run the interactive `docs` REPL locally. The easiest way to debug it in node, is to create a local test file and run it in an editor like VS Code. +- If you would like to debug prettier locally, you can either debug it in node or the browser. The easiest way to debug it in the browser is to run the interactive `docs` REPL locally. The easiest way to debug it in node, is to create a local test file with some example code you want formatted and either run it in an editor like VS Code or run it directly via `./bin/prettier.js `. Run `yarn lint --fix` to automatically format files. diff --git a/docs/api.md b/docs/api.md index 249d598822d8..a2126dc2753f 100644 --- a/docs/api.md +++ b/docs/api.md @@ -58,16 +58,26 @@ If `options.editorconfig` is `true` and an [`.editorconfig` file](http://editorc Use `prettier.resolveConfig.sync(filePath [, options])` if you'd like to use sync version. -## `prettier.resolveConfigFile(filePath [, options])` +## `prettier.resolveConfigFile([filePath])` -`resolveConfigFile` can be used to find the path of the Prettier's configuration file will be used when resolving the config (i.e. when calling `resolveConfig`). A promise is returned which will resolve to: +`resolveConfigFile` can be used to find the path of the Prettier configuration file that will be used when resolving the config (i.e. when calling `resolveConfig`). A promise is returned which will resolve to: - The path of the configuration file. - `null`, if no file was found. The promise will be rejected if there was an error parsing the configuration file. -If `options.useCache` is `false`, all caching will be bypassed. +The search starts at `process.cwd()`, or at `filePath` if provided. Please see the [cosmiconfig docs](https://github.com/davidtheclark/cosmiconfig#explorersearch) for details on how the resolving works. + +```js +prettier.resolveConfigFile().then(filePath => { + prettier.resolveConfig(filePath).then(options => { + const formatted = prettier.format(text, options); + }); +}); +``` + +Use `prettier.resolveConfigFile.sync([filePath])` if you'd like to use sync version. ## `prettier.clearConfigCache()` @@ -84,10 +94,14 @@ As you repeatedly call `resolveConfig`, the file system structure will be cached } ``` +The promise will be rejected if the type of `filePath` is not `string`. + Setting `options.ignorePath` (`string`) and `options.withNodeModules` (`boolean`) influence the value of `ignored` (`false` by default). Providing [plugin](plugins.md) paths in `options.plugins` (`string[]`) helps extract `inferredParser` for files that are not supported by Prettier core. +When setting `options.resolveConfig` (`boolean`, default `false`), Prettier will resolve the configuration for the given `filePath`. This is useful, for example, when the `inferredParser` might be overridden for a subset of files. + Use `prettier.getFileInfo.sync(filePath [, options])` if you'd like to use sync version. ## `prettier.getSupportInfo([version])` diff --git a/docs/cli.md b/docs/cli.md index 5dab730fc527..d1ef8bae0cac 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -17,7 +17,7 @@ In practice, this may look something like: prettier --single-quote --trailing-comma es5 --write "{app,__{tests,mocks}__}/**/*.js" ``` -Don't forget the quotes around the globs! The quotes make sure that Prettier expands the globs rather than your shell, for cross-platform usage. The [glob syntax from the glob module](https://github.com/isaacs/node-glob/blob/master/README.md#glob-primer) is used. +Don't forget the quotes around the globs! The quotes make sure that Prettier expands the globs rather than your shell, for cross-platform usage. The [glob syntax from the `fast-glob` module](https://github.com/mrmlnc/fast-glob/blob/master/README.md#pattern-syntax) is used. Prettier CLI will ignore files located in `node_modules` directory. To opt-out from this behavior use `--with-node-modules` flag. diff --git a/docs/configuration.md b/docs/configuration.md index 14cbbe67adca..b28f61c90b12 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -3,12 +3,12 @@ id: configuration title: Configuration File --- -Prettier uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for configuration file support. This means you can configure prettier via: +Prettier uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for configuration file support. This means you can configure prettier via (in order of precedence): -- A `.prettierrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json`. -- A `.prettierrc.toml` file, written in TOML (the `.toml` extension is _required_). -- A `prettier.config.js` or `.prettierrc.js` file that exports an object. - A `"prettier"` key in your `package.json` file. +- A `.prettierrc` file, written in JSON or YAML, with optional extensions: `.json/.yaml/.yml` (without extension takes precedence). +- A `.prettierrc.js` or `prettier.config.js` file that exports an object. +- A `.prettierrc.toml` file, written in TOML (the `.toml` extension is _required_). The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found. @@ -61,7 +61,9 @@ singleQuote = true ## Configuration Overrides -Prettier borrows eslint's [override format](http://eslint.org/docs/user-guide/configuring#example-configuration). This allows you to apply configuration to specific files. +Overrides let you have different configuration for certain file extensions, folders and specific files. + +Prettier borrows ESLint’s [override format](http://eslint.org/docs/user-guide/configuring#example-configuration). JSON: @@ -74,6 +76,12 @@ JSON: "options": { "semi": true } + }, + { + "files": ["*.html", "legacy/**/*.js"], + "options": { + "tabWidth": 4 + } } ] } @@ -87,6 +95,11 @@ overrides: - files: "*.test.js" options: semi: true + - files: + - "*.html" + - "legacy/**/*.js" + options: + tabWidth: 4 ``` `files` is required for each override, and may be a string or array of strings. `excludeFiles` may be optionally provided to exclude files for a given rule, and may also be a string or array of strings. diff --git a/docs/integrating-with-linters.md b/docs/integrating-with-linters.md index c2a92330adc1..57fa98f72a63 100644 --- a/docs/integrating-with-linters.md +++ b/docs/integrating-with-linters.md @@ -9,13 +9,13 @@ This allows you to use Prettier for code formatting concerns, while letting your Whatever linting tool you wish to integrate with, the steps are broadly similar. First disable any existing formatting rules in your linter that may conflict with how Prettier wishes to format your code. Then you can either add an extension to your linting tool to format your file with Prettier - so that you only need a single command for format a file, or run your linter then Prettier as separate steps. -All these instructions assume you have already installed `prettier` in your `devDependencies`. +All these instructions assume you have already installed `prettier` in your [`devDependencies`]. ## ESLint ### Disable formatting rules -[`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your `devDependencies`, then extend from it within your `.eslintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. +[`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your [`devDependencies`], then extend from it within your `.eslintrc` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. ```bash yarn add --dev eslint-config-prettier @@ -31,7 +31,7 @@ Then in `.eslintrc.json`: ### Use ESLint to run Prettier -[`eslint-plugin-prettier`](https://github.com/prettier/eslint-plugin-prettier) is a plugin that adds a rule that formats content using Prettier. Add it to your `devDependencies`, then enable the plugin and rule. +[`eslint-plugin-prettier`](https://github.com/prettier/eslint-plugin-prettier) is a plugin that adds a rule that formats content using Prettier. Add it to your [`devDependencies`], then enable the plugin and rule. ```bash yarn add --dev eslint-plugin-prettier @@ -68,7 +68,7 @@ Then in `.eslintrc.json`: ### Disable formatting rules -[`tslint-config-prettier`](https://github.com/alexjoverm/tslint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your `devDependencies`, then extend from it within your `tslint.json` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. +[`tslint-config-prettier`](https://github.com/alexjoverm/tslint-config-prettier) is a config that disables rules that conflict with Prettier. Add it to your [`devDependencies`], then extend from it within your `tslint.json` configuration. Make sure to put it last in the `extends` array, so it gets the chance to override other configs. ```bash yarn add --dev tslint-config-prettier @@ -84,7 +84,7 @@ Then in `tslint.json`: ### Use TSLint to run Prettier -[`tslint-plugin-prettier`](https://github.com/ikatyang/tslint-plugin-prettier) is a plugin that adds a rule that formats content using Prettier. Add it to your `devDependencies`, then enable the plugin and rule. +[`tslint-plugin-prettier`](https://github.com/ikatyang/tslint-plugin-prettier) is a plugin that adds a rule that formats content using Prettier. Add it to your [`devDependencies`], then enable the plugin and rule. ```bash yarn add --dev tslint-plugin-prettier @@ -140,7 +140,7 @@ Then in `.stylelintrc`: ### Use Stylelint to run Prettier -[`stylelint-prettier`](https://github.com/prettier/stylelint-prettier) is a plugin that adds a rule that formats content using Prettier. Add it to your `devDependencies`, then enable the plugin and rule. +[`stylelint-prettier`](https://github.com/prettier/stylelint-prettier) is a plugin that adds a rule that formats content using Prettier. Add it to your [`devDependencies`], then enable the plugin and rule. ```bash yarn add --dev stylelint-prettier @@ -172,3 +172,5 @@ Then in `.stylelintrc`: "extends": ["stylelint-prettier/recommended"] } ``` + +[`devdependencies`]: https://docs.npmjs.com/specifying-dependencies-and-devdependencies-in-a-package-json-file diff --git a/docs/option-philosophy.md b/docs/option-philosophy.md index d3bd181b410f..f56fdda7afd2 100644 --- a/docs/option-philosophy.md +++ b/docs/option-philosophy.md @@ -3,6 +3,10 @@ id: option-philosophy title: Option Philosophy --- +> Prettier has a few options because of history. **But we don’t want more of them.** +> +> Read on to learn more. + Prettier is not a kitchen-sink code formatter that attempts to print your code in any way you wish. It is _opinionated._ Quoting the [Why Prettier?](why-prettier.md) page: > By far the biggest reason for adopting Prettier is to stop all the on-going debates over styles. @@ -11,21 +15,33 @@ The more options Prettier has, the further from the above goal it gets. **The de The issue about [resisting adding configuration](https://github.com/prettier/prettier/issues/40) has more 👍s than any option request issue. -So why does Prettier have options at all? +So why are there any options at all? + +- A few were added during Prettier’s infancy to make it take off at all. 🚀 +- A couple were added after “great demand.” 🤔 +- Some were added for compatibility reasons. 👍 + +What we’ve learned during the years is that it’s really hard to measure demand. Prettier has grown _a lot_ in usage. What was “great demand” back in the day is not as much today. How many is many? What about all silent users? + +It’s so easy to add “just one more“ option. But where do we stop? When is one too many? There will always be a “top issue” in the issue tracker. Even if we add just that one final option. + +The downside of options is that they open up for debate within teams. Which options should we use? Why? Did we make the right choices? + +Every option also makes it much harder to say no to new ones. If _those_ options exist, why can’t this one? + +We’ve had several users open up option requests only to close them themselves a couple of months later. They had realized that they don’t care at all about that little syntax choice they used to feel so strongly about. Examples: [#3101](https://github.com/prettier/prettier/issues/3101#issuecomment-500927917) and [#5501](https://github.com/prettier/prettier/issues/5501#issuecomment-487025417). -Well, had Prettier been created around the same time as JavaScript itself was born it could have made choices that the community would have picked up (which is the case for [elm-format](https://github.com/avh4/elm-format/)). But JavaScript is far older than Prettier so the community has had time to start their holy wars about tabs vs spaces, single vs double quotes, indentation levels, trailing commas and semicolons, so Prettier more or less has to support those. +All of this makes the topic of options in Prettier very difficult. And mentally tiring for maintainers. What do people want? What do people _really_ want in 6 months? Are we spending time and energy on the right things? -Then there's a bunch of interesting cases. +Some options are easier to motivate: -- `--trailing-comma es5` was added to make it easier to use trailing commas in most environments without having to transpile (trailing function commas were added in ES2017). +- `--trailing-comma es5` lets you use trailing commas in most environments without having to transpile (trailing function commas were added in ES2017). - `--prose-wrap` is important to support all quirky markdown renderers in the wild. - `--html-whitespace-sensitivity` is needed due to the unfortunate whitespace rules of HTML. - `--end-of-line` makes it easier for teams to keep CRLFs out of their git repositories. -- `--arrow-parens` was added after – at the time – [huge demand](https://github.com/prettier/prettier/issues/812). Prettier has to strike a balance between ideal goals and listening to the community. -- `--jsx-single-quote` was also added after [great demand](https://github.com/prettier/prettier/issues/1080), but after more consideration. It took quite some time to figure out the right approach. -- `--jsx-bracket-same-line` was needed for a big company with a huge code base (Facebook), which backed the project when it got started, to be able to [adopt Prettier at all](https://github.com/prettier/prettier/pull/661#issuecomment-295770645). +- `--quote-props` is important for advanced usage of the Google Closure Compiler. -Finally, perhaps the most interesting of them all is `--bracket-spacing`. -The truth is that not even [Prettier's creator knows exactly why it exists](https://github.com/prettier/prettier/issues/715#issuecomment-281096495). It was added super early on without much thought. It now serves as an example of the types of options we should avoid. +But others are harder to motivate in hindsight, and usually end up with bike shedding. `--arrow-parens`, +`--jsx-single-quote`, `--jsx-bracket-same-line` and `--no-bracket-spacing` are not the type of options we want more of. They exist (and are difficult to remove now), but should not motivate adding more options like them. -Remember, it is easy to _add_ features to a program, but hard to remove them. +Feel free to open issues! Prettier isn’t perfect. Many times things can be improved without adding options. But if the issue _does_ seem to need a new option, we’ll generally keep it open, to let people 👍 it and add comments. diff --git a/docs/options.md b/docs/options.md index 46450310fb81..00f647107da2 100644 --- a/docs/options.md +++ b/docs/options.md @@ -307,6 +307,21 @@ Valid options: | ------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------- | | `"css"` | --html-whitespace-sensitivity | htmlWhitespaceSensitivity: "" | +## Vue files script and style tags indentation + +_First available in v1.19.0_ + +Whether or not to indent the code inside ` + +
+ +=====================================output===================================== + + +
+================================================================================ +`; + +exports[`basic-handlebars.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== + + +
+ +=====================================output===================================== + + +
+================================================================================ +`; + +exports[`component.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== + +{{@greeting}}, {{@name}}! + +
+ +
+ +
+ + hello + + + + + + + + + + + + +
Hello
+ +=====================================output===================================== + +{{@greeting}}, {{@name}}! + +
+ +
+ +
+ + + hello + + + + + + + + + + + + + +
+ Hello +
+================================================================================ +`; + +exports[`component.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== + +{{@greeting}}, {{@name}}! + +
+ +
+ +
+ + hello + + + + + + + + + + + + +
Hello
+ +=====================================output===================================== + +{{@greeting}}, {{@name}}! + +
+ +
+ +
+ + + hello + + + + + + + + + + + + + +
+ Hello +
+================================================================================ +`; + +exports[`literals.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +{{mustache true}} +{{mustache 5}} +{{mustache undefined}} +{{mustache null}} + +{{! Mustache Comment}} +{{!-- Mustache Comment }} --}} + +=====================================output===================================== +{{mustache true}} +{{mustache 5}} +{{mustache undefined}} +{{mustache null}} + +{{! Mustache Comment}} +{{!-- Mustache Comment }} --}} +================================================================================ +`; + +exports[`literals.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +{{mustache true}} +{{mustache 5}} +{{mustache undefined}} +{{mustache null}} + +{{! Mustache Comment}} +{{!-- Mustache Comment }} --}} + +=====================================output===================================== +{{mustache true}} +{{mustache 5}} +{{mustache undefined}} +{{mustache null}} + +{{! Mustache Comment}} +{{!-- Mustache Comment }} --}} +================================================================================ +`; + +exports[`nested-path.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +
+

{{title}}

+

By {{author.name}}

+ +
+ {{body}} +
+
+ +=====================================output===================================== +
+

+ {{title}} +

+

+ By {{author.name}} +

+ +
+ {{body}} +
+
+================================================================================ +`; + +exports[`nested-path.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +
+

{{title}}

+

By {{author.name}}

+ +
+ {{body}} +
+
+ +=====================================output===================================== +
+

+ {{title}} +

+

+ By {{author.name}} +

+ +
+ {{body}} +
+
+================================================================================ +`; + +exports[`raw.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +

{{{raw}}}

+ +=====================================output===================================== +

+ {{{raw}}} +

+================================================================================ +`; + +exports[`raw.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +

{{{raw}}}

+ +=====================================output===================================== +

+ {{{raw}}} +

+================================================================================ +`; + +exports[`string-literals.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +{{"abc"}} +{{'abc'}} +{{" \\" \\" ' more double quote than single quote "}} +{{' \\' \\' " more single quote than double quote '}} +{{' " \\' \\" \\\\ '}} +{{" \\" \\' ' \\\\ "}} + +=====================================output===================================== +{{"abc"}} +{{"abc"}} +{{' " " \\' more double quote than single quote '}} +{{" ' ' \\" more single quote than double quote "}} +{{' " \\' \\" \\\\ '}} +{{" \\" \\' ' \\\\ "}} +================================================================================ +`; + +exports[`string-literals.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +{{"abc"}} +{{'abc'}} +{{" \\" \\" ' more double quote than single quote "}} +{{' \\' \\' " more single quote than double quote '}} +{{' " \\' \\" \\\\ '}} +{{" \\" \\' ' \\\\ "}} + +=====================================output===================================== +{{'abc'}} +{{'abc'}} +{{' " " \\' more double quote than single quote '}} +{{" ' ' \\" more single quote than double quote "}} +{{' " \\' \\" \\\\ '}} +{{" \\" \\' ' \\\\ "}} +================================================================================ +`; diff --git a/tests/handlebars/basic-handlebars.hbs b/tests/handlebars-basics/basic-handlebars.hbs similarity index 100% rename from tests/handlebars/basic-handlebars.hbs rename to tests/handlebars-basics/basic-handlebars.hbs diff --git a/tests/glimmer/component.hbs b/tests/handlebars-basics/component.hbs similarity index 100% rename from tests/glimmer/component.hbs rename to tests/handlebars-basics/component.hbs diff --git a/tests/handlebars-basics/jsfmt.spec.js b/tests/handlebars-basics/jsfmt.spec.js new file mode 100644 index 000000000000..4abf117d9346 --- /dev/null +++ b/tests/handlebars-basics/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["glimmer"]); +run_spec(__dirname, ["glimmer"], { singleQuote: true }); diff --git a/tests/glimmer/literals.hbs b/tests/handlebars-basics/literals.hbs similarity index 100% rename from tests/glimmer/literals.hbs rename to tests/handlebars-basics/literals.hbs diff --git a/tests/handlebars/nested-path.hbs b/tests/handlebars-basics/nested-path.hbs similarity index 100% rename from tests/handlebars/nested-path.hbs rename to tests/handlebars-basics/nested-path.hbs diff --git a/tests/handlebars/raw.hbs b/tests/handlebars-basics/raw.hbs similarity index 100% rename from tests/handlebars/raw.hbs rename to tests/handlebars-basics/raw.hbs diff --git a/tests/glimmer/string-literals.hbs b/tests/handlebars-basics/string-literals.hbs similarity index 100% rename from tests/glimmer/string-literals.hbs rename to tests/handlebars-basics/string-literals.hbs diff --git a/tests/handlebars-block-statement/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-block-statement/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..6c7aeb52d838 --- /dev/null +++ b/tests/handlebars-block-statement/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,865 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`block-statement.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +{{#block param hashKey=hashValue as |blockParam|}} + Hello +{{/block}} + +{{#block almost80CharacterLongPositionalParamThatIsFirstAlmost80Chars helloWorldParam key=here}} +{{/block}} + +{{#block param param param param param param param hashKey=hashValue as |blockParam|}} + Hello +{{/block}} + +{{#block param param param param param param param hashKey=HashValue hashKey=hashValue}} + Hello +{{/block}} + +{{#block param param param param param param param param param param param param param}} + Hello +{{/block}} + +{{#block hashKey=HashValue hashKey=hashValue hashKey=HashValue hashKey=hashValue hashKey=HashValue}} + Hello +{{/block}} + +{{#block}} + {{#block}} + hello + {{/block}} +{{/block}} + +{{#block}} + {{#block param}} + hello + {{/block}} +{{/block}} + +{{#block param}} + {{#block param}} + hello + {{/block}} +{{/block}} + +{{#block}} + hello +{{/block}} + + + {{firstName}} + + + + {{firstName}} {{lastName}} + + +=====================================output===================================== +{{#block param hashKey=hashValue as |blockParam|}} + Hello +{{/block}} + +{{#block + almost80CharacterLongPositionalParamThatIsFirstAlmost80Chars + helloWorldParam + key=here +}}{{/block}} + +{{#block + param + param + param + param + param + param + param + hashKey=hashValue as |blockParam| +}} + Hello +{{/block}} + +{{#block + param + param + param + param + param + param + param + hashKey=HashValue + hashKey=hashValue +}} + Hello +{{/block}} + +{{#block + param + param + param + param + param + param + param + param + param + param + param + param + param +}} + Hello +{{/block}} + +{{#block + hashKey=HashValue + hashKey=hashValue + hashKey=HashValue + hashKey=hashValue + hashKey=HashValue +}} + Hello +{{/block}} + +{{#block}} + {{#block}} + hello + {{/block}} +{{/block}} + +{{#block}} + {{#block param}} + hello + {{/block}} +{{/block}} + +{{#block param}} + {{#block param}} + hello + {{/block}} +{{/block}} + +{{#block}} + hello +{{/block}} + + + {{firstName}} + + + + {{firstName}} {{lastName}} + +================================================================================ +`; + +exports[`block-statement.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +{{#block param hashKey=hashValue as |blockParam|}} + Hello +{{/block}} + +{{#block almost80CharacterLongPositionalParamThatIsFirstAlmost80Chars helloWorldParam key=here}} +{{/block}} + +{{#block param param param param param param param hashKey=hashValue as |blockParam|}} + Hello +{{/block}} + +{{#block param param param param param param param hashKey=HashValue hashKey=hashValue}} + Hello +{{/block}} + +{{#block param param param param param param param param param param param param param}} + Hello +{{/block}} + +{{#block hashKey=HashValue hashKey=hashValue hashKey=HashValue hashKey=hashValue hashKey=HashValue}} + Hello +{{/block}} + +{{#block}} + {{#block}} + hello + {{/block}} +{{/block}} + +{{#block}} + {{#block param}} + hello + {{/block}} +{{/block}} + +{{#block param}} + {{#block param}} + hello + {{/block}} +{{/block}} + +{{#block}} + hello +{{/block}} + + + {{firstName}} + + + + {{firstName}} {{lastName}} + + +=====================================output===================================== +{{#block param hashKey=hashValue as |blockParam|}} + Hello +{{/block}} + +{{#block + almost80CharacterLongPositionalParamThatIsFirstAlmost80Chars + helloWorldParam + key=here +}}{{/block}} + +{{#block + param + param + param + param + param + param + param + hashKey=hashValue as |blockParam| +}} + Hello +{{/block}} + +{{#block + param + param + param + param + param + param + param + hashKey=HashValue + hashKey=hashValue +}} + Hello +{{/block}} + +{{#block + param + param + param + param + param + param + param + param + param + param + param + param + param +}} + Hello +{{/block}} + +{{#block + hashKey=HashValue + hashKey=hashValue + hashKey=HashValue + hashKey=hashValue + hashKey=HashValue +}} + Hello +{{/block}} + +{{#block}} + {{#block}} + hello + {{/block}} +{{/block}} + +{{#block}} + {{#block param}} + hello + {{/block}} +{{/block}} + +{{#block param}} + {{#block param}} + hello + {{/block}} +{{/block}} + +{{#block}} + hello +{{/block}} + + + {{firstName}} + + + + {{firstName}} {{lastName}} + +================================================================================ +`; + +exports[`each.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +
+ {{#each comments}} +

{{title}}

+
{{body}}
+ {{/each}} +
+ +=====================================output===================================== +
+ {{#each comments}} +

+ + {{title}} + +

+
+ {{body}} +
+ {{/each}} +
+================================================================================ +`; + +exports[`each.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +
+ {{#each comments}} +

{{title}}

+
{{body}}
+ {{/each}} +
+ +=====================================output===================================== +
+ {{#each comments}} +

+ + {{title}} + +

+
+ {{body}} +
+ {{/each}} +
+================================================================================ +`; + +exports[`if-else.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +

+{{#if isAtWork}} + Ship that code! +{{else if isReading}} + You can finish War and Peace eventually... +{{else}} + Go to bed! +{{/if}} +

+ +

+{{#if a}} + A +{{else}} + B +{{/if}} +

+ +{{#if a}} + b +{{else if c}} + d +{{else}} + e +{{/if}} + +{{#if a}} + b +{{else if c}} + d +{{else}} + hello + {{#if f}} + g + {{/if}} + e +{{/if}} + +{{#if a}} + b +{{else if c}} + d +{{else if e}} + f +{{else if g}} + h +{{else}} + j +{{/if}} + +
+ {{#if a}} + b + {{else if c}} + d + {{else}} + e + {{/if}} +
+ +
+
+ {{#if a}} + b + {{else if c}} + d + {{else}} + e + {{/if}} +
+
+ +{{#if a}} + b +{{else}} + {{#each c as |d|}} + e + {{/each}} +{{/if}} + +{{#if a}} + {{#if b}} + ab + {{else if c}} + ac + {{/if}} +{{/if}} + +{{#if a}} + a +
b
+ c +{{else}} + {{#if c}} + a + b +
c
+ {{/if}} +
a
+ b + c +{{/if}} + +=====================================output===================================== +

+ {{#if isAtWork}} + Ship that code! + {{else if isReading}} + You can finish War and Peace eventually... + {{else}} + Go to bed! + {{/if}} +

+ +

+ {{#if a}} + A + {{else}} + B + {{/if}} +

+ +{{#if a}} + b +{{else if c}} + d +{{else}} + e +{{/if}} + +{{#if a}} + b +{{else if c}} + d +{{else}} + hello + {{#if f}} + g + {{/if}} + e +{{/if}} + +{{#if a}} + b +{{else if c}} + d +{{else if e}} + f +{{else if g}} + h +{{else}} + j +{{/if}} + +
+ {{#if a}} + b + {{else if c}} + d + {{else}} + e + {{/if}} +
+ +
+
+ {{#if a}} + b + {{else if c}} + d + {{else}} + e + {{/if}} +
+
+ +{{#if a}} + b +{{else}} + {{#each c as |d|}} + e + {{/each}} +{{/if}} + +{{#if a}} + {{#if b}} + ab + {{else if c}} + ac + {{/if}} +{{/if}} + +{{#if a}} + a +
+ b +
+ c +{{else}} + {{#if c}} + a + b +
+ c +
+ {{/if}} +
+ a +
+ b + c +{{/if}} +================================================================================ +`; + +exports[`if-else.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +

+{{#if isAtWork}} + Ship that code! +{{else if isReading}} + You can finish War and Peace eventually... +{{else}} + Go to bed! +{{/if}} +

+ +

+{{#if a}} + A +{{else}} + B +{{/if}} +

+ +{{#if a}} + b +{{else if c}} + d +{{else}} + e +{{/if}} + +{{#if a}} + b +{{else if c}} + d +{{else}} + hello + {{#if f}} + g + {{/if}} + e +{{/if}} + +{{#if a}} + b +{{else if c}} + d +{{else if e}} + f +{{else if g}} + h +{{else}} + j +{{/if}} + +
+ {{#if a}} + b + {{else if c}} + d + {{else}} + e + {{/if}} +
+ +
+
+ {{#if a}} + b + {{else if c}} + d + {{else}} + e + {{/if}} +
+
+ +{{#if a}} + b +{{else}} + {{#each c as |d|}} + e + {{/each}} +{{/if}} + +{{#if a}} + {{#if b}} + ab + {{else if c}} + ac + {{/if}} +{{/if}} + +{{#if a}} + a +
b
+ c +{{else}} + {{#if c}} + a + b +
c
+ {{/if}} +
a
+ b + c +{{/if}} + +=====================================output===================================== +

+ {{#if isAtWork}} + Ship that code! + {{else if isReading}} + You can finish War and Peace eventually... + {{else}} + Go to bed! + {{/if}} +

+ +

+ {{#if a}} + A + {{else}} + B + {{/if}} +

+ +{{#if a}} + b +{{else if c}} + d +{{else}} + e +{{/if}} + +{{#if a}} + b +{{else if c}} + d +{{else}} + hello + {{#if f}} + g + {{/if}} + e +{{/if}} + +{{#if a}} + b +{{else if c}} + d +{{else if e}} + f +{{else if g}} + h +{{else}} + j +{{/if}} + +
+ {{#if a}} + b + {{else if c}} + d + {{else}} + e + {{/if}} +
+ +
+
+ {{#if a}} + b + {{else if c}} + d + {{else}} + e + {{/if}} +
+
+ +{{#if a}} + b +{{else}} + {{#each c as |d|}} + e + {{/each}} +{{/if}} + +{{#if a}} + {{#if b}} + ab + {{else if c}} + ac + {{/if}} +{{/if}} + +{{#if a}} + a +
+ b +
+ c +{{else}} + {{#if c}} + a + b +
+ c +
+ {{/if}} +
+ a +
+ b + c +{{/if}} +================================================================================ +`; + +exports[`loop.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +
    + {{#each speakers key="@index" as |speaker|}} +
  • {{speaker}}
  • + {{/each}} +
+ +=====================================output===================================== +
    + {{#each speakers key="@index" as |speaker|}} +
  • + {{speaker}} +
  • + {{/each}} +
+================================================================================ +`; + +exports[`loop.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +
    + {{#each speakers key="@index" as |speaker|}} +
  • {{speaker}}
  • + {{/each}} +
+ +=====================================output===================================== +
    + {{#each speakers key='@index' as |speaker|}} +
  • + {{speaker}} +
  • + {{/each}} +
+================================================================================ +`; diff --git a/tests/glimmer/block-statement.hbs b/tests/handlebars-block-statement/block-statement.hbs similarity index 100% rename from tests/glimmer/block-statement.hbs rename to tests/handlebars-block-statement/block-statement.hbs diff --git a/tests/handlebars/each.hbs b/tests/handlebars-block-statement/each.hbs similarity index 100% rename from tests/handlebars/each.hbs rename to tests/handlebars-block-statement/each.hbs diff --git a/tests/glimmer/else-if.hbs b/tests/handlebars-block-statement/if-else.hbs similarity index 78% rename from tests/glimmer/else-if.hbs rename to tests/handlebars-block-statement/if-else.hbs index 94e1fdf809ca..350252fcab5b 100644 --- a/tests/glimmer/else-if.hbs +++ b/tests/handlebars-block-statement/if-else.hbs @@ -1,3 +1,21 @@ +

+{{#if isAtWork}} + Ship that code! +{{else if isReading}} + You can finish War and Peace eventually... +{{else}} + Go to bed! +{{/if}} +

+ +

+{{#if a}} + A +{{else}} + B +{{/if}} +

+ {{#if a}} b {{else if c}} diff --git a/tests/handlebars-block-statement/jsfmt.spec.js b/tests/handlebars-block-statement/jsfmt.spec.js new file mode 100644 index 000000000000..4abf117d9346 --- /dev/null +++ b/tests/handlebars-block-statement/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["glimmer"]); +run_spec(__dirname, ["glimmer"], { singleQuote: true }); diff --git a/tests/glimmer/loop.hbs b/tests/handlebars-block-statement/loop.hbs similarity index 73% rename from tests/glimmer/loop.hbs rename to tests/handlebars-block-statement/loop.hbs index 608d12596c96..5e28341d6667 100644 --- a/tests/glimmer/loop.hbs +++ b/tests/handlebars-block-statement/loop.hbs @@ -1,5 +1,5 @@
    {{#each speakers key="@index" as |speaker|}} -
  • {{speaker}}
  • +
  • {{speaker}}
  • {{/each}}
diff --git a/tests/handlebars-comment/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-comment/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..619dac97204e --- /dev/null +++ b/tests/handlebars-comment/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,46 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`comments.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +
+ {{! Foo }} + {{#if @foo}} + Foo + {{/if}} + + {{! Bar }} + {{#if @bar}} + Bar + {{/if}} +
+ +
+ {{! This comment will not be in the output }} + {{!-- This comment as }} and will not be in the output --}} + +
+ +=====================================output===================================== +
+ {{! Foo }} + {{#if @foo}} + Foo + {{/if}} + + {{! Bar }} + {{#if @bar}} + Bar + {{/if}} +
+ +
+ {{! This comment will not be in the output }} + {{!-- This comment as }} and will not be in the output --}} + +
+================================================================================ +`; diff --git a/tests/handlebars/comments.hbs b/tests/handlebars-comment/comments.hbs similarity index 63% rename from tests/handlebars/comments.hbs rename to tests/handlebars-comment/comments.hbs index c2a47ee0861f..5df2a8a45acb 100644 --- a/tests/handlebars/comments.hbs +++ b/tests/handlebars-comment/comments.hbs @@ -1,3 +1,15 @@ +
+ {{! Foo }} + {{#if @foo}} + Foo + {{/if}} + + {{! Bar }} + {{#if @bar}} + Bar + {{/if}} +
+
{{! This comment will not be in the output }} {{!-- This comment as }} and will not be in the output --}} diff --git a/tests/handlebars/jsfmt.spec.js b/tests/handlebars-comment/jsfmt.spec.js similarity index 100% rename from tests/handlebars/jsfmt.spec.js rename to tests/handlebars-comment/jsfmt.spec.js diff --git a/tests/handlebars-concat-statement/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-concat-statement/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..4be7aaf87d14 --- /dev/null +++ b/tests/handlebars-concat-statement/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,124 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`concat-statement.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +
+ Hello +
+ +
+ Hello +
+ + + +
+
+
+
+
+
+
+
+
+
+=====================================output===================================== +
+ Hello +
+ +
+ Hello +
+ + + +
+
+
+
+
+
+
+
+
+
+================================================================================ +`; + +exports[`concat-statement.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +
+ Hello +
+ +
+ Hello +
+ + + +
+
+
+
+
+
+
+
+
+
+=====================================output===================================== +
+ Hello +
+ +
+ Hello +
+ + + +
+
+
+
+
+
+
+
+
+
+================================================================================ +`; diff --git a/tests/glimmer/concat-statement.hbs b/tests/handlebars-concat-statement/concat-statement.hbs similarity index 100% rename from tests/glimmer/concat-statement.hbs rename to tests/handlebars-concat-statement/concat-statement.hbs diff --git a/tests/handlebars-concat-statement/jsfmt.spec.js b/tests/handlebars-concat-statement/jsfmt.spec.js new file mode 100644 index 000000000000..4abf117d9346 --- /dev/null +++ b/tests/handlebars-concat-statement/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["glimmer"]); +run_spec(__dirname, ["glimmer"], { singleQuote: true }); diff --git a/tests/handlebars-element-node/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-element-node/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..f7914071bab8 --- /dev/null +++ b/tests/handlebars-element-node/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,168 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`element-node.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +
+ Hello +
+ +
+ Hello +
+ +
+ hi +
+ +
+ A long enough string to trigger a line break that would prevent wrapping. +
+ +
+ A long enough string to trigger a line break that would prevent wrapping more. +
+ +
+ A long enough string to trigger a line break that would prevent wrapping more and more. +
+ +
+ {{#block}} + {{hello}} + {{/block}} +
+ +
+ {{hello}} +
+ +
+ + +=====================================output===================================== +
+ Hello +
+ +
+ Hello +
+ +
+ hi +
+ +
+ A long enough string to trigger a line break that would prevent wrapping. +
+ +
+ A long enough string to trigger a line break that would prevent wrapping more. +
+ +
+ A long enough string to trigger a line break that would prevent wrapping more and more. +
+ +
+ {{#block}} + {{hello}} + {{/block}} +
+ +
+ {{hello}} +
+ +
+ +================================================================================ +`; + +exports[`element-node.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +
+ Hello +
+ +
+ Hello +
+ +
+ hi +
+ +
+ A long enough string to trigger a line break that would prevent wrapping. +
+ +
+ A long enough string to trigger a line break that would prevent wrapping more. +
+ +
+ A long enough string to trigger a line break that would prevent wrapping more and more. +
+ +
+ {{#block}} + {{hello}} + {{/block}} +
+ +
+ {{hello}} +
+ +
+ + +=====================================output===================================== +
+ Hello +
+ +
+ Hello +
+ +
+ hi +
+ +
+ A long enough string to trigger a line break that would prevent wrapping. +
+ +
+ A long enough string to trigger a line break that would prevent wrapping more. +
+ +
+ A long enough string to trigger a line break that would prevent wrapping more and more. +
+ +
+ {{#block}} + {{hello}} + {{/block}} +
+ +
+ {{hello}} +
+ +
+ +================================================================================ +`; diff --git a/tests/glimmer/element-node.hbs b/tests/handlebars-element-node/element-node.hbs similarity index 100% rename from tests/glimmer/element-node.hbs rename to tests/handlebars-element-node/element-node.hbs diff --git a/tests/handlebars-element-node/jsfmt.spec.js b/tests/handlebars-element-node/jsfmt.spec.js new file mode 100644 index 000000000000..4abf117d9346 --- /dev/null +++ b/tests/handlebars-element-node/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["glimmer"]); +run_spec(__dirname, ["glimmer"], { singleQuote: true }); diff --git a/tests/handlebars-escape/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-escape/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..f593d0c0846c --- /dev/null +++ b/tests/handlebars-escape/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,30 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`html-entities.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +

Some escaped characters: < > &

+=====================================output===================================== +

+ Some escaped characters: < > & +

+================================================================================ +`; + +exports[`html-entities.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +

Some escaped characters: < > &

+=====================================output===================================== +

+ Some escaped characters: < > & +

+================================================================================ +`; diff --git a/tests/glimmer/html-entities.hbs b/tests/handlebars-escape/html-entities.hbs similarity index 100% rename from tests/glimmer/html-entities.hbs rename to tests/handlebars-escape/html-entities.hbs diff --git a/tests/handlebars-escape/jsfmt.spec.js b/tests/handlebars-escape/jsfmt.spec.js new file mode 100644 index 000000000000..4abf117d9346 --- /dev/null +++ b/tests/handlebars-escape/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["glimmer"]); +run_spec(__dirname, ["glimmer"], { singleQuote: true }); diff --git a/tests/handlebars/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-last-line/__snapshots__/jsfmt.spec.js.snap similarity index 52% rename from tests/handlebars/__snapshots__/jsfmt.spec.js.snap rename to tests/handlebars-last-line/__snapshots__/jsfmt.spec.js.snap index c7ee2c910f33..ba4ac6a88c60 100644 --- a/tests/handlebars/__snapshots__/jsfmt.spec.js.snap +++ b/tests/handlebars-last-line/__snapshots__/jsfmt.spec.js.snap @@ -1,190 +1,80 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`basic-handlebars.hbs 1`] = ` +exports[`empty-with-no-trailing-newline.hbs 1`] = ` ====================================options===================================== parsers: ["glimmer"] printWidth: 80 | printWidth =====================================input====================================== - - -
=====================================output===================================== - -
-================================================================================ -`; -exports[`comments.hbs 1`] = ` -====================================options===================================== -parsers: ["glimmer"] -printWidth: 80 - | printWidth -=====================================input====================================== -
- {{! This comment will not be in the output }} - {{!-- This comment as }} and will not be in the output --}} - -
- -=====================================output===================================== -
- {{! This comment will not be in the output }} - {{!-- This comment as }} and will not be in the output --}} - -
================================================================================ `; -exports[`each.hbs 1`] = ` +exports[`empty-with-no-trailing-newline.hbs 2`] = ` ====================================options===================================== parsers: ["glimmer"] printWidth: 80 +singleQuote: true | printWidth =====================================input====================================== -
- {{#each comments}} -

{{title}}

-
{{body}}
- {{/each}} -
=====================================output===================================== -
- {{#each comments}} -

- - {{title}} - -

-
- {{body}} -
- {{/each}} -
+ ================================================================================ `; -exports[`if.hbs 1`] = ` +exports[`empty-with-trailing-newline.hbs 1`] = ` ====================================options===================================== parsers: ["glimmer"] printWidth: 80 | printWidth =====================================input====================================== -{{#if title}} - {{permalink}} -{{/if}} + =====================================output===================================== -{{#if title}} - {{permalink}} -{{/if}} + ================================================================================ `; -exports[`if-else.hbs 1`] = ` +exports[`empty-with-trailing-newline.hbs 2`] = ` ====================================options===================================== parsers: ["glimmer"] printWidth: 80 +singleQuote: true | printWidth =====================================input====================================== -

-{{#if isAtWork}} - Ship that code! -{{else if isReading}} - You can finish War and Peace eventually... -{{else}} - Go to bed! -{{/if}} -

- -

-{{#if a}} - A -{{else}} - B -{{/if}} -

=====================================output===================================== -

- {{#if isAtWork}} - Ship that code! - {{else if isReading}} - You can finish War and Peace eventually... - {{else}} - Go to bed! - {{/if}} -

-

- {{#if a}} - A - {{else}} - B - {{/if}} -

+ ================================================================================ `; -exports[`nested-path.hbs 1`] = ` +exports[`end-of-line-last.hbs 1`] = ` ====================================options===================================== parsers: ["glimmer"] printWidth: 80 | printWidth =====================================input====================================== -
-

{{title}}

-

By {{author.name}}

- -
- {{body}} -
-
+a bare string to hightlight eol last handling =====================================output===================================== -
-

- {{title}} -

-

- By {{author.name}} -

-
- {{body}} -
-
+a bare string to hightlight eol last handling ================================================================================ `; -exports[`raw.hbs 1`] = ` +exports[`end-of-line-last.hbs 2`] = ` ====================================options===================================== parsers: ["glimmer"] printWidth: 80 +singleQuote: true | printWidth =====================================input====================================== -

{{{raw}}}

+a bare string to hightlight eol last handling =====================================output===================================== -

- {{{raw}}} -

+a bare string to hightlight eol last handling ================================================================================ `; diff --git a/tests/handlebars-last-line/empty-with-no-trailing-newline.hbs b/tests/handlebars-last-line/empty-with-no-trailing-newline.hbs new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/tests/handlebars-last-line/empty-with-trailing-newline.hbs b/tests/handlebars-last-line/empty-with-trailing-newline.hbs new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/tests/handlebars-last-line/empty-with-trailing-newline.hbs @@ -0,0 +1 @@ + diff --git a/tests/handlebars-last-line/end-of-line-last.hbs b/tests/handlebars-last-line/end-of-line-last.hbs new file mode 100644 index 000000000000..71ec7dc1d166 --- /dev/null +++ b/tests/handlebars-last-line/end-of-line-last.hbs @@ -0,0 +1 @@ +a bare string to hightlight eol last handling diff --git a/tests/handlebars-last-line/jsfmt.spec.js b/tests/handlebars-last-line/jsfmt.spec.js new file mode 100644 index 000000000000..4abf117d9346 --- /dev/null +++ b/tests/handlebars-last-line/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["glimmer"]); +run_spec(__dirname, ["glimmer"], { singleQuote: true }); diff --git a/tests/handlebars-mustache-statement/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-mustache-statement/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..13a4e586c1d9 --- /dev/null +++ b/tests/handlebars-mustache-statement/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,154 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`element-modifier-statement.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +
+ Hello +
+ +
+ Hello +
+ +
+ Hello +
+ +
+ Hello +
+ +=====================================output===================================== +
+ Hello +
+ +
+ Hello +
+ +
+ Hello +
+ +
+ Hello +
+================================================================================ +`; + +exports[`element-modifier-statement.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +
+ Hello +
+ +
+ Hello +
+ +
+ Hello +
+ +
+ Hello +
+ +=====================================output===================================== +
+ Hello +
+ +
+ Hello +
+ +
+ Hello +
+ +
+ Hello +
+================================================================================ +`; diff --git a/tests/glimmer/element-modifier-statement.hbs b/tests/handlebars-mustache-statement/element-modifier-statement.hbs similarity index 100% rename from tests/glimmer/element-modifier-statement.hbs rename to tests/handlebars-mustache-statement/element-modifier-statement.hbs diff --git a/tests/handlebars-mustache-statement/jsfmt.spec.js b/tests/handlebars-mustache-statement/jsfmt.spec.js new file mode 100644 index 000000000000..4abf117d9346 --- /dev/null +++ b/tests/handlebars-mustache-statement/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["glimmer"]); +run_spec(__dirname, ["glimmer"], { singleQuote: true }); diff --git a/tests/handlebars-newline/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-newline/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..d0695fdb9791 --- /dev/null +++ b/tests/handlebars-newline/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,149 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +

+ Welcome to the Ember.js Guides. + This documentation will take you from total beginner to Ember expert. +

+ +{{!-- newlines text --}} +
+ hi + there + how + + are you + + + are you fine today? +
+ +{{!-- newlines text spaced --}} +
+ + space above + + space below + +
+ +{{!-- newlines elems spaced --}} +
+ + space above + + space below + +
+ +{{!-- newlines mixed --}} +
+ hi + there + + how + + are you + + + are you fine today? +
+ +{{!-- newlines elems --}} +
+
+ + +
+ + +
+ + + hi + + +
+ + + + + +
+ +=====================================output===================================== +

+ Welcome to the + + Ember.js Guides + + . + This documentation will take you from total beginner to Ember expert. +

+ +{{! newlines text }} +
+ hi + there + how + + are you + + + are you fine today? +
+ +{{! newlines text spaced }} +
+ space above + + space below +
+ +{{! newlines elems spaced }} +
+ + space above + + + + space below + +
+ +{{! newlines mixed }} +
+ hi + + there + + + how + + are + + you + + + are you fine today? +
+ +{{! newlines elems }} +
+
+
+
+ + hi + +
+ + +
+================================================================================ +`; diff --git a/tests/handlebars-newline/jsfmt.spec.js b/tests/handlebars-newline/jsfmt.spec.js new file mode 100644 index 000000000000..da9b88409539 --- /dev/null +++ b/tests/handlebars-newline/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["glimmer"]); diff --git a/tests/handlebars-newline/test.hbs b/tests/handlebars-newline/test.hbs new file mode 100644 index 000000000000..0f8bf4e49807 --- /dev/null +++ b/tests/handlebars-newline/test.hbs @@ -0,0 +1,69 @@ +

+ Welcome to the Ember.js Guides. + This documentation will take you from total beginner to Ember expert. +

+ +{{!-- newlines text --}} +
+ hi + there + how + + are you + + + are you fine today? +
+ +{{!-- newlines text spaced --}} +
+ + space above + + space below + +
+ +{{!-- newlines elems spaced --}} +
+ + space above + + space below + +
+ +{{!-- newlines mixed --}} +
+ hi + there + + how + + are you + + + are you fine today? +
+ +{{!-- newlines elems --}} +
+
+ + +
+ + +
+ + + hi + + +
+ + + + + +
diff --git a/tests/handlebars-sub-expression/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-sub-expression/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..9b29346fd8a5 --- /dev/null +++ b/tests/handlebars-sub-expression/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,198 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`sub-expressions.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +
+ +{{#block + (concat + (service) + (helper param hashPair=Value) + (largeNameHelper param param param param hashPair=value hashPair=value hashPair=Value) + hashPair=(helper param param param param param param hashPair=value hashPair=value hashPair=value) + hashPair=(does not need a line break due to being under 80 chars long) + ) +}} + +{{/block}} + +{{foobar-sub-component/foobar-foo + hook="stringLiteral" + foo= + (t + (concat "stringLiteral" (get blockParam "stringLiteral") hash=hash hash=hash) + foo=(simple-helper (hash hashKey=blockParam.foo assignParam=blockParam.bar)) + ) +}} + +=====================================output===================================== +
+ +{{#block + (concat + (service) + (helper param hashPair=Value) + (largeNameHelper + param param param param hashPair=value hashPair=value hashPair=Value + ) + hashPair=(helper + param + param + param + param + param + param + hashPair=value + hashPair=value + hashPair=value + ) + hashPair=(does not need a line break due to being under 80 chars long) + ) +}}{{/block}} + +{{foobar-sub-component/foobar-foo + hook="stringLiteral" + foo=(t + (concat + "stringLiteral" (get blockParam "stringLiteral") hash=hash hash=hash + ) + foo=(simple-helper (hash hashKey=blockParam.foo assignParam=blockParam.bar)) + ) +}} +================================================================================ +`; + +exports[`sub-expressions.hbs 2`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +
+ +{{#block + (concat + (service) + (helper param hashPair=Value) + (largeNameHelper param param param param hashPair=value hashPair=value hashPair=Value) + hashPair=(helper param param param param param param hashPair=value hashPair=value hashPair=value) + hashPair=(does not need a line break due to being under 80 chars long) + ) +}} + +{{/block}} + +{{foobar-sub-component/foobar-foo + hook="stringLiteral" + foo= + (t + (concat "stringLiteral" (get blockParam "stringLiteral") hash=hash hash=hash) + foo=(simple-helper (hash hashKey=blockParam.foo assignParam=blockParam.bar)) + ) +}} + +=====================================output===================================== +
+ +{{#block + (concat + (service) + (helper param hashPair=Value) + (largeNameHelper + param param param param hashPair=value hashPair=value hashPair=Value + ) + hashPair=(helper + param + param + param + param + param + param + hashPair=value + hashPair=value + hashPair=value + ) + hashPair=(does not need a line break due to being under 80 chars long) + ) +}}{{/block}} + +{{foobar-sub-component/foobar-foo + hook='stringLiteral' + foo=(t + (concat + 'stringLiteral' (get blockParam 'stringLiteral') hash=hash hash=hash + ) + foo=(simple-helper (hash hashKey=blockParam.foo assignParam=blockParam.bar)) + ) +}} +================================================================================ +`; diff --git a/tests/handlebars-sub-expression/jsfmt.spec.js b/tests/handlebars-sub-expression/jsfmt.spec.js new file mode 100644 index 000000000000..4abf117d9346 --- /dev/null +++ b/tests/handlebars-sub-expression/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["glimmer"]); +run_spec(__dirname, ["glimmer"], { singleQuote: true }); diff --git a/tests/glimmer/sub-expressions.hbs b/tests/handlebars-sub-expression/sub-expressions.hbs similarity index 100% rename from tests/glimmer/sub-expressions.hbs rename to tests/handlebars-sub-expression/sub-expressions.hbs diff --git a/tests/handlebars-text-wrap/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-text-wrap/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..4fc3c28e941d --- /dev/null +++ b/tests/handlebars-text-wrap/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,415 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 80 + | printWidth +=====================================input====================================== +{{!-- Wrapping text --}} +
+ Some text that would need to wrap on to a new line in order to display correctly and nicely +
+ +{{!-- Wrapping tags --}} +
+ f f f f f f +
+ +{{!-- Wrapping tags --}} +
+ ffffff +
+ +{{!-- Wrapping tags --}} +
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa f +
+ +
+ before
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at mollis lorem.
after +
+ +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}{stuff}{stuff}after{stuff}after +
+ +
+ before {{stuff}} after {{stuff}} after {{stuff}} after {{stuff}} after {{stuff}} after {{stuff}} {{stuff}} {{stuff}} after {{stuff}} after +
+ +
+ Please state your name and occupation for the board of school directors. +
+ +
+ First second third +
Something
+
+ +
+
+ First +
+ Second +
+ Third +
+
+ +
+ First
+ Second +
Third +
+ +{{!-- leading whitespace --}} +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +{{!-- trailing whitespace --}} +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +{{!-- no leading or trailing whitespace --}} +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +{{!-- translation leave text around tag --}} +
+ + First + , + ( + Second + ) +
+ +
+ + First second third fourth fifth sixth seventh + , + ( + Second + ) +
+ +{{!-- this really should split across lines --}} +
+ before{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after +
+ +{{!-- solitary whitespace --}} +
+ +{{!-- whitespace on newline --}} +
+
+ First +
+ Second +
+ Third +
+
+ +{{!-- around multiline element --}} +
Before
{"Enough text to make this element wrap on to multiple lines when formatting"}
After
+ +{{!-- around multiline element second pass --}} +
+ Before{" "} +
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
{" "} + After +
+ +{{!-- dont preserve blank lines when contains text --}} +
+ +
Zeroth
+ +
First
+ + Second + +
+ +{{!-- multiple expressions --}} +
+ {{header}} + {{body}} + {{footer}} +
+ +{{!-- single expression child tags --}} +
+ You currently have {{dashboardStr}} and {{userStr}} +
+ +{{!-- expression does not break --}} +
texty text text text text text text text text text text text {{this.props.type}}
+ +// FIXME + +=====================================output===================================== +{{! Wrapping text }} +
+ Some text that would need to wrap on to a new line in order to display correctly and nicely +
+ +{{! Wrapping tags }} +
+ + f + + + + f + + + + f + + + + f + + + + f + + + + f + +
+ +{{! Wrapping tags }} +
+ + f + + + f + + + f + + + f + + + f + + + f + +
+ +{{! Wrapping tags }} +
+ + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + + + f + +
+ +
+ before +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at mollis lorem. +
+ after +
+ +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}{stuff}{stuff}after{stuff}after +
+ +
+ before {{stuff}} after {{stuff}} after {{stuff}} after {{stuff}} after {{stuff + }} after {{stuff}} {{stuff}} {{stuff}} after {{stuff}} after +
+ +
+ Please state your + + name + + and + + occupation + + for the board of + + school + + directors. +
+ +
+ First second third +
+ Something +
+
+ +
+
+ First +
+ Second +
+ Third +
+
+ +
+ First +
+ Second +
+ Third +
+ +{{! leading whitespace }} +
+ First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth +
+ +{{! trailing whitespace }} +
+ First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth +
+ +{{! no leading or trailing whitespace }} +
+ First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth +
+ +{{! translation leave text around tag }} +
+ + First + + , + ( + + Second + + ) +
+ +
+ + First second third fourth fifth sixth seventh + + , + ( + + Second + + ) +
+ +{{! this really should split across lines }} +
+ before{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff + }}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff + }}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after +
+ +{{! solitary whitespace }} +
+
+ +{{! whitespace on newline }} +
+
+ First +
+ +
+ Second +
+ +
+ Third +
+
+ +{{! around multiline element }} +
+ Before +
+ {"Enough text to make this element wrap on to multiple lines when formatting"} +
+ After +
+ +{{! around multiline element second pass }} +
+ Before{" "} +
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
+ {" "} + After +
+ +{{! dont preserve blank lines when contains text }} +
+
+ Zeroth +
+ +
+ First +
+ + Second +
+ +{{! multiple expressions }} +
+ {{header}} + {{body}} + {{footer}} +
+ +{{! single expression child tags }} +
+ You currently have + + {{dashboardStr}} + + and + + {{userStr}} + +
+ +{{! expression does not break }} +
+ texty text text text text text text text text text text text {{this.props.type + }} +
+ +// FIXME +================================================================================ +`; diff --git a/tests/handlebars-text-wrap/jsfmt.spec.js b/tests/handlebars-text-wrap/jsfmt.spec.js new file mode 100644 index 000000000000..da9b88409539 --- /dev/null +++ b/tests/handlebars-text-wrap/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["glimmer"]); diff --git a/tests/handlebars-text-wrap/test.hbs b/tests/handlebars-text-wrap/test.hbs new file mode 100644 index 000000000000..449053348e81 --- /dev/null +++ b/tests/handlebars-text-wrap/test.hbs @@ -0,0 +1,145 @@ +{{!-- Wrapping text --}} +
+ Some text that would need to wrap on to a new line in order to display correctly and nicely +
+ +{{!-- Wrapping tags --}} +
+ f f f f f f +
+ +{{!-- Wrapping tags --}} +
+ ffffff +
+ +{{!-- Wrapping tags --}} +
+ aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa f +
+ +
+ before
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur at mollis lorem.
after +
+ +
+ before{stuff}after{stuff}after{stuff}after{stuff}after{stuff}after{stuff}{stuff}{stuff}after{stuff}after +
+ +
+ before {{stuff}} after {{stuff}} after {{stuff}} after {{stuff}} after {{stuff}} after {{stuff}} {{stuff}} {{stuff}} after {{stuff}} after +
+ +
+ Please state your name and occupation for the board of school directors. +
+ +
+ First second third +
Something
+
+ +
+
+ First +
+ Second +
+ Third +
+
+ +
+ First
+ Second +
Third +
+ +{{!-- leading whitespace --}} +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +{{!-- trailing whitespace --}} +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +{{!-- no leading or trailing whitespace --}} +
First Second Third Fourth Fifth Sixth Seventh Eighth Ninth Tenth Eleventh Twelfth Thirteenth Fourteenth
+ +{{!-- translation leave text around tag --}} +
+ + First + , + ( + Second + ) +
+ +
+ + First second third fourth fifth sixth seventh + , + ( + Second + ) +
+ +{{!-- this really should split across lines --}} +
+ before{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after{{stuff}}after +
+ +{{!-- solitary whitespace --}} +
+ +{{!-- whitespace on newline --}} +
+
+ First +
+ Second +
+ Third +
+
+ +{{!-- around multiline element --}} +
Before
{"Enough text to make this element wrap on to multiple lines when formatting"}
After
+ +{{!-- around multiline element second pass --}} +
+ Before{" "} +
+ { + "Enough text to make this element wrap on to multiple lines when formatting" + } +
{" "} + After +
+ +{{!-- dont preserve blank lines when contains text --}} +
+ +
Zeroth
+ +
First
+ + Second + +
+ +{{!-- multiple expressions --}} +
+ {{header}} + {{body}} + {{footer}} +
+ +{{!-- single expression child tags --}} +
+ You currently have {{dashboardStr}} and {{userStr}} +
+ +{{!-- expression does not break --}} +
texty text text text text text text text text text text text {{this.props.type}}
+ +// FIXME diff --git a/tests/handlebars-whitespace/__snapshots__/jsfmt.spec.js.snap b/tests/handlebars-whitespace/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..3ebddb6cc831 --- /dev/null +++ b/tests/handlebars-whitespace/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,519 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`basics.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== +{{!-- after --}} + + foo bar + + +{{!-- before --}} + + bar foo + + +{{!-- within --}} + + foo bar + + +{{!-- break components --}} +
+ +

foobar bar bar

yep

+
+

nope

+
+ +
+ hello hi sdkflsdfjk +
; + +=====================================output===================================== +{{! after }} + + foo + + bar + + + +{{! before }} + + + bar + + foo + + +{{! within }} + + foo + + bar + + + +{{! break components }} +
+ +

+ foo + + bar bar bar + +

+

+ + + yep + + +

+
+

+ nope +

+
+ +
+ hello + + hi + + + + sdkflsdfjk + +
+; +================================================================================ +`; + +exports[`boss.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== +

Hi {{firstName}} {{lastName}} , welcome!

+{{#component propA}} + for {{propB}} do {{propC}} f +{{/component}} +{{#component propA}} + for {{propB}} namedo {{propC}} f +{{/component}} +{{propA}} {{propB}} +{{propC}}{{propD}} +{{propE}} {{propF}} +{{propG}}{{propH}} + + + +hey + +=====================================output===================================== +

+ Hi {{firstName}} {{lastName + }} , welcome! +

+{{#component propA}} + for {{propB}} do {{propC}} f +{{/component}} +{{#component propA}} + for {{propB}} + + name + + do {{propC}} f +{{/component}} +{{propA}} {{propB}} +{{propC}}{{propD}} + + {{propE}} {{propF}} + + + {{propG}}{{propH}} + + +hey +================================================================================ +`; + +exports[`curly.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== +

Your username is @{{name}}

+

Hi {{firstName}} {{lastName}}

+=====================================output===================================== +

+ Your username is @{{name}} +

+

+ Hi {{firstName}} {{lastName}} +

+================================================================================ +`; + +exports[`display-inline-block.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== + + +
+ +
+
+ + +
+ + +=====================================output===================================== + + +
+ + +
+
+ + +
+ +================================================================================ +`; + +exports[`display-none.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== +{{!-- TO FIX --}} +My tITlE + +=====================================output===================================== +{{! TO FIX }} + + + + My tITlE + + + +================================================================================ +`; + +exports[`fill.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== +

+ about fedco bottom imageWe are a cooperative, one of the few seed companies so organized + in the United States. Because we do not have an individual owner or beneficiary, + profit is not our primary goal. Consumers own 60% of the cooperative and worker + members 40%. Consumer and worker members share proportionately in the cooperative’s + profits through our annual patronage dividends. +

+ +=====================================output===================================== +

+ about fedco bottom image + + We are a cooperative + + , one of the few seed companies so organized + in the United States. Because we do not have an individual owner or beneficiary, + profit is not our primary goal. Consumers own 60% of the cooperative and worker + members 40%. Consumer and worker members share proportionately in the cooperative’s + profits through our annual patronage dividends. +

+================================================================================ +`; + +exports[`inline-element.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== +{{!-- TO FIX --}} +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue +vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim. +Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh. +Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui. +Sed eu scelerisque neque. Donec maximus rhoncus pellentesque. Aenean purus turpis, vehicula +euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per +conubia nostra, per inceptos himenaeos. Donec in ornare velit.

+ +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue +vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim. +Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh. +Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui. +Sed eu scelerisque neque. Donec maximus rhoncus pellentesque. Aenean purus turpis, vehicula +euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per +conubia nostra, per inceptos himenaeos. Donec in ornare velit.

+ +=====================================output===================================== +{{! TO FIX }} +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue +vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim. +Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh. +Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui. +Sed eu scelerisque neque. Donec + + maximus + + rhoncus pellentesque. Aenean purus turpis, vehicula +euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per +conubia nostra, per inceptos himenaeos. Donec in ornare velit. +

+ +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue +vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim. +Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh. +Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui. +Sed eu scelerisque neque. Donec + + + maximus + + + rhoncus pellentesque. Aenean purus turpis, vehicula +euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per +conubia nostra, per inceptos himenaeos. Donec in ornare velit. +

+================================================================================ +`; + +exports[`non-breaking-whitespace.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== + +Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. + +Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. + +Prix : 32 € + +=====================================output===================================== + + + Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. + + + + Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. + + + + Prix : 32 € + +================================================================================ +`; + +exports[`punctuation.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== +This is your name: {{name}}. +This is your name: {{name}} (employee) +This is your name: {{name}} ({{role}}) + +=====================================output===================================== + + This is your name: {{name}}. + + + This is your name: {{name}} (employee) + + + This is your name: {{name}} ({{role}}) + +================================================================================ +`; + +exports[`surrounding-linebreak.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== +123 + +123 +123 + + +123 + + +
123
+
+123
+
123 +
+
+123 +
+ +=====================================output===================================== + + 123 + + + 123 + + + 123 + + + 123 + + +
+ 123 +
+
+ 123 +
+
+ 123 +
+
+ 123 +
+================================================================================ +`; + +exports[`table.hbs 1`] = ` +====================================options===================================== +parsers: ["glimmer"] +printWidth: 40 + | printWidth +=====================================input====================================== + + + + + + + + +
ABC
+ +
ABC
+ +
A B C
+ + + + + + +
+ +=====================================output===================================== + + + + + + + + +
+ A + + B + + C +
+ + + + + + + + + +
+ A + + B + + C +
+ + + + + + + + + + + +
+ A + + B + + C +
+ + + + + + +
+================================================================================ +`; diff --git a/tests/handlebars-whitespace/basics.hbs b/tests/handlebars-whitespace/basics.hbs new file mode 100644 index 000000000000..89cae36b604d --- /dev/null +++ b/tests/handlebars-whitespace/basics.hbs @@ -0,0 +1,26 @@ +{{!-- after --}} + + foo bar + + +{{!-- before --}} + + bar foo + + +{{!-- within --}} + + foo bar + + +{{!-- break components --}} +
+ +

foobar bar bar

yep

+
+

nope

+
+ +
+ hello hi sdkflsdfjk +
; diff --git a/tests/handlebars-whitespace/boss.hbs b/tests/handlebars-whitespace/boss.hbs new file mode 100644 index 000000000000..1e15a8a9c5e1 --- /dev/null +++ b/tests/handlebars-whitespace/boss.hbs @@ -0,0 +1,15 @@ +

Hi {{firstName}} {{lastName}} , welcome!

+{{#component propA}} + for {{propB}} do {{propC}} f +{{/component}} +{{#component propA}} + for {{propB}} namedo {{propC}} f +{{/component}} +{{propA}} {{propB}} +{{propC}}{{propD}} +{{propE}} {{propF}} +{{propG}}{{propH}} + + + +hey diff --git a/tests/glimmer/curly.hbs b/tests/handlebars-whitespace/curly.hbs similarity index 100% rename from tests/glimmer/curly.hbs rename to tests/handlebars-whitespace/curly.hbs diff --git a/tests/handlebars-whitespace/display-inline-block.hbs b/tests/handlebars-whitespace/display-inline-block.hbs new file mode 100644 index 000000000000..abb068528c14 --- /dev/null +++ b/tests/handlebars-whitespace/display-inline-block.hbs @@ -0,0 +1,12 @@ + + +
+ +
+
+ + +
+ diff --git a/tests/handlebars-whitespace/display-none.hbs b/tests/handlebars-whitespace/display-none.hbs new file mode 100644 index 000000000000..0570c11ee3ad --- /dev/null +++ b/tests/handlebars-whitespace/display-none.hbs @@ -0,0 +1,2 @@ +{{!-- TO FIX --}} +My tITlE diff --git a/tests/handlebars-whitespace/fill.hbs b/tests/handlebars-whitespace/fill.hbs new file mode 100644 index 000000000000..3a475a4263da --- /dev/null +++ b/tests/handlebars-whitespace/fill.hbs @@ -0,0 +1,11 @@ +

+ about fedco bottom imageWe are a cooperative, one of the few seed companies so organized + in the United States. Because we do not have an individual owner or beneficiary, + profit is not our primary goal. Consumers own 60% of the cooperative and worker + members 40%. Consumer and worker members share proportionately in the cooperative’s + profits through our annual patronage dividends. +

diff --git a/tests/handlebars-whitespace/inline-element.hbs b/tests/handlebars-whitespace/inline-element.hbs new file mode 100644 index 000000000000..749afd13cdff --- /dev/null +++ b/tests/handlebars-whitespace/inline-element.hbs @@ -0,0 +1,16 @@ +{{!-- TO FIX --}} +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue +vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim. +Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh. +Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui. +Sed eu scelerisque neque. Donec maximus rhoncus pellentesque. Aenean purus turpis, vehicula +euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per +conubia nostra, per inceptos himenaeos. Donec in ornare velit.

+ +

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce cursus massa vel augue +vestibulum facilisis in porta turpis. Ut faucibus lectus sit amet urna consectetur dignissim. +Sam vitae neque quis ex dapibus faucibus at sed ligula. Nulla sit amet aliquet nibh. +Vestibulum at congue mi. Suspendisse vitae odio vitae massa hendrerit mattis sed eget dui. +Sed eu scelerisque neque. Donec maximus rhoncus pellentesque. Aenean purus turpis, vehicula +euismod ante vel, ultricies eleifend dui. Class aptent taciti sociosqu ad litora torquent per +conubia nostra, per inceptos himenaeos. Donec in ornare velit.

diff --git a/tests/handlebars-whitespace/jsfmt.spec.js b/tests/handlebars-whitespace/jsfmt.spec.js new file mode 100644 index 000000000000..36123c9a9e0f --- /dev/null +++ b/tests/handlebars-whitespace/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["glimmer"], { printWidth: 40 }); diff --git a/tests/handlebars-whitespace/non-breaking-whitespace.hbs b/tests/handlebars-whitespace/non-breaking-whitespace.hbs new file mode 100644 index 000000000000..55a8b9477611 --- /dev/null +++ b/tests/handlebars-whitespace/non-breaking-whitespace.hbs @@ -0,0 +1,6 @@ + +Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. + +Nihil aut odit omnis. Quam maxime est molestiae. Maxime dolorem dolores voluptas quaerat ut qui sunt vitae error. + +Prix : 32 € diff --git a/tests/handlebars-whitespace/punctuation.hbs b/tests/handlebars-whitespace/punctuation.hbs new file mode 100644 index 000000000000..762851bd11c5 --- /dev/null +++ b/tests/handlebars-whitespace/punctuation.hbs @@ -0,0 +1,3 @@ +This is your name: {{name}}. +This is your name: {{name}} (employee) +This is your name: {{name}} ({{role}}) diff --git a/tests/handlebars-whitespace/surrounding-linebreak.hbs b/tests/handlebars-whitespace/surrounding-linebreak.hbs new file mode 100644 index 000000000000..06862ebaa584 --- /dev/null +++ b/tests/handlebars-whitespace/surrounding-linebreak.hbs @@ -0,0 +1,17 @@ +123 + +123 +123 + + +123 + + +
123
+
+123
+
123 +
+
+123 +
diff --git a/tests/handlebars-whitespace/table.hbs b/tests/handlebars-whitespace/table.hbs new file mode 100644 index 000000000000..c161476daa7e --- /dev/null +++ b/tests/handlebars-whitespace/table.hbs @@ -0,0 +1,20 @@ + + + + + + + + +
ABC
+ +
ABC
+ +
A B C
+ + + + + + +
diff --git a/tests/handlebars/if-else.hbs b/tests/handlebars/if-else.hbs deleted file mode 100644 index 9d0ce58574d1..000000000000 --- a/tests/handlebars/if-else.hbs +++ /dev/null @@ -1,18 +0,0 @@ -

-{{#if isAtWork}} - Ship that code! -{{else if isReading}} - You can finish War and Peace eventually... -{{else}} - Go to bed! -{{/if}} -

- -

-{{#if a}} - A -{{else}} - B -{{/if}} -

- diff --git a/tests/handlebars/if.hbs b/tests/handlebars/if.hbs deleted file mode 100644 index 0ac91886f2cc..000000000000 --- a/tests/handlebars/if.hbs +++ /dev/null @@ -1,3 +0,0 @@ -{{#if title}} - {{permalink}} -{{/if}} diff --git a/tests/html_script/__snapshots__/jsfmt.spec.js.snap b/tests/html_script/__snapshots__/jsfmt.spec.js.snap index 18a5cad25c06..cb08b08ca503 100644 --- a/tests/html_script/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_script/__snapshots__/jsfmt.spec.js.snap @@ -7,13 +7,49 @@ printWidth: 80 | printWidth =====================================input====================================== + + + + + =====================================output===================================== + + + + + + + ================================================================================ `; diff --git a/tests/html_script/script.html b/tests/html_script/script.html index 5010a12a80e2..580ac1738f9a 100644 --- a/tests/html_script/script.html +++ b/tests/html_script/script.html @@ -1,3 +1,20 @@ + + + + + diff --git a/tests/html_vue_indent/__snapshots__/jsfmt.spec.js.snap b/tests/html_vue_indent/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..f9bcc9196e2f --- /dev/null +++ b/tests/html_vue_indent/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,229 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`inside-template.vue 1`] = ` +====================================options===================================== +parsers: ["vue"] +printWidth: 80 +vueIndentScriptAndStyle: true + | printWidth +=====================================input====================================== + + +=====================================output===================================== + + +================================================================================ +`; + +exports[`inside-template.vue 2`] = ` +====================================options===================================== +parsers: ["vue"] +printWidth: 80 +vueIndentScriptAndStyle: false + | printWidth +=====================================input====================================== + + +=====================================output===================================== + + +================================================================================ +`; + +exports[`vue-tag-indent.vue 1`] = ` +====================================options===================================== +parsers: ["vue"] +printWidth: 80 +vueIndentScriptAndStyle: true + | printWidth +=====================================input====================================== + + + + + + +=====================================output===================================== + + + + + + +================================================================================ +`; + +exports[`vue-tag-indent.vue 2`] = ` +====================================options===================================== +parsers: ["vue"] +printWidth: 80 +vueIndentScriptAndStyle: false + | printWidth +=====================================input====================================== + + + + + + +=====================================output===================================== + + + + + + +================================================================================ +`; diff --git a/tests/html_vue_indent/inside-template.vue b/tests/html_vue_indent/inside-template.vue new file mode 100644 index 000000000000..3966a06e9d41 --- /dev/null +++ b/tests/html_vue_indent/inside-template.vue @@ -0,0 +1,22 @@ + diff --git a/tests/html_vue_indent/jsfmt.spec.js b/tests/html_vue_indent/jsfmt.spec.js new file mode 100644 index 000000000000..7f407e46e2d8 --- /dev/null +++ b/tests/html_vue_indent/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["vue"], { vueIndentScriptAndStyle: true }); +run_spec(__dirname, ["vue"], { vueIndentScriptAndStyle: false }); diff --git a/tests/html_vue_indent/vue-tag-indent.vue b/tests/html_vue_indent/vue-tag-indent.vue new file mode 100644 index 000000000000..62a729e9e100 --- /dev/null +++ b/tests/html_vue_indent/vue-tag-indent.vue @@ -0,0 +1,22 @@ + + + + + diff --git a/tests/html_whitespace/__snapshots__/jsfmt.spec.js.snap b/tests/html_whitespace/__snapshots__/jsfmt.spec.js.snap index 4e8a8a5339be..8d0eeb6c8f71 100644 --- a/tests/html_whitespace/__snapshots__/jsfmt.spec.js.snap +++ b/tests/html_whitespace/__snapshots__/jsfmt.spec.js.snap @@ -332,3 +332,31 @@ printWidth: 80 ================================================================================ `; + +exports[`template.html 1`] = ` +====================================options===================================== +parsers: ["html"] +printWidth: 80 + | printWidth +=====================================input====================================== + + + + +=====================================output===================================== + + + + +================================================================================ +`; diff --git a/tests/html_whitespace/template.html b/tests/html_whitespace/template.html new file mode 100644 index 000000000000..c1910c0e82c5 --- /dev/null +++ b/tests/html_whitespace/template.html @@ -0,0 +1,7 @@ + + + diff --git a/tests/if/__snapshots__/jsfmt.spec.js.snap b/tests/if/__snapshots__/jsfmt.spec.js.snap index 865fb4bbfc65..c69c01c205d0 100644 --- a/tests/if/__snapshots__/jsfmt.spec.js.snap +++ b/tests/if/__snapshots__/jsfmt.spec.js.snap @@ -93,7 +93,7 @@ parsers: ["flow", "typescript"] printWidth: 80 | printWidth =====================================input====================================== -async function f() { +async function f1() { if (untrackedChoice === 0) /* Cancel */ { return null; } else if (untrackedChoice === 1) /* Add */ { @@ -104,7 +104,7 @@ async function f() { } } -async function f() { +async function f2() { if (untrackedChoice === 0) /* Cancel */ null; else if (untrackedChoice === 1) /* Add */ @@ -113,7 +113,7 @@ async function f() { allowUntracked = true; } -async function f() { +async function f3() { if (untrackedChoice === 0) /* Cancel */ // Cancel null; else if (untrackedChoice === 1) /* Add */ // Add @@ -122,7 +122,7 @@ async function f() { allowUntracked = true; } -async function f() { +async function f4() { if (untrackedChoice === 0) /* Cancel */ { return null; @@ -138,7 +138,7 @@ async function f() { } } -async function f() { +async function f5() { if (untrackedChoice === 0) { /* Cancel */ return null; } else if (untrackedChoice === 1) { @@ -150,7 +150,7 @@ async function f() { } =====================================output===================================== -async function f() { +async function f1() { if (untrackedChoice === 0) { /* Cancel */ return null; } else if (untrackedChoice === 1) { @@ -161,7 +161,7 @@ async function f() { } } -async function f() { +async function f2() { if (untrackedChoice === 0) /* Cancel */ null; @@ -173,7 +173,7 @@ async function f() { allowUntracked = true; } -async function f() { +async function f3() { if (untrackedChoice === 0) /* Cancel */ // Cancel null; @@ -185,7 +185,7 @@ async function f() { allowUntracked = true; } -async function f() { +async function f4() { if (untrackedChoice === 0) { /* Cancel */ return null; } else if (untrackedChoice === 1) { @@ -196,7 +196,7 @@ async function f() { } } -async function f() { +async function f5() { if (untrackedChoice === 0) { /* Cancel */ return null; } else if (untrackedChoice === 1) { diff --git a/tests/if/if_comments.js b/tests/if/if_comments.js index 2295fe836613..bf2a7d61eef2 100644 --- a/tests/if/if_comments.js +++ b/tests/if/if_comments.js @@ -1,4 +1,4 @@ -async function f() { +async function f1() { if (untrackedChoice === 0) /* Cancel */ { return null; } else if (untrackedChoice === 1) /* Add */ { @@ -9,7 +9,7 @@ async function f() { } } -async function f() { +async function f2() { if (untrackedChoice === 0) /* Cancel */ null; else if (untrackedChoice === 1) /* Add */ @@ -18,7 +18,7 @@ async function f() { allowUntracked = true; } -async function f() { +async function f3() { if (untrackedChoice === 0) /* Cancel */ // Cancel null; else if (untrackedChoice === 1) /* Add */ // Add @@ -27,7 +27,7 @@ async function f() { allowUntracked = true; } -async function f() { +async function f4() { if (untrackedChoice === 0) /* Cancel */ { return null; @@ -43,7 +43,7 @@ async function f() { } } -async function f() { +async function f5() { if (untrackedChoice === 0) { /* Cancel */ return null; } else if (untrackedChoice === 1) { diff --git a/tests/import/__snapshots__/jsfmt.spec.js.snap b/tests/import/__snapshots__/jsfmt.spec.js.snap index fef6c294a1db..53473bdf0ad6 100644 --- a/tests/import/__snapshots__/jsfmt.spec.js.snap +++ b/tests/import/__snapshots__/jsfmt.spec.js.snap @@ -84,18 +84,18 @@ import { a as //comment1 //comment2 //comment3 - b + b1 } from ""; import { a as //comment2 //comment1 //comment3 - b + b2 } from ""; import { a as //comment3 //comment2 //comment1 - b + b3 } from ""; import { @@ -133,18 +133,18 @@ import { //comment1 //comment2 //comment3 - a as b + a as b1 } from ""; import { //comment2 //comment1 //comment3 - a as b + a as b2 } from ""; import { //comment3 //comment2 //comment1 - a as b + a as b3 } from ""; import { @@ -189,18 +189,18 @@ import { a as //comment1 //comment2 //comment3 - b + b1 } from ""; import { a as //comment2 //comment1 //comment3 - b + b2 } from ""; import { a as //comment3 //comment2 //comment1 - b + b3 } from ""; import { @@ -238,18 +238,18 @@ import { //comment1 //comment2 //comment3 - a as b + a as b1 } from ""; import { //comment2 //comment1 //comment3 - a as b + a as b2 } from ""; import { //comment3 //comment2 //comment1 - a as b + a as b3 } from ""; import { @@ -314,19 +314,19 @@ printWidth: 80 | printWidth =====================================input====================================== import somethingSuperLongsomethingSuperLong from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import {somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import a, {somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import {a, somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import {somethingSuperLongsomethingSuperLong1} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import a, {somethingSuperLongsomethingSuperLong2} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import {a2, somethingSuperLongsomethingSuperLong3} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' =====================================output===================================== import somethingSuperLongsomethingSuperLong from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; -import { somethingSuperLongsomethingSuperLong } from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; +import { somethingSuperLongsomethingSuperLong1 } from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; import a, { - somethingSuperLongsomethingSuperLong + somethingSuperLongsomethingSuperLong2 } from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; import { - a, - somethingSuperLongsomethingSuperLong + a2, + somethingSuperLongsomethingSuperLong3 } from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; ================================================================================ @@ -340,19 +340,19 @@ printWidth: 80 | printWidth =====================================input====================================== import somethingSuperLongsomethingSuperLong from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import {somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import a, {somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import {a, somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import {somethingSuperLongsomethingSuperLong1} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import a, {somethingSuperLongsomethingSuperLong2} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import {a2, somethingSuperLongsomethingSuperLong3} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' =====================================output===================================== import somethingSuperLongsomethingSuperLong from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; -import {somethingSuperLongsomethingSuperLong} from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; +import {somethingSuperLongsomethingSuperLong1} from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; import a, { - somethingSuperLongsomethingSuperLong + somethingSuperLongsomethingSuperLong2 } from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; import { - a, - somethingSuperLongsomethingSuperLong + a2, + somethingSuperLongsomethingSuperLong3 } from "somethingSuperLongsomethingSuperLongsomethingSuperLong"; ================================================================================ diff --git a/tests/import/comments.js b/tests/import/comments.js index 856785db6c5a..f8eca8be3d98 100644 --- a/tests/import/comments.js +++ b/tests/import/comments.js @@ -7,18 +7,18 @@ import { a as //comment1 //comment2 //comment3 - b + b1 } from ""; import { a as //comment2 //comment1 //comment3 - b + b2 } from ""; import { a as //comment3 //comment2 //comment1 - b + b3 } from ""; import { diff --git a/tests/import/inline.js b/tests/import/inline.js index ec88cd08cd09..179c63d5c362 100644 --- a/tests/import/inline.js +++ b/tests/import/inline.js @@ -1,4 +1,4 @@ import somethingSuperLongsomethingSuperLong from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import {somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import a, {somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' -import {a, somethingSuperLongsomethingSuperLong} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import {somethingSuperLongsomethingSuperLong1} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import a, {somethingSuperLongsomethingSuperLong2} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' +import {a2, somethingSuperLongsomethingSuperLong3} from 'somethingSuperLongsomethingSuperLongsomethingSuperLong' diff --git a/tests/jsx_fragment/__snapshots__/jsfmt.spec.js.snap b/tests/jsx_fragment/__snapshots__/jsfmt.spec.js.snap index 7091ec5ecdd6..d28daccb1af5 100644 --- a/tests/jsx_fragment/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx_fragment/__snapshots__/jsfmt.spec.js.snap @@ -55,6 +55,30 @@ foo = ( ; +[<>, <>]; +const fun1 = () => <>; +x = <> +function fun2(param = <>) {} +1 + <>; +1 || <>; +fun2(<>); +test ? <> : x; +<>; + + <> +; +const obj = { + foo: <> +}; +const fragmentVar = <>; +function fun3() { + return <>; +} +(<>).toString(); +(<>).props; +(<>)["computed"]; +(<>)["computed"](); + =====================================output===================================== <>; @@ -105,5 +129,29 @@ foo = ( // close fragment >; +[<>, <>]; +const fun1 = () => <>; +x = <>; +function fun2(param = <>) {} +1 + <>; +1 || <>; +fun2(<>); +test ? <> : x; +<>; + + <> +; +const obj = { + foo: <> +}; +const fragmentVar = <>; +function fun3() { + return <>; +} +(<>).toString(); +(<>).props; +(<>)["computed"]; +(<>)["computed"](); + ================================================================================ `; diff --git a/tests/jsx_fragment/fragment.js b/tests/jsx_fragment/fragment.js index fcf30ee1b445..c8c4657fd907 100644 --- a/tests/jsx_fragment/fragment.js +++ b/tests/jsx_fragment/fragment.js @@ -46,3 +46,27 @@ foo = ( ; + +[<>, <>]; +const fun1 = () => <>; +x = <> +function fun2(param = <>) {} +1 + <>; +1 || <>; +fun2(<>); +test ? <> : x; +<>; + + <> +; +const obj = { + foo: <> +}; +const fragmentVar = <>; +function fun3() { + return <>; +} +(<>).toString(); +(<>).props; +(<>)["computed"]; +(<>)["computed"](); diff --git a/tests/mdx/__snapshots__/jsfmt.spec.js.snap b/tests/mdx/__snapshots__/jsfmt.spec.js.snap index f7d5593854f9..942f1e22aa1e 100644 --- a/tests/mdx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/mdx/__snapshots__/jsfmt.spec.js.snap @@ -6,13 +6,13 @@ parsers: ["mdx"] printWidth: 80 | printWidth =====================================input====================================== -import A from 'a' +import D from 'd' import {A,B,C} from "hello-world" import {AAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBB, CCCCCCCCCCCCCCCCCCCCCCC} from 'xyz'; --- -import A from 'a' +import D from 'd' import {A,B,C} from "hello-world" @@ -41,7 +41,7 @@ export const a = 1; export const b = 1; =====================================output===================================== -import A from "a"; +import D from "d"; import { A, B, C } from "hello-world"; import { AAAAAAAAAAAAAAAAAAAAAAAA, @@ -51,7 +51,7 @@ import { --- -import A from "a"; +import D from "d"; import { A, B, C } from "hello-world"; @@ -93,13 +93,13 @@ printWidth: 80 semi: false | printWidth =====================================input====================================== -import A from 'a' +import D from 'd' import {A,B,C} from "hello-world" import {AAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBB, CCCCCCCCCCCCCCCCCCCCCCC} from 'xyz'; --- -import A from 'a' +import D from 'd' import {A,B,C} from "hello-world" @@ -128,7 +128,7 @@ export const a = 1; export const b = 1; =====================================output===================================== -import A from "a" +import D from "d" import { A, B, C } from "hello-world" import { AAAAAAAAAAAAAAAAAAAAAAAA, @@ -138,7 +138,7 @@ import { --- -import A from "a" +import D from "d" import { A, B, C } from "hello-world" @@ -241,9 +241,27 @@ printWidth: 80 --- + + test test +123 + +--- + test test + + test test +123 + +--- + + + test test + 123 + + test test + 234 --- @@ -256,9 +274,27 @@ printWidth: 80 --- + + test test +123 + +--- + test test + + test test +123 + +--- + + + test test + 123 + + test test + 234 --- @@ -281,9 +317,27 @@ semi: false --- + + test test +123 + +--- + test test + + test test +123 + +--- + + + test test + 123 + + test test + 234 --- @@ -296,9 +350,27 @@ semi: false --- + + test test +123 + +--- + test test + + test test +123 + +--- + + + test test + 123 + + test test + 234 --- @@ -393,7 +465,7 @@ export const foo = { hi { hello } - { /* another commment */} + { /* another comment */} \`\`\` @@ -432,7 +504,7 @@ I'm an awesome paragraph. hi {hello} - {/* another commment */} + {/* another comment */} \`\`\` @@ -484,7 +556,7 @@ export const foo = { hi { hello } - { /* another commment */} + { /* another comment */} \`\`\` @@ -523,7 +595,7 @@ I'm an awesome paragraph. hi {hello} - {/* another commment */} + {/* another comment */} \`\`\` diff --git a/tests/mdx/import-export.mdx b/tests/mdx/import-export.mdx index 02d17ef14d4d..725c8908a62c 100644 --- a/tests/mdx/import-export.mdx +++ b/tests/mdx/import-export.mdx @@ -1,10 +1,10 @@ -import A from 'a' +import D from 'd' import {A,B,C} from "hello-world" import {AAAAAAAAAAAAAAAAAAAAAAAA, BBBBBBBBBBBBBBBBBBBBBB, CCCCCCCCCCCCCCCCCCCCCCC} from 'xyz'; --- -import A from 'a' +import D from 'd' import {A,B,C} from "hello-world" diff --git a/tests/mdx/jsx.mdx b/tests/mdx/jsx.mdx index ca80625b98d7..47b911be62dd 100644 --- a/tests/mdx/jsx.mdx +++ b/tests/mdx/jsx.mdx @@ -3,9 +3,27 @@ --- + + test test +123 + +--- + test test + + test test +123 + +--- + + + test test + 123 + + test test + 234 --- diff --git a/tests/mdx/mixed.mdx b/tests/mdx/mixed.mdx index efe333f3550e..ba32587b1136 100644 --- a/tests/mdx/mixed.mdx +++ b/tests/mdx/mixed.mdx @@ -19,7 +19,7 @@ export const foo = { hi { hello } - { /* another commment */} + { /* another comment */} ``` diff --git a/tests/member/__snapshots__/jsfmt.spec.js.snap b/tests/member/__snapshots__/jsfmt.spec.js.snap index 237b1fadb660..faee486f7f33 100644 --- a/tests/member/__snapshots__/jsfmt.spec.js.snap +++ b/tests/member/__snapshots__/jsfmt.spec.js.snap @@ -38,7 +38,7 @@ const promises = [ other.fetch(), ]; -const promises = [ +const promises2 = [ promise.resolve().veryLongFunctionCall().veryLongFunctionCall().then(console.log).catch(err => { console.log(err) return null @@ -79,7 +79,7 @@ const promises = [ other.fetch() ]; -const promises = [ +const promises2 = [ promise .resolve() .veryLongFunctionCall() diff --git a/tests/member/expand.js b/tests/member/expand.js index e7a31a81b116..2170c2b0611d 100644 --- a/tests/member/expand.js +++ b/tests/member/expand.js @@ -10,7 +10,7 @@ const promises = [ other.fetch(), ]; -const promises = [ +const promises2 = [ promise.resolve().veryLongFunctionCall().veryLongFunctionCall().then(console.log).catch(err => { console.log(err) return null diff --git a/tests/multiparser_js_css/__snapshots__/jsfmt.spec.js.snap b/tests/multiparser_js_css/__snapshots__/jsfmt.spec.js.snap index 5358044aed2f..e21296a285a5 100644 --- a/tests/multiparser_js_css/__snapshots__/jsfmt.spec.js.snap +++ b/tests/multiparser_js_css/__snapshots__/jsfmt.spec.js.snap @@ -6,9 +6,9 @@ parsers: ["babel"] printWidth: 80 | printWidth =====================================input====================================== -const ListItem = styled.li\`\`; +const ListItem1 = styled.li\`\`; -const ListItem = styled.li\` \`; +const ListItem2 = styled.li\` \`; const Dropdown = styled.div\`position: relative;\` @@ -146,7 +146,7 @@ styled.a\` } \` -const StyledComponent = styled.div\` +const StyledComponent1 = styled.div\` \${anInterpolation} /* a comment */ @@ -155,7 +155,7 @@ const StyledComponent = styled.div\` } \`; -const StyledComponent = styled.div\` +const StyledComponent2 = styled.div\` \${anInterpolation} /* a comment */ @@ -166,9 +166,9 @@ const StyledComponent = styled.div\` \`; =====================================output===================================== -const ListItem = styled.li\`\`; +const ListItem1 = styled.li\`\`; -const ListItem = styled.li\`\`; +const ListItem2 = styled.li\`\`; const Dropdown = styled.div\` position: relative; @@ -307,7 +307,7 @@ styled.a\` } \`; -const StyledComponent = styled.div\` +const StyledComponent1 = styled.div\` \${anInterpolation} /* a comment */ @@ -316,7 +316,7 @@ const StyledComponent = styled.div\` } \`; -const StyledComponent = styled.div\` +const StyledComponent2 = styled.div\` \${anInterpolation} /* a comment */ diff --git a/tests/multiparser_js_css/styled-components.js b/tests/multiparser_js_css/styled-components.js index 54d2cf0252e4..8c07ef487406 100644 --- a/tests/multiparser_js_css/styled-components.js +++ b/tests/multiparser_js_css/styled-components.js @@ -1,6 +1,6 @@ -const ListItem = styled.li``; +const ListItem1 = styled.li``; -const ListItem = styled.li` `; +const ListItem2 = styled.li` `; const Dropdown = styled.div`position: relative;` @@ -138,7 +138,7 @@ styled.a` } ` -const StyledComponent = styled.div` +const StyledComponent1 = styled.div` ${anInterpolation} /* a comment */ @@ -147,7 +147,7 @@ const StyledComponent = styled.div` } `; -const StyledComponent = styled.div` +const StyledComponent2 = styled.div` ${anInterpolation} /* a comment */ diff --git a/tests/new_expression/__snapshots__/jsfmt.spec.js.snap b/tests/new_expression/__snapshots__/jsfmt.spec.js.snap index 15e40b2148bb..187ddb955d3d 100644 --- a/tests/new_expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/new_expression/__snapshots__/jsfmt.spec.js.snap @@ -32,14 +32,20 @@ new (createObj()).prop(a()); new (x()\`\`.y)(); new e[f().x].y(); new e[f()].y(); +new (a().b)(); +new (a().b().c)(); +new (a\`\`()); =====================================output===================================== new (memoize.Cache || MapCache)(); new (typeof this == "function" ? this : Dict())(); -new (createObj()).prop(a()); -new (x())\`\`.y(); +new (createObj().prop)(a()); +new (x()\`\`.y)(); new e[f().x].y(); new e[f()].y(); +new (a().b)(); +new (a().b().c)(); +new (a\`\`())(); ================================================================================ `; diff --git a/tests/new_expression/new_expression.js b/tests/new_expression/new_expression.js index c85c355a8468..2aa1d5e02367 100644 --- a/tests/new_expression/new_expression.js +++ b/tests/new_expression/new_expression.js @@ -4,3 +4,6 @@ new (createObj()).prop(a()); new (x()``.y)(); new e[f().x].y(); new e[f()].y(); +new (a().b)(); +new (a().b().c)(); +new (a``()); diff --git a/tests/no-semi/__snapshots__/jsfmt.spec.js.snap b/tests/no-semi/__snapshots__/jsfmt.spec.js.snap index bd77217c5e6a..e0278222d505 100644 --- a/tests/no-semi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/no-semi/__snapshots__/jsfmt.spec.js.snap @@ -484,19 +484,19 @@ class X {} [1, 2, 3].forEach(fn) // x(){} // } -class C { +class C1 { get; // The semicolon *is* necessary x(){} } -class C { +class C2 { get = () => {}; // The semicolon is *not* necessary x(){} } -class C { +class C3 { set; // The semicolon *is* necessary x(){} } -class C { +class C4 { set = () => {}; // The semicolon is *not* necessary x(){} } @@ -545,16 +545,16 @@ class A { } // being first/last shouldn't break things -class G { +class G1 { x = 1 } -class G { +class G2 { x() {} } -class G { +class G3 { *x() {} } -class G { +class G4 { [x] = 1 } @@ -662,19 +662,19 @@ class X {} // x(){} // } -class C { +class C1 { get; // The semicolon *is* necessary x() {} } -class C { +class C2 { get = () => {}; // The semicolon is *not* necessary x() {} } -class C { +class C3 { set; // The semicolon *is* necessary x() {} } -class C { +class C4 { set = () => {}; // The semicolon is *not* necessary x() {} } @@ -722,16 +722,16 @@ class A { } // being first/last shouldn't break things -class G { +class G1 { x = 1; } -class G { +class G2 { x() {} } -class G { +class G3 { *x() {} } -class G { +class G4 { [x] = 1; } @@ -835,19 +835,19 @@ class X {} [1, 2, 3].forEach(fn) // x(){} // } -class C { +class C1 { get; // The semicolon *is* necessary x(){} } -class C { +class C2 { get = () => {}; // The semicolon is *not* necessary x(){} } -class C { +class C3 { set; // The semicolon *is* necessary x(){} } -class C { +class C4 { set = () => {}; // The semicolon is *not* necessary x(){} } @@ -896,16 +896,16 @@ class A { } // being first/last shouldn't break things -class G { +class G1 { x = 1 } -class G { +class G2 { x() {} } -class G { +class G3 { *x() {} } -class G { +class G4 { [x] = 1 } @@ -1013,19 +1013,19 @@ class X {} // x(){} // } -class C { +class C1 { get; // The semicolon *is* necessary x() {} } -class C { +class C2 { get = () => {} // The semicolon is *not* necessary x() {} } -class C { +class C3 { set; // The semicolon *is* necessary x() {} } -class C { +class C4 { set = () => {} // The semicolon is *not* necessary x() {} } @@ -1073,16 +1073,16 @@ class A { } // being first/last shouldn't break things -class G { +class G1 { x = 1 } -class G { +class G2 { x() {} } -class G { +class G3 { *x() {} } -class G { +class G4 { [x] = 1 } @@ -1186,19 +1186,19 @@ class X {} [1, 2, 3].forEach(fn) // x(){} // } -class C { +class C1 { get; // The semicolon *is* necessary x(){} } -class C { +class C2 { get = () => {}; // The semicolon is *not* necessary x(){} } -class C { +class C3 { set; // The semicolon *is* necessary x(){} } -class C { +class C4 { set = () => {}; // The semicolon is *not* necessary x(){} } @@ -1247,16 +1247,16 @@ class A { } // being first/last shouldn't break things -class G { +class G1 { x = 1 } -class G { +class G2 { x() {} } -class G { +class G3 { *x() {} } -class G { +class G4 { [x] = 1 } @@ -1364,19 +1364,19 @@ class X {} // x(){} // } -class C { +class C1 { get; // The semicolon *is* necessary x() {} } -class C { +class C2 { get = () => {} // The semicolon is *not* necessary x() {} } -class C { +class C3 { set; // The semicolon *is* necessary x() {} } -class C { +class C4 { set = () => {} // The semicolon is *not* necessary x() {} } @@ -1424,16 +1424,16 @@ class A { } // being first/last shouldn't break things -class G { +class G1 { x = 1 } -class G { +class G2 { x() {} } -class G { +class G3 { *x() {} } -class G { +class G4 { [x] = 1 } diff --git a/tests/no-semi/no-semi.js b/tests/no-semi/no-semi.js index 91b370a4eb9f..351c104b4920 100644 --- a/tests/no-semi/no-semi.js +++ b/tests/no-semi/no-semi.js @@ -29,19 +29,19 @@ class X {} [1, 2, 3].forEach(fn) // x(){} // } -class C { +class C1 { get; // The semicolon *is* necessary x(){} } -class C { +class C2 { get = () => {}; // The semicolon is *not* necessary x(){} } -class C { +class C3 { set; // The semicolon *is* necessary x(){} } -class C { +class C4 { set = () => {}; // The semicolon is *not* necessary x(){} } @@ -90,16 +90,16 @@ class A { } // being first/last shouldn't break things -class G { +class G1 { x = 1 } -class G { +class G2 { x() {} } -class G { +class G3 { *x() {} } -class G { +class G4 { [x] = 1 } diff --git a/tests/nullish_coalescing/__snapshots__/jsfmt.spec.js.snap b/tests/nullish_coalescing/__snapshots__/jsfmt.spec.js.snap index 0fc3d0e7c5dd..a85951d9d650 100644 --- a/tests/nullish_coalescing/__snapshots__/jsfmt.spec.js.snap +++ b/tests/nullish_coalescing/__snapshots__/jsfmt.spec.js.snap @@ -14,7 +14,7 @@ foo ? bar ?? foo : baz; foo ?? (bar ?? baz); -foo ?? baz || baz; +(foo ?? baz) || baz; (foo && baz) ?? baz; foo && (baz ?? baz); @@ -28,7 +28,7 @@ foo ? bar ?? foo : baz; foo ?? (bar ?? baz); -foo ?? baz || baz; +(foo ?? baz) || baz; (foo && baz) ?? baz; foo && (baz ?? baz); diff --git a/tests/nullish_coalescing/nullish_coalesing_operator.js b/tests/nullish_coalescing/nullish_coalesing_operator.js index 49261d78b5a7..197fca77b9a8 100644 --- a/tests/nullish_coalescing/nullish_coalesing_operator.js +++ b/tests/nullish_coalescing/nullish_coalesing_operator.js @@ -6,7 +6,7 @@ foo ? bar ?? foo : baz; foo ?? (bar ?? baz); -foo ?? baz || baz; +(foo ?? baz) || baz; (foo && baz) ?? baz; foo && (baz ?? baz); diff --git a/tests/object_property_comment/__snapshots__/jsfmt.spec.js.snap b/tests/object_property_comment/__snapshots__/jsfmt.spec.js.snap index c2d63ec9ab34..e59748f1380a 100644 --- a/tests/object_property_comment/__snapshots__/jsfmt.spec.js.snap +++ b/tests/object_property_comment/__snapshots__/jsfmt.spec.js.snap @@ -10,7 +10,7 @@ let a = { a /* comment */: () => 1 }; -let a = { +let b = { "a" /* comment */: () => 1 }; @@ -19,7 +19,7 @@ let a = { a /* comment */: () => 1 }; -let a = { +let b = { a /* comment */: () => 1 }; diff --git a/tests/object_property_comment/after-key.js b/tests/object_property_comment/after-key.js index 40b49c87b30a..27388e0c5fdb 100644 --- a/tests/object_property_comment/after-key.js +++ b/tests/object_property_comment/after-key.js @@ -2,6 +2,6 @@ let a = { a /* comment */: () => 1 }; -let a = { +let b = { "a" /* comment */: () => 1 }; diff --git a/tests/objects/__snapshots__/jsfmt.spec.js.snap b/tests/objects/__snapshots__/jsfmt.spec.js.snap index f53fea6279fd..74537c035ed6 100644 --- a/tests/objects/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objects/__snapshots__/jsfmt.spec.js.snap @@ -40,17 +40,17 @@ a = () => ({}).x; ({} = 0); (({} = 0), 1); -const a = { +const a1 = { someKey: (shortName, shortName) }; -const a = { +const a2 = { someKey: (longLongLongLongLongLongLongLongLongLongLongLongLongLongName, shortName) }; -const a = { +const a3 = { someKey: (longLongLongLongLongLongLongLongLongLongLongLongLongLongName, longLongLongLongLongLongLongLongLongLongLongLongLongLongName, longLongLongLongLongLongLongLongLongLongLongLongLongLongName) }; @@ -66,16 +66,16 @@ a = () => ({}.x); ({} = 0); ({} = 0), 1; -const a = { +const a1 = { someKey: (shortName, shortName) }; -const a = { +const a2 = { someKey: (longLongLongLongLongLongLongLongLongLongLongLongLongLongName, shortName) }; -const a = { +const a3 = { someKey: (longLongLongLongLongLongLongLongLongLongLongLongLongLongName, longLongLongLongLongLongLongLongLongLongLongLongLongLongName, diff --git a/tests/objects/expression.js b/tests/objects/expression.js index 2878e61f98a3..0487809a184d 100644 --- a/tests/objects/expression.js +++ b/tests/objects/expression.js @@ -8,17 +8,17 @@ a = () => ({}).x; ({} = 0); (({} = 0), 1); -const a = { +const a1 = { someKey: (shortName, shortName) }; -const a = { +const a2 = { someKey: (longLongLongLongLongLongLongLongLongLongLongLongLongLongName, shortName) }; -const a = { +const a3 = { someKey: (longLongLongLongLongLongLongLongLongLongLongLongLongLongName, longLongLongLongLongLongLongLongLongLongLongLongLongLongName, longLongLongLongLongLongLongLongLongLongLongLongLongLongName) }; diff --git a/tests/optional_chaining/__snapshots__/jsfmt.spec.js.snap b/tests/optional_chaining/__snapshots__/jsfmt.spec.js.snap index fc97cb3f06bf..72697a723e3c 100644 --- a/tests/optional_chaining/__snapshots__/jsfmt.spec.js.snap +++ b/tests/optional_chaining/__snapshots__/jsfmt.spec.js.snap @@ -71,3 +71,109 @@ async function HelloWorld() { ================================================================================ `; + +exports[`comments.js 1`] = ` +====================================options===================================== +parsers: ["babel", "flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo() { + return a + .b() + .c() + // Comment + ?.d() +} + +fooBar + .doSomething("Hello World") + .doAnotherThing("Foo", { foo: bar }) + + // App configuration. + .doOneMoreThing(config) + + ?.run(() => console.log("Bar")); + +bigDeal + + .doSomething("Hello World") + + // Hello world + ?.doAnotherThing("Foo", { foo: bar }) + + // App configuration. + .doOneMoreThing(config) + + ?.run(() => console.log("Bar")); + +foo.bar.baz + + ?.doSomething("Hello World") + + // Hello world + .foo.bar.doAnotherThing("Foo", { foo: bar }) + + .doOneMoreThing(config) + ?.bar.run(() => console.log("Bar")); + +(somethingGood ? thisIsIt : maybeNot) + +// Hello world +.doSomething("Hello World") + + ?.doAnotherThing("Foo", { foo: bar }) // Run this + .run(() => console.log("Bar")); // Do this + +=====================================output===================================== +function foo() { + return ( + a + .b() + .c() + // Comment + ?.d() + ); +} + +fooBar + .doSomething("Hello World") + .doAnotherThing("Foo", { foo: bar }) + + // App configuration. + .doOneMoreThing(config) + + ?.run(() => console.log("Bar")); + +bigDeal + + .doSomething("Hello World") + + // Hello world + ?.doAnotherThing("Foo", { foo: bar }) + + // App configuration. + .doOneMoreThing(config) + + ?.run(() => console.log("Bar")); + +foo.bar.baz + + ?.doSomething("Hello World") + + // Hello world + .foo.bar.doAnotherThing("Foo", { foo: bar }) + + .doOneMoreThing(config) + ?.bar.run(() => console.log("Bar")); + +(somethingGood ? thisIsIt : maybeNot) + + // Hello world + .doSomething("Hello World") + + ?.doAnotherThing("Foo", { foo: bar }) // Run this + .run(() => console.log("Bar")); // Do this + +================================================================================ +`; diff --git a/tests/optional_chaining/comments.js b/tests/optional_chaining/comments.js new file mode 100644 index 000000000000..898cfc091ac5 --- /dev/null +++ b/tests/optional_chaining/comments.js @@ -0,0 +1,46 @@ +function foo() { + return a + .b() + .c() + // Comment + ?.d() +} + +fooBar + .doSomething("Hello World") + .doAnotherThing("Foo", { foo: bar }) + + // App configuration. + .doOneMoreThing(config) + + ?.run(() => console.log("Bar")); + +bigDeal + + .doSomething("Hello World") + + // Hello world + ?.doAnotherThing("Foo", { foo: bar }) + + // App configuration. + .doOneMoreThing(config) + + ?.run(() => console.log("Bar")); + +foo.bar.baz + + ?.doSomething("Hello World") + + // Hello world + .foo.bar.doAnotherThing("Foo", { foo: bar }) + + .doOneMoreThing(config) + ?.bar.run(() => console.log("Bar")); + +(somethingGood ? thisIsIt : maybeNot) + +// Hello world +.doSomething("Hello World") + + ?.doAnotherThing("Foo", { foo: bar }) // Run this + .run(() => console.log("Bar")); // Do this diff --git a/tests/partial_application/__snapshots__/jsfmt.spec.js.snap b/tests/partial_application/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..c59cf1d2f551 --- /dev/null +++ b/tests/partial_application/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,31 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`test.js 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +const addOne = add(1, ?); // apply from the left +addOne(2); // 3 + +const addTen = add(?, 10); // apply from the right +addTen(2); // 12 + +// with pipeline +let newScore = player.score + |> add(7, ?) + |> clamp(0, 100, ?); // shallow stack, the pipe to \`clamp\` is the same frame as the pipe to \`add\`. + +=====================================output===================================== +const addOne = add(1, ?); // apply from the left +addOne(2); // 3 + +const addTen = add(?, 10); // apply from the right +addTen(2); // 12 + +// with pipeline +let newScore = player.score |> add(7, ?) |> clamp(0, 100, ?); // shallow stack, the pipe to \`clamp\` is the same frame as the pipe to \`add\`. + +================================================================================ +`; diff --git a/tests/partial_application/jsfmt.spec.js b/tests/partial_application/jsfmt.spec.js new file mode 100644 index 000000000000..8382eddeb1db --- /dev/null +++ b/tests/partial_application/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["babel"]); diff --git a/tests/partial_application/test.js b/tests/partial_application/test.js new file mode 100644 index 000000000000..e0892a802cce --- /dev/null +++ b/tests/partial_application/test.js @@ -0,0 +1,10 @@ +const addOne = add(1, ?); // apply from the left +addOne(2); // 3 + +const addTen = add(?, 10); // apply from the right +addTen(2); // 12 + +// with pipeline +let newScore = player.score + |> add(7, ?) + |> clamp(0, 100, ?); // shallow stack, the pipe to `clamp` is the same frame as the pipe to `add`. diff --git a/tests/require/__snapshots__/jsfmt.spec.js.snap b/tests/require/__snapshots__/jsfmt.spec.js.snap index 37eef2d6f5b5..71fa674bbb0f 100644 --- a/tests/require/__snapshots__/jsfmt.spec.js.snap +++ b/tests/require/__snapshots__/jsfmt.spec.js.snap @@ -6,8 +6,8 @@ parsers: ["flow", "typescript"] printWidth: 80 | printWidth =====================================input====================================== -const { one, two, thee, four, five, six, seven, eight, nine, ten } = require('./my-utils'); -const { one, two, thee, four, five, six, seven, eight, nine, ten, eleven } = require('./my-utils'); +const { one, two, three, four, five, six, seven, eight, nine, ten } = require('./my-utils'); +const { one1, two1, three1, four1, five1, six1, seven1, eight1, nine1, ten1, eleven1 } = require('./my-utils'); const MyReallyExtrememlyLongModuleName = require('MyReallyExtrememlyLongModuleName'); @@ -15,7 +15,7 @@ const MyReallyExtrememlyLongModuleName = require('MyReallyExtrememlyLongModuleNa const { one, two, - thee, + three, four, five, six, @@ -25,17 +25,17 @@ const { ten } = require("./my-utils"); const { - one, - two, - thee, - four, - five, - six, - seven, - eight, - nine, - ten, - eleven + one1, + two1, + three1, + four1, + five1, + six1, + seven1, + eight1, + nine1, + ten1, + eleven1 } = require("./my-utils"); const MyReallyExtrememlyLongModuleName = require("MyReallyExtrememlyLongModuleName"); diff --git a/tests/require/require.js b/tests/require/require.js index f36550a9d8c4..a990ca9f3ede 100644 --- a/tests/require/require.js +++ b/tests/require/require.js @@ -1,4 +1,4 @@ -const { one, two, thee, four, five, six, seven, eight, nine, ten } = require('./my-utils'); -const { one, two, thee, four, five, six, seven, eight, nine, ten, eleven } = require('./my-utils'); +const { one, two, three, four, five, six, seven, eight, nine, ten } = require('./my-utils'); +const { one1, two1, three1, four1, five1, six1, seven1, eight1, nine1, ten1, eleven1 } = require('./my-utils'); const MyReallyExtrememlyLongModuleName = require('MyReallyExtrememlyLongModuleName'); diff --git a/tests/switch/__snapshots__/jsfmt.spec.js.snap b/tests/switch/__snapshots__/jsfmt.spec.js.snap index ec686651d886..276315579ece 100644 --- a/tests/switch/__snapshots__/jsfmt.spec.js.snap +++ b/tests/switch/__snapshots__/jsfmt.spec.js.snap @@ -288,6 +288,12 @@ switch (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery alert( 'default' ); } +switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName) { +} + +switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) { +} + =====================================output===================================== switch (a) { case 3: @@ -315,7 +321,7 @@ switch ( switch ( veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong > - veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong + veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong ) { case 3: alert("3"); @@ -324,5 +330,17 @@ switch ( alert("default"); } +switch ( + $veryLongAndVeryVerboseVariableName && + $anotherVeryLongAndVeryVerboseVariableName +) { +} + +switch ( + $longButSlightlyShorterVariableName && + $anotherSlightlyShorterVariableName +) { +} + ================================================================================ `; diff --git a/tests/switch/switch.js b/tests/switch/switch.js index c4c7ac13366a..5ba6976753d3 100644 --- a/tests/switch/switch.js +++ b/tests/switch/switch.js @@ -27,3 +27,9 @@ switch (veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery default: alert( 'default' ); } + +switch ($veryLongAndVeryVerboseVariableName && $anotherVeryLongAndVeryVerboseVariableName) { +} + +switch ($longButSlightlyShorterVariableName && $anotherSlightlyShorterVariableName) { +} diff --git a/tests/template/__snapshots__/jsfmt.spec.js.snap b/tests/template/__snapshots__/jsfmt.spec.js.snap index 6e51337331d1..d62faad06820 100644 --- a/tests/template/__snapshots__/jsfmt.spec.js.snap +++ b/tests/template/__snapshots__/jsfmt.spec.js.snap @@ -421,7 +421,7 @@ b.c\`\`; (++b)\`\`; // "YieldExpression" -function* f() { +function* d() { (yield 1)\`\`; } @@ -477,7 +477,7 @@ new B()\`\`; (++b)\`\`; // "YieldExpression" -function* f() { +function* d() { (yield 1)\`\`; } diff --git a/tests/template/parenthesis.js b/tests/template/parenthesis.js index aba408999ee1..d4c43a30cf6f 100644 --- a/tests/template/parenthesis.js +++ b/tests/template/parenthesis.js @@ -49,6 +49,6 @@ b.c``; (++b)``; // "YieldExpression" -function* f() { +function* d() { (yield 1)``; } diff --git a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap index c49494084e4b..1a5fcf27afae 100644 --- a/tests/ternaries/__snapshots__/jsfmt.spec.js.snap +++ b/tests/ternaries/__snapshots__/jsfmt.spec.js.snap @@ -1672,7 +1672,7 @@ const paymentMessage = state == 'success' : 'There was an issue with the payment. Please contact support.' -const paymentMessage = state == 'success' +const paymentMessage2 = state == 'success' ? 1 //'Payment completed successfully' : state == 'processing' @@ -1764,7 +1764,7 @@ const paymentMessage = ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; -const paymentMessage = +const paymentMessage2 = state == "success" ? 1 //'Payment completed successfully' : state == "processing" @@ -1876,7 +1876,7 @@ const paymentMessage = state == 'success' : 'There was an issue with the payment. Please contact support.' -const paymentMessage = state == 'success' +const paymentMessage2 = state == 'success' ? 1 //'Payment completed successfully' : state == 'processing' @@ -1968,7 +1968,7 @@ const paymentMessage = ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; -const paymentMessage = +const paymentMessage2 = state == "success" ? 1 //'Payment completed successfully' : state == "processing" @@ -2080,7 +2080,7 @@ const paymentMessage = state == 'success' : 'There was an issue with the payment. Please contact support.' -const paymentMessage = state == 'success' +const paymentMessage2 = state == 'success' ? 1 //'Payment completed successfully' : state == 'processing' @@ -2172,7 +2172,7 @@ const paymentMessage = ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; -const paymentMessage = +const paymentMessage2 = state == "success" ? 1 //'Payment completed successfully' : state == "processing" @@ -2285,7 +2285,7 @@ const paymentMessage = state == 'success' : 'There was an issue with the payment. Please contact support.' -const paymentMessage = state == 'success' +const paymentMessage2 = state == 'success' ? 1 //'Payment completed successfully' : state == 'processing' @@ -2377,7 +2377,7 @@ const paymentMessage = ? "Expiry must be sometime in the past." : "There was an issue with the payment. Please contact support."; -const paymentMessage = +const paymentMessage2 = state == "success" ? 1 //'Payment completed successfully' : state == "processing" diff --git a/tests/ternaries/nested.js b/tests/ternaries/nested.js index 7b47011eaab0..bfc1cba444b8 100644 --- a/tests/ternaries/nested.js +++ b/tests/ternaries/nested.js @@ -56,7 +56,7 @@ const paymentMessage = state == 'success' : 'There was an issue with the payment. Please contact support.' -const paymentMessage = state == 'success' +const paymentMessage2 = state == 'success' ? 1 //'Payment completed successfully' : state == 'processing' diff --git a/tests/typescript/custom/typeParameters/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/custom/typeParameters/__snapshots__/jsfmt.spec.js.snap index 9d6d6aa61650..acb80ddcacea 100644 --- a/tests/typescript/custom/typeParameters/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/custom/typeParameters/__snapshots__/jsfmt.spec.js.snap @@ -108,3 +108,52 @@ type ReallyReallyReallyLongName< ================================================================================ `; + +exports[`variables.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +const foo: SomeThing = func(); +const bar: SomeThing = func(); +const fooo: SomeThing<{ [P in "x" | "y"]: number }> = func(); +const baar: SomeThing = func(); +const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaar: SomeThing<{ [P in "x" | "y"]: number }> = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); +const isAnySuccessfulAttempt$: Observable = this._quizService.isAnySuccessfulAttempt$().pipe( + tap((isAnySuccessfulAttempt: boolean) => { + this.isAnySuccessfulAttempt = isAnySuccessfulAttempt; + }), +); +const isAnySuccessfulAttempt2$: Observable = this._someMethodWithLongName(); + +=====================================output===================================== +const foo: SomeThing = func(); +const bar: SomeThing = func(); +const fooo: SomeThing<{ [P in "x" | "y"]: number }> = func(); +const baar: SomeThing = func(); +const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaaaaaaaar: SomeThing< + boolean, + boolean +> = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaar: SomeThing< + { [P in "x" | "y"]: number } +> = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaaar: SomeThing< + K extends T ? G : S +> = looooooooooooooooooooooooooooooongNameFunc(); +const isAnySuccessfulAttempt$: Observable = this._quizService + .isAnySuccessfulAttempt$() + .pipe( + tap((isAnySuccessfulAttempt: boolean) => { + this.isAnySuccessfulAttempt = isAnySuccessfulAttempt; + }) + ); +const isAnySuccessfulAttempt2$: Observable = this._someMethodWithLongName(); + +================================================================================ +`; diff --git a/tests/typescript/custom/typeParameters/variables.ts b/tests/typescript/custom/typeParameters/variables.ts new file mode 100644 index 000000000000..9322fff5572a --- /dev/null +++ b/tests/typescript/custom/typeParameters/variables.ts @@ -0,0 +1,14 @@ +const foo: SomeThing = func(); +const bar: SomeThing = func(); +const fooo: SomeThing<{ [P in "x" | "y"]: number }> = func(); +const baar: SomeThing = func(); +const fooooooooooooooo: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaar: SomeThing<{ [P in "x" | "y"]: number }> = looooooooooooooooooooooooooooooongNameFunc(); +const baaaaaaaaaaaaaaaar: SomeThing = looooooooooooooooooooooooooooooongNameFunc(); +const isAnySuccessfulAttempt$: Observable = this._quizService.isAnySuccessfulAttempt$().pipe( + tap((isAnySuccessfulAttempt: boolean) => { + this.isAnySuccessfulAttempt = isAnySuccessfulAttempt; + }), +); +const isAnySuccessfulAttempt2$: Observable = this._someMethodWithLongName(); diff --git a/tests/typescript_argument_expansion/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_argument_expansion/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..bd7c16c29ce7 --- /dev/null +++ b/tests/typescript_argument_expansion/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,87 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`argument_expansion.js 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +const bar1 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([] as unknown) as number[]); + +const bar2 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, >[]); + +const bar3 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([1, 2, 3] as unknown) as number[]); + +const bar4 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, >[1, 2, 3]); + +const bar5 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({} as unknown) as {[key: number]: boolean}); + +const bar6 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, <{[key: number]: boolean}>{}); + +const bar7 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({1: true} as unknown) as {[key: number]: boolean}); + +const bar8 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, <{[key: number]: boolean}>{1: true}); + +=====================================output===================================== +const bar1 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, ([] as unknown) as number[]); + +const bar2 = [1, 2, 3].reduce((carry, value) => { + return [...carry, value]; +}, >[]); + +const bar3 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + ([1, 2, 3] as unknown) as number[] +); + +const bar4 = [1, 2, 3].reduce( + (carry, value) => { + return [...carry, value]; + }, + >[1, 2, 3] +); + +const bar5 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, ({} as unknown) as { [key: number]: boolean }); + +const bar6 = [1, 2, 3].reduce((carry, value) => { + return { ...carry, [value]: true }; +}, <{ [key: number]: boolean }>{}); + +const bar7 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + ({ 1: true } as unknown) as { [key: number]: boolean } +); + +const bar8 = [1, 2, 3].reduce( + (carry, value) => { + return { ...carry, [value]: true }; + }, + <{ [key: number]: boolean }>{ 1: true } +); + +================================================================================ +`; diff --git a/tests/typescript_argument_expansion/argument_expansion.js b/tests/typescript_argument_expansion/argument_expansion.js new file mode 100644 index 000000000000..37f77d346e1b --- /dev/null +++ b/tests/typescript_argument_expansion/argument_expansion.js @@ -0,0 +1,31 @@ +const bar1 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([] as unknown) as number[]); + +const bar2 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, >[]); + +const bar3 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, ([1, 2, 3] as unknown) as number[]); + +const bar4 = [1,2,3].reduce((carry, value) => { + return [...carry, value]; +}, >[1, 2, 3]); + +const bar5 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({} as unknown) as {[key: number]: boolean}); + +const bar6 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, <{[key: number]: boolean}>{}); + +const bar7 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, ({1: true} as unknown) as {[key: number]: boolean}); + +const bar8 = [1,2,3].reduce((carry, value) => { + return {...carry, [value]: true}; +}, <{[key: number]: boolean}>{1: true}); diff --git a/tests/typescript_argument_expansion/jsfmt.spec.js b/tests/typescript_argument_expansion/jsfmt.spec.js new file mode 100644 index 000000000000..2ea3bb6eb2e4 --- /dev/null +++ b/tests/typescript_argument_expansion/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/typescript_arrow/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_arrow/__snapshots__/jsfmt.spec.js.snap index ee60d5be169d..394c70a0b64d 100644 --- a/tests/typescript_arrow/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_arrow/__snapshots__/jsfmt.spec.js.snap @@ -27,7 +27,12 @@ const bar = (...varargs: any[]) => { console.log(varargs); }; -const foo = (x: string): void => bar(x, () => {}, () => {}); +const foo = (x: string): void => + bar( + x, + () => {}, + () => {} + ); app.get("/", (req, res): void => { res.send("Hello world"); diff --git a/tests/typescript_as/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_as/__snapshots__/jsfmt.spec.js.snap index e1fbf2921285..0dbd537e4f20 100644 --- a/tests/typescript_as/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_as/__snapshots__/jsfmt.spec.js.snap @@ -14,12 +14,12 @@ start + (yearSelectTotal as number) scrollTop > (visibilityHeight as number) export default class Column extends (RcTable.Column as React.ComponentClass,ColumnProps,ColumnProps,ColumnProps>) {} export const MobxTypedForm = class extends (Form as { new (): any }) {} -export abstract class MobxTypedForm extends (Form as { new (): any }) {} +export abstract class MobxTypedForm1 extends (Form as { new (): any }) {} ({}) as {}; function*g() { const test = (yield 'foo') as number; } -async function g() { +async function g1() { const test = (await 'foo') as number; } ({}) as X; @@ -52,12 +52,12 @@ export default class Column extends (RcTable.Column as React.ComponentClass< ColumnProps >) {} export const MobxTypedForm = class extends (Form as { new (): any }) {}; -export abstract class MobxTypedForm extends (Form as { new (): any }) {} +export abstract class MobxTypedForm1 extends (Form as { new (): any }) {} ({} as {}); function* g() { const test = (yield "foo") as number; } -async function g() { +async function g1() { const test = (await "foo") as number; } ({} as X); diff --git a/tests/typescript_as/as.js b/tests/typescript_as/as.js index b90dc0dd32cf..596bdd8d2c92 100644 --- a/tests/typescript_as/as.js +++ b/tests/typescript_as/as.js @@ -6,12 +6,12 @@ start + (yearSelectTotal as number) scrollTop > (visibilityHeight as number) export default class Column extends (RcTable.Column as React.ComponentClass,ColumnProps,ColumnProps,ColumnProps>) {} export const MobxTypedForm = class extends (Form as { new (): any }) {} -export abstract class MobxTypedForm extends (Form as { new (): any }) {} +export abstract class MobxTypedForm1 extends (Form as { new (): any }) {} ({}) as {}; function*g() { const test = (yield 'foo') as number; } -async function g() { +async function g1() { const test = (await 'foo') as number; } ({}) as X; diff --git a/tests/typescript_class/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_class/__snapshots__/jsfmt.spec.js.snap index ed34063a01d9..0edc7ee97ee1 100644 --- a/tests/typescript_class/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_class/__snapshots__/jsfmt.spec.js.snap @@ -48,14 +48,14 @@ printWidth: 80 =====================================input====================================== class Class extends AbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces extends AbstractClass +class ExtendsAbstractClassAndImplementsInterfaces1 extends AbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces2 extends AAAAAAAAAAAAAAbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces3 extends AAAAAAAAAAAAAAbstractClass implements Interface1, @@ -67,10 +67,10 @@ class ExtendsAbstractClassAndImplementsInterfaces Interface7, Interface8 {} -class ExtendsAbstractClassAndImplementsInterfaces - extends AAAAAAAAAAAAAAbstractClass {} +class ExtendsAbstractClassAndImplementsInterfaces4 + extends AAAAAAAAAAAAAAbstractClass {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces5 extends AAAAAAAAAAAAAAbstractClass implements Interface1, @@ -86,14 +86,14 @@ class ExtendsAbstractClassAndImplementsInterfaces class Class extends AbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces extends AbstractClass +class ExtendsAbstractClassAndImplementsInterfaces1 extends AbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces2 extends AAAAAAAAAAAAAAbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces3 extends AAAAAAAAAAAAAAbstractClass implements Interface1, @@ -105,7 +105,7 @@ class ExtendsAbstractClassAndImplementsInterfaces Interface7, Interface8 {} -class ExtendsAbstractClassAndImplementsInterfaces extends AAAAAAAAAAAAAAbstractClass< +class ExtendsAbstractClassAndImplementsInterfaces4 extends AAAAAAAAAAAAAAbstractClass< Type1, Type2, Type3, @@ -115,7 +115,7 @@ class ExtendsAbstractClassAndImplementsInterfaces extends AAAAAAAAAAAAAAbstractC Type7 > {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces5 extends AAAAAAAAAAAAAAbstractClass< Type1, Type2, @@ -205,12 +205,20 @@ class X { "a-prop"?: boolean; } +class A { + protected [s]?() {} +} + =====================================output===================================== class X { private foo? = undefined; "a-prop"?: boolean; } +class A { + protected [s]?() {} +} + ================================================================================ `; diff --git a/tests/typescript_class/extends_implements.ts b/tests/typescript_class/extends_implements.ts index 0daed0358c1a..ac4839930a25 100644 --- a/tests/typescript_class/extends_implements.ts +++ b/tests/typescript_class/extends_implements.ts @@ -1,13 +1,13 @@ class Class extends AbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces extends AbstractClass +class ExtendsAbstractClassAndImplementsInterfaces1 extends AbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces2 extends AAAAAAAAAAAAAAbstractClass implements Interface1, Interface2, Interface3, Interface4 {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces3 extends AAAAAAAAAAAAAAbstractClass implements Interface1, @@ -19,10 +19,10 @@ class ExtendsAbstractClassAndImplementsInterfaces Interface7, Interface8 {} -class ExtendsAbstractClassAndImplementsInterfaces - extends AAAAAAAAAAAAAAbstractClass {} +class ExtendsAbstractClassAndImplementsInterfaces4 + extends AAAAAAAAAAAAAAbstractClass {} -class ExtendsAbstractClassAndImplementsInterfaces +class ExtendsAbstractClassAndImplementsInterfaces5 extends AAAAAAAAAAAAAAbstractClass implements Interface1, diff --git a/tests/typescript_class/optional.ts b/tests/typescript_class/optional.ts index 1e0752da3507..b540e547762f 100644 --- a/tests/typescript_class/optional.ts +++ b/tests/typescript_class/optional.ts @@ -2,3 +2,7 @@ class X { private foo? = undefined; "a-prop"?: boolean; } + +class A { + protected [s]?() {} +} diff --git a/tests/typescript_conditional_types/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_conditional_types/__snapshots__/jsfmt.spec.js.snap index 571cbc44a271..e06f96aeee4b 100644 --- a/tests/typescript_conditional_types/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_conditional_types/__snapshots__/jsfmt.spec.js.snap @@ -24,6 +24,25 @@ type TypeName = T extends Function ? "function" : "object"; +type Type01 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6; +type Type02 = 0 extends ((1 extends 2 ? 3 : 4)) ? 5 : 6; +type Type03 = 0 extends (((1 extends 2 ? 3 : 4))) ? 5 : 6; +type Type04 = 0 extends ((((1 extends 2 ? 3 : 4)))) ? 5 : 6; +type Type05 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6; +type Type06 = ((0 extends 1 ? 2 : 3)) extends 4 ? 5 : 6; +type Type07 = (((0 extends 1 ? 2 : 3))) extends 4 ? 5 : 6; +type Type08 = ((((0 extends 1 ? 2 : 3)))) extends 4 ? 5 : 6; + +type T1 = () => void extends T ? U : V; +type T1a = () => (void extends T ? U : V); +type T1b = () => (void) extends T ? U : V; +type T2 = (() => void) extends T ? U : V; + +type U1 = new () => X extends T ? U : V; +type U1a = new () => (X extends T ? U : V); +type U1b = new () => (X) extends T ? U : V; +type U2 = (new () => X) extends T ? U : V; + =====================================output===================================== export type DeepReadonly = T extends any[] ? DeepReadonlyArray @@ -32,7 +51,7 @@ export type DeepReadonly = T extends any[] : T; type NonFunctionPropertyNames = { - [K in keyof T]: T[K] extends Function ? never : K + [K in keyof T]: T[K] extends Function ? never : K; }[keyof T]; interface DeepReadonlyArray extends ReadonlyArray> {} @@ -53,6 +72,25 @@ type TypeName = T extends string ? "function" : "object"; +type Type01 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6; +type Type02 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6; +type Type03 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6; +type Type04 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6; +type Type05 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6; +type Type06 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6; +type Type07 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6; +type Type08 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6; + +type T1 = () => void extends T ? U : V; +type T1a = () => void extends T ? U : V; +type T1b = () => void extends T ? U : V; +type T2 = (() => void) extends T ? U : V; + +type U1 = new () => X extends T ? U : V; +type U1a = new () => X extends T ? U : V; +type U1b = new () => X extends T ? U : V; +type U2 = (new () => X) extends T ? U : V; + ================================================================================ `; @@ -64,6 +102,12 @@ printWidth: 80 =====================================input====================================== type TestReturnType any> = T extends (...args: any[]) => infer R ? R : any; +type Unpacked = + T extends (infer U)[] ? U : + T extends (...args: any[]) => infer U ? U : + T extends Promise ? U : + T; + =====================================output===================================== type TestReturnType any> = T extends ( ...args: any[] @@ -71,5 +115,13 @@ type TestReturnType any> = T extends ( ? R : any; +type Unpacked = T extends (infer U)[] + ? U + : T extends (...args: any[]) => infer U + ? U + : T extends Promise + ? U + : T; + ================================================================================ `; diff --git a/tests/typescript_conditional_types/conditonal-types.ts b/tests/typescript_conditional_types/conditonal-types.ts index f1cfd069beee..b2ce6ad05c79 100644 --- a/tests/typescript_conditional_types/conditonal-types.ts +++ b/tests/typescript_conditional_types/conditonal-types.ts @@ -15,3 +15,22 @@ type TypeName = T extends undefined ? "undefined" : T extends Function ? "function" : "object"; + +type Type01 = 0 extends (1 extends 2 ? 3 : 4) ? 5 : 6; +type Type02 = 0 extends ((1 extends 2 ? 3 : 4)) ? 5 : 6; +type Type03 = 0 extends (((1 extends 2 ? 3 : 4))) ? 5 : 6; +type Type04 = 0 extends ((((1 extends 2 ? 3 : 4)))) ? 5 : 6; +type Type05 = (0 extends 1 ? 2 : 3) extends 4 ? 5 : 6; +type Type06 = ((0 extends 1 ? 2 : 3)) extends 4 ? 5 : 6; +type Type07 = (((0 extends 1 ? 2 : 3))) extends 4 ? 5 : 6; +type Type08 = ((((0 extends 1 ? 2 : 3)))) extends 4 ? 5 : 6; + +type T1 = () => void extends T ? U : V; +type T1a = () => (void extends T ? U : V); +type T1b = () => (void) extends T ? U : V; +type T2 = (() => void) extends T ? U : V; + +type U1 = new () => X extends T ? U : V; +type U1a = new () => (X extends T ? U : V); +type U1b = new () => (X) extends T ? U : V; +type U2 = (new () => X) extends T ? U : V; diff --git a/tests/typescript_conditional_types/infer-type.ts b/tests/typescript_conditional_types/infer-type.ts index ed8e81c89583..eb20f81cde29 100644 --- a/tests/typescript_conditional_types/infer-type.ts +++ b/tests/typescript_conditional_types/infer-type.ts @@ -1 +1,7 @@ type TestReturnType any> = T extends (...args: any[]) => infer R ? R : any; + +type Unpacked = + T extends (infer U)[] ? U : + T extends (...args: any[]) => infer U ? U : + T extends Promise ? U : + T; diff --git a/tests/typescript_declare/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_declare/__snapshots__/jsfmt.spec.js.snap index 142df472da85..44fb4d5909d1 100644 --- a/tests/typescript_declare/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_declare/__snapshots__/jsfmt.spec.js.snap @@ -70,14 +70,14 @@ printWidth: 80 const hello = 5; // tslint:disable-next-line:no-use-before-declare -declare const hello = 5; +declare const hello2 = 5; =====================================output===================================== // tslint:disable-next-line:no-use-before-declare const hello = 5; // tslint:disable-next-line:no-use-before-declare -declare const hello = 5; +declare const hello2 = 5; ================================================================================ `; diff --git a/tests/typescript_declare/declare_var.ts b/tests/typescript_declare/declare_var.ts index 24bdd8a7fb0f..953c23f50eab 100644 --- a/tests/typescript_declare/declare_var.ts +++ b/tests/typescript_declare/declare_var.ts @@ -2,4 +2,4 @@ const hello = 5; // tslint:disable-next-line:no-use-before-declare -declare const hello = 5; +declare const hello2 = 5; diff --git a/tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap index d6f0f540ecd8..79e152c1ee1a 100644 --- a/tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_decorators/__snapshots__/jsfmt.spec.js.snap @@ -87,6 +87,49 @@ class AngularComponent { @Input() myInput: string; } +class Class { + method( + @Decorator + { prop1, prop2 }: Type + ) { + doSomething(); + } +} + +class Class2 { + method( + @Decorator1 + @Decorator2 + { prop1, prop2 }: Type + ) { + doSomething(); + } +} + +class Class3 { + method( + @Decorator + { prop1_1, prop1_2 }: Type, + { prop2_1, prop2_2 }: Type + ) { + doSomething(); + } +} + +class Class4 { + method( + param1, + @Decorator + { prop1, prop2 }: Type + ) {} +} + +class Class5 { + method( + @Decorator { prop1 }: Type + ) {} +} + =====================================output===================================== export class TestTextFileService { constructor(@ILifecycleService lifecycleService) {} @@ -102,6 +145,47 @@ class AngularComponent { @Input() myInput: string; } +class Class { + method( + @Decorator + { prop1, prop2 }: Type + ) { + doSomething(); + } +} + +class Class2 { + method( + @Decorator1 + @Decorator2 + { prop1, prop2 }: Type + ) { + doSomething(); + } +} + +class Class3 { + method( + @Decorator + { prop1_1, prop1_2 }: Type, + { prop2_1, prop2_2 }: Type + ) { + doSomething(); + } +} + +class Class4 { + method( + param1, + @Decorator + { prop1, prop2 }: Type + ) {} +} + +class Class5 { + method(@Decorator { prop1 }: Type) {} +} + ================================================================================ `; @@ -142,13 +226,13 @@ class Something { readonly property: Array } -class Something { +class Something2 { @foo() // comment abstract property: Array } -class Something { +class Something3 { @foo() // comment abstract method(): Array @@ -185,13 +269,13 @@ class Something { readonly property: Array; } -class Something { +class Something2 { @foo() // comment abstract property: Array; } -class Something { +class Something3 { @foo() // comment abstract method(): Array; diff --git a/tests/typescript_decorators/decorators-comments.js b/tests/typescript_decorators/decorators-comments.js index e67b1534100f..002e8c099744 100644 --- a/tests/typescript_decorators/decorators-comments.js +++ b/tests/typescript_decorators/decorators-comments.js @@ -29,13 +29,13 @@ class Something { readonly property: Array } -class Something { +class Something2 { @foo() // comment abstract property: Array } -class Something { +class Something3 { @foo() // comment abstract method(): Array diff --git a/tests/typescript_decorators/decorators.js b/tests/typescript_decorators/decorators.js index 3224863b247c..4abd4dab8397 100644 --- a/tests/typescript_decorators/decorators.js +++ b/tests/typescript_decorators/decorators.js @@ -15,3 +15,46 @@ export class TabCompletionController { class AngularComponent { @Input() myInput: string; } + +class Class { + method( + @Decorator + { prop1, prop2 }: Type + ) { + doSomething(); + } +} + +class Class2 { + method( + @Decorator1 + @Decorator2 + { prop1, prop2 }: Type + ) { + doSomething(); + } +} + +class Class3 { + method( + @Decorator + { prop1_1, prop1_2 }: Type, + { prop2_1, prop2_2 }: Type + ) { + doSomething(); + } +} + +class Class4 { + method( + param1, + @Decorator + { prop1, prop2 }: Type + ) {} +} + +class Class5 { + method( + @Decorator { prop1 }: Type + ) {} +} diff --git a/tests/typescript_intersection/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_intersection/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..8c7b31db8868 --- /dev/null +++ b/tests/typescript_intersection/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,198 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`intersection-parens.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type A = (number | string) & boolean; +type B = ((number | string)) & boolean; +type C = (((number | string))) & boolean; +type D = ((((number | string)))) & boolean; + +let b1 : C; +let b2 : & C; +let b3 : (& C); +let b4 : & (C); +let b5 : (& (C)); +let b6 : /*1*/ & C; +let b7 : /*1*/ & (C); +let b8 : /*1*/ (& C); +let b9 : (/*1*/ & C); +let b10: /*1*/ & /*2*/ C; +let b11: /*1*/ (& /*2*/ C); + +let bb1: /*1*/ & /*2*/ C & D; +let bb2: /*1*/ & /*2*/ C & /*3*/ D; +let bb3: /*1*/ & /*2*/ C & /*3*/ D /*5*/; + +type B2 = & C; +type B3 = (& C); +type B4 = & (C); +type B5 = (& (C)); +type B6 = /*1*/ & C; +type B7 = /*1*/ & (C); +type B8 = /*1*/ (& C); +type B9 = (/*1*/ & C); +type B10 = /*1*/ & /*2*/ C; +type B11 = /*1*/ (& /*2*/ C); +type B12 = /*1*/ & ( (C)); + +type Bb1 = /*1*/ & /*2*/ C & D; +type Bb2 = /*1*/ & /*2*/ C & /*3*/ D; +type Bb3 = /*1*/ & /*2*/ C & /*3*/ D /*4*/; + +type D1 = /*1*/ | a & b; +type D2 = /*1*/ | a & (b); +type D3 = /*1*/ | a & (| b); +type D4 = /*1*/ | (a & b); +type D5 = /*1*/ (| a & b); +type D6 /*0*/ = /*1*/ (| a & b); + +=====================================output===================================== +type A = (number | string) & boolean; +type B = (number | string) & boolean; +type C = (number | string) & boolean; +type D = (number | string) & boolean; + +let b1: C; +let b2: C; +let b3: C; +let b4: C; +let b5: C; +let b6: /*1*/ C; +let b7: /*1*/ C; +let b8: /*1*/ C; +let b9: /*1*/ C; +let b10: /*1*/ /*2*/ C; +let b11: /*1*/ /*2*/ C; + +let bb1: /*1*/ /*2*/ C & D; +let bb2: /*1*/ /*2*/ C & /*3*/ D; +let bb3: /*1*/ /*2*/ C & /*3*/ D /*5*/; + +type B2 = C; +type B3 = C; +type B4 = C; +type B5 = C; +type B6 = /*1*/ C; +type B7 = /*1*/ C; +type B8 = /*1*/ C; +type B9 = /*1*/ C; +type B10 = /*1*/ /*2*/ C; +type B11 = /*1*/ /*2*/ C; +type B12 = /*1*/ C; + +type Bb1 = /*1*/ /*2*/ C & D; +type Bb2 = /*1*/ /*2*/ C & /*3*/ D; +type Bb3 = /*1*/ /*2*/ C & /*3*/ D /*4*/; + +type D1 = /*1*/ a & b; +type D2 = /*1*/ a & b; +type D3 = /*1*/ a & b; +type D4 = /*1*/ a & b; +type D5 = /*1*/ a & b; +type D6 /*0*/ = /*1*/ a & b; + +================================================================================ +`; + +exports[`intersection-parens.ts 2`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 +semi: false + | printWidth +=====================================input====================================== +type A = (number | string) & boolean; +type B = ((number | string)) & boolean; +type C = (((number | string))) & boolean; +type D = ((((number | string)))) & boolean; + +let b1 : C; +let b2 : & C; +let b3 : (& C); +let b4 : & (C); +let b5 : (& (C)); +let b6 : /*1*/ & C; +let b7 : /*1*/ & (C); +let b8 : /*1*/ (& C); +let b9 : (/*1*/ & C); +let b10: /*1*/ & /*2*/ C; +let b11: /*1*/ (& /*2*/ C); + +let bb1: /*1*/ & /*2*/ C & D; +let bb2: /*1*/ & /*2*/ C & /*3*/ D; +let bb3: /*1*/ & /*2*/ C & /*3*/ D /*5*/; + +type B2 = & C; +type B3 = (& C); +type B4 = & (C); +type B5 = (& (C)); +type B6 = /*1*/ & C; +type B7 = /*1*/ & (C); +type B8 = /*1*/ (& C); +type B9 = (/*1*/ & C); +type B10 = /*1*/ & /*2*/ C; +type B11 = /*1*/ (& /*2*/ C); +type B12 = /*1*/ & ( (C)); + +type Bb1 = /*1*/ & /*2*/ C & D; +type Bb2 = /*1*/ & /*2*/ C & /*3*/ D; +type Bb3 = /*1*/ & /*2*/ C & /*3*/ D /*4*/; + +type D1 = /*1*/ | a & b; +type D2 = /*1*/ | a & (b); +type D3 = /*1*/ | a & (| b); +type D4 = /*1*/ | (a & b); +type D5 = /*1*/ (| a & b); +type D6 /*0*/ = /*1*/ (| a & b); + +=====================================output===================================== +type A = (number | string) & boolean +type B = (number | string) & boolean +type C = (number | string) & boolean +type D = (number | string) & boolean + +let b1: C +let b2: C +let b3: C +let b4: C +let b5: C +let b6: /*1*/ C +let b7: /*1*/ C +let b8: /*1*/ C +let b9: /*1*/ C +let b10: /*1*/ /*2*/ C +let b11: /*1*/ /*2*/ C + +let bb1: /*1*/ /*2*/ C & D +let bb2: /*1*/ /*2*/ C & /*3*/ D +let bb3: /*1*/ /*2*/ C & /*3*/ D /*5*/ + +type B2 = C +type B3 = C +type B4 = C +type B5 = C +type B6 = /*1*/ C +type B7 = /*1*/ C +type B8 = /*1*/ C +type B9 = /*1*/ C +type B10 = /*1*/ /*2*/ C +type B11 = /*1*/ /*2*/ C +type B12 = /*1*/ C + +type Bb1 = /*1*/ /*2*/ C & D +type Bb2 = /*1*/ /*2*/ C & /*3*/ D +type Bb3 = /*1*/ /*2*/ C & /*3*/ D /*4*/ + +type D1 = /*1*/ a & b +type D2 = /*1*/ a & b +type D3 = /*1*/ a & b +type D4 = /*1*/ a & b +type D5 = /*1*/ a & b +type D6 /*0*/ = /*1*/ a & b + +================================================================================ +`; diff --git a/tests/typescript_intersection/intersection-parens.ts b/tests/typescript_intersection/intersection-parens.ts new file mode 100644 index 000000000000..b19671acd128 --- /dev/null +++ b/tests/typescript_intersection/intersection-parens.ts @@ -0,0 +1,43 @@ +type A = (number | string) & boolean; +type B = ((number | string)) & boolean; +type C = (((number | string))) & boolean; +type D = ((((number | string)))) & boolean; + +let b1 : C; +let b2 : & C; +let b3 : (& C); +let b4 : & (C); +let b5 : (& (C)); +let b6 : /*1*/ & C; +let b7 : /*1*/ & (C); +let b8 : /*1*/ (& C); +let b9 : (/*1*/ & C); +let b10: /*1*/ & /*2*/ C; +let b11: /*1*/ (& /*2*/ C); + +let bb1: /*1*/ & /*2*/ C & D; +let bb2: /*1*/ & /*2*/ C & /*3*/ D; +let bb3: /*1*/ & /*2*/ C & /*3*/ D /*5*/; + +type B2 = & C; +type B3 = (& C); +type B4 = & (C); +type B5 = (& (C)); +type B6 = /*1*/ & C; +type B7 = /*1*/ & (C); +type B8 = /*1*/ (& C); +type B9 = (/*1*/ & C); +type B10 = /*1*/ & /*2*/ C; +type B11 = /*1*/ (& /*2*/ C); +type B12 = /*1*/ & ( (C)); + +type Bb1 = /*1*/ & /*2*/ C & D; +type Bb2 = /*1*/ & /*2*/ C & /*3*/ D; +type Bb3 = /*1*/ & /*2*/ C & /*3*/ D /*4*/; + +type D1 = /*1*/ | a & b; +type D2 = /*1*/ | a & (b); +type D3 = /*1*/ | a & (| b); +type D4 = /*1*/ | (a & b); +type D5 = /*1*/ (| a & b); +type D6 /*0*/ = /*1*/ (| a & b); diff --git a/tests/typescript_intersection/jsfmt.spec.js b/tests/typescript_intersection/jsfmt.spec.js new file mode 100644 index 000000000000..ba52aeb62efa --- /dev/null +++ b/tests/typescript_intersection/jsfmt.spec.js @@ -0,0 +1,2 @@ +run_spec(__dirname, ["typescript"]); +run_spec(__dirname, ["typescript"], { semi: false }); diff --git a/tests/typescript_keyof/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_keyof/__snapshots__/jsfmt.spec.js.snap index 779fc272cf80..225968d912e2 100644 --- a/tests/typescript_keyof/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_keyof/__snapshots__/jsfmt.spec.js.snap @@ -12,7 +12,10 @@ type C = keyof T | U; type D = keyof X & Y; type E = (keyof T)[]; type F = ((keyof T))[]; - +type G = (keyof T1)["foo"]; +type H = ((keyof T1))["foo"]; +type I = (((keyof T1)))["foo"]; +type J = ((((keyof T1))))["foo"]; =====================================output===================================== type A = keyof (T | U); @@ -21,6 +24,10 @@ type C = keyof T | U; type D = keyof X & Y; type E = (keyof T)[]; type F = (keyof T)[]; +type G = (keyof T1)["foo"]; +type H = (keyof T1)["foo"]; +type I = (keyof T1)["foo"]; +type J = (keyof T1)["foo"]; ================================================================================ `; diff --git a/tests/typescript_keyof/keyof.ts b/tests/typescript_keyof/keyof.ts index fc2043cc7b92..bb48a7af1456 100644 --- a/tests/typescript_keyof/keyof.ts +++ b/tests/typescript_keyof/keyof.ts @@ -4,4 +4,7 @@ type C = keyof T | U; type D = keyof X & Y; type E = (keyof T)[]; type F = ((keyof T))[]; - +type G = (keyof T1)["foo"]; +type H = ((keyof T1))["foo"]; +type I = (((keyof T1)))["foo"]; +type J = ((((keyof T1))))["foo"]; diff --git a/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap index 39235371d3ad..ba39f4800fda 100644 --- a/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_non_null/__snapshots__/jsfmt.spec.js.snap @@ -8,7 +8,7 @@ printWidth: 80 =====================================input====================================== const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!; -const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!.anotherObject; +const { somePropThatHasAReallyLongName2, anotherPropThatHasALongName2 } = this.props.imReallySureAboutThis!.anotherObject; this.foo.get("bar")!.doThings().more(); @@ -21,8 +21,8 @@ const { } = this.props.imReallySureAboutThis!; const { - somePropThatHasAReallyLongName, - anotherPropThatHasALongName + somePropThatHasAReallyLongName2, + anotherPropThatHasALongName2 } = this.props.imReallySureAboutThis!.anotherObject; this.foo @@ -60,9 +60,13 @@ const a = (b()!)(); // parens aren't necessary const b = c!(); // parens are necessary if the expression result is called as a constructor -const c = new (d()!)(); -const c = new (d()!); -const c = new (d()!.e)(); +const c1 = new (d()!)(); +const c2 = new (d()!); +const c3 = new (d()!.e)(); +new (x()\`\`.y!)(); +new (x()\`\`!.y)(); +new (x()!\`\`.y)(); +new (x!()\`\`.y)(); =====================================output===================================== (a ? b : c)![tokenKey]; @@ -81,9 +85,13 @@ const a = b()!(); // parens aren't necessary const b = c!(); // parens are necessary if the expression result is called as a constructor -const c = new (d())!(); -const c = new (d())!(); -const c = new (d())!.e(); +const c1 = new (d()!)(); +const c2 = new (d()!)(); +const c3 = new (d()!.e)(); +new (x()\`\`.y!)(); +new (x()\`\`!.y)(); +new (x()!\`\`.y)(); +new (x!()\`\`.y)(); ================================================================================ `; diff --git a/tests/typescript_non_null/member-chain.js b/tests/typescript_non_null/member-chain.js index 7d6ba3972439..753ae6695eb9 100644 --- a/tests/typescript_non_null/member-chain.js +++ b/tests/typescript_non_null/member-chain.js @@ -1,6 +1,6 @@ const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!; -const { somePropThatHasAReallyLongName, anotherPropThatHasALongName } = this.props.imReallySureAboutThis!.anotherObject; +const { somePropThatHasAReallyLongName2, anotherPropThatHasALongName2 } = this.props.imReallySureAboutThis!.anotherObject; this.foo.get("bar")!.doThings().more(); diff --git a/tests/typescript_non_null/parens.ts b/tests/typescript_non_null/parens.ts index b96c63dda29b..3f064920e7d9 100644 --- a/tests/typescript_non_null/parens.ts +++ b/tests/typescript_non_null/parens.ts @@ -14,6 +14,10 @@ const a = (b()!)(); // parens aren't necessary const b = c!(); // parens are necessary if the expression result is called as a constructor -const c = new (d()!)(); -const c = new (d()!); -const c = new (d()!.e)(); +const c1 = new (d()!)(); +const c2 = new (d()!); +const c3 = new (d()!.e)(); +new (x()``.y!)(); +new (x()``!.y)(); +new (x()!``.y)(); +new (x!()``.y)(); diff --git a/tests/typescript_optional_type/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_optional_type/__snapshots__/jsfmt.spec.js.snap index 01af5d6b0a19..fcf68d508280 100644 --- a/tests/typescript_optional_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_optional_type/__snapshots__/jsfmt.spec.js.snap @@ -7,9 +7,11 @@ printWidth: 80 | printWidth =====================================input====================================== type T = [("a" | "b")?]; +type TupleWithOptional = [number, (1 extends 2 ? string[] : number[])?]; =====================================output===================================== type T = [("a" | "b")?]; +type TupleWithOptional = [number, (1 extends 2 ? string[] : number[])?]; ================================================================================ `; diff --git a/tests/typescript_optional_type/complex.ts b/tests/typescript_optional_type/complex.ts index f5c170a36ff9..b6cda8b440f5 100644 --- a/tests/typescript_optional_type/complex.ts +++ b/tests/typescript_optional_type/complex.ts @@ -1 +1,2 @@ type T = [("a" | "b")?]; +type TupleWithOptional = [number, (1 extends 2 ? string[] : number[])?]; diff --git a/tests/typescript_rest_type/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_rest_type/__snapshots__/jsfmt.spec.js.snap index fef6f8952cde..1334dc24674e 100644 --- a/tests/typescript_rest_type/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_rest_type/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`complex.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type TupleWithRest = [number, ...(1 extends 2 ? string[] : number[])]; + +=====================================output===================================== +type TupleWithRest = [number, ...(1 extends 2 ? string[] : number[])]; + +================================================================================ +`; + exports[`simple.ts 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/typescript_rest_type/complex.ts b/tests/typescript_rest_type/complex.ts new file mode 100644 index 000000000000..db3038425b8a --- /dev/null +++ b/tests/typescript_rest_type/complex.ts @@ -0,0 +1 @@ +type TupleWithRest = [number, ...(1 extends 2 ? string[] : number[])]; diff --git a/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap index 062380b23d87..761df1b1ff23 100644 --- a/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_tsx/__snapshots__/jsfmt.spec.js.snap @@ -38,6 +38,66 @@ printWidth: 80 ================================================================================ `; +exports[`member-expression.tsx 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +().method(); +().property; +()["computed"]; +()["computed"](); +( + +).method(); +( +
+ foo +
+).property; +( +
+ foo +
+)["computed"]; +( +
+ foo +
+)["computed"](); + +=====================================output===================================== +().method(); +().property; +()["computed"]; +()["computed"](); +( + +).method(); +( +
+ foo +
+).property; +( +
+ foo +
+)["computed"]; +( +
+ foo +
+)["computed"](); + +================================================================================ +`; + exports[`not-react.ts 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/typescript_tsx/member-expression.tsx b/tests/typescript_tsx/member-expression.tsx new file mode 100644 index 000000000000..2a91dee44e4d --- /dev/null +++ b/tests/typescript_tsx/member-expression.tsx @@ -0,0 +1,24 @@ +().method(); +().property; +()["computed"]; +()["computed"](); +( + +).method(); +( +
+ foo +
+).property; +( +
+ foo +
+)["computed"]; +( +
+ foo +
+)["computed"](); diff --git a/tests/typescript_typeparams/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_typeparams/__snapshots__/jsfmt.spec.js.snap index f071b3cd1d07..b5ee44792929 100644 --- a/tests/typescript_typeparams/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_typeparams/__snapshots__/jsfmt.spec.js.snap @@ -297,7 +297,7 @@ export const forwardS = R.curry( R.assoc(prop, reducer(value, state[prop]), state) ) -export const forwardS = R.curry( +export const forwardS1 = R.curry( (prop: string, reducer: ReducerFunction, value: V, state: {[name: string]: T}) => R.assoc(prop, reducer(value, state[prop]), state) ) @@ -313,7 +313,7 @@ export const forwardS = R.curry( ) => R.assoc(prop, reducer(value, state[prop]), state) ); -export const forwardS = R.curry( +export const forwardS1 = R.curry( < VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV, TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT diff --git a/tests/typescript_typeparams/long-function-arg.ts b/tests/typescript_typeparams/long-function-arg.ts index f5625fbf6950..15bb25716f20 100644 --- a/tests/typescript_typeparams/long-function-arg.ts +++ b/tests/typescript_typeparams/long-function-arg.ts @@ -3,7 +3,7 @@ export const forwardS = R.curry( R.assoc(prop, reducer(value, state[prop]), state) ) -export const forwardS = R.curry( +export const forwardS1 = R.curry( (prop: string, reducer: ReducerFunction, value: V, state: {[name: string]: T}) => R.assoc(prop, reducer(value, state[prop]), state) ) diff --git a/tests/typescript_union/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_union/__snapshots__/jsfmt.spec.js.snap index 4ad0014d78a0..7349aea3c9cb 100644 --- a/tests/typescript_union/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript_union/__snapshots__/jsfmt.spec.js.snap @@ -25,7 +25,7 @@ type UploadState // Uploading to aws3 and CreatePostMutation succeeded | {type: "Success", data: D}; -type UploadState +type UploadState2 // The upload hasnt begun yet = A // The upload timed out @@ -39,6 +39,15 @@ type window = Window & { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function; }; +type T1 = (number | string)["toString"]; +type T2 = ((number | string))["toString"]; +type T3 = (((number | string)))["toString"]; +type T4 = ((((number | string))))["toString"]; +type T5 = number | ((arg: any) => void); +type T6 = number | (((arg: any) => void)); +type T7 = number | ((((arg: any) => void))); +type T8 = number | (((((arg: any) => void)))); + =====================================output===================================== interface RelayProps { articles: a | null; @@ -59,7 +68,7 @@ type UploadState = // Uploading to aws3 and CreatePostMutation succeeded | { type: "Success"; data: D }; -type UploadState = +type UploadState2 = // The upload hasnt begun yet | A // The upload timed out @@ -73,6 +82,15 @@ type window = Window & { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function; }; +type T1 = (number | string)["toString"]; +type T2 = (number | string)["toString"]; +type T3 = (number | string)["toString"]; +type T4 = (number | string)["toString"]; +type T5 = number | ((arg: any) => void); +type T6 = number | ((arg: any) => void); +type T7 = number | ((arg: any) => void); +type T8 = number | ((arg: any) => void); + ================================================================================ `; @@ -120,9 +138,80 @@ type State = { } & ( | { discriminant: "FOO"; foo: any } | { discriminant: "BAR"; bar: any } - | { discriminant: "BAZ"; baz: any } + | { discriminant: "BAZ"; baz: any } ); +const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +const foo2: ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +)[] = []; + +const foo3: keyof ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +) = bar; + +const foo4: + | foo + | ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) = bar; + +let a1 : C; +let a2 : | C; +let a3 : (| C); +let a4 : | (C); +let a5 : (| (C)); +let a6 : /*1*/ | C; +let a7 : /*1*/ | (C); +let a8 : /*1*/ (| C); +let a9 : (/*1*/ | C); +let a10: /*1*/ | /*2*/ C; +let a11: /*1*/ (| /*2*/ C); + +let aa1: /*1*/ | /*2*/ C | D; +let aa2: /*1*/ | /*2*/ C | /*3*/ D; +let aa3: /*1*/ | /*2*/ C | /*3*/ D /*4*/; + +type A1 = C; +type A2 = | C; +type A3 = (| C); +type A4 = | (C); +type A5 = (| (C)); +type A6 = /*1*/ | C; +type A7 = /*1*/ | (C); +type A8 = /*1*/ (| C); +type A9 = (/*1*/ | C); +type A10 = /*1*/ | /*2*/ C; +type A11 = /*1*/ (| /*2*/ C); +type A12 = /*1*/ | ( (C)); +type A13 = /*1*/ ( (C)); + +type Aa1 = /*1*/ | /*2*/ C | D; +type Aa2 = /*1*/ | /*2*/ C | /*3*/ D; +type Aa3 = /*1*/ | /*2*/ C | /*3*/ D /*4*/; + +type C1 = /*1*/ & a | b; +type C2 = /*1*/ & a | (b); +type C3 = /*1*/ & a | (& b); +type C4 = /*1*/ & (a | b); +type C5 = /*1*/ (& a | b); +type C6 /*0*/ = /*1*/ (& a | b); + +type Ctor = (new () => X) | Y; + =====================================output===================================== export type A = | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa @@ -159,7 +248,79 @@ type State = { } & ( | { discriminant: "FOO"; foo: any } | { discriminant: "BAR"; bar: any } - | { discriminant: "BAZ"; baz: any }); + | { discriminant: "BAZ"; baz: any } +); + +const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +const foo2: ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +)[] = []; + +const foo3: keyof ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +) = bar; + +const foo4: + | foo + | ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) = bar; + +let a1: C; +let a2: C; +let a3: C; +let a4: C; +let a5: C; +let a6: /*1*/ C; +let a7: /*1*/ C; +let a8: /*1*/ C; +let a9: /*1*/ C; +let a10: /*1*/ /*2*/ C; +let a11: /*1*/ /*2*/ C; + +let aa1: /*1*/ /*2*/ C | D; +let aa2: /*1*/ /*2*/ C | /*3*/ D; +let aa3: /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type A1 = C; +type A2 = C; +type A3 = C; +type A4 = C; +type A5 = C; +type A6 = /*1*/ C; +type A7 = /*1*/ C; +type A8 = /*1*/ C; +type A9 = /*1*/ C; +type A10 = /*1*/ /*2*/ C; +type A11 = /*1*/ /*2*/ C; +type A12 = /*1*/ C; +type A13 = /*1*/ C; + +type Aa1 = /*1*/ /*2*/ C | D; +type Aa2 = /*1*/ /*2*/ C | /*3*/ D; +type Aa3 = /*1*/ /*2*/ C | /*3*/ D /*4*/; + +type C1 = /*1*/ a | b; +type C2 = /*1*/ a | b; +type C3 = /*1*/ a | b; +type C4 = /*1*/ a | b; +type C5 = /*1*/ a | b; +type C6 /*0*/ = /*1*/ a | b; + +type Ctor = (new () => X) | Y; ================================================================================ `; @@ -193,3 +354,171 @@ type GetChatsSagaEffects = ================================================================================ `; + +exports[`within-tuple.ts 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +type A = [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type B1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type C = [ + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] +] + +type D = [ + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD), + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD) +] + +type D1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type D2 = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type E = [ AA | BB, AA | BB ] + +type F = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB +] + +=====================================output===================================== +type A = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +]; + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +]; + +type B1 = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +]; + +type C = [ + | [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ] + | [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ] +]; + +type D = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +]; + +type D1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +]; + +type D2 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +]; + +type E = [AA | BB, AA | BB]; + +type F = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB +]; + +================================================================================ +`; diff --git a/tests/typescript_union/inlining.ts b/tests/typescript_union/inlining.ts index 54b60617c619..76f7dfb18201 100644 --- a/tests/typescript_union/inlining.ts +++ b/tests/typescript_union/inlining.ts @@ -17,7 +17,7 @@ type UploadState // Uploading to aws3 and CreatePostMutation succeeded | {type: "Success", data: D}; -type UploadState +type UploadState2 // The upload hasnt begun yet = A // The upload timed out @@ -30,3 +30,12 @@ type UploadState type window = Window & { __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: Function; }; + +type T1 = (number | string)["toString"]; +type T2 = ((number | string))["toString"]; +type T3 = (((number | string)))["toString"]; +type T4 = ((((number | string))))["toString"]; +type T5 = number | ((arg: any) => void); +type T6 = number | (((arg: any) => void)); +type T7 = number | ((((arg: any) => void))); +type T8 = number | (((((arg: any) => void)))); diff --git a/tests/typescript_union/union-parens.ts b/tests/typescript_union/union-parens.ts index 76b5a8a2e01b..9a368440977e 100644 --- a/tests/typescript_union/union-parens.ts +++ b/tests/typescript_union/union-parens.ts @@ -36,5 +36,76 @@ type State = { } & ( | { discriminant: "FOO"; foo: any } | { discriminant: "BAR"; bar: any } - | { discriminant: "BAZ"; baz: any } + | { discriminant: "BAZ"; baz: any } ); + +const foo1 = [abc, def, ghi, jkl, mno, pqr, stu, vwx, yz] as ( + | string + | undefined +)[]; + +const foo2: ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +)[] = []; + +const foo3: keyof ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +) = bar; + +const foo4: + | foo + | ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) = bar; + +let a1 : C; +let a2 : | C; +let a3 : (| C); +let a4 : | (C); +let a5 : (| (C)); +let a6 : /*1*/ | C; +let a7 : /*1*/ | (C); +let a8 : /*1*/ (| C); +let a9 : (/*1*/ | C); +let a10: /*1*/ | /*2*/ C; +let a11: /*1*/ (| /*2*/ C); + +let aa1: /*1*/ | /*2*/ C | D; +let aa2: /*1*/ | /*2*/ C | /*3*/ D; +let aa3: /*1*/ | /*2*/ C | /*3*/ D /*4*/; + +type A1 = C; +type A2 = | C; +type A3 = (| C); +type A4 = | (C); +type A5 = (| (C)); +type A6 = /*1*/ | C; +type A7 = /*1*/ | (C); +type A8 = /*1*/ (| C); +type A9 = (/*1*/ | C); +type A10 = /*1*/ | /*2*/ C; +type A11 = /*1*/ (| /*2*/ C); +type A12 = /*1*/ | ( (C)); +type A13 = /*1*/ ( (C)); + +type Aa1 = /*1*/ | /*2*/ C | D; +type Aa2 = /*1*/ | /*2*/ C | /*3*/ D; +type Aa3 = /*1*/ | /*2*/ C | /*3*/ D /*4*/; + +type C1 = /*1*/ & a | b; +type C2 = /*1*/ & a | (b); +type C3 = /*1*/ & a | (& b); +type C4 = /*1*/ & (a | b); +type C5 = /*1*/ (& a | b); +type C6 /*0*/ = /*1*/ (& a | b); + +type Ctor = (new () => X) | Y; diff --git a/tests/typescript_union/within-tuple.ts b/tests/typescript_union/within-tuple.ts new file mode 100644 index 000000000000..7539bc9d7868 --- /dev/null +++ b/tests/typescript_union/within-tuple.ts @@ -0,0 +1,64 @@ +type A = [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + +type B = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type B1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type C = [ + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] + | [AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD] +] + +type D = [ + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD), + (AAAAAAAAAAAAAAAAAAAAAA | BBBBBBBBBBBBBBBBBBBBBB | CCCCCCCCCCCCCCCCCCCCCC | DDDDDDDDDDDDDDDDDDDDDD) +] + +type D1 = [ + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ), + ( + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD + ) +] + +type D2 = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD +] + +type E = [ AA | BB, AA | BB ] + +type F = [ + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB + | CCCCCCCCCCCCCCCCCCCCCC + | DDDDDDDDDDDDDDDDDDDDDD, + | AAAAAAAAAAAAAAAAAAAAAA + | BBBBBBBBBBBBBBBBBBBBBB +] diff --git a/tests/unary_expression/__snapshots__/jsfmt.spec.js.snap b/tests/unary_expression/__snapshots__/jsfmt.spec.js.snap index 15d492f7e05b..545fb81270ed 100644 --- a/tests/unary_expression/__snapshots__/jsfmt.spec.js.snap +++ b/tests/unary_expression/__snapshots__/jsfmt.spec.js.snap @@ -275,7 +275,7 @@ function* bar() { ); } -async function bar() { +async function bar2() { !(await x); !(await x /* foo */); !(/* foo */ await x); @@ -560,7 +560,7 @@ function* bar() { ); } -async function bar() { +async function bar2() { !(await x); !((await x) /* foo */); !(/* foo */ (await x)); diff --git a/tests/unary_expression/comments.js b/tests/unary_expression/comments.js index 5acb1afbb49c..e912b89d9a72 100644 --- a/tests/unary_expression/comments.js +++ b/tests/unary_expression/comments.js @@ -267,7 +267,7 @@ function* bar() { ); } -async function bar() { +async function bar2() { !(await x); !(await x /* foo */); !(/* foo */ await x); diff --git a/tests/v8_intrinsic/__snapshots__/jsfmt.spec.js.snap b/tests/v8_intrinsic/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..0248f069144c --- /dev/null +++ b/tests/v8_intrinsic/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,47 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`intrinsic_call.js 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +function doSmth() { + %DebugPrint + ( + foo ) + } + + function printFunc ( + f +) { + if(% + IsAsmWasmCode(f)) console.log("asm.js"); + if( + + % IsWasmCode( + f)) + console.log ( + "wasm" + ); + + console.log + (% + GetFunctioName(f) + ); +} + +=====================================output===================================== +function doSmth() { + %DebugPrint(foo); +} + +function printFunc(f) { + if (%IsAsmWasmCode(f)) console.log("asm.js"); + if (%IsWasmCode(f)) console.log("wasm"); + + console.log(%GetFunctioName(f)); +} + +================================================================================ +`; diff --git a/tests/v8_intrinsic/intrinsic_call.js b/tests/v8_intrinsic/intrinsic_call.js new file mode 100644 index 000000000000..43f8bbd7e936 --- /dev/null +++ b/tests/v8_intrinsic/intrinsic_call.js @@ -0,0 +1,24 @@ +function doSmth() { + %DebugPrint + ( + foo ) + } + + function printFunc ( + f +) { + if(% + IsAsmWasmCode(f)) console.log("asm.js"); + if( + + % IsWasmCode( + f)) + console.log ( + "wasm" + ); + + console.log + (% + GetFunctioName(f) + ); +} diff --git a/tests/v8_intrinsic/jsfmt.spec.js b/tests/v8_intrinsic/jsfmt.spec.js new file mode 100644 index 000000000000..8382eddeb1db --- /dev/null +++ b/tests/v8_intrinsic/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["babel"]); diff --git a/tests/yield/__snapshots__/jsfmt.spec.js.snap b/tests/yield/__snapshots__/jsfmt.spec.js.snap index 78a36fd23a5b..ea0f5bce79c4 100644 --- a/tests/yield/__snapshots__/jsfmt.spec.js.snap +++ b/tests/yield/__snapshots__/jsfmt.spec.js.snap @@ -28,7 +28,7 @@ parsers: ["babel", "typescript"] printWidth: 80 | printWidth =====================================input====================================== -function* f() { +function* f1() { a = (yield) ? 1 : 1; a = yield 1 ? 1 : 1; a = (yield 1) ? 1 : 1; @@ -36,20 +36,20 @@ function* f() { a = 1 ? yield 1 : yield 1; } -function* f() { +function* f2() { a = yield* 1 ? 1 : 1; a = (yield* 1) ? 1 : 1; a = 1 ? yield* 1 : yield* 1; } -async function f() { +async function f3() { a = await 1 ? 1 : 1; a = (await 1) ? 1 : 1; a = 1 ? await 1 : await 1; } =====================================output===================================== -function* f() { +function* f1() { a = (yield) ? 1 : 1; a = yield 1 ? 1 : 1; a = (yield 1) ? 1 : 1; @@ -57,13 +57,13 @@ function* f() { a = 1 ? yield 1 : yield 1; } -function* f() { +function* f2() { a = yield* 1 ? 1 : 1; a = (yield* 1) ? 1 : 1; a = 1 ? yield* 1 : yield* 1; } -async function f() { +async function f3() { a = (await 1) ? 1 : 1; a = (await 1) ? 1 : 1; a = 1 ? await 1 : await 1; diff --git a/tests/yield/conditional.js b/tests/yield/conditional.js index 0dfb0c4cb005..91256ad8661a 100644 --- a/tests/yield/conditional.js +++ b/tests/yield/conditional.js @@ -1,4 +1,4 @@ -function* f() { +function* f1() { a = (yield) ? 1 : 1; a = yield 1 ? 1 : 1; a = (yield 1) ? 1 : 1; @@ -6,13 +6,13 @@ function* f() { a = 1 ? yield 1 : yield 1; } -function* f() { +function* f2() { a = yield* 1 ? 1 : 1; a = (yield* 1) ? 1 : 1; a = 1 ? yield* 1 : yield* 1; } -async function f() { +async function f3() { a = await 1 ? 1 : 1; a = (await 1) ? 1 : 1; a = 1 ? await 1 : await 1; diff --git a/tests_integration/__tests__/__snapshots__/early-exit.js.snap b/tests_integration/__tests__/__snapshots__/early-exit.js.snap index 458a18be656d..95af8c1c27f7 100644 --- a/tests_integration/__tests__/__snapshots__/early-exit.js.snap +++ b/tests_integration/__tests__/__snapshots__/early-exit.js.snap @@ -92,6 +92,9 @@ Format options: Defaults to none. --use-tabs Indent with tabs instead of spaces. Defaults to false. + --vue-indent-script-and-style + Indent script and style tags in Vue files. + Defaults to false. Config options: @@ -245,6 +248,9 @@ Format options: Defaults to none. --use-tabs Indent with tabs instead of spaces. Defaults to false. + --vue-indent-script-and-style + Indent script and style tags in Vue files. + Defaults to false. Config options: diff --git a/tests_integration/__tests__/__snapshots__/help-options.js.snap b/tests_integration/__tests__/__snapshots__/help-options.js.snap index 4f43f9fa9f3c..4e4d216b1fbb 100644 --- a/tests_integration/__tests__/__snapshots__/help-options.js.snap +++ b/tests_integration/__tests__/__snapshots__/help-options.js.snap @@ -599,6 +599,19 @@ exports[`show detailed usage with --help version (stdout) 1`] = ` exports[`show detailed usage with --help version (write) 1`] = `Array []`; +exports[`show detailed usage with --help vue-indent-script-and-style (stderr) 1`] = `""`; + +exports[`show detailed usage with --help vue-indent-script-and-style (stdout) 1`] = ` +"--vue-indent-script-and-style + + Indent script and style tags in Vue files. + +Default: false +" +`; + +exports[`show detailed usage with --help vue-indent-script-and-style (write) 1`] = `Array []`; + exports[`show detailed usage with --help with-node-modules (stderr) 1`] = `""`; exports[`show detailed usage with --help with-node-modules (stdout) 1`] = ` diff --git a/tests_integration/__tests__/__snapshots__/support-info.js.snap b/tests_integration/__tests__/__snapshots__/support-info.js.snap index 0a9974b62e4d..e654050ebb11 100644 --- a/tests_integration/__tests__/__snapshots__/support-info.js.snap +++ b/tests_integration/__tests__/__snapshots__/support-info.js.snap @@ -141,7 +141,7 @@ exports[`API getSupportInfo() with version 1.0.0 -> 1.4.0 1`] = ` \\"flow\\", ], \\"JSX\\": Array [ -@@ -10,24 +13,51 @@ +@@ -10,24 +13,54 @@ ], \\"JavaScript\\": Array [ \\"babylon\\", @@ -156,6 +156,9 @@ exports[`API getSupportInfo() with version 1.0.0 -> 1.4.0 1`] = ` + \\"SCSS\\": Array [ + \\"postcss\\", + ], ++ \\"TSX\\": Array [ ++ \\"typescript\\", ++ ], + \\"TypeScript\\": Array [ + \\"typescript\\", + ], @@ -193,7 +196,7 @@ exports[`API getSupportInfo() with version 1.0.0 -> 1.4.0 1`] = ` \\"type\\": \\"choice\\", }, \\"printWidth\\": Object { -@@ -37,10 +67,28 @@ +@@ -37,10 +70,28 @@ \\"start\\": 0, \\"step\\": 1, }, @@ -249,7 +252,7 @@ exports[`API getSupportInfo() with version 1.4.0 -> 1.5.0 1`] = ` \\"flow\\", ], \\"JavaScript\\": Array [ -@@ -54,10 +63,12 @@ +@@ -57,10 +66,12 @@ \\"choices\\": Array [ \\"flow\\", \\"babylon\\", @@ -297,11 +300,11 @@ exports[`API getSupportInfo() with version 1.5.0 -> 1.7.1 1`] = ` - \\"postcss\\", + \\"scss\\", ], - \\"TypeScript\\": Array [ + \\"TSX\\": Array [ \\"typescript\\", ], - }, -@@ -62,11 +62,13 @@ + \\"TypeScript\\": Array [ +@@ -65,11 +65,13 @@ \\"parser\\": Object { \\"choices\\": Array [ \\"flow\\", @@ -316,7 +319,7 @@ exports[`API getSupportInfo() with version 1.5.0 -> 1.7.1 1`] = ` ], \\"default\\": \\"babylon\\", \\"type\\": \\"choice\\", -@@ -96,10 +98,14 @@ +@@ -99,10 +101,14 @@ \\"start\\": 0, \\"step\\": 1, }, @@ -352,7 +355,7 @@ exports[`API getSupportInfo() with version 1.7.1 -> 1.8.0 1`] = ` ], \\"SCSS\\": Array [ \\"scss\\", -@@ -53,10 +56,14 @@ +@@ -56,10 +59,14 @@ }, \\"filepath\\": Object { \\"default\\": undefined, @@ -367,7 +370,7 @@ exports[`API getSupportInfo() with version 1.7.1 -> 1.8.0 1`] = ` \\"type\\": \\"boolean\\", }, \\"parser\\": Object { -@@ -67,10 +74,11 @@ +@@ -70,10 +77,11 @@ \\"css\\", \\"less\\", \\"scss\\", @@ -386,7 +389,7 @@ exports[`API getSupportInfo() with version 1.8.0 -> 1.8.2 1`] = ` - First value + Second value -@@ -88,10 +88,18 @@ +@@ -91,10 +91,18 @@ \\"start\\": 0, \\"step\\": 1, }, @@ -465,8 +468,8 @@ exports[`API getSupportInfo() with version 1.8.2 -> 1.16.0 1`] = ` ], \\"PostCSS\\": Array [ \\"css\\", -@@ -37,12 +52,26 @@ - \\"scss\\", +@@ -40,12 +55,26 @@ + \\"typescript\\", ], \\"TypeScript\\": Array [ \\"typescript\\", @@ -492,7 +495,7 @@ exports[`API getSupportInfo() with version 1.8.2 -> 1.16.0 1`] = ` \\"type\\": \\"boolean\\", }, \\"cursorOffset\\": Object { -@@ -52,37 +81,76 @@ +@@ -55,37 +84,76 @@ \\"start\\": -1, \\"step\\": 1, }, @@ -571,7 +574,7 @@ exports[`API getSupportInfo() with version 1.8.2 -> 1.16.0 1`] = ` \\"range\\": Object { \\"end\\": Infinity, \\"start\\": 0, -@@ -90,14 +158,15 @@ +@@ -93,14 +161,15 @@ }, \\"type\\": \\"int\\", }, @@ -611,7 +614,7 @@ exports[`API getSupportInfo() with version 1.16.0 -> undefined 1`] = ` ], \\"Markdown\\": Array [ \\"markdown\\", -@@ -135,10 +138,11 @@ +@@ -138,10 +141,11 @@ \\"mdx\\", \\"vue\\", \\"yaml\\", @@ -623,7 +626,7 @@ exports[`API getSupportInfo() with version 1.16.0 -> undefined 1`] = ` \\"type\\": \\"choice\\", }, \\"pluginSearchDirs\\": Object { -@@ -165,10 +169,19 @@ +@@ -168,10 +172,19 @@ \\"preserve\\", ], \\"default\\": \\"preserve\\", @@ -679,7 +682,16 @@ exports[`CLI --support-info (stdout) 1`] = ` \\".xsjslib\\" ], \\"filenames\\": [\\"Jakefile\\"], - \\"interpreters\\": [\\"node\\", \\"nodejs\\"], + \\"interpreters\\": [ + \\"chakra\\", + \\"d8\\", + \\"js\\", + \\"node\\", + \\"rhino\\", + \\"v8\\", + \\"v8-shell\\", + \\"nodejs\\" + ], \\"linguistLanguageId\\": 183, \\"name\\": \\"JavaScript\\", \\"parsers\\": [\\"babel\\", \\"flow\\"], @@ -696,7 +708,7 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"color\\": \\"#f1e05a\\", \\"extensions\\": [\\".js.flow\\"], \\"filenames\\": [], - \\"interpreters\\": [\\"node\\"], + \\"interpreters\\": [\\"chakra\\", \\"d8\\", \\"js\\", \\"node\\", \\"rhino\\", \\"v8\\", \\"v8-shell\\"], \\"linguistLanguageId\\": 183, \\"name\\": \\"Flow\\", \\"parsers\\": [\\"babel\\", \\"flow\\"], @@ -725,14 +737,29 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"codemirrorMimeType\\": \\"application/typescript\\", \\"codemirrorMode\\": \\"javascript\\", \\"color\\": \\"#2b7489\\", - \\"extensions\\": [\\".ts\\", \\".tsx\\"], + \\"extensions\\": [\\".ts\\"], + \\"interpreters\\": [\\"deno\\", \\"ts-node\\"], \\"linguistLanguageId\\": 378, \\"name\\": \\"TypeScript\\", \\"parsers\\": [\\"typescript\\"], \\"since\\": \\"1.4.0\\", \\"tmScope\\": \\"source.ts\\", \\"type\\": \\"programming\\", - \\"vscodeLanguageIds\\": [\\"typescript\\", \\"typescriptreact\\"] + \\"vscodeLanguageIds\\": [\\"typescript\\"] + }, + { + \\"aceMode\\": \\"javascript\\", + \\"codemirrorMimeType\\": \\"text/jsx\\", + \\"codemirrorMode\\": \\"jsx\\", + \\"extensions\\": [\\".tsx\\"], + \\"group\\": \\"TypeScript\\", + \\"linguistLanguageId\\": 94901924, + \\"name\\": \\"TSX\\", + \\"parsers\\": [\\"typescript\\"], + \\"since\\": \\"1.4.0\\", + \\"tmScope\\": \\"source.tsx\\", + \\"type\\": \\"programming\\", + \\"vscodeLanguageIds\\": [\\"typescriptreact\\"] }, { \\"aceMode\\": \\"json\\", @@ -740,7 +767,6 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"codemirrorMode\\": \\"javascript\\", \\"extensions\\": [], \\"filenames\\": [\\"package.json\\", \\"package-lock.json\\", \\"composer.json\\"], - \\"group\\": \\"JavaScript\\", \\"linguistLanguageId\\": 174, \\"name\\": \\"JSON.stringify\\", \\"parsers\\": [\\"json-stringify\\"], @@ -759,24 +785,29 @@ exports[`CLI --support-info (stdout) 1`] = ` \\".avsc\\", \\".geojson\\", \\".gltf\\", + \\".har\\", + \\".ice\\", \\".JSON-tmLanguage\\", \\".jsonl\\", + \\".mcmeta\\", \\".tfstate\\", \\".tfstate.backup\\", \\".topojson\\", \\".webapp\\", - \\".webmanifest\\" + \\".webmanifest\\", + \\".yy\\", + \\".yyp\\" ], \\"filenames\\": [ \\".arcconfig\\", \\".htmlhintrc\\", \\".tern-config\\", \\".tern-project\\", + \\".watchmanconfig\\", \\"composer.lock\\", \\"mcmod.info\\", \\".prettierrc\\" ], - \\"group\\": \\"JavaScript\\", \\"linguistLanguageId\\": 174, \\"name\\": \\"JSON\\", \\"parsers\\": [\\"json\\"], @@ -812,6 +843,8 @@ exports[`CLI --support-info (stdout) 1`] = ` \\".jscsrc\\", \\".jshintrc\\", \\".jslintrc\\", + \\"jsconfig.json\\", + \\"language-configuration.json\\", \\"tsconfig.json\\", \\".eslintrc\\" ], @@ -887,13 +920,13 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"name\\": \\"SCSS\\", \\"parsers\\": [\\"scss\\"], \\"since\\": \\"1.4.0\\", - \\"tmScope\\": \\"source.scss\\", + \\"tmScope\\": \\"source.css.scss\\", \\"type\\": \\"markup\\", \\"vscodeLanguageIds\\": [\\"scss\\"] }, { \\"aceMode\\": \\"text\\", - \\"extensions\\": [\\".graphql\\", \\".gql\\"], + \\"extensions\\": [\\".graphql\\", \\".gql\\", \\".graphqls\\"], \\"linguistLanguageId\\": 139, \\"name\\": \\"GraphQL\\", \\"parsers\\": [\\"graphql\\"], @@ -918,7 +951,7 @@ exports[`CLI --support-info (stdout) 1`] = ` \\".ronn\\", \\".workbook\\" ], - \\"filenames\\": [\\"README\\"], + \\"filenames\\": [\\"contents.lr\\", \\"README\\"], \\"linguistLanguageId\\": 222, \\"name\\": \\"Markdown\\", \\"parsers\\": [\\"markdown\\"], @@ -929,11 +962,20 @@ exports[`CLI --support-info (stdout) 1`] = ` \\"wrap\\": true }, { + \\"aceMode\\": \\"markdown\\", + \\"aliases\\": [\\"pandoc\\"], + \\"codemirrorMimeType\\": \\"text/x-gfm\\", + \\"codemirrorMode\\": \\"gfm\\", \\"extensions\\": [\\".mdx\\"], + \\"filenames\\": [], + \\"linguistLanguageId\\": 222, \\"name\\": \\"MDX\\", \\"parsers\\": [\\"mdx\\"], \\"since\\": \\"1.15.0\\", - \\"vscodeLanguageIds\\": [\\"mdx\\"] + \\"tmScope\\": \\"source.gfm\\", + \\"type\\": \\"prose\\", + \\"vscodeLanguageIds\\": [\\"mdx\\"], + \\"wrap\\": true }, { \\"aceMode\\": \\"html\\", diff --git a/tests_integration/__tests__/file-info.js b/tests_integration/__tests__/file-info.js index ac7c32ca9d08..9150d48a3854 100644 --- a/tests_integration/__tests__/file-info.js +++ b/tests_integration/__tests__/file-info.js @@ -106,16 +106,15 @@ describe("extracts file-info with inferredParser=foo when a plugin is hand-picke }); test("API getFileInfo with no args", () => { - // TODO: change this to `rejects.toThrow()` when we upgrade to Jest >= 22 - // https://github.com/facebook/jest/issues/3601 - expect.assertions(1); - return prettier.getFileInfo().catch(err => { - expect(err).toBeDefined(); - }); + return expect(prettier.getFileInfo()).rejects.toThrow( + new TypeError("expect `filePath` to be a string, got `undefined`") + ); }); test("API getFileInfo.sync with no args", () => { - expect(() => prettier.getFileInfo.sync()).toThrow(); + expect(() => prettier.getFileInfo.sync()).toThrow( + new TypeError("expect `filePath` to be a string, got `undefined`") + ); }); test("API getFileInfo with filepath only", () => { @@ -132,6 +131,142 @@ test("API getFileInfo.sync with filepath only", () => { }); }); +test("API getFileInfo with resolveConfig", () => { + const file1 = path.resolve( + path.join(__dirname, "../cli/with-resolve-config/file.foo") + ); + const file2 = path.resolve( + path.join(__dirname, "../cli/with-resolve-config/file.bar") + ); + + expect(prettier.getFileInfo(file1)).resolves.toMatchObject({ + ignored: false, + inferredParser: null + }); + expect(prettier.getFileInfo(file2)).resolves.toMatchObject({ + ignored: false, + inferredParser: null + }); + expect( + prettier.getFileInfo(file1, { + resolveConfig: true + }) + ).resolves.toMatchObject({ + ignored: false, + inferredParser: "json" + }); + expect( + prettier.getFileInfo(file2, { + resolveConfig: true + }) + ).resolves.toMatchObject({ + ignored: false, + inferredParser: "babel" + }); +}); + +test("API getFileInfo with resolveConfig when no config is present", () => { + const file1 = path.resolve( + path.join(__dirname, "../cli/with-resolve-config-no-config/file.foo") + ); + const file2 = path.resolve( + path.join(__dirname, "../cli/with-resolve-config-no-config/file.bar") + ); + + expect(prettier.getFileInfo(file1)).resolves.toMatchObject({ + ignored: false, + inferredParser: null + }); + expect(prettier.getFileInfo(file2)).resolves.toMatchObject({ + ignored: false, + inferredParser: null + }); + expect( + prettier.getFileInfo(file1, { + resolveConfig: true + }) + ).resolves.toMatchObject({ + ignored: false, + inferredParser: null + }); + expect( + prettier.getFileInfo(file2, { + resolveConfig: true + }) + ).resolves.toMatchObject({ + ignored: false, + inferredParser: null + }); +}); + +test("API getFileInfo.sync with resolveConfig", () => { + const file1 = path.resolve( + path.join(__dirname, "../cli/with-resolve-config/file.foo") + ); + const file2 = path.resolve( + path.join(__dirname, "../cli/with-resolve-config/file.bar") + ); + + expect(prettier.getFileInfo.sync(file1)).toMatchObject({ + ignored: false, + inferredParser: null + }); + expect(prettier.getFileInfo.sync(file2)).toMatchObject({ + ignored: false, + inferredParser: null + }); + expect( + prettier.getFileInfo.sync(file1, { + resolveConfig: true + }) + ).toMatchObject({ + ignored: false, + inferredParser: "json" + }); + expect( + prettier.getFileInfo.sync(file2, { + resolveConfig: true + }) + ).toMatchObject({ + ignored: false, + inferredParser: "babel" + }); +}); + +test("API getFileInfo.sync with resolveConfig when no config is present", () => { + const file1 = path.resolve( + path.join(__dirname, "../cli/with-resolve-config-no-config/file.foo") + ); + const file2 = path.resolve( + path.join(__dirname, "../cli/with-resolve-config-no-config/file.bar") + ); + + expect(prettier.getFileInfo.sync(file1)).toMatchObject({ + ignored: false, + inferredParser: null + }); + expect(prettier.getFileInfo.sync(file2)).toMatchObject({ + ignored: false, + inferredParser: null + }); + expect( + prettier.getFileInfo.sync(file1, { + resolveConfig: true + }) + ).toMatchObject({ + ignored: false, + inferredParser: null + }); + expect( + prettier.getFileInfo.sync(file2, { + resolveConfig: true + }) + ).toMatchObject({ + ignored: false, + inferredParser: null + }); +}); + test("API getFileInfo with ignorePath", () => { const file = path.resolve( path.join(__dirname, "../cli/ignore-path/regular-module.js") diff --git a/tests_integration/__tests__/format.js b/tests_integration/__tests__/format.js index e7067593e275..d81c5a822eed 100644 --- a/tests_integration/__tests__/format.js +++ b/tests_integration/__tests__/format.js @@ -49,5 +49,7 @@ test("should work with foo plugin instance", () => { JSON.stringify( prettier.format(input, { parser: "foo-parser", plugins: [fooPlugin] }) ) - ).toMatchInlineSnapshot(`"\\"tabWidth:8\\""`); + ).toMatchInlineSnapshot( + `"\\"{\\\\\\"tabWidth\\\\\\":8,\\\\\\"bracketSpacing\\\\\\":false}\\""` + ); }); diff --git a/tests_integration/__tests__/plugin-default-options.js b/tests_integration/__tests__/plugin-default-options.js index 2a9bad9b8555..08bce75ae378 100644 --- a/tests_integration/__tests__/plugin-default-options.js +++ b/tests_integration/__tests__/plugin-default-options.js @@ -8,7 +8,10 @@ describe("plugin default options should work", () => { ["--stdin-filepath", "example.foo", "--plugin=./plugin"], { input: "hello-world" } ).test({ - stdout: "tabWidth:8", + stdout: JSON.stringify({ + tabWidth: 8, + bracketSpacing: false + }), stderr: "", status: 0, write: [] @@ -21,7 +24,10 @@ describe("overriding plugin default options should work", () => { ["--stdin-filepath", "example.foo", "--plugin=./plugin", "--tab-width=4"], { input: "hello-world" } ).test({ - stdout: "tabWidth:4", + stdout: JSON.stringify({ + tabWidth: 4, + bracketSpacing: false + }), stderr: "", status: 0, write: [] diff --git a/tests_integration/cli/with-resolve-config-no-config/file.bar b/tests_integration/cli/with-resolve-config-no-config/file.bar new file mode 100644 index 000000000000..4f4b4c84302c --- /dev/null +++ b/tests_integration/cli/with-resolve-config-no-config/file.bar @@ -0,0 +1 @@ +const foo = "bar"; diff --git a/tests_integration/cli/with-resolve-config-no-config/file.foo b/tests_integration/cli/with-resolve-config-no-config/file.foo new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/tests_integration/cli/with-resolve-config-no-config/file.foo @@ -0,0 +1 @@ +{} diff --git a/tests_integration/cli/with-resolve-config/.prettierrc b/tests_integration/cli/with-resolve-config/.prettierrc new file mode 100644 index 000000000000..a7d13fff139a --- /dev/null +++ b/tests_integration/cli/with-resolve-config/.prettierrc @@ -0,0 +1,12 @@ +{ + "overrides": [ + { + "files": "*.foo", + "options": { "parser": "json" } + }, + { + "files": "*.bar", + "options": { "parser": "babel" } + } + ] +} diff --git a/tests_integration/cli/with-resolve-config/file.bar b/tests_integration/cli/with-resolve-config/file.bar new file mode 100644 index 000000000000..4f4b4c84302c --- /dev/null +++ b/tests_integration/cli/with-resolve-config/file.bar @@ -0,0 +1 @@ +const foo = "bar"; diff --git a/tests_integration/cli/with-resolve-config/file.foo b/tests_integration/cli/with-resolve-config/file.foo new file mode 100644 index 000000000000..0967ef424bce --- /dev/null +++ b/tests_integration/cli/with-resolve-config/file.foo @@ -0,0 +1 @@ +{} diff --git a/tests_integration/plugins/defaultOptions/.config.json.swp b/tests_integration/plugins/defaultOptions/.config.json.swp deleted file mode 100644 index 5a1ea1a99fce..000000000000 Binary files a/tests_integration/plugins/defaultOptions/.config.json.swp and /dev/null differ diff --git a/tests_integration/plugins/defaultOptions/plugin.js b/tests_integration/plugins/defaultOptions/plugin.js index ba094ac7a404..1c72441cc245 100644 --- a/tests_integration/plugins/defaultOptions/plugin.js +++ b/tests_integration/plugins/defaultOptions/plugin.js @@ -9,7 +9,8 @@ module.exports = { } ], defaultOptions: { - tabWidth: 8 + tabWidth: 8, + bracketSpacing: false }, parsers: { "foo-parser": { @@ -20,7 +21,10 @@ module.exports = { printers: { "foo-ast": { print: (path, options) => - options.tabWidth ? `tabWidth:${options.tabWidth}` : path.getValue().text + JSON.stringify({ + tabWidth: options.tabWidth, + bracketSpacing: options.bracketSpacing + }) } } }; diff --git a/website/blog/2017-04-13-1.0.0.md b/website/blog/2017-04-13-1.0.0.md index a1644e7f3f1a..e5579fb3c4c8 100644 --- a/website/blog/2017-04-13-1.0.0.md +++ b/website/blog/2017-04-13-1.0.0.md @@ -950,13 +950,13 @@ let { ```js // Before a = Math.random() * (yRange * (1 - minVerticalFraction)) + - minVerticalFraction * yRange// Commment + minVerticalFraction * yRange// Comment - offset; // After a = - // Commment + // Comment Math.random() * (yRange * (1 - minVerticalFraction)) + minVerticalFraction * yRange - offset; diff --git a/website/blog/2017-06-28-1.5.0.md b/website/blog/2017-06-28-1.5.0.md index ec247f099561..f17500699d58 100644 --- a/website/blog/2017-06-28-1.5.0.md +++ b/website/blog/2017-06-28-1.5.0.md @@ -24,7 +24,7 @@ Prettier is not only a useful tool but it's also a really cool piece of technolo Thanks to [@stubailo](https://github.com/stubailo), [@jnwng](https://github.com/jnwng), [@tgriesser](https://github.com/tgriesser) and [@azz](https://github.com/azz), prettier now supports printing GraphQL queries! -It works for `.graphql` files and within JavaScipt templates that start with `graphql`, `graphql.experimental` and `gql` in order to work with [Relay](https://facebook.github.io/relay/) and [Apollo](https://www.apollodata.com/). +It works for `.graphql` files and within JavaScript templates that start with `graphql`, `graphql.experimental` and `gql` in order to work with [Relay](https://facebook.github.io/relay/) and [Apollo](https://www.apollodata.com/). ```jsx diff --git a/website/blog/2018-11-07-1.15.0.md b/website/blog/2018-11-07-1.15.0.md index 288a06bd06c4..26ed13a7310f 100644 --- a/website/blog/2018-11-07-1.15.0.md +++ b/website/blog/2018-11-07-1.15.0.md @@ -37,7 +37,7 @@ As you may notice during daily HTML works, the following two cases won't produce | with spaces | `1 2 3` | 1 2 3 | | without spaces | `123` | 123 | -This is because whitespaces are sensitive in inline elements. +This happens because whitespace is significant in inline elements. For this reason, we cannot safely format @@ -59,8 +59,8 @@ since it may modify the displayed output in the browser. Instead of breaking your code or just doing nothing, we introduce _whitespace-sensitive formatting_, which: -- follows the default CSS `display` value for every element to identify if the whitespace is sensitive, -- and borrows the opening or closing tags (if necessary) to avoid adding or removing sensitive whitespaces. +- follows the default CSS `display` value for every element to identify if the whitespace inside it is significant, +- and wraps the tags in such a way as to avoid adding or removing significant whitespace. For example: @@ -81,7 +81,7 @@ For example:
``` -We also allow magic comments (e.g., ``) to tell Prettier how to format this element +We also allow magic comments (e.g., ``) to tell Prettier how to format elements due to the fact that CSS display can be changed: @@ -98,13 +98,13 @@ due to the fact that CSS display can be changed: ``` There's also an option for the global whitespace sensitivity -in case you may want maximum safety or you just don't care about those whitespaces: +in case you may want maximum safety or you just don't care about that whitespace: `--html-whitespace-sensitivity` (defaults to `css`) - `css` - Respect the default value of CSS `display` property. -- `strict` - Whitespaces are considered sensitive. -- `ignore` - Whitespaces are considered insensitive. +- `strict` - All whitespace is considered significant. +- `ignore` - All whitespace is considered insignificant. ##### Automatic parser inference diff --git a/website/blog/assets/github-diff-ternary-in-jsx.png b/website/blog/assets/github-diff-ternary-in-jsx.png index eb25e659add7..d96837f9ba8b 100644 Binary files a/website/blog/assets/github-diff-ternary-in-jsx.png and b/website/blog/assets/github-diff-ternary-in-jsx.png differ diff --git a/website/blog/assets/markdown-list-indent.gif b/website/blog/assets/markdown-list-indent.gif index 2bd06bc30ceb..b995fc55f2a2 100644 Binary files a/website/blog/assets/markdown-list-indent.gif and b/website/blog/assets/markdown-list-indent.gif differ diff --git a/website/blog/assets/markdown-lists.gif b/website/blog/assets/markdown-lists.gif index d9b78e58dbd0..213613703429 100644 Binary files a/website/blog/assets/markdown-lists.gif and b/website/blog/assets/markdown-lists.gif differ diff --git a/website/blog/assets/prettier-revolution-conf.png b/website/blog/assets/prettier-revolution-conf.png index c626b6b22ba7..3ed6cc3d3853 100644 Binary files a/website/blog/assets/prettier-revolution-conf.png and b/website/blog/assets/prettier-revolution-conf.png differ diff --git a/website/data/users.yml b/website/data/users.yml index 87865b17b351..f564f9447faa 100644 --- a/website/data/users.yml +++ b/website/data/users.yml @@ -224,3 +224,15 @@ - caption: Openbravo image: /images/users/openbravo-200x100.png infoLink: https://openbravo.com +- caption: Campusjäger + image: /images/users/campusjaeger.svg + infoLink: https://campusjaeger.de +- caption: Research & Design + image: /images/users/researchanddesign.svg + infoLink: https://rd.digital +- caption: Build + image: /images/users/buildcom.svg + infoLink: https://www.build.com +- caption: Estalee + image: /images/users/estalee.svg + infoLink: https://estalee.com/ diff --git a/website/package.json b/website/package.json index 80929781231f..0625ff0c9041 100644 --- a/website/package.json +++ b/website/package.json @@ -9,25 +9,25 @@ "update-stable-docs": "rm -rf ./versioned_docs ./versions.json && docusaurus-version stable" }, "dependencies": { - "clipboard": "2.0.0", - "codemirror": "5.36.0", - "codemirror-graphql": "0.6.12", + "clipboard": "2.0.4", + "codemirror": "5.49.2", + "codemirror-graphql": "0.11.2", "lodash.groupby": "4.6.0", "lz-string": "1.4.4", - "prop-types": "15.6.1", - "react": "16.3.1", - "react-dom": "16.3.3" + "prop-types": "15.7.2", + "react": "16.10.2", + "react-dom": "16.10.2" }, "devDependencies": { + "@babel/preset-env": "7.6.3", + "@babel/preset-react": "7.6.3", "@sandhose/prettier-animated-logo": "1.0.3", - "babel-loader": "7.1.4", - "babel-preset-env": "1.6.1", - "babel-preset-react": "6.24.1", - "concurrently": "3.5.1", - "docusaurus": "1.6.2", + "babel-loader": "8.0.6", + "concurrently": "5.0.0", + "docusaurus": "1.14.0", "js-yaml": "3.13.1", - "svgo": "1.0.4", - "webpack": "4.29.6", - "webpack-cli": "2.0.14" + "svgo": "1.3.0", + "webpack": "4.41.2", + "webpack-cli": "3.3.9" } } diff --git a/website/pages/en/index.js b/website/pages/en/index.js index 53c36a646fb0..14c490f9109d 100755 --- a/website/pages/en/index.js +++ b/website/pages/en/index.js @@ -417,7 +417,9 @@ const UsersSection = ({ language }) => {
-

More than 2000 tools and integrations on npm

+

+ More than 3000 tools and integrations on npm +

@@ -432,7 +434,9 @@ const UsersSection = ({ language }) => {
-

More than 400,000 dependent repositories on GitHub

+

+ More than 1M dependent repositories on GitHub +

diff --git a/website/playground/Playground.js b/website/playground/Playground.js index 1a79bcf06ab5..265ff6677aac 100644 --- a/website/playground/Playground.js +++ b/website/playground/Playground.js @@ -1,6 +1,6 @@ import React from "react"; -import { Button, ClipboardButton, LinkButton } from "./buttons"; +import { Button, ClipboardButton } from "./buttons"; import EditorState from "./EditorState"; import { DebugPanel, InputPanel, OutputPanel } from "./panels"; import PrettierFormat from "./PrettierFormat"; @@ -39,8 +39,13 @@ const ENABLED_OPTIONS = [ "proseWrap", "htmlWhitespaceSensitivity", "insertPragma", - "requirePragma" + "requirePragma", + "vueIndentScriptAndStyle" ]; +const ISSUES_URL = "https://github.com/prettier/prettier/issues/new?body="; +const MAX_LENGTH = 8000 - ISSUES_URL.length; // it seems that GitHub limit is 8195 +const COPY_MESSAGE = + "\n"; class Playground extends React.Component { constructor(props) { @@ -134,131 +139,144 @@ class Playground extends React.Component { debugDoc={editorState.showDoc} reformat={editorState.showSecondFormat} > - {({ formatted, debug }) => ( - -
- - - - -