Skip to content

fix: move JSX DOM types back to @vue/runtime-dom #7979

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 29, 2023
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
2 changes: 2 additions & 0 deletions packages/runtime-dom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,5 @@ export const initDirectivesForSSR = __SSR__
// re-export everything from core
// h, Component, reactivity API, nextTick, flags & types
export * from '@vue/runtime-core'

export * from './jsx'
Original file line number Diff line number Diff line change
Expand Up @@ -1319,3 +1319,17 @@ type EventHandlers<E> = {
? E[K]
: (payload: E[K]) => void
}

import { VNodeRef } from '@vue/runtime-core'

export type ReservedProps = {
key?: string | number | symbol
ref?: VNodeRef
ref_for?: boolean
ref_key?: string
}

export type NativeElements = {
[K in keyof IntrinsicElementAttributes]: IntrinsicElementAttributes[K] &
ReservedProps
}
20 changes: 6 additions & 14 deletions packages/vue/jsx-runtime/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import { VNode, VNodeRef } from '@vue/runtime-dom'
import { IntrinsicElementAttributes } from './dom'

export type ReservedProps = {
key?: string | number | symbol
ref?: VNodeRef
ref_for?: boolean
ref_key?: string
}

export type NativeElements = {
[K in keyof IntrinsicElementAttributes]: IntrinsicElementAttributes[K] &
ReservedProps
}
import type {
VNode,
IntrinsicElementAttributes,
ReservedProps,
NativeElements
} from '@vue/runtime-dom'

/**
* JSX namespace for usage with @jsxImportsSource directive
Expand Down
22 changes: 6 additions & 16 deletions packages/vue/jsx.d.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
// global JSX namespace registration
// somehow we have to copy=pase the jsx-runtime types here to make TypeScript happy
import { VNode, VNodeRef } from '@vue/runtime-dom'
import { IntrinsicElementAttributes } from './jsx-runtime/dom'

export * from './jsx-runtime/dom'

export type ReservedProps = {
key?: string | number | symbol
ref?: VNodeRef
ref_for?: boolean
ref_key?: string
}

export type NativeElements = {
[K in keyof IntrinsicElementAttributes]: IntrinsicElementAttributes[K] &
ReservedProps
}
import type {
VNode,
IntrinsicElementAttributes,
ReservedProps,
NativeElements
} from '@vue/runtime-dom'

declare global {
namespace JSX {
Expand Down
2 changes: 0 additions & 2 deletions packages/vue/types/jsx-register.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
// imports the global JSX namespace registration for compat.
// TODO: remove in 3.4
import '../jsx'

export * from '../jsx-runtime/dom'
23 changes: 20 additions & 3 deletions rollup.dts.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,35 @@ function patchTypes(pkg) {
return false
}

const isExported = new Set()
const shouldRemoveExport = new Set()

// pass 0: check all exported types
for (const node of ast.program.body) {
if (node.type === 'ExportNamedDeclaration' && !node.source) {
for (let i = 0; i < node.specifiers.length; i++) {
const spec = node.specifiers[i]
if (spec.type === 'ExportSpecifier') {
isExported.add(spec.local.name)
}
}
}
}

// pass 1: remove internals + add exports
for (const node of ast.program.body) {
if (
(node.type === 'TSTypeAliasDeclaration' ||
node.type === 'TSInterfaceDeclaration') &&
!node.id.name.startsWith(`_`)
) {
shouldRemoveExport.add(node.id.name)
const name = node.id.name
shouldRemoveExport.add(name)
if (!removeInternal(node)) {
// @ts-ignore
s.prependLeft(node.start, `export `)
if (isExported.has(name)) {
// @ts-ignore
s.prependLeft(node.start, `export `)
}
// traverse further for internal properties
if (node.type === 'TSInterfaceDeclaration') {
node.body.body.forEach(removeInternal)
Expand Down