Skip to content

Commit

Permalink
fix(jsx/dom): remove lookbehind assertion in event regexp (#2524)
Browse files Browse the repository at this point in the history
* fix(jsx/dom): remove lookbehind assertion in event regexp for iOS Safari 16.3

* chore: denoify
  • Loading branch information
usualoma committed Apr 18, 2024
1 parent ed51b0b commit 68cabde
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion deno_dist/jsx/dom/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let nameSpaceContext: JSXContext<string> | undefined = undefined
const isNodeString = (node: Node): node is NodeString => Array.isArray(node)

const getEventSpec = (key: string): [string, boolean] | undefined => {
const match = key.match(/^on([A-Z][a-zA-Z]+?)((?<!Pointer)Capture)?$/)
const match = key.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/)
if (match) {
const [, eventName, capture] = match
return [(eventAliasMap[eventName] || eventName).toLowerCase(), !!capture]
Expand Down
27 changes: 27 additions & 0 deletions src/jsx/dom/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,33 @@ describe('DOM', () => {
root.querySelector('button')?.click()
expect(clicked).toEqual(['div', 'button', 'button'])
})

it('onGotPointerCapture', async () => {
const App = () => {
return <div onGotPointerCapture={() => {}}></div>
}
const addEventListenerSpy = vi.spyOn(dom.window.Node.prototype, 'addEventListener')
render(<App />, root)
expect(addEventListenerSpy).toHaveBeenCalledOnce()
expect(addEventListenerSpy).toHaveBeenCalledWith(
'gotpointercapture',
expect.any(Function),
false
)
})
it('onGotPointerCaptureCapture', async () => {
const App = () => {
return <div onGotPointerCaptureCapture={() => {}}></div>
}
const addEventListenerSpy = vi.spyOn(dom.window.Node.prototype, 'addEventListener')
render(<App />, root)
expect(addEventListenerSpy).toHaveBeenCalledOnce()
expect(addEventListenerSpy).toHaveBeenCalledWith(
'gotpointercapture',
expect.any(Function),
true
)
})
})

it('simple Counter', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/jsx/dom/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ let nameSpaceContext: JSXContext<string> | undefined = undefined
const isNodeString = (node: Node): node is NodeString => Array.isArray(node)

const getEventSpec = (key: string): [string, boolean] | undefined => {
const match = key.match(/^on([A-Z][a-zA-Z]+?)((?<!Pointer)Capture)?$/)
const match = key.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/)
if (match) {
const [, eventName, capture] = match
return [(eventAliasMap[eventName] || eventName).toLowerCase(), !!capture]
Expand Down

0 comments on commit 68cabde

Please sign in to comment.