Skip to content

Commit

Permalink
fix jest
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Mar 28, 2023
1 parent 33492ae commit affd06d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/babel-generator/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class Printer {
_indentInnerComments: boolean = true;

generate(ast: t.Node) {
// Avoid inserting unexpected blank lines at the beginning and in the middle.
if (this.format.retainLines && ast.loc) {
this._buf._position.line = ast.loc.start.line;
}

this.print(ast);
this._maybeAddAuxComment();

Expand Down Expand Up @@ -556,9 +561,9 @@ class Printer {
if (!this.format.retainLines) return;

// catch up to this nodes newline if we're behind
const pos = loc ? loc[prop] : null;
if (pos?.line != null) {
const count = pos.line - this._buf.getCurrentLine();
const line = loc?.[prop]?.line;
if (line != null) {
const count = line - this._buf.getCurrentLine();

for (let i = 0; i < count; i++) {
this._newline();
Expand Down

0 comments on commit affd06d

Please sign in to comment.