Skip to content

Commit 226be21

Browse files
committed
Fix self-closing-comp to treat non-breaking spaces as content (fixes #496)
1 parent cfca370 commit 226be21

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/rules/self-closing-comp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = function(context) {
2323
var childrens = node.parent.children;
2424
if (
2525
!childrens.length ||
26-
(childrens.length === 1 && childrens[0].type === 'Literal' && !childrens[0].value.trim())
26+
(childrens.length === 1 && childrens[0].type === 'Literal' && !childrens[0].value.replace(/(?!\xA0)\s/g, ''))
2727
) {
2828
return false;
2929
}

tests/lib/rules/self-closing-comp.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ ruleTester.run('self-closing-comp', rule, {
4141
<Hello name="John" />\
4242
</Hello>',
4343
parserOptions: parserOptions
44+
}, {
45+
code: 'var HelloJohn = <div>&nbsp;</div>;',
46+
parserOptions: parserOptions
47+
}, {
48+
code: 'var HelloJohn = <Hello name="John">&nbsp;</Hello>;',
49+
parserOptions: parserOptions
4450
}
4551
],
4652

0 commit comments

Comments
 (0)