Skip to content

Commit 3889972

Browse files
committed
Update to use new TSDoc API
1 parent 6da8406 commit 3889972

6 files changed

Lines changed: 21 additions & 24 deletions

File tree

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

Lines changed: 10 additions & 9 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.s
33

4-
import { StringChecks } from '@microsoft/tsdoc/lib/parser/StringChecks';
4+
import { DeclarationReference } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItem, IApiItemJson, IApiItemConstructor, IApiItemOptions } from '../items/ApiItem';
66
import { DeserializerContext } from '../model/DeserializerContext';
77

@@ -49,7 +49,7 @@ export interface ApiNameMixin extends ApiItem {
4949
serializeInto(jsonObject: Partial<IApiItemJson>): void;
5050

5151
/** @internal */
52-
_getCanonicalReferenceName(): string;
52+
_getCanonicalReferenceName(): string | DeclarationReference;
5353
}
5454

5555
/**
@@ -100,14 +100,15 @@ export function ApiNameMixin<TBaseClass extends IApiItemConstructor>(baseClass:
100100
}
101101

102102
/** @internal */
103-
public _getCanonicalReferenceName(): string {
104-
// TODO: This is a temporary workaround for a limitation of the experimental DeclarationReference API.
105-
// We will remove this when the final implementation is in place.
106-
if (StringChecks.explainIfInvalidUnquotedIdentifier(this.name)) {
107-
return JSON.stringify(this.name);
108-
} else {
109-
return this.name;
103+
public _getCanonicalReferenceName(): string | DeclarationReference {
104+
const name: string = this.name;
105+
if (name[0] === '"') {
106+
return JSON.parse(name);
110107
}
108+
if (name[0] === '[') {
109+
return DeclarationReference.parse(name);
110+
}
111+
return name;
111112
}
112113
}
113114

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export class ApiClass extends ApiItemContainerMixin(ApiNameMixin(ApiTypeParamete
121121
/** @beta @override */
122122
public buildCanonicalReference(): DeclarationReference {
123123
return (this.parent ? this.parent.canonicalReference : DeclarationReference.empty())
124-
.addNavigationStep(Navigation.Exports, this.name)
124+
.addNavigationStep(Navigation.Exports, this._getCanonicalReferenceName())
125125
.withMeaning(Meaning.Class);
126126
}
127127
}

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

Lines changed: 2 additions & 11 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, ModuleSource } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItem, ApiItemKind } from '../items/ApiItem';
66
import { ApiItemContainerMixin, IApiItemContainerMixinOptions } from '../mixins/ApiItemContainerMixin';
77
import { IApiNameMixinOptions, ApiNameMixin } from '../mixins/ApiNameMixin';
@@ -56,18 +56,9 @@ export class ApiEntryPoint extends ApiItemContainerMixin(ApiNameMixin(ApiItem))
5656

5757
/** @beta @override */
5858
public buildCanonicalReference(): DeclarationReference {
59-
let modulePath: string = '';
6059

6160
if (this.parent instanceof ApiPackage) {
62-
modulePath = this.parent.name;
63-
}
64-
65-
if (this.name) {
66-
modulePath += this.name;
67-
}
68-
69-
if (modulePath) {
70-
return new DeclarationReference(new ModuleSource(modulePath));
61+
return DeclarationReference.package(this.parent.name, this.name);
7162
}
7263

7364
return DeclarationReference.empty();

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

Lines changed: 2 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, ModuleSource } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
4+
import { DeclarationReference } from '@microsoft/tsdoc/lib/beta/DeclarationReference';
55
import { ApiItem, ApiItemKind, IApiItemJson } from '../items/ApiItem';
66
import { ApiItemContainerMixin, IApiItemContainerMixinOptions } from '../mixins/ApiItemContainerMixin';
77
import { JsonFile, IJsonFileSaveOptions, PackageJsonLookup, IPackageJson } from '@microsoft/node-core-library';
@@ -207,6 +207,6 @@ export class ApiPackage extends ApiItemContainerMixin(ApiNameMixin(ApiDocumented
207207

208208
/** @beta @override */
209209
public buildCanonicalReference(): DeclarationReference {
210-
return DeclarationReference.module(this.name);
210+
return DeclarationReference.package(this.name);
211211
}
212212
}

build-tests/api-documenter-test/etc/api-documenter-test.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,7 @@
689689
},
690690
{
691691
"kind": "Namespace",
692+
"canonicalReference": "api-documenter-test!EcmaSmbols:namespace",
692693
"docComment": "/**\n * A namespace containing an ECMAScript symbol\n *\n * @public\n */\n",
693694
"excerptTokens": [
694695
{
@@ -709,6 +710,7 @@
709710
"members": [
710711
{
711712
"kind": "Variable",
713+
"canonicalReference": "api-documenter-test!EcmaSmbols.example:var",
712714
"docComment": "/**\n * An ECMAScript symbol\n */\n",
713715
"excerptTokens": [
714716
{
@@ -1017,6 +1019,7 @@
10171019
"members": [
10181020
{
10191021
"kind": "PropertySignature",
1022+
"canonicalReference": "api-documenter-test!IDocInterface3#\"[not.a.symbol]\":member",
10201023
"docComment": "/**\n * An identifier that does needs quotes. It misleadingly looks like an ECMAScript symbol.\n */\n",
10211024
"excerptTokens": [
10221025
{
@@ -1041,6 +1044,7 @@
10411044
},
10421045
{
10431046
"kind": "PropertySignature",
1047+
"canonicalReference": "api-documenter-test!IDocInterface3#[[EcmaSmbols.example]]:member",
10441048
"docComment": "/**\n * ECMAScript symbol\n */\n",
10451049
"excerptTokens": [
10461050
{
@@ -1207,6 +1211,7 @@
12071211
},
12081212
{
12091213
"kind": "PropertySignature",
1214+
"canonicalReference": "api-documenter-test!IDocInterface3#redundantQuotes:member",
12101215
"docComment": "/**\n * A quoted identifier with redundant quotes.\n */\n",
12111216
"excerptTokens": [
12121217
{

common/reviews/api/api-extractor-model.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ export function ApiNameMixin<TBaseClass extends IApiItemConstructor>(baseClass:
382382
// @public
383383
export interface ApiNameMixin extends ApiItem {
384384
// @internal (undocumented)
385-
_getCanonicalReferenceName(): string;
385+
_getCanonicalReferenceName(): string | DeclarationReference;
386386
readonly name: string;
387387
// @override (undocumented)
388388
serializeInto(jsonObject: Partial<IApiItemJson>): void;

0 commit comments

Comments
 (0)