1+ import * as ts from 'typescript' ;
12import { Component , ConverterComponent } from 'typedoc/dist/lib/converter/components' ;
23import { Context } from 'typedoc/dist/lib/converter/context' ;
34import { Converter } from 'typedoc/dist/lib/converter/converter' ;
@@ -6,12 +7,9 @@ import { Comment, ProjectReflection } from 'typedoc/dist/lib/models';
67import { Reflection , ReflectionKind } from 'typedoc/dist/lib/models/reflections/abstract' ;
78import { ContainerReflection } from 'typedoc/dist/lib/models/reflections/container' ;
89import { DeclarationReflection } from 'typedoc/dist/lib/models/reflections/declaration' ;
10+ import { isTypedocVersion } from './typedocVersion' ;
911import { getRawComment } from './getRawComment' ;
1012
11- import { satisfies } from 'semver' ;
12- const version = require ( 'typedoc/package.json' ) . version ;
13- const useOldDeclarationReflectionConstructor = satisfies ( version , '< 0.14.0' ) ;
14-
1513/**
1614 * This plugin allows an ES6 module to specify its TypeDoc name.
1715 * It also allows multiple ES6 modules to be merged together into a single TypeDoc module.
@@ -79,7 +77,7 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
7977 this . moduleRenames . push ( {
8078 renameTo : match [ 1 ] ,
8179 preferred : preferred != null ,
82- symbolId : context . getSymbolID ( node . symbol ) ,
80+ symbol : node . symbol ,
8381 reflection : < ContainerReflection > reflection ,
8482 } ) ;
8583 }
@@ -116,8 +114,7 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
116114 for ( let i = 0 ; i < nameParts . length - 1 ; ++ i ) {
117115 let child : DeclarationReflection = parent . children . filter ( ref => ref . name === nameParts [ i ] ) [ 0 ] ;
118116 if ( ! child ) {
119- if ( useOldDeclarationReflectionConstructor ) {
120- // for typedoc < 0.15.0
117+ if ( isTypedocVersion ( '< 0.14.0' ) ) {
121118 child = new ( DeclarationReflection as any ) ( parent , nameParts [ i ] , ReflectionKind . ExternalModule ) ;
122119 } else {
123120 child = new DeclarationReflection ( nameParts [ i ] , ReflectionKind . ExternalModule , parent ) ;
@@ -147,11 +144,11 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
147144 }
148145 item . reflection . parent = parent ;
149146 parent . children . push ( < DeclarationReflection > renaming ) ;
150- updateSymbolMapping ( context . project , item . symbolId , parent . id ) ;
147+ updateSymbolMapping ( context , item . symbol , parent ) ;
151148 return ;
152149 }
153150
154- updateSymbolMapping ( context . project , item . symbolId , mergeTarget . id ) ;
151+ updateSymbolMapping ( context , item . symbol , mergeTarget ) ;
155152 if ( ! mergeTarget . children ) {
156153 mergeTarget . children = [ ] ;
157154 }
@@ -171,7 +168,7 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
171168 // Now that all the children have been relocated to the mergeTarget, delete the empty module
172169 // Make sure the module being renamed doesn't have children, or they will be deleted
173170 if ( renaming . children ) renaming . children . length = 0 ;
174- CommentPlugin . removeReflection ( context . project , renaming ) ;
171+ removeReflection ( context , renaming ) ;
175172
176173 // Remove @module and @preferred from the comment, if found.
177174 CommentPlugin . removeTags ( mergeTarget . comment , 'module' ) ;
@@ -183,13 +180,25 @@ export class ExternalModuleNamePlugin extends ConverterComponent {
183180 }
184181}
185182
183+ function removeReflection ( context : Context , reflection : Reflection ) {
184+ CommentPlugin . removeReflection ( context . project , reflection ) ;
185+ if ( isTypedocVersion ( '>=0.16.0 <0.17.0' ) ) {
186+ delete context . project . reflections [ reflection . id ] ;
187+ }
188+ }
189+
186190/**
187191 * When we delete reflections, update the symbol mapping in order to fix:
188192 * https://github.com/christopherthielen/typedoc-plugin-external-module-name/issues/313
189193 * https://github.com/christopherthielen/typedoc-plugin-external-module-name/issues/193
190194 */
191- function updateSymbolMapping ( project : ProjectReflection , symbolId : number , mappedReflectionId : number ) {
192- project . symbolMapping [ symbolId ] = mappedReflectionId ;
195+ function updateSymbolMapping ( context : Context , symbol : ts . Symbol , reflection : Reflection ) {
196+ if ( isTypedocVersion ( '< 0.16.0' ) ) {
197+ // (context as any).registerReflection(reflection, null, symbol);
198+ ( context . project as any ) . symbolMapping [ ( symbol as any ) . id ] = reflection . id ;
199+ } else {
200+ context . registerReflection ( reflection , symbol ) ;
201+ }
193202}
194203
195204function isEmptyComment ( comment : Comment ) {
@@ -199,6 +208,6 @@ function isEmptyComment(comment: Comment) {
199208interface ModuleRename {
200209 renameTo : string ;
201210 preferred : boolean ;
202- symbolId : number ;
211+ symbol : ts . Symbol ;
203212 reflection : ContainerReflection ;
204213}
0 commit comments