diff --git a/lib/printer.ts b/lib/printer.ts index dee5dffa..e3f834f0 100644 --- a/lib/printer.ts +++ b/lib/printer.ts @@ -1314,7 +1314,7 @@ function genericPrintNoParens(path: any, options: any, print: any) { typeof child.value === "string" ) { if (/\S/.test(child.value)) { - return child.value.replace(/^\s+|\s+$/g, ""); + return child.value.replace(/^\s+/g, ""); } else if (/\n/.test(child.value)) { return "\n"; } diff --git a/test/jsx.ts b/test/jsx.ts index d4d2e466..173ca03e 100644 --- a/test/jsx.ts +++ b/test/jsx.ts @@ -2,6 +2,7 @@ import { parse } from "../lib/parser"; import { Printer } from "../lib/printer"; +import assert from "assert"; import * as types from "ast-types"; const nodeMajorVersion = parseInt(process.versions.node, 10); @@ -61,3 +62,35 @@ for (const { title, parser } of [ }); }); } + +it("should not remove trailing whitespaces", function () { + const printer = new Printer({ tabWidth: 2 }); + const source = + 'function App() {\n' + + ' const name = "world";\n' + + '\n' + + ' return (\n' + + '