Skip to content

Commit 18c666b

Browse files
committed
feature: @putout/plugin-react-hooks: convert to ESM
1 parent 18f2edb commit 18c666b

File tree

27 files changed

+101
-153
lines changed

27 files changed

+101
-153
lines changed

packages/plugin-react-hooks/lib/apply-short-fragment/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 {types, operator} = require('putout');
1+
import {types, operator} from 'putout';
42

53
const {
64
JSXClosingFragment,
@@ -10,20 +8,20 @@ const {
108

119
const {replaceWith} = operator;
1210

13-
module.exports.report = () => `Apply shorthand syntax for 'Fragment'`;
11+
export const report = () => `Apply shorthand syntax for 'Fragment'`;
1412

15-
module.exports.include = () => [
13+
export const include = () => [
1614
'JSXOpeningElement',
1715
];
1816

19-
module.exports.fix = (path) => {
17+
export const fix = (path) => {
2018
const {parentPath} = path;
2119
const {children} = path.parentPath.node;
2220

2321
replaceWith(parentPath, JSXFragment(JSXOpeningFragment(), JSXClosingFragment(), children));
2422
};
2523

26-
module.exports.filter = (path) => {
24+
export const filter = (path) => {
2725
if (path.node.attributes.length)
2826
return false;
2927

packages/plugin-react-hooks/lib/apply-short-fragment/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
['react-hooks/apply-short-fragment', plugin],
97
],

packages/plugin-react-hooks/lib/common.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict';
2-
3-
module.exports.traverseClass = (traverse, ast, visitor) => {
1+
export const traverseClass = (traverse, ast, visitor) => {
42
traverse(ast, {
53
'class __ extends React.Component {}': push(visitor),
64
'class __ extends Component {}': push(visitor),

packages/plugin-react-hooks/lib/convert-class-to-function/class-to-function.js

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

53
const {replaceWith, remove} = operator;
64

@@ -10,7 +8,7 @@ const {
108
functionDeclaration,
119
} = types;
1210

13-
module.exports = (path) => {
11+
export default (path) => {
1412
const {node} = path;
1513
const {body} = node;
1614

packages/plugin-react-hooks/lib/convert-class-to-function/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
'use strict';
2-
3-
const {types} = require('putout');
4-
5-
const classToFunction = require('./class-to-function');
6-
const {traverseClass} = require('../common');
1+
import {types} from 'putout';
2+
import classToFunction from './class-to-function.js';
3+
import {traverseClass} from '../common.js';
74

85
const {isIdentifier, isClassMethod} = types;
96

10-
module.exports.report = ({name}) => {
7+
export const report = ({name}) => {
118
return `class ${name} should be a function`;
129
};
1310

14-
module.exports.fix = ({path}) => {
11+
export const fix = ({path}) => {
1512
classToFunction(path);
1613
};
1714

18-
module.exports.find = (ast, {push, traverse}) => {
15+
export const find = (ast, {push, traverse}) => {
1916
traverseClass(traverse, ast, {
2017
Identifier(path) {
2118
const {name} = path.node;

packages/plugin-react-hooks/lib/convert-class-to-function/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 convertClassToFunction from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const convertClassToFunction = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-class-to-function', convertClassToFunction],
97
],

packages/plugin-react-hooks/lib/convert-component-to-use-state/index.js

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

33
const {
44
isIdentifier,
55
isObjectPattern,
6-
} = require('putout').types;
6+
} = types;
77

8-
module.exports.report = () => 'useState should be used instead of Component';
8+
export const report = () => 'useState should be used instead of Component';
99

10-
module.exports.fix = ({node}) => {
10+
export const fix = ({node}) => {
1111
node.key.name = 'useState';
1212
node.value.name = 'useState';
1313
};
1414

15-
module.exports.find = (ast, {traverse}) => {
15+
export const find = (ast, {traverse}) => {
1616
const places = [];
1717

1818
traverse(ast, {

packages/plugin-react-hooks/lib/convert-component-to-use-state/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 convertComponentToUseState from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const convertComponentToUseState = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-component-to-use-state', convertComponentToUseState],
97
],

packages/plugin-react-hooks/lib/convert-import-component-to-use-state/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict';
1+
export const report = () => 'useState should be used instead of Component';
22

3-
module.exports.report = () => 'useState should be used instead of Component';
4-
5-
module.exports.fix = ({node}) => {
3+
export const fix = ({node}) => {
64
node.imported.name = 'useState';
75
node.local.name = 'useState';
86
};
97

10-
module.exports.traverse = ({push}) => ({
8+
export const traverse = ({push}) => ({
119
ImportDeclaration(path) {
1210
const {source} = path.node;
1311

packages/plugin-react-hooks/lib/convert-import-component-to-use-state/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 convertImportComponentToUseState from './index.js';
23

3-
const {createTest} = require('@putout/test');
4-
const convertImportComponentToUseState = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['convert-import-component-to-use-state', convertImportComponentToUseState],
97
],

0 commit comments

Comments
 (0)