Skip to content

Commit

Permalink
revert and add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Mar 28, 2023
1 parent affd06d commit 4ce1257
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
5 changes: 0 additions & 5 deletions packages/babel-generator/src/printer.ts
Expand Up @@ -130,11 +130,6 @@ 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
22 changes: 22 additions & 0 deletions packages/babel-generator/test/index.js
Expand Up @@ -1047,6 +1047,28 @@ describe("programmatic generation", function () {
expect(output).toBe("() => void");
});

it("generate a child node with retainLines", () => {
const node = parse("a;\n\nexpect(a).toMatchInlineSnapshot(`[1, 2]`\n);")
.program.body[1].expression;

expect(node.type).toBe("CallExpression");

expect(generate(node, { retainLines: true }).code).toMatchInlineSnapshot(`
"
expect(a).toMatchInlineSnapshot(\`[1, 2]\`
)"
`);

node.loc.end.line = node.loc.start.line;

expect(generate(node, { retainLines: true }).code).toMatchInlineSnapshot(`
"
expect(a).toMatchInlineSnapshot(\`[1, 2]\`)"
`);
});

describe("directives", function () {
it("preserves escapes", function () {
const directive = t.directive(
Expand Down

0 comments on commit 4ce1257

Please sign in to comment.