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

Fix casing issues with React attributes #21

Merged
merged 2 commits into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
var html = require('property-information/html')
var svg = require('property-information/svg')
var find = require('property-information/find')
var hastToReact = require('property-information/hast-to-react')
var spaces = require('space-separated-tokens')
var commas = require('comma-separated-tokens')
var style = require('style-to-object')
Expand Down Expand Up @@ -193,7 +194,11 @@ function addAttribute(props, prop, value, ctx) {

props[subprop][info.attribute] = value
} else {
props[ctx.react && info.space ? info.property : info.attribute] = value
if (ctx.react && info.space) {
props[hastToReact[info.property] || info.property] = value
} else {
props[info.attribute] = value
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
"dependencies": {
"comma-separated-tokens": "^1.0.0",
"property-information": "^5.0.0",
"property-information": "^5.3.0",
"space-separated-tokens": "^1.0.0",
"style-to-object": "^0.2.1",
"unist-util-is": "^3.0.0",
Expand Down
41 changes: 41 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,47 @@ test('hast-to-hyperscript', function(t) {
st.end()
})

t.test('should support mapping to React properties', function (st) {
var actual = toH(
r,
u(
'element',
{
tagName: 'svg',
properties: { xmlnsXLink: 'http://www.w3.org/1999/xlink' }
},
[
u(
'element',
{
tagName: 'line',
properties: { strokeDashArray: 4 }
}
)
]
)
)
var expected = r(
'svg',
{
key: 'h-1',
xmlnsXlink: 'http://www.w3.org/1999/xlink'
},
[
r(
'line',
{
key: 'h-2',
strokeDasharray: 4
}
)
]
)

st.deepEqual(json(actual), json(expected), 'equal syntax trees')
st.end()
})

t.end()
})

Expand Down