Skip to content

Commit

Permalink
added additional test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
danay1999 committed Aug 11, 2022
1 parent 868ef27 commit ecfbf8b
Show file tree
Hide file tree
Showing 16 changed files with 9,003 additions and 83 deletions.
8,853 changes: 8,840 additions & 13 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/compiler/checker.ts
Expand Up @@ -42215,16 +42215,14 @@ namespace ts {

if (name.kind === SyntaxKind.PropertyAccessExpression) {
checkPropertyAccessExpression(name, CheckMode.Normal);
if(!links.resolvedSymbol){
if (!links.resolvedSymbol) {
const expressionType = checkExpressionCached(name.expression);
let infos = getApplicableIndexInfos(expressionType, getLiteralTypeFromPropertyName(name.name));
if(infos.length === 0 && getIndexInfosOfType(expressionType).filter(type => type.keyType.flags & TypeFlags.TemplateLiteral || type.keyType.flags & TypeFlags.ESSymbol).length > 0){
infos = getApplicableIndexInfos(expressionType, checkExpressionCached(name.name));
}
const infos = getApplicableIndexInfos(expressionType, getLiteralTypeFromPropertyName(name.name));
if (length(infos) && infos[0].declaration && infos[0].declaration?.symbol.flags & SymbolFlags.Signature && infos[0].declaration?.jsDoc) {
const copy = createSymbol(SymbolFlags.Signature, InternalSymbolName.Index);
copy.declarations = mapDefined(infos, i => i.declaration);
copy.parent = expressionType.symbol ? expressionType.symbol : getSymbolAtLocation(copy.declarations[0].parent);
copy.parent = expressionType.aliasSymbol ? expressionType.aliasSymbol : expressionType.symbol ? expressionType.symbol : getSymbolAtLocation(copy.declarations[0].parent);
links.resolvedSymbol = copy;
return copy;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/services/symbolDisplay.ts
Expand Up @@ -653,18 +653,18 @@ namespace ts.SymbolDisplay {
symbolToDisplay = alias;
}
const fullSymbolDisplayParts = symbolToDisplayParts(typeChecker, symbolToDisplay, enclosingDeclaration || sourceFile, /*meaning*/ undefined,
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing | SymbolFormatFlags.AllowAnyNodeKind);
if(symbolToDisplay.flags & SymbolFlags.Signature){
if(indexInfos){
SymbolFormatFlags.WriteTypeParametersOrArguments | SymbolFormatFlags.UseOnlyExternalAliasing | SymbolFormatFlags.AllowAnyNodeKind);
if (symbolToDisplay.flags & SymbolFlags.Signature) {
if (indexInfos) {
let index = 1;
fullSymbolDisplayParts[index++] = punctuationPart(SyntaxKind.OpenBracketToken);
if(length(indexInfos)){
if (length(indexInfos)) {
//Needed to handle more than one type of index
for(let info=0; info<indexInfos.length; info++){
for (let info = 0; info < indexInfos.length; info++) {
const indexTypeDisplayParts = typeToDisplayParts(typeChecker, indexInfos[info].keyType);
//Needed to handle template literals
for (const part of indexTypeDisplayParts) fullSymbolDisplayParts[index++] = part;
if(info !== indexInfos.length-1){
if (info !== indexInfos.length - 1) {
fullSymbolDisplayParts[index++] = spacePart();
fullSymbolDisplayParts[index++] = punctuationPart(SyntaxKind.BarToken);
fullSymbolDisplayParts[index++] = spacePart();
Expand All @@ -673,8 +673,8 @@ namespace ts.SymbolDisplay {
fullSymbolDisplayParts[index] = punctuationPart(SyntaxKind.CloseBracketToken);
}
}
else{
fullSymbolDisplayParts[2] = textOrKeywordPart(TypeFlags[`1`]); //This is the fallback in case else fails
else {
fullSymbolDisplayParts[2] = textOrKeywordPart("Any"); //This is the fallback in case else fails
}
}
addRange(displayParts, fullSymbolDisplayParts);
Expand Down
15 changes: 15 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription1.ts
@@ -0,0 +1,15 @@
///<reference path="fourslash.ts" />

//// interface StringExample {
//// /** Something generic */
//// [p: string]: any;
//// /** Something specific */
//// property: number;
//// }
//// function stringExample(e: StringExample) {
//// console.log(e./*property*/property);
//// console.log(e./*string*/anything);
//// }

verify.quickInfoAt("property", "(property) StringExample.property: number", 'Something specific');
verify.quickInfoAt("string", "(index) StringExample[string]: any", "Something generic");
11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription10.ts
@@ -0,0 +1,11 @@
///<reference path="fourslash.ts" />

//// class MultipleClass {
//// /** Something generic */
//// [key: number | symbol | `data-${string}` | `data-${number}`]: string;
//// }
//// function multipleClass(e: typeof MultipleClass) {
//// console.log(e./*multipleClass*/anything);
//// }

verify.quickInfoAt("multipleClass", "any");
12 changes: 12 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription11.ts
@@ -0,0 +1,12 @@
///<reference path="fourslash.ts" />

//// type AliasExample = {
//// /** Something generic */
//// [p: string]: string;
//// [key: `any${string}`]: string; //TODOFIX add JSDoc here
//// }
//// function aliasExample(e: AliasExample) {
//// console.log(e./*alias*/anything);
//// }

verify.quickInfoAt("alias", "(index) AliasExample[string | `any${string}`]: string", "Something generic");
11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription12.ts
@@ -0,0 +1,11 @@
///<reference path="fourslash.ts" />

//// type SymbolAlias = {
//// /** Something generic */
//// [p: symbol]: string;
//// }
//// function symbolAlias(e: SymbolAlias) {
//// console.log(e./*symbolAlias*/anything);
//// }

verify.quickInfoAt("symbolAlias", "any");
11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription2.ts
@@ -0,0 +1,11 @@
///<reference path="fourslash.ts" />

//// interface SymbolExample {
//// /** Something generic */
//// [key: symbol]: string;
//// }
//// function symbolExample(e: SymbolExample) {
//// console.log(e./*symbol*/anything);
//// }

verify.quickInfoAt("symbol", "any")
13 changes: 13 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription3.ts
@@ -0,0 +1,13 @@
///<reference path="fourslash.ts" />

//// interface LiteralExample {
//// /** Something generic */
//// [key: `data-${string}`]: string;
//// /** Something else */
//// [key: `prefix${number}`]: number;
//// }
//// function literalExample(e: LiteralExample) {
//// console.log(e./*literal*/anything);
//// }

verify.quickInfoAt("literal", "any");
11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription4.ts
@@ -0,0 +1,11 @@
///<reference path="fourslash.ts" />

//// interface MultipleExample {
//// /** Something generic */
//// [key: string | number | symbol]: string;
//// }
//// function multipleExample(e: MultipleExample) {
//// console.log(e./*multiple*/anything);
//// }

verify.quickInfoAt("multiple", "(index) MultipleExample[string | number | symbol]: string", "Something generic");
11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription5.ts
@@ -0,0 +1,11 @@
///<reference path="fourslash.ts" />

//// interface Multiple1Example {
//// /** Something generic */
//// [key: number | symbol | `data-${string}` | `data-${number}`]: string;
//// }
//// function multiple1Example(e: Multiple1Example) {
//// console.log(e./*multiple1*/anything);
//// }

verify.quickInfoAt("multiple1", "any");
17 changes: 17 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription6.ts
@@ -0,0 +1,17 @@
///<reference path="fourslash.ts" />

//// interface Literal1Example {
//// /** Something generic */
//// [key: `prefix${string}`]: number | string;
//// /** Something else */
//// [key: `prefix${number}`]: number;
//// }
//// function literal1Example(e: Literal1Example) {
//// console.log(e./*literal1*/prefixMember);
//// console.log(e./*literal2*/anything);
//// console.log(e./*literal3*/prefix0);
//// }

verify.quickInfoAt("literal1", "(index) Literal1Example[`prefix${string}`]: string | number", "Something generic");
verify.quickInfoAt("literal2", "any");
verify.quickInfoAt("literal3", "(index) Literal1Example[`prefix${string}` | `prefix${number}`]: string | number", "Something generic\nSomething else");
11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription7.ts
@@ -0,0 +1,11 @@
///<reference path="fourslash.ts" />

//// class StringClass {
//// /** Something generic */
//// static [p: string]: any;
//// }
//// function stringClass(e: typeof StringClass) {
//// console.log(e./*stringClass*/anything);
//// }

verify.quickInfoAt("stringClass", "(index) StringClass[string]: any", "Something generic");
11 changes: 11 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription8.ts
@@ -0,0 +1,11 @@
///<reference path="fourslash.ts" />

//// class SymbolClass {
//// /** Something generic */
//// static [p: symbol]: any;
//// }
//// function symbolClass(e: typeof SymbolClass) {
//// console.log(e./*symbolClass*/anything);
//// }

verify.quickInfoAt("symbolClass", "any");
17 changes: 17 additions & 0 deletions tests/cases/fourslash/jsDocPropertyDescription9.ts
@@ -0,0 +1,17 @@
///<reference path="fourslash.ts" />

//// class LiteralClass {
//// /** Something generic */
//// static [key: `prefix${string}`]: any;
//// /** Something else */
//// static [key: `prefix${number}`]: number;
//// }
//// function literalClass(e: typeof LiteralClass) {
//// console.log(e./*literal1Class*/prefixMember);
//// console.log(e./*literal2Class*/anything);
//// console.log(e./*literal3Class*/prefix0);
//// }

verify.quickInfoAt("literal1Class", "(index) LiteralClass[`prefix${string}`]: any", "Something generic");
verify.quickInfoAt("literal2Class", "any");
verify.quickInfoAt("literal3Class", "(index) LiteralClass[`prefix${string}` | `prefix${number}`]: any", "Something generic\nSomething else")
56 changes: 0 additions & 56 deletions tests/cases/fourslash/jsdocPropertyDescription.ts

This file was deleted.

0 comments on commit ecfbf8b

Please sign in to comment.