From 3b7473ef9c6937a8a99bb22c46edd805733ae6d6 Mon Sep 17 00:00:00 2001 From: Hossein Mohammadi Date: Sat, 2 Jan 2021 08:12:05 +0330 Subject: [PATCH] fix: remove empty comments --- src/parser.ts | 7 ++++++- tests/__snapshots__/main.test.js.snap | 5 +++++ tests/main.test.js | 8 ++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/parser.ts b/src/parser.ts index afed241..374b5aa 100755 --- a/src/parser.ts +++ b/src/parser.ts @@ -191,8 +191,13 @@ export const getParser = (parser: any) => ); }); - comment.value = addStarsToTheBeginningOfTheLines(comment.value.trimEnd()); + comment.value = comment.value.trimEnd(); + if (comment.value) { + comment.value = addStarsToTheBeginningOfTheLines(comment.value); + } }); + ast.comments = ast.comments.filter(({ value }) => value); + return ast; }; diff --git a/tests/__snapshots__/main.test.js.snap b/tests/__snapshots__/main.test.js.snap index 891eed4..49c2580 100644 --- a/tests/__snapshots__/main.test.js.snap +++ b/tests/__snapshots__/main.test.js.snap @@ -47,6 +47,11 @@ export class Dummy {} " `; +exports[`Incorrect comment 2`] = ` +"export class Dummy {} +" +`; + exports[`JS code should be formatted as usuall 1`] = ` "const variable1 = 1; // No semicolon const stringVar = \\"text\\"; // Wrong quotes diff --git a/tests/main.test.js b/tests/main.test.js index 29d6d60..971e04d 100755 --- a/tests/main.test.js +++ b/tests/main.test.js @@ -369,5 +369,13 @@ test("Incorrect comment", () => { export class Dummy {} `); + const result2 = subject(` + /** + * + */ + export class Dummy {} + `); + expect(result).toMatchSnapshot(); + expect(result2).toMatchSnapshot(); });