@@ -83,10 +83,6 @@ export function createFakeJsPlugin({
8383} : Pick < OptionsResolved , 'sourcemap' | 'cjsDefault' | 'sideEffects' > ) : Plugin {
8484 let declarationIdx = 0
8585 const declarationMap = new Map < number /* declaration id */ , DeclarationInfo > ( )
86- const moduleDeclarationsMap = new Map <
87- string /* filename */ ,
88- number [ ] /* declaration ids */
89- > ( )
9086 const commentsMap = new Map < string /* filename */ , t . Comment [ ] > ( )
9187 const fileCommentsMap = new Map < string /* filename */ , t . Comment [ ] > ( )
9288 const moduleExportsMap = new Map < string /* filename */ , ModuleExports > ( )
@@ -95,6 +91,16 @@ export function createFakeJsPlugin({
9591 return {
9692 name : 'rolldown-plugin-dts:fake-js' ,
9793
94+ buildStart ( ) {
95+ // The plugin instance lives across watch rebuilds, which transform every
96+ // module again, so the previous build's state is never used again.
97+ // Rolldown's dev engine reuses cached transforms and is not supported.
98+ declarationMap . clear ( )
99+ moduleExportsMap . clear ( )
100+ commentsMap . clear ( )
101+ fileCommentsMap . clear ( )
102+ } ,
103+
98104 outputOptions ( options ) {
99105 if ( options . format === 'cjs' || options . format === 'commonjs' ) {
100106 throw new Error (
@@ -195,11 +201,6 @@ export function createFakeJsPlugin({
195201 )
196202 }
197203
198- // A watch rebuild transforms changed modules again, so drop what the
199- // previous transform stored. Unchanged modules may keep their cached
200- // output with incremental builds, so their state must stay.
201- clearModuleState ( id )
202-
203204 const { program } = file
204205 moduleExportsMap . set ( id , await collectModuleExports ( this , program . body , id ) )
205206 const identifierMap : Record < string , number > = Object . create ( null )
@@ -341,7 +342,7 @@ export function createFakeJsPlugin({
341342 decl . comments = stmt . comments
342343 }
343344
344- const declarationId = registerDeclaration ( id , {
345+ const declarationId = registerDeclaration ( {
345346 decl,
346347 deps,
347348 bindings,
@@ -700,27 +701,12 @@ export function createFakeJsPlugin({
700701 }
701702 }
702703
703- function registerDeclaration ( id : string , info : DeclarationInfo ) {
704+ function registerDeclaration ( info : DeclarationInfo ) {
704705 const declarationId = declarationIdx ++
705706 declarationMap . set ( declarationId , info )
706-
707- let ids = moduleDeclarationsMap . get ( id )
708- if ( ! ids ) moduleDeclarationsMap . set ( id , ( ids = [ ] ) )
709- ids . push ( declarationId )
710-
711707 return declarationId
712708 }
713709
714- function clearModuleState ( id : string ) {
715- for ( const declarationId of moduleDeclarationsMap . get ( id ) || [ ] ) {
716- declarationMap . delete ( declarationId )
717- }
718- moduleDeclarationsMap . delete ( id )
719- moduleExportsMap . delete ( id )
720- commentsMap . delete ( id )
721- fileCommentsMap . delete ( id )
722- }
723-
724710 function getDeclaration ( declarationId : number ) {
725711 return declarationMap . get ( declarationId ) !
726712 }
0 commit comments