Fix duplicated comments (#8742)

* Add failed test

* Fix issue

* more tests

* Restore verify parser

* Add changelog

* Update snapshots
This commit is contained in:
fisker Cheung authored and GitHub committed 2020-07-14 15:06:57 +03:00
1 parent b61088094c
commit 639e7fc869
4 files changed
+86 -1

No files matched your search

@@ -0,0 +1,16 @@
#### Fix duplicated `prettier-ignore` comments ([#8742](https://github.com/prettier/prettier/pull/8742) by [@fisker](https://github.com/fisker))
<!-- prettier-ignore -->
```js
// Input
a = <div {.../* prettier-ignore */{}}/>
a = <div {...{}/* prettier-ignore */}/>
// Prettier stable
a = <div {/* prettier-ignore */ .../* prettier-ignore */ {}} />;
a = <div {...{} /* prettier-ignore */ /* prettier-ignore */} />;
// Prettier master
a = <div {.../* prettier-ignore */ {}} />;
a = <div {...{} /* prettier-ignore */} />;
```
+1 -1
View File
@@ -1919,7 +1919,7 @@ function printPathNoParens(path, options, print, args) {
(p) => {
const printed = concat(["...", print(p)]);
const n = p.getValue();
if (!n.comments || !n.comments.length) {
if (!n.comments || !n.comments.length || !willPrintOwnComments(p)) {
return printed;
}
return concat([
@@ -148,3 +148,53 @@ const response = {
================================================================================
`;
exports[`ignore-2.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow"]
printWidth: 80
| printWidth
=====================================input======================================
// #8736
function HelloWorld() {
return (
<div
{...{} /*
// @ts-ignore */ /* prettier-ignore */}
invalidProp="HelloWorld"
>
test
</div>
);
}
a = <div {.../* prettier-ignore */b}/>
a = <div {...b/* prettier-ignore */}/>
a = <div {.../* prettier-ignore */{}}/>
a = <div {...{/* prettier-ignore */}}/>
a = <div {...{}/* prettier-ignore */}/>
=====================================output=====================================
// #8736
function HelloWorld() {
return (
<div
{...{} /*
// @ts-ignore */ /* prettier-ignore */}
invalidProp="HelloWorld"
>
test
</div>
);
}
a = <div {.../* prettier-ignore */ b} />;
a = <div {...b /* prettier-ignore */} />;
a = <div {.../* prettier-ignore */ {}} />;
a = <div {...{/* prettier-ignore */}} />;
a = <div {...{} /* prettier-ignore */} />;
================================================================================
`;
+19
View File
@@ -0,0 +1,19 @@
// #8736
function HelloWorld() {
return (
<div
{...{} /*
// @ts-ignore */ /* prettier-ignore */}
invalidProp="HelloWorld"
>
test
</div>
);
}
a = <div {.../* prettier-ignore */b}/>
a = <div {...b/* prettier-ignore */}/>
a = <div {.../* prettier-ignore */{}}/>
a = <div {...{/* prettier-ignore */}}/>
a = <div {...{}/* prettier-ignore */}/>