Skip to content

Commit 3100343

Browse files
committed
feature: @putout/plugin-react: convert to ESM
1 parent 70a0572 commit 3100343

21 files changed

Lines changed: 83 additions & 100 deletions

File tree

packages/plugin-react/lib/apply-create-root/index.js

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

53
const {insertAfter} = operator;
64
const notRender = ({imported}) => imported.name !== 'render';
75
const notDeclaredRoot = (vars, path) => !path.scope.bindings.root;
86

97
const nodeCreateImport = template.ast(`import {createRoot} from 'react-dom/client'`);
108

11-
module.exports.report = () => `Use 'if condition' instead of 'ternary expression'`;
9+
export const report = () => `Use 'if condition' instead of 'ternary expression'`;
1210

13-
module.exports.match = () => ({
11+
export const match = () => ({
1412
'import __imports from "react-dom"': notDeclaredRoot,
1513
'render(__a, __b)': notDeclaredRoot,
1614
});
1715

18-
module.exports.replace = () => ({
16+
export const replace = () => ({
1917
'import __imports from "react-dom"': ({__imports}, path) => {
2018
path.node.specifiers = __imports.filter(notRender);
2119

packages/plugin-react/lib/apply-create-root/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
['apply-create-root', plugin],
97
],

packages/plugin-react/lib/index.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict';
1+
import * as removeUselessProvider from './remove-useless-provider/index.js';
2+
import * as removeImplicitRefReturn from './remove-implicit-ref-return/index.js';
3+
import * as removeUselessForwardRef from './remove-useless-forward-ref/index.js';
4+
import * as applyCreateRoot from './apply-create-root/index.js';
5+
import * as renameFileJsToJsx from './rename-file-js-to-jsx/index.js';
6+
import * as renameFileJsxToJs from './rename-file-jsx-to-js/index.js';
27

3-
const removeUselessProvider = require('./remove-useless-provider');
4-
const removeImplicitRefReturn = require('./remove-implicit-ref-return');
5-
const removeUselessForwardRef = require('./remove-useless-forward-ref');
6-
const applyCreateRoot = require('./apply-create-root');
7-
const renameFileJsToJsx = require('./rename-file-js-to-jsx');
8-
const renameFileJsxToJs = require('./rename-file-jsx-to-js');
9-
10-
module.exports.rules = {
8+
export const rules = {
119
'remove-useless-provider': removeUselessProvider,
1210
'remove-implicit-ref-return': removeImplicitRefReturn,
1311
'remove-useless-forward-ref': removeUselessForwardRef,
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
'use strict';
2-
3-
const noop = () => {};
4-
5-
module.exports.report = () => '';
6-
module.exports.fix = noop;
7-
module.exports.include = () => ['JSXElement'];
1+
export const report = () => '';
2+
export const fix = () => {};
3+
export const include = () => ['JSXElement'];

packages/plugin-react/lib/is-jsx/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
['is-jsx', plugin],
97
],
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
1+
export const report = () => `Remove implicit 'ref' return`;
22

3-
module.exports.report = () => `Remove implicit 'ref' return`;
4-
5-
module.exports.replace = () => ({
3+
export const replace = () => ({
64
'<div ref={__a => (__b = __a)} />': '<div ref={__a=> {__b= __a}} />',
75
});

packages/plugin-react/lib/remove-implicit-ref-return/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
['remove-implicit-ref-return', plugin],
97
],

packages/plugin-react/lib/remove-useless-forward-ref/index.js

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

3-
const {types} = require('putout');
43
const {
54
restElement,
65
objectPattern,
76
isIdentifier,
87
objectProperty,
98
} = types;
109

11-
module.exports.report = () => `Avoid useless 'forwardRef' in react > 19`;
10+
export const report = () => `Avoid useless 'forwardRef' in react > 19`;
1211

13-
module.exports.replace = () => ({
12+
export const replace = () => ({
1413
'forwardRef(__a)': ({__a}) => {
1514
__a.params = buildParams(__a);
1615

0 commit comments

Comments
 (0)