Skip to content

Commit 766298d

Browse files
committed
feature: @putout/plugin-return: convert to ESM
1 parent e64e93c commit 766298d

File tree

19 files changed

+82
-79
lines changed

19 files changed

+82
-79
lines changed

packages/plugin-return/.putout.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"rules": {
3+
"putout/apply-exports": ["on", {
4+
"convertFrom": [
5+
"report",
6+
"traverse",
7+
"fix"
8+
]
9+
}]
10+
},
211
"match": {
312
"*.md": {
413
"return": "off"

packages/plugin-return/lib/apply-early/index.js

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

53
const {isIdentifier} = types;
64
const {compare, remove} = operator;
75

8-
module.exports.report = () => `Apply early return`;
6+
export const report = () => `Apply early return`;
97

108
const FROM = `
119
if (__a)
@@ -21,7 +19,7 @@ const TO = `{
2119
return __e;
2220
}`;
2321

24-
module.exports.match = () => ({
22+
export const match = () => ({
2523
[FROM]: ({__b}, path) => {
2624
if (!isIdentifier(__b))
2725
return;
@@ -32,7 +30,7 @@ module.exports.match = () => ({
3230
},
3331
});
3432

35-
module.exports.replace = () => ({
33+
export const replace = () => ({
3634
[FROM]: (vars, path) => {
3735
remove(path.getNextSibling());
3836

packages/plugin-return/lib/apply-early/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 applyEarlyReturn from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const applyEarlyReturn = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['apply-early-return', applyEarlyReturn],
97
],
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
'use strict';
1+
import {convertFrom} from '../convert-from.js';
22

3-
const {convertFrom} = require('../convert-from');
3+
const {
4+
report,
5+
traverse,
6+
fix,
7+
} = convertFrom('break');
48

5-
module.exports = convertFrom('break');
9+
export {
10+
report,
11+
traverse,
12+
fix,
13+
};

packages/plugin-return/lib/convert-from-break/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
['convert-from-break', plugin],
97
],
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
'use strict';
1+
import {convertFrom} from '../convert-from.js';
22

3-
const {convertFrom} = require('../convert-from');
3+
const {
4+
report,
5+
traverse,
6+
fix,
7+
} = convertFrom('continue');
48

5-
module.exports = convertFrom('continue');
9+
export {
10+
report,
11+
traverse,
12+
fix,
13+
};

packages/plugin-return/lib/convert-from-continue/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
['convert-from-continue', plugin],
97
],

packages/plugin-return/lib/convert-from.js

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

3-
const {types, operator} = require('putout');
43
const {replaceWith} = operator;
54
const {
65
isLabeledStatement,
@@ -13,7 +12,7 @@ const fix = (path) => {
1312
replaceWith(path, returnStatement());
1413
};
1514

16-
module.exports.convertFrom = (name) => {
15+
export const convertFrom = (name) => {
1716
const visitor = name[0].toUpperCase() + name.slice(1) + `Statement`;
1817

1918
return {

0 commit comments

Comments
 (0)