Test: visualize the range (#8420)

This commit is contained in:
fisker Cheung authored and GitHub committed 2020-05-28 01:16:52 +08:00
1 parent cf5d899d44
commit 12d379d29d
10 files changed
+498 -344

No files matched your search

@@ -4,10 +4,11 @@ exports[`issue2267.css format 1`] = `
====================================options=====================================
parsers: ["css"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
.x{}
> 1 | .x{}
| ^^^^
2 |
=====================================output=====================================
.x{}
@@ -4,10 +4,11 @@ exports[`issue2296.graphql format 1`] = `
====================================options=====================================
parsers: ["graphql"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
{NPC{life}}
> 1 | {NPC{life}}
| ^^^
2 |
=====================================output=====================================
{
NPC {
@@ -292,14 +292,17 @@ exports[`range-0.js format 1`] = `
====================================options=====================================
parsers: ["babel", "typescript", "flow"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
thisWontBeFormatted ( 1 ,3)
thisWillBeFormatted <|> (2 ,3, )
thisWontBeFormatted (2, 90 ,)
1 | thisWontBeFormatted ( 1 ,3)
2 |
> 3 | thisWillBeFormatted <|> (2 ,3, )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 |
| ^
> 5 | thisWontBeFormatted (2, 90 ,)
| ^
6 |
=====================================output=====================================
thisWontBeFormatted ( 1 ,3)
@@ -314,14 +317,17 @@ exports[`range-1.js format 1`] = `
====================================options=====================================
parsers: ["babel", "typescript", "flow"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
thisWontBeFormatted ( 1 ,3)
thisWillBeFormatted (2 ,3<|>, )
thisWontBeFormatted (2, 90 ,)
1 | thisWontBeFormatted ( 1 ,3)
2 |
> 3 | thisWillBeFormatted (2 ,3<|>, )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 |
| ^
> 5 | thisWontBeFormatted (2, 90 ,)
| ^
6 |
=====================================output=====================================
thisWontBeFormatted ( 1 ,3)
@@ -336,14 +342,17 @@ exports[`range-2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "typescript", "flow"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
thisWontBeFormatted ( 1 ,3)
thisWillBeFormatted (2 ,3, <|> )
thisWontBeFormatted (2, 90 ,)
1 | thisWontBeFormatted ( 1 ,3)
2 |
> 3 | thisWillBeFormatted (2 ,3, <|> )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 |
| ^
> 5 | thisWontBeFormatted (2, 90 ,)
| ^
6 |
=====================================output=====================================
thisWontBeFormatted ( 1 ,3)
@@ -358,14 +367,19 @@ exports[`range-3.js format 1`] = `
====================================options=====================================
parsers: ["babel", "typescript", "flow"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
thisWontBeFormatted <|> ( 1 ,3)
thisWillBeFormatted (2 ,3, )
thisWontBeFormatted (2, 90 ,)
> 1 | thisWontBeFormatted <|> ( 1 ,3)
| ^
> 2 |
| ^
> 3 | thisWillBeFormatted (2 ,3, )
| ^
> 4 |
| ^
> 5 | thisWontBeFormatted (2, 90 ,)
| ^
6 |
=====================================output=====================================
thisWontBeFormatted <|> ( 1 ,3)
@@ -380,14 +394,17 @@ exports[`range-4.js format 1`] = `
====================================options=====================================
parsers: ["babel", "typescript", "flow"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
thisWontBeFormatted ( 1 ,3)
thisWillBeFormatted (2 ,3, )
thisWontBeFormatted (2, 9<|>0 ,)
1 | thisWontBeFormatted ( 1 ,3)
2 |
> 3 | thisWillBeFormatted (2 ,3, )
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 |
| ^
> 5 | thisWontBeFormatted (2, 9<|>0 ,)
| ^^^^
6 |
=====================================output=====================================
thisWontBeFormatted ( 1 ,3)
+319 -247
View File
@@ -4,15 +4,17 @@ exports[`class-declaration.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
class a {
b( ) {}
}
let x
1 |
2 |
> 3 | class a {
| ^^^^
> 4 | b( ) {}
| ^^^^^^^^^^^
5 | }
6 |
7 | let x
=====================================output=====================================
@@ -28,14 +30,17 @@ exports[`different-levels.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
call(1,2,3)
call(1,2,3)
function f() {
call(1,2,3)
}
1 | call(1,2,3)
> 2 | call(1,2,3)
| ^^^^
> 3 | function f() {
| ^^^^^^^^^^^^^^
> 4 | call(1,2,3)
| ^^^^^^^^^
5 | }
6 |
=====================================output=====================================
call(1,2,3)
call(1, 2, 3);
@@ -50,10 +55,11 @@ exports[`function-declaration.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
function ugly ( {a=1, b = 2 } ) {}
> 1 | function ugly ( {a=1, b = 2 } ) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 |
=====================================output=====================================
function ugly({ a = 1, b = 2 }) {}
@@ -64,17 +70,18 @@ exports[`ignore-indentation.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
function ugly ( {a=1, b = 2 } ) {
function ugly ( {a=1, b = 2 } ) {
function ugly ( {a=1, b = 2 } ) {
\`multiline template string
with too much indentation\`
}
}
}
1 | function ugly ( {a=1, b = 2 } ) {
2 | function ugly ( {a=1, b = 2 } ) {
3 | function ugly ( {a=1, b = 2 } ) {
4 | \`multiline template string
> 5 | with too much indentation\`
| ^^^
6 | }
7 | }
8 | }
9 |
=====================================output=====================================
function ugly ( {a=1, b = 2 } ) {
function ugly ( {a=1, b = 2 } ) {
@@ -92,18 +99,19 @@ exports[`issue-3789-1.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
export class F {
reformatThis() {
return 1;
}
dontTouchThis(){
return 2 ;
}
}
1 | export class F {
> 2 | reformatThis() {
| ^^^^^^^^^^^^^^
3 | return 1;
4 | }
5 |
6 | dontTouchThis(){
7 | return 2 ;
8 | }
9 | }
10 |
=====================================output=====================================
export class F {
reformatThis() {
@@ -122,18 +130,19 @@ exports[`issue-3789-2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
export class F {
reformatThis() {
return 1;
}
dontTouchThis(){
return 2 ;
}
}
1 | export class F {
> 2 | reformatThis() {
| ^
3 | return 1;
4 | }
5 |
6 | dontTouchThis(){
7 | return 2 ;
8 | }
9 | }
10 |
=====================================output=====================================
export class F {
reformatThis() {
@@ -152,12 +161,14 @@ exports[`issue-4206-1.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
export default class Foo{
/**/
}
> 1 | export default class Foo{
| ^^^^^^^^^
> 2 | /**/
| ^^^^
3 | }
4 |
=====================================output=====================================
export default class Foo {
/**/
@@ -170,12 +181,13 @@ exports[`issue-4206-2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
export default function Foo(){
/**/
}
> 1 | export default function Foo(){
| ^^^^^^^^^^^^^^
2 | /**/
3 | }
4 |
=====================================output=====================================
export default function Foo() {
/**/
@@ -188,12 +200,15 @@ exports[`issue-4206-3.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
/* */ function Foo(){
/**/
}
> 1 | /* */ function Foo(){
| ^^^^^
> 2 | /**/
| ^^^^
> 3 | }
| ^
4 |
=====================================output=====================================
/* */ function Foo() {
/**/
@@ -206,12 +221,14 @@ exports[`issue-4206-4.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
/* */ class Foo{
/**/
}
1 | /* */ class Foo{
> 2 | /**/
| ^^^^
> 3 | }
| ^
4 |
=====================================output=====================================
/* */ class Foo {
/**/
@@ -224,12 +241,14 @@ exports[`issue-7082.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
export const Button = styled.button\`
color: blue;
\`;
> 1 | export const Button = styled.button\`
| ^^^^^^^
> 2 | color: blue;
| ^^^^^
3 | \`;
4 |
=====================================output=====================================
export const Button = styled.button\`
color: blue;
@@ -242,17 +261,20 @@ exports[`large-dict.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
function ugly() {
const dictWithSeveralEntries = {
key: "value",
anotherKey: "another value",
firstNumber: 1,
secondNumber: 2
};
}
1 | function ugly() {
2 | const dictWithSeveralEntries = {
3 | key: "value",
> 4 | anotherKey: "another value",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 5 | firstNumber: 1,
| ^^^^^^^^^^^^^^^^^^^^
> 6 | secondNumber: 2
| ^^^^^^^^^^^^^^^^^^^
7 | };
8 | }
9 |
=====================================output=====================================
function ugly() {
const dictWithSeveralEntries = {
@@ -270,18 +292,19 @@ exports[`module-export1.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
import def , {named} from 'x'
export * from 'd'
export const x
= 42
export default 42
1 | import def , {named} from 'x'
2 |
> 3 | export * from 'd'
| ^^^^^^^^^^^
4 |
5 | export const x
6 | = 42
7 |
8 | export default 42
9 |
10 |
=====================================output=====================================
import def , {named} from 'x'
@@ -300,18 +323,21 @@ exports[`module-export2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
import def , {named} from 'x'
export * from 'd'
export const x
= 42
export default 42
1 | import def , {named} from 'x'
2 |
3 | export * from 'd'
> 4 |
| ^
> 5 | export const x
| ^^^^^^^^^^^^^^^^^^
> 6 | = 42
| ^^
7 |
8 | export default 42
9 |
10 |
=====================================output=====================================
import def , {named} from 'x'
@@ -329,18 +355,19 @@ exports[`module-export3.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
import def , {named} from 'x'
export * from 'd'
export const x
= 42
export default 42
1 | import def , {named} from 'x'
2 |
3 | export * from 'd'
4 |
5 | export const x
6 | = 42
7 |
> 8 | export default 42
| ^^^^
9 |
10 |
=====================================output=====================================
import def , {named} from 'x'
@@ -359,18 +386,19 @@ exports[`module-import.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
import def , {named} from 'x'
export * from 'd'
export const x
= 42
export default 42
> 1 | import def , {named} from 'x'
| ^^^^^^^^^^^^^^^
2 |
3 | export * from 'd'
4 |
5 | export const x
6 | = 42
7 |
8 | export default 42
9 |
10 |
=====================================output=====================================
import def, { named } from "x";
@@ -389,24 +417,29 @@ exports[`multiple-statements.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
call(
1, 2,3
);
call(
1, 2,3
);
call(
1, 2,3
);
call(
1, 2,3
);
1 | call(
2 | 1, 2,3
3 | );
4 |
5 | call(
> 6 | 1, 2,3
| ^^^
> 7 | );
| ^^
> 8 |
| ^^
> 9 | call(
| ^^
> 10 | 1, 2,3
| ^^^^^
11 | );
12 |
13 | call(
14 | 1, 2,3
15 | );
16 |
=====================================output=====================================
call(
1, 2,3
@@ -427,24 +460,33 @@ exports[`multiple-statements2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
call(
1, 2,3
);
call(
1, 2,3
);
call(
1, 2,3
);
call(
1, 2,3
);
1 | call(
2 | 1, 2,3
3 | );
> 4 |
| ^
> 5 | call(
| ^^^^^
> 6 | 1, 2,3
| ^^^^^
> 7 | );
| ^^^^^
> 8 |
| ^^^^^
> 9 | call(
| ^^^^^
> 10 | 1, 2,3
| ^^^^^
> 11 | );
| ^^^^^
> 12 |
| ^
13 | call(
14 | 1, 2,3
15 | );
16 |
=====================================output=====================================
call(
1, 2,3
@@ -465,15 +507,19 @@ exports[`nested.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
try {
if (condition) {
body
}
}
catch (err) {}
> 1 | try {
| ^^^^^
> 2 | if (condition) {
| ^^^^^^^^^^^^^^^^^^
> 3 | body
| ^^^^^^^^^^^^^^^^^^
> 4 | }
| ^^^
5 | }
6 | catch (err) {}
7 |
=====================================output=====================================
try {
if (condition) {
@@ -488,14 +534,17 @@ exports[`nested-print-width.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
function f() {
if (true) {
call("this line is 79 chars", "long", "it should", "stay as single line");
}
}
1 | function f() {
> 2 | if (true) {
| ^
> 3 | call("this line is 79 chars", "long", "it should", "stay as single line");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 | }
| ^^
5 | }
6 |
=====================================output=====================================
function f() {
if (true) {
@@ -510,15 +559,18 @@ exports[`nested2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
try {
if (condition) {
body
}
}
catch (err) {}
1 | try {
> 2 | if (condition) {
| ^^^^^^^^^^^^^^^
> 3 | body
| ^^^^^^^^
> 4 | }
| ^^^
5 | }
6 | catch (err) {}
7 |
=====================================output=====================================
try {
if (condition) {
@@ -534,15 +586,18 @@ exports[`nested3.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
try {
1;if (condition) {
body
}
}
catch (err) {}
1 | try {
> 2 | 1;if (condition) {
| ^^^^^^^^^^^^^^^
> 3 | body
| ^^^^^^^^
> 4 | }
| ^^^
5 | }
6 | catch (err) {}
7 |
=====================================output=====================================
try {
1;if (condition) {
@@ -558,10 +613,11 @@ exports[`object-expression.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
const y = {a:1, b:2}
> 1 | const y = {a:1, b:2}
| ^^^
2 |
=====================================output=====================================
const y = { a: 1, b: 2 };
@@ -572,19 +628,24 @@ exports[`object-expression2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
const y = [
{
a: 1,
},
{
a: 1,
b:2
},
]
1 |
2 | const y = [
3 | {
4 | a: 1,
> 5 | },
| ^
> 6 | {
| ^^^^^
> 7 | a: 1,
| ^^^^^
> 8 | b:2
| ^^^^^
> 9 | },
| ^^^^^^
10 | ]
11 |
=====================================output=====================================
const y = [
@@ -604,17 +665,18 @@ exports[`range.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
function ugly ( {a=1, b = 2 } ) {
function ugly ( {a=1, b = 2 } ) {
function ugly ( {a=1, b = 2 } ) {
\`multiline template string
with too much indentation\`
}
}
}
1 | function ugly ( {a=1, b = 2 } ) {
2 | function ugly ( {a=1, b = 2 } ) {
3 | function ugly ( {a=1, b = 2 } ) {
4 | \`multiline template string
> 5 | with too much indentation\`
| ^^^
6 | }
7 | }
8 | }
9 |
=====================================output=====================================
function ugly ( {a=1, b = 2 } ) {
function ugly ( {a=1, b = 2 } ) {
@@ -632,17 +694,21 @@ exports[`range-end.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
// Unchanged
call(
1, 2,3
);
call(
1, 2,3
);
1 | // Unchanged
2 | call(
3 | 1, 2,3
4 | );
5 |
> 6 |
| ^
> 7 | call(
| ^^^^^
> 8 | 1, 2,3
| ^^^^^
> 9 | );
| ^^
=====================================output=====================================
// Unchanged
call(
@@ -658,18 +724,22 @@ exports[`range-start.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
call(
1, 2,3
);
// Unchanged
call(
1, 2,3
);
> 1 | call(
| ^^^^^
> 2 | 1, 2,3
| ^^^^^^^^
> 3 | );
| ^^^^^^^^
> 4 |
| ^
5 |
6 | // Unchanged
7 | call(
8 | 1, 2,3
9 | );
10 |
=====================================output=====================================
call(1, 2, 3);
@@ -686,11 +756,12 @@ exports[`try-catch.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
try {}
catch (err) {}
1 | try {}
> 2 | catch (err) {}
| ^
3 |
=====================================output=====================================
try {
} catch (err) {}
@@ -702,10 +773,11 @@ exports[`whitespace.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
> 1 |
| ^
2 |
=====================================output=====================================
@@ -4,10 +4,11 @@ exports[`identifier.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
{"a":1, "b":2}
> 1 | {"a":1, "b":2}
| ^^^
2 |
=====================================output=====================================
{"a":1, "b":2}
@@ -18,10 +19,11 @@ exports[`issue2297.json format 1`] = `
====================================options=====================================
parsers: ["json"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
{"a":1, "b":2}
> 1 | {"a":1, "b":2}
| ^
2 |
=====================================output=====================================
{"a":1, "b":2}
@@ -79,13 +79,14 @@ exports[`range-with-pragma.js - {"requirePragma":true} format 1`] = `
parsers: ["flow", "babel", "typescript"]
printWidth: 80
requirePragma: true
| printWidth
| | printWidth
=====================================input======================================
/**
* @prettier
*/
var test = true
1 | /**
2 | * @prettier
3 | */
> 4 | var test = true
| ^^^^^^^^^^^^^^^
5 |
=====================================output=====================================
/**
* @prettier
@@ -100,10 +101,11 @@ exports[`range-without-pragma.js - {"requirePragma":true} format 1`] = `
parsers: ["flow", "babel", "typescript"]
printWidth: 80
requirePragma: true
| printWidth
| | printWidth
=====================================input======================================
var test = true
> 1 | var test = true
| ^^^^^^^^^^^^^^^
2 |
=====================================output=====================================
var test = true
@@ -4,19 +4,25 @@ exports[`issue-4926.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
class Foo {
/** Does this key match a given MinimalKey extending object? */
match(keyevent) {
// 'in' doesn't include prototypes, so it's safe for this object.
for (let attr in this) {
if (this[attr] !== keyevent[attr]) return false
}
return true
}
}
1 | class Foo {
2 | /** Does this key match a given MinimalKey extending object? */
3 | match(keyevent) {
> 4 | // 'in' doesn't include prototypes, so it's safe for this object.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 5 | for (let attr in this) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 6 | if (this[attr] !== keyevent[attr]) return false
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 7 | }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 8 | return true
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 9 | }
| ^^^^^
10 | }
11 |
=====================================output=====================================
class Foo {
/** Does this key match a given MinimalKey extending object? */
@@ -36,12 +42,13 @@ exports[`issue-7148.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
export default class Test {
private obj = { isTest: true }
}
1 | export default class Test {
> 2 | private obj = { isTest: true }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 | }
4 |
=====================================output=====================================
export default class Test {
private obj = { isTest: true };
@@ -4,21 +4,24 @@ exports[`example.vue format 1`] = `
====================================options=====================================
parsers: ["vue"]
printWidth: 80
| printWidth
| | printWidth
=====================================input======================================
<template>
<p>Templates are formatted as well...
</p>
</template>
<script>
let Prettier = format => { your.js('though') }
</script>
<style>
.and { css: too !important }
</style>
1 | <template>
2 | <p>Templates are formatted as well...
3 | </p>
4 | </template>
5 |
> 6 | <script>
| ^^^^^^^^
> 7 | let Prettier = format => { your.js('though') }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 8 | </script>
| ^^^^^^^^^
9 |
10 | <style>
11 | .and { css: too !important }
12 | </style>
13 |
=====================================output=====================================
<template>
<p>Templates are formatted as well...</p>
+27 -10
View File
@@ -5,6 +5,7 @@ const path = require("path");
const raw = require("jest-snapshot-serializer-raw").wrap;
const { isCI } = require("ci-info");
const checkParsers = require("./utils/check-parsers");
const visualizeRange = require("./utils/visualize-range");
const { TEST_STANDALONE } = process.env;
const AST_COMPARE = isCI || process.env.AST_COMPARE;
@@ -170,18 +171,32 @@ global.run_spec = (fixtures, parsers, options) => {
if (typeof output === "string") {
expect(formatted).toEqual(output);
} else {
let codeForSnapshot = hasEndOfLine
? code
.replace(RANGE_START_PLACEHOLDER, "")
.replace(RANGE_END_PLACEHOLDER, "")
: source;
let codeOffset = 0;
if (
typeof baseOptions.rangeStart === "number" ||
typeof baseOptions.rangeEnd === "number"
) {
codeForSnapshot = visualizeRange(codeForSnapshot, baseOptions);
codeOffset = codeForSnapshot.match(/^>?\s+1 \| /)[0].length;
}
if (hasEndOfLine) {
codeForSnapshot = visualizeEndOfLine(codeForSnapshot);
}
expect(
raw(
createSnapshot(
hasEndOfLine
? visualizeEndOfLine(
code
.replace(RANGE_START_PLACEHOLDER, "")
.replace(RANGE_END_PLACEHOLDER, "")
)
: source,
codeForSnapshot,
hasEndOfLine ? visualizedOutput : formattedWithCursor,
{ ...baseOptions, parsers }
{ ...baseOptions, parsers },
{ codeOffset }
)
)
).toMatchSnapshot();
@@ -290,11 +305,13 @@ function visualizeEndOfLine(text) {
});
}
function createSnapshot(input, output, options) {
function createSnapshot(input, output, options, { codeOffset }) {
const separatorWidth = 80;
const printWidthIndicator =
options.printWidth > 0 && Number.isFinite(options.printWidth)
? " ".repeat(options.printWidth) + "| printWidth"
? (codeOffset ? " ".repeat(codeOffset - 1) + "|" : "") +
" ".repeat(options.printWidth) +
"| printWidth"
: [];
return []
.concat(
+32
View File
@@ -0,0 +1,32 @@
"use strict";
const LinesAndColumns = require("lines-and-columns").default;
const { codeFrameColumns } = require("@babel/code-frame");
const codeFrameColumnsOptions = { linesAbove: Infinity, linesBelow: Infinity };
const locationForRange = (text, rangeStart, rangeEnd) => {
const lines = new LinesAndColumns(text);
const start = lines.locationForIndex(rangeStart);
const end = lines.locationForIndex(rangeEnd);
start.line += 1;
start.column += 1;
end.line += 1;
if (start.line === end.line) {
end.column += 1;
}
return {
start,
end,
};
};
const visualizeRange = (text, { rangeStart = 0, rangeEnd = text.length }) =>
codeFrameColumns(
text,
locationForRange(text, rangeStart, rangeEnd),
codeFrameColumnsOptions
);
module.exports = visualizeRange;