diff --git a/packages/convert/add-array/index.js b/packages/convert/add-array/index.js new file mode 100644 index 0000000..d913a89 --- /dev/null +++ b/packages/convert/add-array/index.js @@ -0,0 +1,4 @@ +export const report = () => `Use 'add-array'`; +export const replace = () => ({ + '__a.push(...__array)': '__a += __array', +}); diff --git a/packages/convert/index.js b/packages/convert/index.js index 7956984..66f7ccc 100644 --- a/packages/convert/index.js +++ b/packages/convert/index.js @@ -3,6 +3,7 @@ import {transform} from 'putout'; import {print} from '../printer/index.js'; import * as removeImportTry from './remove-import-try/index.js'; import * as applyTry from './apply-try/index.js'; +import * as addArray from './add-array/index.js'; import { fixEmpty, parse, @@ -13,6 +14,7 @@ export const convert = (source) => { transform(ast, source, { plugins: [ + ['add-array', addArray], ['apply-try', applyTry], ['remove-import-try', removeImportTry], ], diff --git a/packages/convert/index.spec.js b/packages/convert/index.spec.js index 7c72e9a..be8dddb 100644 --- a/packages/convert/index.spec.js +++ b/packages/convert/index.spec.js @@ -29,3 +29,18 @@ test('goldstein: convert: tryCatch: import', (t) => { t.equal(result, expected); t.end(); }); + +test('goldstein: convert: add-array', (t) => { + const source = ` + a.push(...[2, 3]); + `; + + const result = convert(source); + + const expected = montag` + a += [2, 3];\n + `; + + t.equal(result, expected); + t.end(); +});