Skip to content

Commit a5783f3

Browse files
authored
Merge pull request #3630 from sranka/3629/fix
[api-extractor] fix references from computed properties
2 parents 785143c + 8545224 commit a5783f3

File tree

6 files changed

+173
-0
lines changed

6 files changed

+173
-0
lines changed

apps/api-extractor/src/generators/DeclarationReferenceGenerator.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class DeclarationReferenceGenerator {
6060
private static _isInExpressionContext(node: ts.Node): boolean {
6161
switch (node.parent.kind) {
6262
case ts.SyntaxKind.TypeQuery:
63+
case ts.SyntaxKind.ComputedPropertyName:
6364
return true;
6465
case ts.SyntaxKind.QualifiedName:
6566
return DeclarationReferenceGenerator._isInExpressionContext(node.parent);

build-tests/api-extractor-scenarios/etc/referenceTokens/api-extractor-scenarios.api.json

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,42 @@
791791
"name": "SomeInterface1",
792792
"preserveMemberOrder": false,
793793
"members": [
794+
{
795+
"kind": "PropertySignature",
796+
"canonicalReference": "api-extractor-scenarios!SomeInterface1#[SomeSymbol1]:member",
797+
"docComment": "",
798+
"excerptTokens": [
799+
{
800+
"kind": "Content",
801+
"text": "["
802+
},
803+
{
804+
"kind": "Reference",
805+
"text": "SomeSymbol1",
806+
"canonicalReference": "api-extractor-scenarios!SomeSymbol1:var"
807+
},
808+
{
809+
"kind": "Content",
810+
"text": "]: "
811+
},
812+
{
813+
"kind": "Content",
814+
"text": "() => string"
815+
},
816+
{
817+
"kind": "Content",
818+
"text": ";"
819+
}
820+
],
821+
"isReadonly": false,
822+
"isOptional": false,
823+
"releaseTag": "Public",
824+
"name": "[SomeSymbol1]",
825+
"propertyTypeTokenRange": {
826+
"startIndex": 3,
827+
"endIndex": 4
828+
}
829+
},
794830
{
795831
"kind": "PropertySignature",
796832
"canonicalReference": "api-extractor-scenarios!SomeInterface1#prop:member",
@@ -817,9 +853,93 @@
817853
"startIndex": 1,
818854
"endIndex": 2
819855
}
856+
},
857+
{
858+
"kind": "PropertySignature",
859+
"canonicalReference": "api-extractor-scenarios!SomeInterface1#ThisIsSomeVar1:member",
860+
"docComment": "",
861+
"excerptTokens": [
862+
{
863+
"kind": "Content",
864+
"text": "["
865+
},
866+
{
867+
"kind": "Reference",
868+
"text": "SomeVar1",
869+
"canonicalReference": "api-extractor-scenarios!SomeVar1:var"
870+
},
871+
{
872+
"kind": "Content",
873+
"text": "]: "
874+
},
875+
{
876+
"kind": "Content",
877+
"text": "() => string"
878+
},
879+
{
880+
"kind": "Content",
881+
"text": ";"
882+
}
883+
],
884+
"isReadonly": false,
885+
"isOptional": false,
886+
"releaseTag": "Public",
887+
"name": "ThisIsSomeVar1",
888+
"propertyTypeTokenRange": {
889+
"startIndex": 3,
890+
"endIndex": 4
891+
}
820892
}
821893
],
822894
"extendsTokenRanges": []
895+
},
896+
{
897+
"kind": "Variable",
898+
"canonicalReference": "api-extractor-scenarios!SomeSymbol1:var",
899+
"docComment": "/**\n * @public\n */\n",
900+
"excerptTokens": [
901+
{
902+
"kind": "Content",
903+
"text": "SomeSymbol1: "
904+
},
905+
{
906+
"kind": "Content",
907+
"text": "unique symbol"
908+
}
909+
],
910+
"isReadonly": true,
911+
"releaseTag": "Public",
912+
"name": "SomeSymbol1",
913+
"variableTypeTokenRange": {
914+
"startIndex": 1,
915+
"endIndex": 2
916+
}
917+
},
918+
{
919+
"kind": "Variable",
920+
"canonicalReference": "api-extractor-scenarios!SomeVar1:var",
921+
"docComment": "/**\n * @public\n */\n",
922+
"excerptTokens": [
923+
{
924+
"kind": "Content",
925+
"text": "SomeVar1 = "
926+
},
927+
{
928+
"kind": "Content",
929+
"text": "\"ThisIsSomeVar1\""
930+
}
931+
],
932+
"initializerTokenRange": {
933+
"startIndex": 1,
934+
"endIndex": 2
935+
},
936+
"isReadonly": true,
937+
"releaseTag": "Public",
938+
"name": "SomeVar1",
939+
"variableTypeTokenRange": {
940+
"startIndex": 0,
941+
"endIndex": 0
942+
}
823943
}
824944
]
825945
}

build-tests/api-extractor-scenarios/etc/referenceTokens/api-extractor-scenarios.api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ export interface SomeInterface1 {
7979
prop: number;
8080
}
8181

82+
// @public
83+
export interface SomeInterface1 {
84+
// (undocumented)
85+
[SomeSymbol1]: () => string;
86+
// (undocumented)
87+
[SomeVar1]: () => string;
88+
}
89+
90+
// @public (undocumented)
91+
export const SomeSymbol1: unique symbol;
92+
93+
// @public (undocumented)
94+
export const SomeVar1 = "ThisIsSomeVar1";
95+
8296
// (No @packageDocumentation comment for this package)
8397

8498
```

build-tests/api-extractor-scenarios/etc/referenceTokens/rollup.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,19 @@ export declare interface SomeInterface1 {
8686
prop: number;
8787
}
8888

89+
/**
90+
* References to computed properties.
91+
* @public
92+
*/
93+
export declare interface SomeInterface1 {
94+
[SomeVar1]: () => string;
95+
[SomeSymbol1]: () => string;
96+
}
97+
98+
/** @public */
99+
export declare const SomeSymbol1: unique symbol;
100+
101+
/** @public */
102+
export declare const SomeVar1 = "ThisIsSomeVar1";
103+
89104
export { }

build-tests/api-extractor-scenarios/src/referenceTokens/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,16 @@ export function someFunction8({ prop: prop2 }: Lib2Class): void {}
102102
* @public
103103
*/
104104
export class SomeClass4 extends SomeClass5 {}
105+
106+
/** @public */
107+
export const SomeSymbol1 = Symbol('ThisIsSomeSymbol1');
108+
/** @public */
109+
export const SomeVar1 = 'ThisIsSomeVar1';
110+
/**
111+
* References to computed properties.
112+
* @public
113+
*/
114+
export interface SomeInterface1 {
115+
[SomeVar1]: () => string;
116+
[SomeSymbol1]: () => string;
117+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/api-extractor",
5+
"comment": "Fix references from computed properties #3629",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft/api-extractor"
10+
}

0 commit comments

Comments
 (0)