From dc62f709edfcec075564c24ab3c17a35492c11ab Mon Sep 17 00:00:00 2001 From: coderaiser Date: Tue, 11 Jun 2024 17:18:19 +0300 Subject: [PATCH] feature: keyword-useless-comma: improve support of identifiers --- packages/goldstein/index.spec.js | 45 +++++++++++++++++++++++++ packages/keyword-useless-comma/index.js | 2 ++ 2 files changed, 47 insertions(+) diff --git a/packages/goldstein/index.spec.js b/packages/goldstein/index.spec.js index 88a72eb..895a87c 100644 --- a/packages/goldstein/index.spec.js +++ b/packages/goldstein/index.spec.js @@ -528,3 +528,48 @@ test('goldstein: compile: parse-maybe-array', (t) => { t.equal(error.message, `☝️Looks like 'keyword-add-array' is missing.`); t.end(); }); + +test('goldstein: compile: missing comma', (t) => { + const source = montag` + const { + isCallExpression + isAwaitExpression + } = types; + + class X extends Parser { + parseExprAtom() { + if (this.type === x) + return parseTryStatement(); + } + }; + `; + + const { + keywordUselessSemicolon, + keywordUselessComma, + } = keywords; + + const result = compile(source, { + keywords: { + keywordUselessComma, + keywordUselessSemicolon, + }, + }); + + const expected = montag` + const { + isCallExpression, + isAwaitExpression, + } = types; + + class X extends Parser { + parseExprAtom() { + if (this.type === x) + return parseTryStatement(); + } + };\n + `; + + t.equal(result, expected); + t.end(); +}); diff --git a/packages/keyword-useless-comma/index.js b/packages/keyword-useless-comma/index.js index b246771..f8cd9a8 100644 --- a/packages/keyword-useless-comma/index.js +++ b/packages/keyword-useless-comma/index.js @@ -19,6 +19,8 @@ export default function fn(Parser) { this.context.pop(); this.type = tt.name; /* c8 ignore end */ + } else { + node.name = this.value; } return node;