Skip to content

Commit

Permalink
feature: goldstein: convert: add-array
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Oct 19, 2023
1 parent 070d081 commit 2346464
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/convert/add-array/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const report = () => `Use 'add-array'`;
export const replace = () => ({
'__a.push(...__array)': '__a += __array',
});
2 changes: 2 additions & 0 deletions packages/convert/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -13,6 +14,7 @@ export const convert = (source) => {

transform(ast, source, {
plugins: [
['add-array', addArray],
['apply-try', applyTry],
['remove-import-try', removeImportTry],
],
Expand Down
15 changes: 15 additions & 0 deletions packages/convert/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 2346464

Please sign in to comment.