@@ -19,32 +19,44 @@ export class FileRegistry {
1919 protected names = new Map < number , string > ( ) ;
2020 protected nameUsage = new Map < string , number > ( ) ;
2121
22- registerAbsolute ( absolute : string ) {
22+ registerAbsolute ( absolute : string ) : {
23+ target : number ;
24+ anchor : string | undefined ;
25+ } {
26+ const anchorIndex = absolute . indexOf ( "#" ) ;
27+ let anchor : string | undefined = undefined ;
28+ if ( anchorIndex !== - 1 ) {
29+ anchor = absolute . substring ( anchorIndex + 1 ) ;
30+ absolute = absolute . substring ( 0 , anchorIndex ) ;
31+ }
2332 absolute = normalizePath ( absolute ) . replace ( / # .* / , "" ) ;
2433 const existing = this . pathToMedia . get ( absolute ) ;
2534 if ( existing ) {
26- return existing ;
35+ return { target : existing , anchor } ;
2736 }
2837
2938 this . mediaToPath . set ( this . nextId , absolute ) ;
3039 this . pathToMedia . set ( absolute , this . nextId ) ;
3140
32- return this . nextId ++ ;
41+ return { target : this . nextId ++ , anchor } ;
3342 }
3443
3544 /** Called by {@link ProjectReflection.registerReflection} @internal */
3645 registerReflection ( absolute : string , reflection : Reflection ) {
3746 absolute = normalizePath ( absolute ) ;
38- const id = this . registerAbsolute ( absolute ) ;
47+ const { target } = this . registerAbsolute ( absolute ) ;
3948 this . reflectionToPath . set ( reflection . id , absolute ) ;
40- this . mediaToReflection . set ( id , reflection . id ) ;
49+ this . mediaToReflection . set ( target , reflection . id ) ;
4150 }
4251
4352 getReflectionPath ( reflection : Reflection ) : string | undefined {
4453 return this . reflectionToPath . get ( reflection . id ) ;
4554 }
4655
47- register ( sourcePath : string , relativePath : string ) : number | undefined {
56+ register (
57+ sourcePath : string ,
58+ relativePath : string ,
59+ ) : { target : number ; anchor : string | undefined } | undefined {
4860 return this . registerAbsolute (
4961 resolve ( dirname ( sourcePath ) , relativePath ) ,
5062 ) ;
@@ -131,7 +143,8 @@ export class FileRegistry {
131143 fromObject ( de : Deserializer , obj : JSONFileRegistry ) : void {
132144 for ( const [ key , val ] of Object . entries ( obj . entries ) ) {
133145 const absolute = normalizePath ( resolve ( de . projectRoot , val ) ) ;
134- de . oldFileIdToNewFileId [ + key ] = this . registerAbsolute ( absolute ) ;
146+ de . oldFileIdToNewFileId [ + key ] =
147+ this . registerAbsolute ( absolute ) . target ;
135148 }
136149
137150 de . defer ( ( project ) => {
@@ -154,12 +167,10 @@ export class ValidatingFileRegistry extends FileRegistry {
154167 override register (
155168 sourcePath : string ,
156169 relativePath : string ,
157- ) : number | undefined {
158- const absolute = resolve ( dirname ( sourcePath ) , relativePath ) . replace (
159- / # .* / ,
160- "" ,
161- ) ;
162- if ( ! isFile ( absolute ) ) {
170+ ) : { target : number ; anchor : string | undefined } | undefined {
171+ const absolute = resolve ( dirname ( sourcePath ) , relativePath ) ;
172+ const absoluteWithoutAnchor = absolute . replace ( / # .* / , "" ) ;
173+ if ( ! isFile ( absoluteWithoutAnchor ) ) {
163174 return ;
164175 }
165176 return this . registerAbsolute ( absolute ) ;
@@ -178,7 +189,8 @@ export class ValidatingFileRegistry extends FileRegistry {
178189 continue ;
179190 }
180191
181- de . oldFileIdToNewFileId [ + key ] = this . registerAbsolute ( absolute ) ;
192+ de . oldFileIdToNewFileId [ + key ] =
193+ this . registerAbsolute ( absolute ) . target ;
182194 }
183195
184196 de . defer ( ( project ) => {
0 commit comments