Skip to content

Commit 20c97bf

Browse files
committed
feature: @putout/plugin-assignment: convert to ESM
1 parent e3ffee0 commit 20c97bf

File tree

13 files changed

+43
-64
lines changed

13 files changed

+43
-64
lines changed
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 {
54
isIdentifier,
65
isMemberExpression,
76
} = types;
87

9-
module.exports.report = () => 'Expected ArrowFunction instead of Assignment';
8+
export const report = () => 'Expected ArrowFunction instead of Assignment';
109

11-
module.exports.match = () => ({
10+
export const match = () => ({
1211
'const __a = __b = __c': ({__b}, path) => {
1312
if (isIdentifier(__b) && path.scope.hasBinding(__b.name))
1413
return false;
@@ -17,6 +16,6 @@ module.exports.match = () => ({
1716
},
1817
});
1918

20-
module.exports.replace = () => ({
19+
export const replace = () => ({
2120
'const __a = __b = __c': 'const __a = __b => __c',
2221
});

packages/plugin-assignment/lib/convert-to-arrow-function/index.spec.js

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

3-
const {createTest} = require('@putout/test');
4-
const convertToArrowFunction = require('.');
5-
6-
const test = createTest(__dirname, {
4+
const test = createTest(import.meta.url, {
75
plugins: [
86
['assignment/convert-to-arrow-function', convertToArrowFunction],
97
],
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
1+
export const report = () => 'Expected comparison instead of assignment';
22

3-
module.exports.report = () => 'Expected comparison instead of assignment';
4-
5-
module.exports.replace = () => ({
3+
export const replace = () => ({
64
'if (__a = __b) __body': 'if (__a === __b) __body',
75
});

packages/plugin-assignment/lib/convert-to-comparison/index.spec.js

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

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

packages/plugin-assignment/lib/convert-to-declaration/index.js

+4-5
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 {
54
variableDeclarator,
65
isIdentifier,
@@ -13,12 +12,12 @@ const {
1312
isKeyword,
1413
} = operator;
1514

16-
module.exports.report = (path) => {
15+
export const report = (path) => {
1716
const {name} = path.node.left;
1817
return `Declare '${name}' before assignment`;
1918
};
2019

21-
module.exports.fix = (path) => {
20+
export const fix = (path) => {
2221
const {left, right} = path.node;
2322
const node = variableDeclaration('const', [
2423
variableDeclarator(left, right),
@@ -27,7 +26,7 @@ module.exports.fix = (path) => {
2726
replaceWith(path, node);
2827
};
2928

30-
module.exports.traverse = ({push}) => ({
29+
export const traverse = ({push}) => ({
3130
AssignmentExpression(path) {
3231
const prevPath = path.parentPath.getPrevSibling();
3332

packages/plugin-assignment/lib/convert-to-declaration/index.spec.js

+3-5
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
['assignment/convert-to-declaration', plugin],
97
],

packages/plugin-assignment/lib/index.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
'use strict';
1+
import * as convertToArrowFunction from './convert-to-arrow-function/index.js';
2+
import * as convertToComparison from './convert-to-comparison/index.js';
3+
import * as convertToDeclaration from './convert-to-declaration/index.js';
4+
import * as simplify from './simplify/index.js';
5+
import * as split from './split/index.js';
26

3-
const convertToArrowFunction = require('./convert-to-arrow-function');
4-
const convertToComparison = require('./convert-to-comparison');
5-
const convertToDeclaration = require('./convert-to-declaration');
6-
const simplify = require('./simplify');
7-
const split = require('./split');
8-
9-
module.exports.rules = {
7+
export const rules = {
108
'convert-to-arrow-function': convertToArrowFunction,
119
'convert-to-comparison': convertToComparison,
1210
'convert-to-declaration': convertToDeclaration,

packages/plugin-assignment/lib/simplify/index.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
'use strict';
1+
export const report = () => 'Simplify assignment';
22

3-
module.exports.report = () => 'Simplify assignment';
4-
5-
module.exports.match = () => ({
3+
export const match = () => ({
64
'const __a = (() => __b)()': check,
75
'__a = (() => __b)()': check,
86
'var __a = (() => __b)()': check,
97
});
108

11-
module.exports.replace = () => ({
9+
export const replace = () => ({
1210
'const {__a} = {__a: __b}': 'const __a = __b',
1311
'const [__a] = [__b]': 'const __a = __b',
1412
'const __a = (() => __b)()': 'const __a = __b',

packages/plugin-assignment/lib/simplify/index.spec.js

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

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

packages/plugin-assignment/lib/split/index.js

+4-5
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 {
54
arrayPattern,
65
isAssignmentExpression,
@@ -11,9 +10,9 @@ const {
1110

1211
const {replaceWithMultiple} = operator;
1312

14-
module.exports.report = () => `Split assignment expressions`;
13+
export const report = () => `Split assignment expressions`;
1514

16-
module.exports.fix = ({path, lefts, right, merged}) => {
15+
export const fix = ({path, lefts, right, merged}) => {
1716
if (merged) {
1817
const rightPath = path.get('right');
1918
const {right, left} = rightPath.node;
@@ -40,7 +39,7 @@ module.exports.fix = ({path, lefts, right, merged}) => {
4039
replaceWithMultiple(path, assignments);
4140
};
4241

43-
module.exports.traverse = ({push}) => ({
42+
export const traverse = ({push}) => ({
4443
AssignmentExpression(path) {
4544
const {node} = path;
4645

packages/plugin-assignment/lib/split/index.spec.js

+3-5
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
['assignment/split', plugin],
97
],

packages/plugin-assignment/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@putout/plugin-assignment",
3-
"version": "1.0.0",
4-
"type": "commonjs",
3+
"version": "1.0.2",
4+
"type": "module",
55
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
66
"description": "🐊Putout plugin adds ability to transform code related to assignment",
77
"homepage": "https://github.com/coderaiser/putout/tree/v38.5.7/packages/plugin-assignment#readme",

packages/plugin-assignment/test/assignment.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict';
1+
import {createTest} from '@putout/test';
2+
import * as assignment from '../lib/index.js';
23

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

0 commit comments

Comments
 (0)