]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types/jsx): move JSX DOM types back to `@vue/runtime-dom` (#7979)
authorHaoqun Jiang <haoqunjiang@gmail.com>
Wed, 29 Mar 2023 12:22:29 +0000 (20:22 +0800)
committerGitHub <noreply@github.com>
Wed, 29 Mar 2023 12:22:29 +0000 (20:22 +0800)
packages/runtime-dom/src/index.ts
packages/runtime-dom/src/jsx.ts [moved from packages/vue/jsx-runtime/dom.d.ts with 99% similarity]
packages/vue/jsx-runtime/index.d.ts
packages/vue/jsx.d.ts
packages/vue/types/jsx-register.d.ts
rollup.dts.config.js

index 19b2ce51abec9658098c684fc8554bff0c458431..354cc4c5bf5c84e32621df506c98f971cea897dd 100644 (file)
@@ -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'
similarity index 99%
rename from packages/vue/jsx-runtime/dom.d.ts
rename to packages/runtime-dom/src/jsx.ts
index c4da2cdd08a8382692c0a6284eead30e0b3d292b..d103278c6e665adfced9ddefc623207d7b3c7070 100644 (file)
@@ -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
+}
index a05a7293da0d931ca068a56edfd4b84cc7d90c5c..a44382cfbb1347b85e95b076e6b8e9c935005115 100644 (file)
@@ -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
index 947a99044196086ccefe4a6923acd599d171f548..afc1039e46d5339dc7241575f15f72183b3a2f4b 100644 (file)
@@ -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 {
index af5d5f29023f50e7feb11ccefcef254217459a9b..a626f798c2abc9d4a571db276d67bbbd81cbbce1 100644 (file)
@@ -2,5 +2,3 @@
 // imports the global JSX namespace registration for compat.
 // TODO: remove in 3.4
 import '../jsx'
-
-export * from '../jsx-runtime/dom'
index 84a6138b44b6632fe13dda3b76907536455e07b0..ca811d349d59c654000393b6c225b54b5f20c0f8 100644 (file)
@@ -88,7 +88,21 @@ 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 (
@@ -96,10 +110,13 @@ function patchTypes(pkg) {
             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)