Skip to content

Commit

Permalink
refactor(jsx): Remove unused HONO_COMPONENT feature (#2139)
Browse files Browse the repository at this point in the history
* refactor(jsx): Remove unused HONO_COMPONENT feature

* chore: denoify
  • Loading branch information
usualoma committed Feb 3, 2024
1 parent 6adc806 commit 88f2983
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 66 deletions.
33 changes: 0 additions & 33 deletions deno_dist/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export type { RefObject } from './hooks/index.ts'
export { createContext, useContext } from './context.ts'
export type { Context } from './context.ts'

export const HONO_COMPONENT = 'hono-component'
export const HONO_COMPONENT_ID = 'hono-component-id'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Props = Record<string, any>

Expand Down Expand Up @@ -205,19 +202,6 @@ export class JSXNode implements HtmlEscaped {
}

class JSXFunctionNode extends JSXNode {
constructor(tag: Function, props: Props, children: Child[]) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((tag as any)[HONO_COMPONENT_ID]) {
props = Object.keys(props).reduce((acc, key) => {
if (/^on[A-Z]/.test(key)) {
acc[key] = props[key]
}
return acc
}, {} as Props)
}
super(tag, props, children)
}

toStringToBuffer(buffer: StringBuffer): void {
const { children } = this

Expand All @@ -226,18 +210,6 @@ class JSXFunctionNode extends JSXNode {
children: children.length <= 1 ? children[0] : children,
})

// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((this.tag as any)[HONO_COMPONENT_ID]) {
const attr = JSON.stringify({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
id: (this.tag as any)[HONO_COMPONENT_ID],
props: this.props,
})
const tmpBuf = ['']
escapeToBuffer(attr, tmpBuf)
buffer[0] += `<${HONO_COMPONENT} data-hono="${tmpBuf[0]}">`
}

if (res instanceof Promise) {
if (globalContexts.length === 0) {
buffer.unshift('', res)
Expand All @@ -261,11 +233,6 @@ class JSXFunctionNode extends JSXNode {
} else {
escapeToBuffer(res, buffer)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((this.tag as any)[HONO_COMPONENT_ID]) {
buffer[0] += `</${HONO_COMPONENT}>`
}
}
}

Expand Down
33 changes: 0 additions & 33 deletions src/jsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ export type { RefObject } from './hooks'
export { createContext, useContext } from './context'
export type { Context } from './context'

export const HONO_COMPONENT = 'hono-component'
export const HONO_COMPONENT_ID = 'hono-component-id'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Props = Record<string, any>

Expand Down Expand Up @@ -205,19 +202,6 @@ export class JSXNode implements HtmlEscaped {
}

class JSXFunctionNode extends JSXNode {
constructor(tag: Function, props: Props, children: Child[]) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((tag as any)[HONO_COMPONENT_ID]) {
props = Object.keys(props).reduce((acc, key) => {
if (/^on[A-Z]/.test(key)) {
acc[key] = props[key]
}
return acc
}, {} as Props)
}
super(tag, props, children)
}

toStringToBuffer(buffer: StringBuffer): void {
const { children } = this

Expand All @@ -226,18 +210,6 @@ class JSXFunctionNode extends JSXNode {
children: children.length <= 1 ? children[0] : children,
})

// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((this.tag as any)[HONO_COMPONENT_ID]) {
const attr = JSON.stringify({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
id: (this.tag as any)[HONO_COMPONENT_ID],
props: this.props,
})
const tmpBuf = ['']
escapeToBuffer(attr, tmpBuf)
buffer[0] += `<${HONO_COMPONENT} data-hono="${tmpBuf[0]}">`
}

if (res instanceof Promise) {
if (globalContexts.length === 0) {
buffer.unshift('', res)
Expand All @@ -261,11 +233,6 @@ class JSXFunctionNode extends JSXNode {
} else {
escapeToBuffer(res, buffer)
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((this.tag as any)[HONO_COMPONENT_ID]) {
buffer[0] += `</${HONO_COMPONENT}>`
}
}
}

Expand Down

0 comments on commit 88f2983

Please sign in to comment.