diff --git a/README.md b/README.md index e01d35d..401fe0f 100644 --- a/README.md +++ b/README.md @@ -464,6 +464,11 @@ const a = { - b; + b, }; + +const a = { +- b(){}, ++ b(){} +}; ``` ### Assign from diff --git a/packages/goldstein/index.js b/packages/goldstein/index.js index 7cf500a..620706a 100644 --- a/packages/goldstein/index.js +++ b/packages/goldstein/index.js @@ -8,7 +8,7 @@ import {parse} from './parser.js'; export {convert} from '../convert/index.js'; export {print} from '../printer/index.js'; export * from './parser.js'; -import * as renameUnnamedIdentifier from '../keyword-useless-comma/rename-unnamed-identifier/index.js'; +import * as removeUnnamedObjectProperty from '../keyword-useless-comma/remove-unnamed-object-property/index.js'; export const compile = (source, options = {}) => { const ast = parse(source, options); @@ -21,7 +21,7 @@ export const compile = (source, options = {}) => { ['try-catch', tryCatchPlugin], ['declare', declarePlugin], ['logical-expressions', logicalExpressionsPlugin], - ['remove-unnamed-identifiers', renameUnnamedIdentifier], + ['remove-unnamed-identifiers', removeUnnamedObjectProperty], ], }); diff --git a/packages/goldstein/index.spec.js b/packages/goldstein/index.spec.js index 29b6395..88a72eb 100644 --- a/packages/goldstein/index.spec.js +++ b/packages/goldstein/index.spec.js @@ -355,6 +355,23 @@ test('goldstein: parse: useless comma', (t) => { t.end(); }); +test('goldstein: parse: useless comma: class', (t) => { + const result = compile(montag` + const a = class { + b() {}, + }; + `); + + const expected = montag` + const a = class { + b() {} + };\n + `; + + t.equal(result, expected); + t.end(); +}); + test('goldstein: parse: useless semicolon', (t) => { const result = compile(montag` const a = { @@ -503,7 +520,9 @@ test('goldstein: compile: parse-maybe-array', (t) => { `; const [error] = tryCatch(compile, source, { - keywords: {}, + keywords: { + keywordAddArray: false, + }, }); t.equal(error.message, `☝️Looks like 'keyword-add-array' is missing.`); diff --git a/packages/keyword-useless-comma/rename-unnamed-identifier/index.js b/packages/keyword-useless-comma/remove-unnamed-object-property/index.js similarity index 85% rename from packages/keyword-useless-comma/rename-unnamed-identifier/index.js rename to packages/keyword-useless-comma/remove-unnamed-object-property/index.js index 718d9f0..78d8d70 100644 --- a/packages/keyword-useless-comma/rename-unnamed-identifier/index.js +++ b/packages/keyword-useless-comma/remove-unnamed-object-property/index.js @@ -1,7 +1,7 @@ export const report = () => {}; export const fix = (path) => path.remove(); export const traverse = ({push}) => ({ - ObjectProperty(path) { + 'ObjectProperty|ClassProperty'(path) { const keyPath = path.get('key'); if (keyPath.isIdentifier() && !keyPath.node.name) diff --git a/packages/keyword-useless-comma/rename-unnamed-identifier/index.spec.js b/packages/keyword-useless-comma/remove-unnamed-object-property/index.spec.js similarity index 53% rename from packages/keyword-useless-comma/rename-unnamed-identifier/index.spec.js rename to packages/keyword-useless-comma/remove-unnamed-object-property/index.spec.js index 04d0422..3678a25 100644 --- a/packages/keyword-useless-comma/rename-unnamed-identifier/index.spec.js +++ b/packages/keyword-useless-comma/remove-unnamed-object-property/index.spec.js @@ -1,11 +1,11 @@ import {test} from 'supertape'; import montag from 'montag'; import {transform} from 'putout'; -import * as renameUnnamedIdentifier from './index.js'; +import * as removeUnnamedIdentifier from './index.js'; import {parse, print} from '../../goldstein/index.js'; import keywordUselessComma from '../index.js'; -test('goldstein: keyword: useless-comma: rename-unnamed-identifier', (t) => { +test('goldstein: keyword: useless-comma: remove-unnamed-object-property', (t) => { const source = montag` const a = { b,, @@ -20,7 +20,7 @@ test('goldstein: keyword: useless-comma: rename-unnamed-identifier', (t) => { transform(ast, source, { plugins: [ - ['rename', renameUnnamedIdentifier], + ['remove', removeUnnamedIdentifier], ], }); @@ -36,7 +36,7 @@ test('goldstein: keyword: useless-comma: rename-unnamed-identifier', (t) => { t.end(); }); -test('goldstein: keyword: useless-comma: rename-unnamed-identifier: StringLiteral', (t) => { +test('goldstein: keyword: useless-comma: remove-unnamed-object-property: StringLiteral', (t) => { const source = montag` const a = { "hello": "world",, @@ -51,7 +51,7 @@ test('goldstein: keyword: useless-comma: rename-unnamed-identifier: StringLitera transform(ast, source, { plugins: [ - ['rename', renameUnnamedIdentifier], + ['rename', removeUnnamedIdentifier], ], }); @@ -66,3 +66,37 @@ test('goldstein: keyword: useless-comma: rename-unnamed-identifier: StringLitera t.equal(code, expected); t.end(); }); + +test('goldstein: keyword: useless-comma: remove-unnamed-class-property', (t) => { + const source = montag` + const a = class { + b() {}, + c() {}, + }; + `; + + const ast = parse(source, { + keywords: [ + keywordUselessComma, + ], + }); + + transform(ast, source, { + plugins: [ + ['remove', removeUnnamedIdentifier], + ], + }); + + const code = print(ast); + + const expected = montag` + const a = class { + b() {} + + c() {} + };\n + `; + + t.equal(code, expected); + t.end(); +});