Skip to content

Commit 34c99e4

Browse files
committed
Don't camelCase data-* props (fix #105)
1 parent 5b11a1b commit 34c99e4

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/plugin.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ export default function (babel) {
3838
);
3939
}
4040

41-
// converts
42-
// <svg stroke-width="5">
43-
// to
44-
// <svg strokeWidth="5">
45-
path.node.name.name = hyphenToCamel(path.node.name.name);
41+
if (path.node.name.name.indexOf('data-') !== 0) {
42+
// converts
43+
// <svg stroke-width="5">
44+
// to
45+
// <svg strokeWidth="5">
46+
path.node.name.name = hyphenToCamel(path.node.name.name);
47+
}
4648
}
4749
}
4850
};

test/loader.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ test('compression: namespace attr', function(t) {
106106
.catch(t.end);
107107
});
108108

109+
test('should not convert data-* props', function(t) {
110+
t.plan(1);
111+
112+
loader(`<svg data-foo="foo"></svg>`)
113+
.then(component => render(React.createElement(component)))
114+
.then(r => {
115+
t.equal(Object.keys(r.props).indexOf('data-foo'), 0, 'data-* shouldn\'t be camelCased')
116+
})
117+
.catch(t.end);
118+
});
119+
109120
const circle = `
110121
<svg class='class1 class2' style='text-align: center; width: 100px;height:100px' fill="#ddd" pointer-events="stroke">
111122
<circle class='class3 class4' cx="50" cy="50" r="25" style="text-align: center; stroke: #000000;" stroke-width="5" />

0 commit comments

Comments
 (0)