Skip to content

Commit 5881498

Browse files
committed
feature: @putout/plugin-printer: convert to ESM
1 parent 8fb6762 commit 5881498

File tree

19 files changed

+78
-103
lines changed

19 files changed

+78
-103
lines changed

packages/plugin-printer/lib/add-args/index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict';
1+
import {operator} from 'putout';
22

3-
const {operator} = require('putout');
43
const {addArgs} = operator;
5-
64
const parents = [
75
'__ = __',
86
'const __ = __',
@@ -13,7 +11,11 @@ const parents = [
1311
'function __(path, __object) {}',
1412
];
1513

16-
module.exports = addArgs({
14+
const {
15+
report,
16+
fix,
17+
traverse,
18+
} = addArgs({
1719
path: ['path', 'module.exports.__a = () => __body'],
1820
maybe: ['{maybe}', parents],
1921
write: ['{write}', parents],
@@ -23,3 +25,9 @@ module.exports = addArgs({
2325
traverse: ['{traverse}', parents],
2426
store: ['{store}', parents],
2527
});
28+
29+
export {
30+
report,
31+
fix,
32+
traverse,
33+
};

packages/plugin-printer/lib/add-args/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as declare from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const declare = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['printer/add-args', declare],
97
],

packages/plugin-printer/lib/apply-breakline/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const {operator, template} = require('putout');
1+
import {operator, template} from 'putout';
42

53
const {
64
compare,
@@ -9,23 +7,23 @@ const {
97
remove,
108
} = operator;
119

12-
module.exports.report = () => `breakline = newline + indent`;
10+
export const report = () => `breakline = newline + indent`;
1311

1412
const next = (path) => path.parentPath.getNextSibling();
1513

16-
module.exports.fix = (path) => {
14+
export const fix = (path) => {
1715
const sibling = next(path);
1816
const newNode = choose(path);
1917

2018
remove(sibling);
2119
replaceWith(path, newNode);
2220
};
2321

24-
module.exports.filter = (path) => {
22+
export const filter = (path) => {
2523
return compareAny(next(path), ['indent()', 'print.indent()', 'write.indent()']);
2624
};
2725

28-
module.exports.include = () => [
26+
export const include = () => [
2927
'print.newline()',
3028
'write.newline()',
3129
];

packages/plugin-printer/lib/apply-breakline/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['printer/apply-breakline', plugin],
97
],

packages/plugin-printer/lib/apply-computed-print/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
'use strict';
2-
31
const {assign} = Object;
42

5-
module.exports.report = () => `Use print('__path') instead of path.get(__path)`;
3+
export const report = () => `Use print('__path') instead of path.get(__path)`;
64

7-
module.exports.replace = () => ({
5+
export const replace = () => ({
86
'print(path.get(__a))': ({__a}) => {
97
const {raw, value} = __a;
108

packages/plugin-printer/lib/apply-computed-print/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['printer/apply-computed-print', plugin],
97
],

packages/plugin-printer/lib/apply-linebreak/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
const {operator, template} = require('putout');
1+
import {operator, template} from 'putout';
42

53
const {
64
compare,
@@ -9,24 +7,24 @@ const {
97
remove,
108
} = operator;
119

12-
module.exports.report = () => `linebreak = indent + newline`;
10+
export const report = () => `linebreak = indent + newline`;
1311

1412
const prev = (path) => path.parentPath.getPrevSibling();
1513

16-
module.exports.fix = (path) => {
14+
export const fix = (path) => {
1715
const sibling = prev(path);
1816
const newNode = choose(path);
1917

2018
remove(sibling);
2119
replaceWith(path, newNode);
2220
};
2321

24-
module.exports.include = () => [
22+
export const include = () => [
2523
'print.newline()',
2624
'write.newline()',
2725
];
2826

29-
module.exports.filter = (path) => {
27+
export const filter = (path) => {
3028
return compareAny(prev(path), ['indent()', 'print.indent()', 'write.indent()']);
3129
};
3230

packages/plugin-printer/lib/apply-linebreak/index.spec.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as plugin from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const plugin = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['printer/apply-linebreak', plugin],
97
],

packages/plugin-printer/lib/apply-types/index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
'use strict';
1+
import {types} from 'putout';
22

3-
const {types} = require('putout');
43
const {isObjectPattern} = types;
54

65
const {keys} = Object;
76
const TYPES = keys(types);
87

9-
module.exports.report = () => `require: ('@putout/babel') -> ('putout/babel').types`;
8+
export const report = () => `require: ('@putout/babel') -> ('putout/babel').types`;
109

11-
module.exports.match = () => ({
10+
export const match = () => ({
1211
'const __a = require("@putout/babel")': ({__a}) => {
1312
if (!isObjectPattern(__a))
1413
return false;
@@ -30,7 +29,7 @@ module.exports.match = () => ({
3029
},
3130
});
3231

33-
module.exports.replace = () => ({
32+
export const replace = () => ({
3433
'const {types, __a} = require("@putout/babel")': `{
3534
const {types} = require("@putout/babel");
3635
const {__a} = types;

packages/plugin-printer/lib/apply-types/index.spec.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import declareBeforeReference from '@putout/plugin-declare-before-reference';
3+
import removeNestedBlocks from '@putout/plugin-remove-nested-blocks';
4+
import * as plugin from './index.js';
25

3-
const {createTest} = require('@putout/test');
4-
5-
const declareBeforeReference = require('@putout/plugin-declare-before-reference');
6-
const removeNestedBlocks = require('@putout/plugin-remove-nested-blocks');
7-
const plugin = require('.');
8-
9-
const test = createTest(__dirname, {
6+
const test = createTest(import.meta.url, {
107
plugins: [
118
['apply-types', plugin],
129
],

0 commit comments

Comments
 (0)