Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit b46d21d

Browse files
jamesopstadwooorm
authored andcommitted
Fix casing issues with React properties
Closes GH-21. Reviewed-by: Merlijn Vos <merlijn@soverin.net> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent d2a1b3d commit b46d21d

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
var html = require('property-information/html')
44
var svg = require('property-information/svg')
55
var find = require('property-information/find')
6+
var hastToReact = require('property-information/hast-to-react')
67
var spaces = require('space-separated-tokens')
78
var commas = require('comma-separated-tokens')
89
var style = require('style-to-object')
@@ -193,7 +194,11 @@ function addAttribute(props, prop, value, ctx) {
193194

194195
props[subprop][info.attribute] = value
195196
} else {
196-
props[ctx.react && info.space ? info.property : info.attribute] = value
197+
if (ctx.react && info.space) {
198+
props[hastToReact[info.property] || info.property] = value
199+
} else {
200+
props[info.attribute] = value
201+
}
197202
}
198203
}
199204

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
"dependencies": {
2828
"comma-separated-tokens": "^1.0.0",
29-
"property-information": "^5.0.0",
29+
"property-information": "^5.3.0",
3030
"space-separated-tokens": "^1.0.0",
3131
"style-to-object": "^0.2.1",
3232
"unist-util-is": "^3.0.0",

test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,47 @@ test('hast-to-hyperscript', function(t) {
672672
st.end()
673673
})
674674

675+
t.test('should support mapping to React properties', function (st) {
676+
var actual = toH(
677+
r,
678+
u(
679+
'element',
680+
{
681+
tagName: 'svg',
682+
properties: { xmlnsXLink: 'http://www.w3.org/1999/xlink' }
683+
},
684+
[
685+
u(
686+
'element',
687+
{
688+
tagName: 'line',
689+
properties: { strokeDashArray: 4 }
690+
}
691+
)
692+
]
693+
)
694+
)
695+
var expected = r(
696+
'svg',
697+
{
698+
key: 'h-1',
699+
xmlnsXlink: 'http://www.w3.org/1999/xlink'
700+
},
701+
[
702+
r(
703+
'line',
704+
{
705+
key: 'h-2',
706+
strokeDasharray: 4
707+
}
708+
)
709+
]
710+
)
711+
712+
st.deepEqual(json(actual), json(expected), 'equal syntax trees')
713+
st.end()
714+
})
715+
675716
t.end()
676717
})
677718

0 commit comments

Comments
 (0)