Skip to content

Commit ffe679c

Browse files
authored
fix(types/jsx): move JSX DOM types back to @vue/runtime-dom (#7979)
1 parent ff60b93 commit ffe679c

File tree

6 files changed

+48
-35
lines changed

6 files changed

+48
-35
lines changed

packages/runtime-dom/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,5 @@ export const initDirectivesForSSR = __SSR__
252252
// re-export everything from core
253253
// h, Component, reactivity API, nextTick, flags & types
254254
export * from '@vue/runtime-core'
255+
256+
export * from './jsx'

packages/vue/jsx-runtime/dom.d.ts renamed to packages/runtime-dom/src/jsx.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1319,3 +1319,17 @@ type EventHandlers<E> = {
13191319
? E[K]
13201320
: (payload: E[K]) => void
13211321
}
1322+
1323+
import { VNodeRef } from '@vue/runtime-core'
1324+
1325+
export type ReservedProps = {
1326+
key?: string | number | symbol
1327+
ref?: VNodeRef
1328+
ref_for?: boolean
1329+
ref_key?: string
1330+
}
1331+
1332+
export type NativeElements = {
1333+
[K in keyof IntrinsicElementAttributes]: IntrinsicElementAttributes[K] &
1334+
ReservedProps
1335+
}

packages/vue/jsx-runtime/index.d.ts

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import { VNode, VNodeRef } from '@vue/runtime-dom'
2-
import { IntrinsicElementAttributes } from './dom'
3-
4-
export type ReservedProps = {
5-
key?: string | number | symbol
6-
ref?: VNodeRef
7-
ref_for?: boolean
8-
ref_key?: string
9-
}
10-
11-
export type NativeElements = {
12-
[K in keyof IntrinsicElementAttributes]: IntrinsicElementAttributes[K] &
13-
ReservedProps
14-
}
1+
import type {
2+
VNode,
3+
IntrinsicElementAttributes,
4+
ReservedProps,
5+
NativeElements
6+
} from '@vue/runtime-dom'
157

168
/**
179
* JSX namespace for usage with @jsxImportsSource directive

packages/vue/jsx.d.ts

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
// global JSX namespace registration
22
// somehow we have to copy=pase the jsx-runtime types here to make TypeScript happy
3-
import { VNode, VNodeRef } from '@vue/runtime-dom'
4-
import { IntrinsicElementAttributes } from './jsx-runtime/dom'
5-
6-
export * from './jsx-runtime/dom'
7-
8-
export type ReservedProps = {
9-
key?: string | number | symbol
10-
ref?: VNodeRef
11-
ref_for?: boolean
12-
ref_key?: string
13-
}
14-
15-
export type NativeElements = {
16-
[K in keyof IntrinsicElementAttributes]: IntrinsicElementAttributes[K] &
17-
ReservedProps
18-
}
3+
import type {
4+
VNode,
5+
IntrinsicElementAttributes,
6+
ReservedProps,
7+
NativeElements
8+
} from '@vue/runtime-dom'
199

2010
declare global {
2111
namespace JSX {

packages/vue/types/jsx-register.d.ts

-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@
22
// imports the global JSX namespace registration for compat.
33
// TODO: remove in 3.4
44
import '../jsx'
5-
6-
export * from '../jsx-runtime/dom'

rollup.dts.config.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,35 @@ function patchTypes(pkg) {
8888
return false
8989
}
9090

91+
const isExported = new Set()
9192
const shouldRemoveExport = new Set()
93+
94+
// pass 0: check all exported types
95+
for (const node of ast.program.body) {
96+
if (node.type === 'ExportNamedDeclaration' && !node.source) {
97+
for (let i = 0; i < node.specifiers.length; i++) {
98+
const spec = node.specifiers[i]
99+
if (spec.type === 'ExportSpecifier') {
100+
isExported.add(spec.local.name)
101+
}
102+
}
103+
}
104+
}
105+
92106
// pass 1: remove internals + add exports
93107
for (const node of ast.program.body) {
94108
if (
95109
(node.type === 'TSTypeAliasDeclaration' ||
96110
node.type === 'TSInterfaceDeclaration') &&
97111
!node.id.name.startsWith(`_`)
98112
) {
99-
shouldRemoveExport.add(node.id.name)
113+
const name = node.id.name
114+
shouldRemoveExport.add(name)
100115
if (!removeInternal(node)) {
101-
// @ts-ignore
102-
s.prependLeft(node.start, `export `)
116+
if (isExported.has(name)) {
117+
// @ts-ignore
118+
s.prependLeft(node.start, `export `)
119+
}
103120
// traverse further for internal properties
104121
if (node.type === 'TSInterfaceDeclaration') {
105122
node.body.body.forEach(removeInternal)

0 commit comments

Comments
 (0)