Skip to content

Commit d3ff003

Browse files
committed
Replace _getCanonicalReferenceName() workaround with new TSDoc API DeclarationReference.parseComponent()
1 parent dec3e00 commit d3ff003

14 files changed

Lines changed: 36 additions & 43 deletions

apps/api-extractor-model/src/mixins/ApiNameMixin.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.s
33

4-
import { DeclarationReference } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
54
import { ApiItem, IApiItemJson, IApiItemConstructor, IApiItemOptions } from '../items/ApiItem';
65
import { DeserializerContext } from '../model/DeserializerContext';
76

@@ -47,9 +46,6 @@ export interface ApiNameMixin extends ApiItem {
4746

4847
/** @override */
4948
serializeInto(jsonObject: Partial<IApiItemJson>): void;
50-
51-
/** @internal */
52-
_getCanonicalReferenceName(): string | DeclarationReference;
5349
}
5450

5551
/**
@@ -98,19 +94,6 @@ export function ApiNameMixin<TBaseClass extends IApiItemConstructor>(baseClass:
9894

9995
jsonObject.name = this.name;
10096
}
101-
102-
/** @internal */
103-
public _getCanonicalReferenceName(): string | DeclarationReference {
104-
const name: string = this.name;
105-
if (name[0] === '"') {
106-
return JSON.parse(name);
107-
}
108-
if (name[0] === '[') {
109-
// Unwrap the [] and parse the reference
110-
return DeclarationReference.parse(name.substr(1, name.length - 2));
111-
}
112-
return name;
113-
}
11497
}
11598

11699
return MixedClass;

