@putout/plugin-return 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,9 @@
1
- 'use strict';
2
-
3
- const {operator, types} = require('putout');
1
+ import {operator, types} from 'putout';
4
2
 
5
3
  const {isIdentifier} = types;
6
4
  const {compare, remove} = operator;
7
5
 
8
- module.exports.report = () => `Apply early return`;
6
+ export const report = () => `Apply early return`;
9
7
 
10
8
  const FROM = `
11
9
  if (__a)
@@ -21,7 +19,7 @@ const TO = `{
21
19
  return __e;
22
20
  }`;
23
21
 
24
- module.exports.match = () => ({
22
+ export const match = () => ({
25
23
  [FROM]: ({__b}, path) => {
26
24
  if (!isIdentifier(__b))
27
25
  return;
@@ -32,7 +30,7 @@ module.exports.match = () => ({
32
30
  },
33
31
  });
34
32
 
35
- module.exports.replace = () => ({
33
+ export const replace = () => ({
36
34
  [FROM]: (vars, path) => {
37
35
  remove(path.getNextSibling());
38
36
 
@@ -1,5 +1,13 @@
1
- 'use strict';
1
+ import {convertFrom} from '../convert-from.js';
2
2
 
3
- const {convertFrom} = require('../convert-from');
3
+ const {
4
+ report,
5
+ traverse,
6
+ fix,
7
+ } = convertFrom('break');
4
8
 
5
- module.exports = convertFrom('break');
9
+ export {
10
+ report,
11
+ traverse,
12
+ fix,
13
+ };
@@ -1,5 +1,13 @@
1
- 'use strict';
1
+ import {convertFrom} from '../convert-from.js';
2
2
 
3
- const {convertFrom} = require('../convert-from');
3
+ const {
4
+ report,
5
+ traverse,
6
+ fix,
7
+ } = convertFrom('continue');
4
8
 
5
- module.exports = convertFrom('continue');
9
+ export {
10
+ report,
11
+ traverse,
12
+ fix,
13
+ };
@@ -1,19 +1,18 @@
1
- 'use strict';
1
+ import {types, operator} from 'putout';
2
2
 
3
- const {types, operator} = require('putout');
4
3
  const {replaceWith} = operator;
5
4
  const {
6
5
  isLabeledStatement,
7
- ReturnStatement,
6
+ returnStatement,
8
7
  } = types;
9
8
 
10
9
  const createReport = (name) => () => `Use 'return' instead of '${name}'`;
11
10
 
12
11
  const fix = (path) => {
13
- replaceWith(path, ReturnStatement());
12
+ replaceWith(path, returnStatement());
14
13
  };
15
14
 
16
- module.exports.convertFrom = (name) => {
15
+ export const convertFrom = (name) => {
17
16
  const visitor = name[0].toUpperCase() + name.slice(1) + `Statement`;
18
17
 
19
18
  return {
package/lib/index.js CHANGED
@@ -1,13 +1,11 @@
1
- 'use strict';
1
+ import * as applyEarly from './apply-early/index.js';
2
+ import * as convertFromContinue from './convert-from-continue/index.js';
3
+ import * as convertFromBreak from './convert-from-break/index.js';
4
+ import * as mergeWithNextSibling from './merge-with-next-sibling/index.js';
5
+ import * as removeUseless from './remove-useless/index.js';
6
+ import * as simplifyBoolean from './simplify-boolean/index.js';
2
7
 
3
- const applyEarly = require('./apply-early');
4
- const convertFromContinue = require('./convert-from-continue');
5
- const convertFromBreak = require('./convert-from-break');
6
- const mergeWithNextSibling = require('./merge-with-next-sibling');
7
- const removeUseless = require('./remove-useless');
8
- const simplifyBoolean = require('./simplify-boolean');
9
-
10
- module.exports.rules = {
8
+ export const rules = {
11
9
  'apply-early': applyEarly,
12
10
  'convert-from-continue': convertFromContinue,
13
11
  'convert-from-break': convertFromBreak,
@@ -1,15 +1,15 @@
1
- 'use strict';
1
+ import {types, operator} from 'putout';
2
2
 
3
- const {types, operator} = require('putout');
4
- const {remove} = operator;
5
3
  const {
6
- ObjectExpression,
7
- ObjectProperty,
4
+ objectExpression,
5
+ objectProperty,
8
6
  } = types;
9
7
 
10
- module.exports.report = () => `Merge 'return' with next sibling`;
8
+ const {remove} = operator;
9
+
10
+ export const report = () => `Merge 'return' with next sibling`;
11
11
 
12
- module.exports.fix = ({path, nextPath}) => {
12
+ export const fix = ({path, nextPath}) => {
13
13
  let {node} = nextPath;
14
14
 
15
15
  if (!nextPath.isBlockStatement()) {
@@ -18,17 +18,17 @@ module.exports.fix = ({path, nextPath}) => {
18
18
  const properties = [];
19
19
 
20
20
  for (const {label, body} of nextPath.node.body) {
21
- const property = ObjectProperty(label, body.expression);
21
+ const property = objectProperty(label, body.expression);
22
22
  properties.push(property);
23
23
  }
24
24
 
25
- node = ObjectExpression(properties);
25
+ node = objectExpression(properties);
26
26
  }
27
27
 
28
28
  path.node.argument = node;
29
29
  remove(nextPath);
30
30
  };
31
- module.exports.traverse = ({push}) => ({
31
+ export const traverse = ({push}) => ({
32
32
  ReturnStatement(path) {
33
33
  if (path.node.argument)
34
34
  return false;
@@ -1,6 +1,5 @@
1
- 'use strict';
1
+ import {types, operator} from 'putout';
2
2
 
3
- const {types, operator} = require('putout');
4
3
  const {replaceWith} = operator;
5
4
  const {
6
5
  isIdentifier,
@@ -8,20 +7,20 @@ const {
8
7
  isAssignmentPattern,
9
8
  } = types;
10
9
 
11
- module.exports.report = () => `Avoid useless 'return'`;
10
+ export const report = () => `Avoid useless 'return'`;
12
11
 
13
- module.exports.include = () => [
12
+ export const include = () => [
14
13
  'ArrowFunctionExpression',
15
14
  ];
16
15
 
17
- module.exports.fix = (path) => {
16
+ export const fix = (path) => {
18
17
  const bodyPath = path.get('body');
19
18
  const returnPath = bodyPath.get('body.0');
20
19
 
21
20
  replaceWith(bodyPath, returnPath.node.argument);
22
21
  };
23
22
 
24
- module.exports.filter = (path) => {
23
+ export const filter = (path) => {
25
24
  const bodyPath = path.get('body');
26
25
 
27
26
  if (!bodyPath.isBlockStatement())
@@ -1,6 +1,10 @@
1
- 'use strict';
1
+ import {operator, types} from 'putout';
2
2
 
3
- const {operator, types} = require('putout');
3
+ const {
4
+ unaryExpression,
5
+ isUnaryExpression,
6
+ returnStatement,
7
+ } = types;
4
8
 
5
9
  const {
6
10
  compareAny,
@@ -8,19 +12,13 @@ const {
8
12
  remove,
9
13
  } = operator;
10
14
 
11
- const {
12
- UnaryExpression,
13
- isUnaryExpression,
14
- ReturnStatement,
15
- } = types;
16
-
17
- module.exports.report = () => `Simplify boolean return`;
15
+ export const report = () => `Simplify boolean return`;
18
16
 
19
- module.exports.match = () => ({
17
+ export const match = () => ({
20
18
  'if (__a) return __bool__a;': checkNext,
21
19
  });
22
20
 
23
- module.exports.replace = () => ({
21
+ export const replace = () => ({
24
22
  'if (__a) return __bool__a;'({__a, __bool__a}, path) {
25
23
  const next = path.getNextSibling();
26
24
 
@@ -31,10 +29,10 @@ module.exports.replace = () => ({
31
29
 
32
30
  if (isUnaryExpression(__a, {operator: '!'})) {
33
31
  const {argument} = __a;
34
- return ReturnStatement(argument);
32
+ return returnStatement(argument);
35
33
  }
36
34
 
37
- const unary = UnaryExpression('!', __a);
35
+ const unary = unaryExpression('!', __a);
38
36
  replaceWith(path.get('test'), unary);
39
37
 
40
38
  return 'return !(__a)';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@putout/plugin-return",
3
- "version": "1.1.2",
4
- "type": "commonjs",
3
+ "version": "2.0.0",
4
+ "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin adds ability to transform code related to return",
7
7
  "homepage": "https://github.com/coderaiser/putout/tree/master/packages/plugin-return#readme",
@@ -31,28 +31,28 @@
31
31
  "return"
32
32
  ],
33
33
  "devDependencies": {
34
+ "@putout/eslint-flat": "^3.0.0",
34
35
  "@putout/plugin-declare": "*",
35
36
  "@putout/plugin-declare-before-reference": "*",
36
37
  "@putout/plugin-putout": "*",
37
38
  "@putout/plugin-remove-unused-variables": "*",
38
39
  "@putout/plugin-reuse-duplicate-init": "*",
39
40
  "@putout/plugin-typescript": "*",
40
- "@putout/test": "^11.0.0",
41
+ "@putout/test": "^13.0.0",
41
42
  "c8": "^10.0.0",
42
43
  "eslint": "^9.0.0",
43
44
  "eslint-plugin-n": "^17.0.0",
44
- "eslint-plugin-putout": "^24.0.0",
45
- "lerna": "^6.0.1",
46
- "madrun": "^10.0.0",
45
+ "eslint-plugin-putout": "^26.0.0",
46
+ "madrun": "^11.0.0",
47
47
  "montag": "^1.2.1",
48
48
  "nodemon": "^3.0.1"
49
49
  },
50
50
  "peerDependencies": {
51
- "putout": ">=38"
51
+ "putout": ">=40"
52
52
  },
53
53
  "license": "MIT",
54
54
  "engines": {
55
- "node": ">=18"
55
+ "node": ">=20"
56
56
  },
57
57
  "publishConfig": {
58
58
  "access": "public"