@@ -3,7 +3,6 @@ import { parse } from '@babel/parser'
33import { existsSync , readdirSync , readFileSync , writeFileSync } from 'fs'
44import MagicString from 'magic-string'
55import dts from 'rollup-plugin-dts'
6- import { walk } from 'estree-walker'
76
87if ( ! existsSync ( 'temp/packages' ) ) {
98 console . warn (
@@ -41,12 +40,11 @@ export default targetPackages.map(pkg => {
4140
4241/**
4342 * Patch the dts generated by rollup-plugin-dts
44- * 1. remove exports marked as @internal
45- * 2. Convert all types to inline exports
43+ * 1. Convert all types to inline exports
4644 * and remove them from the big export {} declaration
4745 * otherwise it gets weird in vitepress `defineComponent` call with
4846 * "the inferred type cannot be named without a reference"
49- * 3 . Append custom augmentations (jsx, macros)
47+ * 2 . Append custom augmentations (jsx, macros)
5048 * @returns {import('rollup').Plugin }
5149 */
5250function patchTypes ( pkg ) {
@@ -73,64 +71,12 @@ function patchTypes(pkg) {
7371 return
7472 }
7573 shouldRemoveExport . add ( name )
76- if ( ! removeInternal ( parentDecl || node ) ) {
77- if ( isExported . has ( name ) ) {
78- // @ts -ignore
79- s . prependLeft ( ( parentDecl || node ) . start , `export ` )
80- }
81- // traverse further for internal properties
82- if (
83- node . type === 'TSInterfaceDeclaration' ||
84- node . type === 'ClassDeclaration'
85- ) {
86- node . body . body . forEach ( removeInternal )
87- } else if ( node . type === 'TSTypeAliasDeclaration' ) {
88- // @ts -ignore
89- walk ( node . typeAnnotation , {
90- enter ( node ) {
91- // @ts -ignore
92- if ( removeInternal ( node ) ) this . skip ( )
93- }
94- } )
95- }
74+ if ( isExported . has ( name ) ) {
75+ // @ts -ignore
76+ s . prependLeft ( ( parentDecl || node ) . start , `export ` )
9677 }
9778 }
9879
99- /**
100- * @param {import('@babel/types').Node } node
101- * @returns {boolean }
102- */
103- function removeInternal ( node ) {
104- if (
105- node . leadingComments &&
106- node . leadingComments . some ( c => {
107- return c . type === 'CommentBlock' && / @ i n t e r n a l \b / . test ( c . value )
108- } )
109- ) {
110- /** @type {any } */
111- const n = node
112- let id
113- if ( n . id && n . id . type === 'Identifier' ) {
114- id = n . id . name
115- } else if ( n . key && n . key . type === 'Identifier' ) {
116- id = n . key . name
117- }
118- if ( id ) {
119- s . overwrite (
120- // @ts -ignore
121- node . leadingComments [ 0 ] . start ,
122- node . end ,
123- `/* removed internal: ${ id } */`
124- )
125- } else {
126- // @ts -ignore
127- s . remove ( node . leadingComments [ 0 ] . start , node . end )
128- }
129- return true
130- }
131- return false
132- }
133-
13480 const isExported = new Set ( )
13581 const shouldRemoveExport = new Set ( )
13682
@@ -146,7 +92,7 @@ function patchTypes(pkg) {
14692 }
14793 }
14894
149- // pass 1: remove internals + add exports
95+ // pass 1: add exports
15096 for ( const node of ast . program . body ) {
15197 if ( node . type === 'VariableDeclaration' ) {
15298 processDeclaration ( node . declarations [ 0 ] , node )
@@ -167,10 +113,6 @@ function patchTypes(pkg) {
167113 node . type === 'ClassDeclaration'
168114 ) {
169115 processDeclaration ( node )
170- } else if ( removeInternal ( node ) ) {
171- throw new Error (
172- `unhandled export type marked as @internal: ${ node . type } `
173- )
174116 }
175117 }
176118
@@ -213,12 +155,6 @@ function patchTypes(pkg) {
213155 }
214156 code = s . toString ( )
215157
216- if ( / @ i n t e r n a l / . test ( code ) ) {
217- throw new Error (
218- `unhandled @internal declarations detected in ${ chunk . fileName } .`
219- )
220- }
221-
222158 // append pkg specific types
223159 const additionalTypeDir = `packages/${ pkg } /types`
224160 if ( existsSync ( additionalTypeDir ) ) {
0 commit comments