Skip to content

Commit 93db4b9

Browse files
committed
feature: @putout/operator-jsx: migrate to ESM
1 parent a646123 commit 93db4b9

File tree

5 files changed

+24
-36
lines changed

5 files changed

+24
-36
lines changed

packages/operator-jsx/lib/jsx.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
'use strict';
1+
import {setLiteralValue} from '@putout/operate';
2+
import {types} from '@putout/babel';
23

3-
const {setLiteralValue} = require('@putout/operate');
4-
const {types} = require('@putout/babel');
54
const {
65
isJSXElement,
76
jsxAttribute,
@@ -11,7 +10,7 @@ const {
1110

1211
const getNode = (a) => a.node || a;
1312

14-
module.exports.hasTagName = (path, name) => {
13+
export const hasTagName = (path, name) => {
1514
const node = getNode(path);
1615

1716
if (!isJSXElement(path))
@@ -20,7 +19,7 @@ module.exports.hasTagName = (path, name) => {
2019
return node.openingElement.name.name === name;
2120
};
2221

23-
module.exports.getAttributePath = (path, name) => {
22+
export const getAttributePath = (path, name) => {
2423
const attributes = path.get('openingElement.attributes');
2524

2625
for (const attr of attributes) {
@@ -31,8 +30,7 @@ module.exports.getAttributePath = (path, name) => {
3130
return null;
3231
};
3332

34-
module.exports.getAttributeNode = getAttributeNode;
35-
function getAttributeNode(path, name) {
33+
export function getAttributeNode(path, name) {
3634
let result = null;
3735
const node = getNode(path);
3836
const {attributes} = node.openingElement;
@@ -47,8 +45,7 @@ function getAttributeNode(path, name) {
4745
return result;
4846
}
4947

50-
module.exports.getAttributeValue = getAttributeValue;
51-
function getAttributeValue(path, attributeName) {
48+
export function getAttributeValue(path, attributeName) {
5249
const attribute = getAttributeNode(path, attributeName);
5350

5451
if (!attribute)
@@ -57,8 +54,7 @@ function getAttributeValue(path, attributeName) {
5754
return attribute.value.value;
5855
}
5956

60-
module.exports.addAttributeValue = addAttributeValue;
61-
function addAttributeValue(path, name, value) {
57+
export function addAttributeValue(path, name, value) {
6258
const attributeNode = getAttributeNode(path, name);
6359

6460
if (!attributeNode)
@@ -70,8 +66,7 @@ function addAttributeValue(path, name, value) {
7066
setLiteralValue(attributeNode.value, `${attributeNode.value.value} ${value}`);
7167
}
7268

73-
module.exports.addAttribute = addAttribute;
74-
function addAttribute(path, name, value) {
69+
export function addAttribute(path, name, value) {
7570
const node = getNode(path);
7671
let attributeNode = getAttributeNode(node, name);
7772

@@ -81,8 +76,7 @@ function addAttribute(path, name, value) {
8176
}
8277
}
8378

84-
module.exports.removeAttributeValue = removeAttributeValue;
85-
function removeAttributeValue(path, name, attributeValue) {
79+
export function removeAttributeValue(path, name, attributeValue) {
8680
if (!path)
8781
return;
8882

@@ -101,7 +95,7 @@ function removeAttributeValue(path, name, attributeValue) {
10195
setLiteralValue(classAttribute.value, newValue);
10296
}
10397

104-
module.exports.setAttributeValue = (path, name, value) => {
98+
export const setAttributeValue = (path, name, value) => {
10599
const attributeNode = getAttributeNode(path, name);
106100

107101
if (!attributeNode)
@@ -110,30 +104,29 @@ module.exports.setAttributeValue = (path, name, value) => {
110104
setLiteralValue(attributeNode.value, value);
111105
};
112106

113-
module.exports.addClassName = (path, name) => {
107+
export const addClassName = (path, name) => {
114108
addAttributeValue(path, 'className', name);
115109
};
116110

117-
module.exports.getClassName = getClassName;
118-
function getClassName(path) {
111+
export function getClassName(path) {
119112
return getAttributeValue(path, 'className');
120113
}
121114

122-
module.exports.removeClassName = (path, name) => {
115+
export const removeClassName = (path, name) => {
123116
removeAttributeValue(path, 'className', name);
124117
};
125118

126-
module.exports.containsClassName = (path, className) => {
119+
export const containsClassName = (path, className) => {
127120
const classNameValue = getClassName(path);
128121
return classNameValue.includes(className);
129122
};
130123

131-
module.exports.hasDataName = (path, value = '') => {
124+
export const hasDataName = (path, value = '') => {
132125
const attribute = getAttributeValue(path, 'data-name');
133126
return attribute === value;
134127
};
135128

136-
module.exports.hasAttributeValue = (path, name, value = '') => {
129+
export const hasAttributeValue = (path, name, value = '') => {
137130
const attribute = getAttributeValue(path, name);
138131
return attribute === value;
139132
};

packages/operator-jsx/lib/jsx.spec.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
'use strict';
2-
3-
const {test} = require('supertape');
4-
5-
const {
1+
import {test} from 'supertape';
2+
import {
63
template,
74
operator,
85
print,
9-
} = require('putout');
10-
11-
const {tryCatch} = require('try-catch');
12-
13-
const {
6+
} from 'putout';
7+
import {tryCatch} from 'try-catch';
8+
import {
149
addClassName,
1510
addAttribute,
1611
removeClassName,
@@ -24,7 +19,7 @@ const {
2419
addAttributeValue,
2520
setAttributeValue,
2621
removeAttributeValue,
27-
} = require('./jsx.js');
22+
} from './jsx.js';
2823

2924
const {traverse} = operator;
3025

packages/operator-jsx/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@putout/operator-jsx",
33
"version": "2.0.0",
4-
"type": "commonjs",
4+
"type": "module",
55
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
66
"description": "🐊Putout operator adds methods that simplifies JSX transformations",
77
"homepage": "https://github.com/coderaiser/putout/tree/master/packages/operator-jsx#readme",
@@ -51,7 +51,7 @@
5151
},
5252
"license": "MIT",
5353
"engines": {
54-
"node": ">=20"
54+
"node": ">=22"
5555
},
5656
"publishConfig": {
5757
"access": "public"

0 commit comments

Comments
 (0)