Skip to content

Commit 3bd8dd4

Browse files
committed
fix: @putout/operator-jsx: removeClassName: space
1 parent 60823e4 commit 3bd8dd4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/operator-jsx/lib/jsx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function removeAttributeValue(path, name, attributeValue) {
9292
const {value} = classAttribute.value;
9393

9494
if (value.includes(attributeValue))
95-
setLiteralValue(classAttribute.value, value.replace(RegExp(`\\s?${attributeValue}`), ''));
95+
setLiteralValue(classAttribute.value, value.replace(RegExp(`\\s?${attributeValue}\\s?`), ''));
9696
}
9797

9898
module.exports.setAttributeValue = (path, name, value) => {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ test('putout: operator: jsx: removeClassName', (t) => {
239239
t.end();
240240
});
241241

242+
test('putout: operator: jsx: removeClassName: first', (t) => {
243+
const node = template.ast.fresh('<hello className="hello world"/>');
244+
removeClassName(node, 'hello');
245+
246+
const result = print(node);
247+
const expected = `<hello className="world"/>;\n`;
248+
249+
t.equal(result, expected);
250+
t.end();
251+
});
252+
242253
test('putout: operator: jsx: containsClassName', (t) => {
243254
const node = template.ast.fresh('<hello className="hello world"/>');
244255
const result = containsClassName(node, 'world');

0 commit comments

Comments
 (0)