-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Unexpected duplication of comments #16110
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -824,6 +824,10 @@ class Printer { | |
if (i < len - 1) separator?.(); | ||
|
||
if (opts.statement) { | ||
if (!node.trailingComments?.length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fixes the extra new line.
|
||
this._lastCommentLine = 0; | ||
} | ||
|
||
if (i + 1 === len) { | ||
this.newline(1); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1492,6 +1492,26 @@ describe("programmatic generation", function () { | |
val | ||
);`); | ||
}); | ||
|
||
it("multi-line leading comment after return 2", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test has nothing to do with this PR, it just ensures that #16104 does not cause regressions. |
||
const ast = parse( | ||
`return ( | ||
/*new | ||
line*/ val);`, | ||
{ | ||
allowReturnOutsideFunction: true, | ||
}, | ||
); | ||
// Remove `parenthesized` | ||
ast.program.body[0].argument.extra = null; | ||
expect(generate(ast).code).toMatchInlineSnapshot(` | ||
"return ( | ||
/*new | ||
line*/ | ||
val | ||
);" | ||
`); | ||
}); | ||
}); | ||
}); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ _e().e; | |
|
||
// The first import is unused, but we keep the require call | ||
// because of the second one | ||
|
||
_g().h; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,4 @@ function func() { | |
} | ||
console.log(_arguments); // [1, 2, 3] | ||
} | ||
|
||
func(1, 2, 3); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Note: TSC doesn't support string module specifiers yet, | ||
// but it's easier for us to support them than not. | ||
|
||
; | ||
export {}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,11 +48,9 @@ export function shareCommentsWithSiblings(this: NodePath) { | |
|
||
function removeIfExisting<T>(list: T[], toRemove?: T[]): T[] { | ||
if (!toRemove) return list; | ||
let lastFoundIndex = -1; | ||
const set = new Set(toRemove); | ||
return list.filter(el => { | ||
const i = toRemove.indexOf(el, lastFoundIndex); | ||
if (i === -1) return true; | ||
lastFoundIndex = i; | ||
return !set.has(el); | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that the order may be reversed. |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we configure Jest to just not load the Babel config for snapshots?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/jestjs/jest/blob/2c3d2409879952157433de215ae0eee5188a4384/packages/jest-snapshot/src/utils.ts#L363-L368
This doesn't seem to be possible at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I even want to open a pr in jest to avoid using
@babel/core
.