Skip to content

Commit

Permalink
don't put JSX on global
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe committed May 12, 2024
1 parent 8b24707 commit 5bd2b71
Show file tree
Hide file tree
Showing 28 changed files with 1,377 additions and 1,377 deletions.
19 changes: 9 additions & 10 deletions deno_dist/jsx/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../utils/html
import type { Context } from './context.ts'
import { globalContexts } from './context.ts'
import type { IntrinsicElements as IntrinsicElementsDefined } from './intrinsic-elements.ts'
import type { Hono } from './intrinsic-elements.ts'
import { normalizeIntrinsicElementProps, styleObjectForEach } from './utils.ts'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -15,16 +16,14 @@ export type FC<P = Props> = {
}
export type DOMAttributes = Hono.HTMLAttributes

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace JSX {
type Element = HtmlEscapedString | Promise<HtmlEscapedString>
interface ElementChildrenAttribute {
children: Child
}
interface IntrinsicElements extends IntrinsicElementsDefined {
[tagName: string]: Props
}
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace JSX {
export type Element = HtmlEscapedString | Promise<HtmlEscapedString>
export interface ElementChildrenAttribute {
children: Child
}
export interface IntrinsicElements extends IntrinsicElementsDefined {
[tagName: string]: Props
}
}

Expand Down
3 changes: 2 additions & 1 deletion deno_dist/jsx/dom/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Props, Child, DOMAttributes, JSXNode } from '../base.ts'
import { memo, isValidElement } from '../base.ts'
import type { Props, Child, DOMAttributes, JSXNode } from '../base.ts'
import type { JSX } from '../base.ts'
import { Children } from '../children.ts'
import { useContext } from '../context.ts'
import {
Expand Down
1 change: 1 addition & 0 deletions deno_dist/jsx/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from '../base.ts'
import { DOM_STASH } from '../constants.ts'
import { buildDataStack, update, build } from '../dom/render.ts'
import type { Node, NodeObject, Context, PendingType, UpdateHook } from '../dom/render.ts'
Expand Down
1,328 changes: 663 additions & 665 deletions deno_dist/jsx/intrinsic-elements.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions deno_dist/jsx/jsx-dev-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { HtmlEscapedString } from '../utils/html.ts'
import { jsxFn } from './base.ts'
import type { JSXNode } from './base.ts'
export { Fragment } from './base.ts'
export type { JSX } from './base.ts'

export function jsxDEV(
tag: string | Function,
Expand Down
1 change: 1 addition & 0 deletions deno_dist/jsx/jsx-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { jsxDEV as jsx, Fragment } from './jsx-dev-runtime.ts'
export { jsxDEV as jsxs } from './jsx-dev-runtime.ts'
export type { JSX } from './jsx-dev-runtime.ts'

import { raw, html } from '../helper/html/index.ts'
import type { HtmlEscapedString } from '../utils/html.ts'
Expand Down
1 change: 1 addition & 0 deletions deno_dist/jsx/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* All types exported from "hono/jsx" are in this file.
*/
import type { Child, JSXNode } from './base.ts'
import type { Hono } from './intrinsic-elements.ts'

export type { Child, JSXNode, FC } from './base.ts'
export type { RefObject } from './hooks/index.ts'
Expand Down
3 changes: 1 addition & 2 deletions src/helper/css/common.case.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable quotes */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, Fragment } from '../../jsx'
/** @jsxImportSource ../../jsx */
import type {
css as cssHelper,
keyframes as keyframesHelper,
Expand Down
4 changes: 2 additions & 2 deletions src/helper/css/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable quotes */
/** @jsxImportSource ../../jsx */
import { Hono } from '../../'
import { html } from '../../helper/html'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, Fragment, isValidElement } from '../../jsx'
import { isValidElement } from '../../jsx'
import type { JSXNode } from '../../jsx'
import { Suspense, renderToReadableStream } from '../../jsx/streaming'
import type { HtmlEscapedString } from '../../utils/html'
Expand Down
3 changes: 1 addition & 2 deletions src/helper/ssg/ssg.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/unbound-method */
/** @jsxImportSource ../../jsx */
import { beforeEach, describe, expect, it } from 'vitest'
import { Hono } from '../../hono'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx } from '../../jsx'
import { poweredBy } from '../../middleware/powered-by'
import {
X_HONO_DISABLE_SSG_HEADER_KEY,
Expand Down
19 changes: 9 additions & 10 deletions src/jsx/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../utils/html
import type { Context } from './context'
import { globalContexts } from './context'
import type { IntrinsicElements as IntrinsicElementsDefined } from './intrinsic-elements'
import type { Hono } from './intrinsic-elements'
import { normalizeIntrinsicElementProps, styleObjectForEach } from './utils'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -15,16 +16,14 @@ export type FC<P = Props> = {
}
export type DOMAttributes = Hono.HTMLAttributes

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace JSX {
type Element = HtmlEscapedString | Promise<HtmlEscapedString>
interface ElementChildrenAttribute {
children: Child
}
interface IntrinsicElements extends IntrinsicElementsDefined {
[tagName: string]: Props
}
// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace JSX {
export type Element = HtmlEscapedString | Promise<HtmlEscapedString>
export interface ElementChildrenAttribute {
children: Child
}
export interface IntrinsicElements extends IntrinsicElementsDefined {
[tagName: string]: Props
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/jsx/components.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/** @jsxImportSource ./ */
import { JSDOM } from 'jsdom'
import type { HtmlEscapedString } from '../utils/html'
import { HtmlEscapedCallbackPhase, resolveCallback as rawResolveCallback } from '../utils/html'
import { ErrorBoundary } from './components'
import { Suspense, renderToReadableStream } from './streaming'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx } from '.'

function resolveCallback(template: string | HtmlEscapedString) {
return rawResolveCallback(template, HtmlEscapedCallbackPhase.Stream, false, {})
Expand Down
3 changes: 1 addition & 2 deletions src/jsx/dom/components.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/** @jsxImportSource ../ */
import { JSDOM } from 'jsdom'
import { Suspense as SuspenseCommon, ErrorBoundary as ErrorBoundaryCommon } from '..' // for common
// run tests by old style jsx default
// hono/jsx/jsx-runtime and hono/jsx/dom/jsx-runtime are tested in their respective settings
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx } from '..'
import { use, useState } from '../hooks'
import { Suspense as SuspenseDom, ErrorBoundary as ErrorBoundaryDom } from '.' // for dom
import { render } from '.'
Expand Down
3 changes: 1 addition & 2 deletions src/jsx/dom/context.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
/** @jsxImportSource ../ */
import { JSDOM } from 'jsdom'
import { createContext as createContextCommon, useContext as useContextCommon } from '..' // for common
import { use, Suspense } from '..'
// run tests by old style jsx default
// hono/jsx/jsx-runtime and hono/jsx/dom/jsx-runtime are tested in their respective settings
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, Fragment } from '..'
import { createContext as createContextDom, useContext as useContextDom } from '.' // for dom
import { render, useState } from '.'

Expand Down
2 changes: 1 addition & 1 deletion src/jsx/dom/css.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @jsxImportSource ../ */
import { JSDOM } from 'jsdom'
// run tests by old style jsx default
// hono/jsx/jsx-runtime and hono/jsx/dom/jsx-runtime are tested in their respective settings
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx } from '..'
import type { JSXNode } from '..'
import { Style, css, rawCssString, createCssContext } from '../../helper/css'
import { minify } from '../../helper/css/common'
Expand Down
4 changes: 2 additions & 2 deletions src/jsx/dom/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @jsxImportSource ../ */
import { JSDOM } from 'jsdom'
import type { FC, Child } from '..'
// run tests by old style jsx default
// hono/jsx/jsx-runtime and hono/jsx/dom/jsx-runtime are tested in their respective settings
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, Fragment, createElement } from '..'
import { createElement, jsx } from '..'
import type { RefObject } from '../hooks'
import {
useState,
Expand Down
3 changes: 2 additions & 1 deletion src/jsx/dom/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Props, Child, DOMAttributes, JSXNode } from '../base'
import { memo, isValidElement } from '../base'
import type { Props, Child, DOMAttributes, JSXNode } from '../base'
import type { JSX } from '../base'
import { Children } from '../children'
import { useContext } from '../context'
import {
Expand Down
3 changes: 1 addition & 2 deletions src/jsx/hooks/dom.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/** @jsxImportSource ../ */
import { JSDOM } from 'jsdom'
// run tests by old style jsx default
// hono/jsx/jsx-runtime and hono/jsx/dom/jsx-runtime are tested in their respective settings
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { jsx, Fragment } from '..'
import { Suspense } from '../dom'
import { render } from '../dom'
import {
Expand Down
1 change: 1 addition & 0 deletions src/jsx/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { JSX } from '../base'
import { DOM_STASH } from '../constants'
import { buildDataStack, update, build } from '../dom/render'
import type { Node, NodeObject, Context, PendingType, UpdateHook } from '../dom/render'
Expand Down
4 changes: 2 additions & 2 deletions src/jsx/hooks/string.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { jsx, useState, useSyncExternalStore } from '..'
/** @jsxImportSource ../ */
import { useState, useSyncExternalStore } from '..'

describe('useState', () => {
it('should be rendered with initial state', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/jsx/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/** @jsxImportSource ./ */
// @denoify-ignore
/* eslint-disable @typescript-eslint/no-explicit-any */
import { html } from '../helper/html'
import { Hono } from '../hono'
import { Suspense, renderToReadableStream } from './streaming'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import DefaultExport, { jsx, memo, Fragment, createContext, useContext } from '.'
import DefaultExport, { memo, Fragment, createContext, useContext } from '.'
import type { Context, FC, PropsWithChildren } from '.'

interface SiteData {
Expand Down
Loading

0 comments on commit 5bd2b71

Please sign in to comment.