apps/api-extractor-model/src/model/ApiClass.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { ApiDeclaredItem, IApiDeclaredItemOptions, IApiDeclaredItemJson } from '../items/ApiDeclaredItem';
77
import { ApiItemContainerMixin, IApiItemContainerMixinOptions } from '../mixins/ApiItemContainerMixin';
@@ -120,8 +120,9 @@ export class ApiClass extends ApiItemContainerMixin(ApiNameMixin(ApiTypeParamete
120120

121121
/** @beta @override */
122122
public buildCanonicalReference(): DeclarationReference {
123+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
123124
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
124-
.addNavigationStep(Navigation.Exports, this._getCanonicalReferenceName())
125+
.addNavigationStep(Navigation.Exports, nameComponent)
125126
.withMeaning(Meaning.Class);
126127
}
127128
}

apps/api-extractor-model/src/model/ApiEnum.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { ApiDeclaredItem, IApiDeclaredItemOptions } from '../items/ApiDeclaredItem';
77
import { ApiReleaseTagMixin, IApiReleaseTagMixinOptions } from '../mixins/ApiReleaseTagMixin';
@@ -75,8 +75,9 @@ export class ApiEnum extends ApiItemContainerMixin(ApiNameMixin(ApiReleaseTagMix
7575

7676
/** @beta @override */
7777
public buildCanonicalReference(): DeclarationReference {
78+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
7879
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
79-
.addNavigationStep(Navigation.Exports, this._getCanonicalReferenceName())
80+
.addNavigationStep(Navigation.Exports, nameComponent)
8081
.withMeaning(Meaning.Enum);
8182
}
8283
}

apps/api-extractor-model/src/model/ApiEnumMember.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { ApiDeclaredItem, IApiDeclaredItemOptions, IApiDeclaredItemJson } from '../items/ApiDeclaredItem';
77
import { ApiReleaseTagMixin, IApiReleaseTagMixinOptions } from '../mixins/ApiReleaseTagMixin';
@@ -90,8 +90,9 @@ export class ApiEnumMember extends ApiNameMixin(ApiReleaseTagMixin(ApiDeclaredIt
9090

9191
/** @beta @override */
9292
public buildCanonicalReference(): DeclarationReference {
93+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
9394
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
94-
.addNavigationStep(Navigation.Exports, this._getCanonicalReferenceName())
95+
.addNavigationStep(Navigation.Exports, nameComponent)
9596
.withMeaning(Meaning.Member);
9697
}
9798
}

apps/api-extractor-model/src/model/ApiFunction.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { IApiDeclaredItemOptions, ApiDeclaredItem } from '../items/ApiDeclaredItem';
77
import { IApiParameterListMixinOptions, ApiParameterListMixin } from '../mixins/ApiParameterListMixin';
@@ -67,8 +67,9 @@ export class ApiFunction extends ApiNameMixin(ApiTypeParameterListMixin(ApiParam
6767

6868
/** @beta @override */
6969
public buildCanonicalReference(): DeclarationReference {
70+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
7071
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
71-
.addNavigationStep(Navigation.Exports, this._getCanonicalReferenceName())
72+
.addNavigationStep(Navigation.Exports, nameComponent)
7273
.withMeaning(Meaning.Function)
7374
.withOverloadIndex(this.overloadIndex);
7475
}

apps/api-extractor-model/src/model/ApiInterface.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { ApiItemContainerMixin, IApiItemContainerMixinOptions, IApiItemContainerJson
77
} from '../mixins/ApiItemContainerMixin';
@@ -107,8 +107,9 @@ export class ApiInterface extends ApiItemContainerMixin(ApiNameMixin(ApiTypePara
107107

108108
/** @beta @override */
109109
public buildCanonicalReference(): DeclarationReference {
110+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
110111
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
111-
.addNavigationStep(Navigation.Exports, this._getCanonicalReferenceName())
112+
.addNavigationStep(Navigation.Exports, nameComponent)
112113
.withMeaning(Meaning.Interface);
113114
}
114115
}

apps/api-extractor-model/src/model/ApiMethod.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { ApiStaticMixin, IApiStaticMixinOptions } from '../mixins/ApiStaticMixin';
77
import { IApiDeclaredItemOptions, ApiDeclaredItem } from '../items/ApiDeclaredItem';
@@ -73,8 +73,9 @@ export class ApiMethod extends ApiNameMixin(ApiTypeParameterListMixin(ApiParamet
7373

7474
/** @beta @override */
7575
public buildCanonicalReference(): DeclarationReference {
76+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
7677
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
77-
.addNavigationStep(this.isStatic ? Navigation.Exports : Navigation.Members, this._getCanonicalReferenceName())
78+
.addNavigationStep(this.isStatic ? Navigation.Exports : Navigation.Members, nameComponent)
7879
.withMeaning(Meaning.Member)
7980
.withOverloadIndex(this.overloadIndex);
8081
}

apps/api-extractor-model/src/model/ApiMethodSignature.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { ApiDeclaredItem, IApiDeclaredItemOptions } from '../items/ApiDeclaredItem';
77
import { ApiParameterListMixin, IApiParameterListMixinOptions } from '../mixins/ApiParameterListMixin';
@@ -64,8 +64,9 @@ export class ApiMethodSignature extends ApiNameMixin(ApiTypeParameterListMixin(A
6464

6565
/** @beta @override */
6666
public buildCanonicalReference(): DeclarationReference {
67+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
6768
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
68-
.addNavigationStep(Navigation.Members, this._getCanonicalReferenceName())
69+
.addNavigationStep(Navigation.Members, nameComponent)
6970
.withMeaning(Meaning.Member)
7071
.withOverloadIndex(this.overloadIndex);
7172
}

apps/api-extractor-model/src/model/ApiNamespace.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { ApiItemContainerMixin, IApiItemContainerMixinOptions } from '../mixins/ApiItemContainerMixin';
77
import { IApiDeclaredItemOptions, ApiDeclaredItem } from '../items/ApiDeclaredItem';
@@ -63,8 +63,9 @@ export class ApiNamespace extends ApiItemContainerMixin(ApiNameMixin(ApiReleaseT
6363

6464
/** @beta @override */
6565
public buildCanonicalReference(): DeclarationReference {
66+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
6667
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
67-
.addNavigationStep(Navigation.Exports, this._getCanonicalReferenceName())
68+
.addNavigationStep(Navigation.Exports, nameComponent)
6869
.withMeaning(Meaning.Namespace);
6970
}
7071
}

apps/api-extractor-model/src/model/ApiProperty.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4-
import { DeclarationReference, Meaning, Navigation } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference, Meaning, Navigation, Component } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItemKind } from '../items/ApiItem';
66
import { ApiStaticMixin, IApiStaticMixinOptions } from '../mixins/ApiStaticMixin';
77
import { ApiPropertyItem, IApiPropertyItemOptions } from '../items/ApiPropertyItem';
@@ -74,8 +74,9 @@ export class ApiProperty extends ApiStaticMixin(ApiPropertyItem) {
7474

7575
/** @beta @override */
7676
public buildCanonicalReference(): DeclarationReference {
77+
const nameComponent: Component = DeclarationReference.parseComponent(this.name);
7778
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
78-
.addNavigationStep(this.isStatic ? Navigation.Exports : Navigation.Members, this._getCanonicalReferenceName())
79+
.addNavigationStep(this.isStatic ? Navigation.Exports : Navigation.Members, nameComponent)
7980
.withMeaning(Meaning.Member);
8081
}
8182
}

0 commit comments

Comments
 (0)