@@ -30,6 +30,7 @@ interface ScriptRoutingState {
3030
3131export class InlineScriptRoutingRegistry implements Disposable {
3232 private readonly states = new Map < string , ScriptRoutingState > ( ) ;
33+ private readonly metadataRevisions = new Map < string , number > ( ) ;
3334 private readonly _onDidChangeRouteability = new EventEmitter < InlineScriptRouteabilityChangeEvent > ( ) ;
3435 private readonly _onDidChangeMetadata = new EventEmitter < InlineScriptMetadataChangeEvent > ( ) ;
3536
@@ -44,16 +45,16 @@ export class InlineScriptRoutingRegistry implements Disposable {
4445 return ;
4546 }
4647 const metadataIdentity = getInlineScriptMetadataRoutingIdentity ( metadata ) ;
48+ const metadataRevision = this . nextMetadataRevision ( scriptPath ) ;
4749 this . update (
4850 scriptPath ,
4951 ( state ) => {
50- const currentRevision = state ?. metadataRevision ?? 0 ;
5152 return {
5253 ...state ,
5354 uri,
5455 metadata,
5556 metadataIdentity,
56- metadataRevision : currentRevision + 1 ,
57+ metadataRevision,
5758 } ;
5859 } ,
5960 true ,
@@ -65,16 +66,16 @@ export class InlineScriptRoutingRegistry implements Disposable {
6566 if ( ! scriptPath ) {
6667 return ;
6768 }
69+ const metadataRevision = this . nextMetadataRevision ( scriptPath ) ;
6870 this . update (
6971 scriptPath ,
7072 ( state ) => {
71- const currentRevision = state ?. metadataRevision ?? 0 ;
7273 return {
7374 ...state ,
7475 uri,
7576 metadata : undefined ,
7677 metadataIdentity : undefined ,
77- metadataRevision : currentRevision + 1 ,
78+ metadataRevision,
7879 } ;
7980 } ,
8081 true ,
@@ -93,7 +94,7 @@ export class InlineScriptRoutingRegistry implements Disposable {
9394
9495 public getMetadataRevision ( script : Uri | string ) : number {
9596 const scriptPath = getInlineScriptRoutingKey ( script ) ;
96- return scriptPath ? ( this . states . get ( scriptPath ) ?. metadataRevision ?? 0 ) : 0 ;
97+ return scriptPath ? ( this . metadataRevisions . get ( scriptPath ) ?? 0 ) : 0 ;
9798 }
9899
99100 public getUri ( script : Uri | string ) : Uri | undefined {
@@ -125,6 +126,7 @@ export class InlineScriptRoutingRegistry implements Disposable {
125126
126127 public dispose ( ) : void {
127128 this . states . clear ( ) ;
129+ this . metadataRevisions . clear ( ) ;
128130 this . _onDidChangeMetadata . dispose ( ) ;
129131 this . _onDidChangeRouteability . dispose ( ) ;
130132 }
@@ -134,7 +136,10 @@ export class InlineScriptRoutingRegistry implements Disposable {
134136 updater : ( state : ScriptRoutingState ) => ScriptRoutingState ,
135137 fireMetadataChange : boolean = false ,
136138 ) : void {
137- const previous = this . states . get ( scriptPath ) ?? { metadataRevision : 0 , validatedAssociation : false } ;
139+ const previous = this . states . get ( scriptPath ) ?? {
140+ metadataRevision : this . metadataRevisions . get ( scriptPath ) ?? 0 ,
141+ validatedAssociation : false ,
142+ } ;
138143 const previousRouteable = this . isRouteable ( previous ) ;
139144 const next = updater ( previous ) ;
140145
@@ -166,6 +171,12 @@ export class InlineScriptRoutingRegistry implements Disposable {
166171 private isRouteable ( state : ScriptRoutingState | undefined ) : boolean {
167172 return ! ! state ?. metadata && state . validatedAssociation ;
168173 }
174+
175+ private nextMetadataRevision ( scriptPath : string ) : number {
176+ const revision = ( this . metadataRevisions . get ( scriptPath ) ?? 0 ) + 1 ;
177+ this . metadataRevisions . set ( scriptPath , revision ) ;
178+ return revision ;
179+ }
169180}
170181
171182export function getInlineScriptRoutingKey ( script : Uri | string ) : string | undefined {
0 commit comments