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

Add support for accessing node in render #23

Merged
merged 1 commit into from
Apr 24, 2020
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
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ function toH(h, node, ctx) {
// Ensure no React warnings are triggered for void elements having children
// passed in.
result =
elements.length === 0 ? h(name, attributes) : h(name, attributes, elements)
elements.length === 0
? h.call(node, name, attributes)
: h.call(node, name, attributes, elements)

// Restore parent schema.
ctx.schema = parentSchema
Expand Down
26 changes: 26 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,32 @@ test('hast-to-hyperscript', function(t) {
st.end()
})

t.test('should use a node as a rendering context', function(st) {
function mockR() {
return {
node: this
}
}

var node = u(
'element',
{
tagName: 'svg',
properties: {xmlnsXLink: 'http://www.w3.org/1999/xlink'}
},
[
u('element', {
tagName: 'line',
properties: {strokeDashArray: 4}
})
]
)
var actual = toH(mockR, node)

st.equal(actual.node, node, 'equal rendering context')
st.end()
})

t.end()
})

Expand Down