Fix formatting for auto-accessors with comments (#14038)
Fixes https://github.com/prettier/prettier/issues/14036
This commit is contained in:
1 parent
d798b55486
commit
ef707da0a2
6 files changed
+128
No files matched your search
@@ -0,0 +1,32 @@
|
||||
#### Fix formatting for auto-accessors with comments (#14038 by @fisker)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```jsx
|
||||
// Input
|
||||
class A {
|
||||
@dec()
|
||||
// comment
|
||||
accessor b;
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
class A {
|
||||
@dec()
|
||||
accessor // comment
|
||||
b;
|
||||
}
|
||||
|
||||
// Prettier stable (second format)
|
||||
class A {
|
||||
@dec()
|
||||
accessor; // comment
|
||||
b;
|
||||
}
|
||||
|
||||
// Prettier main
|
||||
class A {
|
||||
@dec()
|
||||
// comment
|
||||
accessor b;
|
||||
}
|
||||
```
|
||||
@@ -453,6 +453,9 @@ const propertyLikeNodeTypes = new Set([
|
||||
"TSAbstractMethodDefinition",
|
||||
"TSDeclareMethod",
|
||||
"MethodDefinition",
|
||||
"ClassAccessorProperty",
|
||||
"AccessorProperty",
|
||||
"TSAbstractAccessorProperty",
|
||||
]);
|
||||
function handleMethodNameComments({
|
||||
comment,
|
||||
|
||||
@@ -73,6 +73,7 @@ const meriyahDisabledTests = new Set([
|
||||
"static.js",
|
||||
"with-semicolon-1.js",
|
||||
"with-semicolon-2.js",
|
||||
"comments.js",
|
||||
].map((filename) =>
|
||||
path.join(__dirname, "../format/js/decorator-auto-accessors", filename)
|
||||
),
|
||||
|
||||
@@ -73,6 +73,91 @@ class Foo {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js [acorn] format 1`] = `
|
||||
"Unexpected character '@' (2:3)
|
||||
1 | class A {
|
||||
> 2 | @dec()
|
||||
| ^
|
||||
3 | // comment
|
||||
4 | accessor b;
|
||||
5 | }"
|
||||
`;
|
||||
|
||||
exports[`comments.js [espree] format 1`] = `
|
||||
"Unexpected character '@' (2:3)
|
||||
1 | class A {
|
||||
> 2 | @dec()
|
||||
| ^
|
||||
3 | // comment
|
||||
4 | accessor b;
|
||||
5 | }"
|
||||
`;
|
||||
|
||||
exports[`comments.js - {"semi":false} [acorn] format 1`] = `
|
||||
"Unexpected character '@' (2:3)
|
||||
1 | class A {
|
||||
> 2 | @dec()
|
||||
| ^
|
||||
3 | // comment
|
||||
4 | accessor b;
|
||||
5 | }"
|
||||
`;
|
||||
|
||||
exports[`comments.js - {"semi":false} [espree] format 1`] = `
|
||||
"Unexpected character '@' (2:3)
|
||||
1 | class A {
|
||||
> 2 | @dec()
|
||||
| ^
|
||||
3 | // comment
|
||||
4 | accessor b;
|
||||
5 | }"
|
||||
`;
|
||||
|
||||
exports[`comments.js - {"semi":false} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "typescript", "babel-flow"]
|
||||
printWidth: 80
|
||||
semi: false
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
class A {
|
||||
@dec()
|
||||
// comment
|
||||
accessor b;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
class A {
|
||||
@dec()
|
||||
// comment
|
||||
accessor b
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`comments.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "typescript", "babel-flow"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
class A {
|
||||
@dec()
|
||||
// comment
|
||||
accessor b;
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
class A {
|
||||
@dec()
|
||||
// comment
|
||||
accessor b;
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`computed.js [acorn] format 1`] = `
|
||||
"Unexpected token (2:12)
|
||||
1 | class Foo {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class A {
|
||||
@dec()
|
||||
// comment
|
||||
accessor b;
|
||||
}
|
||||
@@ -9,6 +9,7 @@ const errors = {
|
||||
"static.js",
|
||||
"with-semicolon-1.js",
|
||||
"with-semicolon-2.js",
|
||||
"comments.js",
|
||||
],
|
||||
acorn: [
|
||||
"basic.js",
|
||||
@@ -19,6 +20,7 @@ const errors = {
|
||||
"static.js",
|
||||
"with-semicolon-1.js",
|
||||
"with-semicolon-2.js",
|
||||
"comments.js",
|
||||
],
|
||||
};
|
||||
run_spec(__dirname, parsers, { errors });
|
||||
|
||||
Reference in new issue
Block a user