From b40bc0c01954a4467a44fd406ce77300ffa45fdf Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 23 May 2017 14:31:37 -0700 Subject: [PATCH 1/4] Add type alias for TypeReferenceType and convert to use JSDoc --- src/compiler/checker.ts | 30 ++++++++++++++++++------------ src/compiler/types.ts | 2 ++ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 07c20ad7aa..7b084a0f26 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6696,8 +6696,10 @@ namespace ts { return length(type.target.typeParameters); } - // Get type from reference to class or interface - function getTypeFromClassOrInterfaceReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol, typeArgs: Type[]): Type { + /** + * Get type from type-reference that reference to class or interface + */ + function getTypeFromClassOrInterfaceReference(node: TypeReferenceType, symbol: Symbol, typeArgs: Type[]): Type { const type = getDeclaredTypeOfSymbol(getMergedSymbol(symbol)); const typeParameters = type.localTypeParameters; if (typeParameters) { @@ -6738,10 +6740,12 @@ namespace ts { return instantiation; } - // Get type from reference to type alias. When a type alias is generic, the declared type of the type alias may include - // references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the - // declared type. Instantiations are cached using the type identities of the type arguments as the key. - function getTypeFromTypeAliasReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol, typeArguments: Type[]): Type { + /** + * Get type from reference to type alias. When a type alias is generic, the declared type of the type alias may include + * references to the type parameters of the alias. We replace those with the actual type arguments by instantiating the + * declared type. Instantiations are cached using the type identities of the type arguments as the key. + */ + function getTypeFromTypeAliasReference(node: TypeReferenceType, symbol: Symbol, typeArguments: Type[]): Type { const type = getDeclaredTypeOfSymbol(symbol); const typeParameters = getSymbolLinks(symbol).typeParameters; if (typeParameters) { @@ -6766,8 +6770,10 @@ namespace ts { return type; } - // Get type from reference to named type that cannot be generic (enum or type parameter) - function getTypeFromNonGenericTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol): Type { + /** + * Get type from reference to named type that cannot be generic (enum or type parameter) + */ + function getTypeFromNonGenericTypeReference(node: TypeReferenceType, symbol: Symbol): Type { if (node.typeArguments) { error(node, Diagnostics.Type_0_is_not_generic, symbolToString(symbol)); return unknownType; @@ -6775,7 +6781,7 @@ namespace ts { return getDeclaredTypeOfSymbol(symbol); } - function getTypeReferenceName(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference): EntityNameOrEntityNameExpression | undefined { + function getTypeReferenceName(node: TypeReferenceType): EntityNameOrEntityNameExpression | undefined { switch (node.kind) { case SyntaxKind.TypeReference: return (node).typeName; @@ -6803,7 +6809,7 @@ namespace ts { return resolveEntityName(typeReferenceName, SymbolFlags.Type) || unknownSymbol; } - function getTypeReferenceType(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference, symbol: Symbol) { + function getTypeReferenceType(node: TypeReferenceType, symbol: Symbol) { const typeArguments = typeArgumentsFromTypeReferenceNode(node); // Do unconditionally so we mark type arguments as referenced. if (symbol === unknownSymbol) { @@ -6862,7 +6868,7 @@ namespace ts { return strictNullChecks ? getUnionType([type, nullType]) : type; } - function getTypeFromTypeReference(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference): Type { + function getTypeFromTypeReference(node: TypeReferenceType): Type { const links = getNodeLinks(node); if (!links.resolvedType) { let symbol: Symbol; @@ -6893,7 +6899,7 @@ namespace ts { return links.resolvedType; } - function typeArgumentsFromTypeReferenceNode(node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference): Type[] { + function typeArgumentsFromTypeReferenceNode(node: TypeReferenceType): Type[] { return map(node.typeArguments, getTypeFromTypeNode); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a8da09a11c..73a2e46be9 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -892,6 +892,8 @@ namespace ts { kind: SyntaxKind.ConstructorType; } + export type TypeReferenceType = TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference; + export interface TypeReferenceNode extends TypeNode { kind: SyntaxKind.TypeReference; typeName: EntityName; From 3d9a1babf78cc5115fe6b1c4295dd9c3de95ef5f Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 23 May 2017 16:10:56 -0700 Subject: [PATCH 2/4] Return "Function for JSDocType {Function} --- src/compiler/checker.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7b084a0f26..2d95f69f41 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2818,9 +2818,11 @@ namespace ts { const parameterDeclaration = getDeclarationOfKind(parameterSymbol, SyntaxKind.Parameter); const modifiers = parameterDeclaration.modifiers && parameterDeclaration.modifiers.map(getSynthesizedClone); const dotDotDotToken = isRestParameter(parameterDeclaration) ? createToken(SyntaxKind.DotDotDotToken) : undefined; - const name = parameterDeclaration.name.kind === SyntaxKind.Identifier ? - setEmitFlags(getSynthesizedClone(parameterDeclaration.name), EmitFlags.NoAsciiEscaping) : - cloneBindingName(parameterDeclaration.name); + const name = parameterDeclaration.name ? + parameterDeclaration.name.kind === SyntaxKind.Identifier ? + setEmitFlags(getSynthesizedClone(parameterDeclaration.name), EmitFlags.NoAsciiEscaping) : + cloneBindingName(parameterDeclaration.name) : + parameterSymbol.name; const questionToken = isOptionalParameter(parameterDeclaration) ? createToken(SyntaxKind.QuestionToken) : undefined; let parameterType = getTypeOfSymbol(parameterSymbol); @@ -6852,7 +6854,7 @@ namespace ts { case "Object": return anyType; case "Function": - return anyFunctionType; + return globalFunctionType; case "Array": case "array": return !node.typeArguments || !node.typeArguments.length ? createArrayType(anyType) : undefined; From 72e6678804f2342e4ee4f1c25173d36b14f89ea4 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 23 May 2017 16:11:13 -0700 Subject: [PATCH 3/4] Update baselines --- ...jsFileCompilationRestParamJsDocFunction.types | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types index 66e3da3e67..54bc793868 100644 --- a/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types +++ b/tests/baselines/reference/jsFileCompilationRestParamJsDocFunction.types @@ -10,8 +10,8 @@ * @returns {*} Returns the result of `func`. */ function apply(func, thisArg, args) { ->apply : (func: {}, thisArg: any, ...args: any[]) => any ->func : {} +>apply : (func: Function, thisArg: any, ...args: any[]) => any +>func : Function >thisArg : any >args : any[] @@ -28,7 +28,7 @@ function apply(func, thisArg, args) { >0 : 0 >func.call(thisArg) : any >func.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->func : {} +>func : Function >call : (this: Function, thisArg: any, ...argArray: any[]) => any >thisArg : any @@ -36,7 +36,7 @@ function apply(func, thisArg, args) { >1 : 1 >func.call(thisArg, args[0]) : any >func.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->func : {} +>func : Function >call : (this: Function, thisArg: any, ...argArray: any[]) => any >thisArg : any >args[0] : any @@ -47,7 +47,7 @@ function apply(func, thisArg, args) { >2 : 2 >func.call(thisArg, args[0], args[1]) : any >func.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->func : {} +>func : Function >call : (this: Function, thisArg: any, ...argArray: any[]) => any >thisArg : any >args[0] : any @@ -61,7 +61,7 @@ function apply(func, thisArg, args) { >3 : 3 >func.call(thisArg, args[0], args[1], args[2]) : any >func.call : (this: Function, thisArg: any, ...argArray: any[]) => any ->func : {} +>func : Function >call : (this: Function, thisArg: any, ...argArray: any[]) => any >thisArg : any >args[0] : any @@ -77,12 +77,12 @@ function apply(func, thisArg, args) { return func.apply(thisArg, args); >func.apply(thisArg, args) : any >func.apply : (this: Function, thisArg: any, argArray?: any) => any ->func : {} +>func : Function >apply : (this: Function, thisArg: any, argArray?: any) => any >thisArg : any >args : any[] } export default apply; ->apply : (func: {}, thisArg: any, ...args: any[]) => any +>apply : (func: Function, thisArg: any, ...args: any[]) => any From bd422e3a524e1fb8c975e660e6a70cb8446a33a8 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 23 May 2017 16:11:23 -0700 Subject: [PATCH 4/4] Add tests and update baselines --- tests/baselines/reference/jsDocTypeTag1.js | 584 +++++++++++++++++ tests/baselines/reference/jsDocTypeTag2.js | 598 ++++++++++++++++++ tests/baselines/reference/jsDocTypes2.js | 37 ++ tests/baselines/reference/jsDocTypes2.symbols | 40 ++ tests/baselines/reference/jsDocTypes2.types | 59 ++ .../reference/jsDocTypes3.errors.txt | 21 + tests/baselines/reference/jsDocTypes3.js | 24 + tests/cases/conformance/salsa/jsDocTypes2.ts | 23 + tests/cases/conformance/salsa/jsDocTypes3.ts | 16 + .../cases/fourslash/jsDocTypeTagQuickInfo1.ts | 43 ++ .../cases/fourslash/jsDocTypeTagQuickInfo2.ts | 40 ++ 11 files changed, 1485 insertions(+) create mode 100644 tests/baselines/reference/jsDocTypeTag1.js create mode 100644 tests/baselines/reference/jsDocTypeTag2.js create mode 100644 tests/baselines/reference/jsDocTypes2.js create mode 100644 tests/baselines/reference/jsDocTypes2.symbols create mode 100644 tests/baselines/reference/jsDocTypes2.types create mode 100644 tests/baselines/reference/jsDocTypes3.errors.txt create mode 100644 tests/baselines/reference/jsDocTypes3.js create mode 100644 tests/cases/conformance/salsa/jsDocTypes2.ts create mode 100644 tests/cases/conformance/salsa/jsDocTypes3.ts create mode 100644 tests/cases/fourslash/jsDocTypeTagQuickInfo1.ts create mode 100644 tests/cases/fourslash/jsDocTypeTagQuickInfo2.ts diff --git a/tests/baselines/reference/jsDocTypeTag1.js b/tests/baselines/reference/jsDocTypeTag1.js new file mode 100644 index 0000000000..5dcabf2aa0 --- /dev/null +++ b/tests/baselines/reference/jsDocTypeTag1.js @@ -0,0 +1,584 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 26 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 26, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "S", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 55 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 55, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "N", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 85 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 85, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "B", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "boolean", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 112 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 112, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "V", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "void", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 144 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 144, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "U", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "undefined", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 171 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 171, + "length": 2 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Nl", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "null", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 200 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 200, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "A", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "any", + "kind": "keyword" + }, + { + "text": "[", + "kind": "punctuation" + }, + { + "text": "]", + "kind": "punctuation" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 230 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 230, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "P", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Promise", + "kind": "interfaceName" + }, + { + "text": "<", + "kind": "punctuation" + }, + { + "text": "any", + "kind": "keyword" + }, + { + "text": ">", + "kind": "punctuation" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 259 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 259, + "length": 3 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Obj", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "any", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 292 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 292, + "length": 4 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Func", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Function", + "kind": "localName" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 319 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 319, + "length": 7 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "AnyType", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "any", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 349 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 349, + "length": 5 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "QType", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "any", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag1.js", + "position": 389 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 389, + "length": 4 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "SOrN", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + } +] \ No newline at end of file diff --git a/tests/baselines/reference/jsDocTypeTag2.js b/tests/baselines/reference/jsDocTypeTag2.js new file mode 100644 index 0000000000..07535dcee0 --- /dev/null +++ b/tests/baselines/reference/jsDocTypeTag2.js @@ -0,0 +1,598 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 26 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 26, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "s", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 55 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 55, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "n", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 85 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 85, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "b", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "boolean", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 112 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 112, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "v", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "void", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 144 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 144, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "u", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "undefined", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 171 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 171, + "length": 2 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "nl", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "null", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 200 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 200, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "a", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "any", + "kind": "keyword" + }, + { + "text": "[", + "kind": "punctuation" + }, + { + "text": "]", + "kind": "punctuation" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 230 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 230, + "length": 1 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "p", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "Promise", + "kind": "interfaceName" + }, + { + "text": "<", + "kind": "punctuation" + }, + { + "text": "any", + "kind": "keyword" + }, + { + "text": ">", + "kind": "punctuation" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 260 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 260, + "length": 8 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "nullable", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 298 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 298, + "length": 4 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "func", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=>", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "any", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 349 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 349, + "length": 5 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "func1", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "arg0", + "kind": "parameterName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "=>", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/jsDocTypeTag2.js", + "position": 391 + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 391, + "length": 4 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "sOrn", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "|", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "number", + "kind": "keyword" + } + ], + "documentation": [], + "tags": [] + } + } +] \ No newline at end of file diff --git a/tests/baselines/reference/jsDocTypes2.js b/tests/baselines/reference/jsDocTypes2.js new file mode 100644 index 0000000000..a3848704fa --- /dev/null +++ b/tests/baselines/reference/jsDocTypes2.js @@ -0,0 +1,37 @@ +//// [0.js] +// @ts-check +/** @type {*} */ +var anyT = 2; + +/** @type {?} */ +var anyT1 = 2; +anyT1 = "hi"; + +/** @type {Function} */ +const x = (a) => a + 1; +x(1); + +/** @type {function (number)} */ +const x1 = (a) => a + 1; +x1(0); + +/** @type {function (number): number} */ +const x2 = (a) => a + 1; +x2(0); + +//// [0.js] +// @ts-check +/** @type {*} */ +var anyT = 2; +/** @type {?} */ +var anyT1 = 2; +anyT1 = "hi"; +/** @type {Function} */ +var x = function (a) { return a + 1; }; +x(1); +/** @type {function (number)} */ +var x1 = function (a) { return a + 1; }; +x1(0); +/** @type {function (number): number} */ +var x2 = function (a) { return a + 1; }; +x2(0); diff --git a/tests/baselines/reference/jsDocTypes2.symbols b/tests/baselines/reference/jsDocTypes2.symbols new file mode 100644 index 0000000000..96b32b9ad9 --- /dev/null +++ b/tests/baselines/reference/jsDocTypes2.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/salsa/0.js === +// @ts-check +/** @type {*} */ +var anyT = 2; +>anyT : Symbol(anyT, Decl(0.js, 2, 3)) + +/** @type {?} */ +var anyT1 = 2; +>anyT1 : Symbol(anyT1, Decl(0.js, 5, 3)) + +anyT1 = "hi"; +>anyT1 : Symbol(anyT1, Decl(0.js, 5, 3)) + +/** @type {Function} */ +const x = (a) => a + 1; +>x : Symbol(x, Decl(0.js, 9, 5)) +>a : Symbol(a, Decl(0.js, 9, 11)) +>a : Symbol(a, Decl(0.js, 9, 11)) + +x(1); +>x : Symbol(x, Decl(0.js, 9, 5)) + +/** @type {function (number)} */ +const x1 = (a) => a + 1; +>x1 : Symbol(x1, Decl(0.js, 13, 5)) +>a : Symbol(a, Decl(0.js, 13, 12)) +>a : Symbol(a, Decl(0.js, 13, 12)) + +x1(0); +>x1 : Symbol(x1, Decl(0.js, 13, 5)) + +/** @type {function (number): number} */ +const x2 = (a) => a + 1; +>x2 : Symbol(x2, Decl(0.js, 17, 5)) +>a : Symbol(a, Decl(0.js, 17, 12)) +>a : Symbol(a, Decl(0.js, 17, 12)) + +x2(0); +>x2 : Symbol(x2, Decl(0.js, 17, 5)) + diff --git a/tests/baselines/reference/jsDocTypes2.types b/tests/baselines/reference/jsDocTypes2.types new file mode 100644 index 0000000000..db5a5902d1 --- /dev/null +++ b/tests/baselines/reference/jsDocTypes2.types @@ -0,0 +1,59 @@ +=== tests/cases/conformance/salsa/0.js === +// @ts-check +/** @type {*} */ +var anyT = 2; +>anyT : any +>2 : 2 + +/** @type {?} */ +var anyT1 = 2; +>anyT1 : any +>2 : 2 + +anyT1 = "hi"; +>anyT1 = "hi" : "hi" +>anyT1 : any +>"hi" : "hi" + +/** @type {Function} */ +const x = (a) => a + 1; +>x : Function +>(a) => a + 1 : (a: any) => any +>a : any +>a + 1 : any +>a : any +>1 : 1 + +x(1); +>x(1) : any +>x : Function +>1 : 1 + +/** @type {function (number)} */ +const x1 = (a) => a + 1; +>x1 : (arg0: number) => any +>(a) => a + 1 : (a: any) => any +>a : any +>a + 1 : any +>a : any +>1 : 1 + +x1(0); +>x1(0) : any +>x1 : (arg0: number) => any +>0 : 0 + +/** @type {function (number): number} */ +const x2 = (a) => a + 1; +>x2 : (arg0: number) => number +>(a) => a + 1 : (a: any) => any +>a : any +>a + 1 : any +>a : any +>1 : 1 + +x2(0); +>x2(0) : number +>x2 : (arg0: number) => number +>0 : 0 + diff --git a/tests/baselines/reference/jsDocTypes3.errors.txt b/tests/baselines/reference/jsDocTypes3.errors.txt new file mode 100644 index 0000000000..5f5feeaf0a --- /dev/null +++ b/tests/baselines/reference/jsDocTypes3.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/salsa/0.js(5,4): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'number'. +tests/cases/conformance/salsa/0.js(12,1): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/conformance/salsa/0.js (2 errors) ==== + // @ts-check + + /** @type {function (number)} */ + const x1 = (a) => a + 1; + x1("string"); + ~~~~~~~~ +!!! error TS2345: Argument of type '"string"' is not assignable to parameter of type 'number'. + + /** @type {function (number): number} */ + const x2 = (a) => a + 1; + + /** @type {string} */ + var a; + a = x2(0); + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/jsDocTypes3.js b/tests/baselines/reference/jsDocTypes3.js new file mode 100644 index 0000000000..2eb50223ba --- /dev/null +++ b/tests/baselines/reference/jsDocTypes3.js @@ -0,0 +1,24 @@ +//// [0.js] +// @ts-check + +/** @type {function (number)} */ +const x1 = (a) => a + 1; +x1("string"); + +/** @type {function (number): number} */ +const x2 = (a) => a + 1; + +/** @type {string} */ +var a; +a = x2(0); + +//// [0.js] +// @ts-check +/** @type {function (number)} */ +var x1 = function (a) { return a + 1; }; +x1("string"); +/** @type {function (number): number} */ +var x2 = function (a) { return a + 1; }; +/** @type {string} */ +var a; +a = x2(0); diff --git a/tests/cases/conformance/salsa/jsDocTypes2.ts b/tests/cases/conformance/salsa/jsDocTypes2.ts new file mode 100644 index 0000000000..612804b91d --- /dev/null +++ b/tests/cases/conformance/salsa/jsDocTypes2.ts @@ -0,0 +1,23 @@ +// @allowJS: true +// @suppressOutputPathCheck: true + +// @filename: 0.js +// @ts-check +/** @type {*} */ +var anyT = 2; + +/** @type {?} */ +var anyT1 = 2; +anyT1 = "hi"; + +/** @type {Function} */ +const x = (a) => a + 1; +x(1); + +/** @type {function (number)} */ +const x1 = (a) => a + 1; +x1(0); + +/** @type {function (number): number} */ +const x2 = (a) => a + 1; +x2(0); \ No newline at end of file diff --git a/tests/cases/conformance/salsa/jsDocTypes3.ts b/tests/cases/conformance/salsa/jsDocTypes3.ts new file mode 100644 index 0000000000..bf207bca86 --- /dev/null +++ b/tests/cases/conformance/salsa/jsDocTypes3.ts @@ -0,0 +1,16 @@ +// @allowJS: true +// @suppressOutputPathCheck: true + +// @filename: 0.js +// @ts-check + +/** @type {function (number)} */ +const x1 = (a) => a + 1; +x1("string"); + +/** @type {function (number): number} */ +const x2 = (a) => a + 1; + +/** @type {string} */ +var a; +a = x2(0); \ No newline at end of file diff --git a/tests/cases/fourslash/jsDocTypeTagQuickInfo1.ts b/tests/cases/fourslash/jsDocTypeTagQuickInfo1.ts new file mode 100644 index 0000000000..240c00e228 --- /dev/null +++ b/tests/cases/fourslash/jsDocTypeTagQuickInfo1.ts @@ -0,0 +1,43 @@ +/// +// @allowJs: true +// @Filename: jsDocTypeTag1.js +//// /** @type {String} */ +//// var /*1*/S; + +//// /** @type {Number} */ +//// var /*2*/N; + +//// /** @type {Boolean} */ +//// var /*3*/B; + +//// /** @type {Void} */ +//// var /*4*/V; + +//// /** @type {Undefined} */ +//// var /*5*/U; + +//// /** @type {Null} */ +//// var /*6*/Nl; + +//// /** @type {Array} */ +//// var /*7*/A; + +//// /** @type {Promise} */ +//// var /*8*/P; + +//// /** @type {Object} */ +//// var /*9*/Obj; + +//// /** @type {Function} */ +//// var /*10*/Func; + +//// /** @type {*} */ +//// var /*11*/AnyType; + +//// /** @type {?} */ +//// var /*12*/QType; + +//// /** @type {String|Number} */ +//// var /*13*/SOrN; + +verify.baselineQuickInfo(); \ No newline at end of file diff --git a/tests/cases/fourslash/jsDocTypeTagQuickInfo2.ts b/tests/cases/fourslash/jsDocTypeTagQuickInfo2.ts new file mode 100644 index 0000000000..7c79116b04 --- /dev/null +++ b/tests/cases/fourslash/jsDocTypeTagQuickInfo2.ts @@ -0,0 +1,40 @@ +/// +// @allowJs: true +// @Filename: jsDocTypeTag2.js +//// /** @type {string} */ +//// var /*1*/s; + +//// /** @type {number} */ +//// var /*2*/n; + +//// /** @type {boolean} */ +//// var /*3*/b; + +//// /** @type {void} */ +//// var /*4*/v; + +//// /** @type {undefined} */ +//// var /*5*/u; + +//// /** @type {null} */ +//// var /*6*/nl; + +//// /** @type {array} */ +//// var /*7*/a; + +//// /** @type {promise} */ +//// var /*8*/p; + +//// /** @type {?number} */ +//// var /*9*/nullable; + +//// /** @type {function} */ +//// var /*10*/func; + +//// /** @type {function (number): number} */ +//// var /*11*/func1; + +//// /** @type {string | number} */ +//// var /*12*/sOrn; + +verify.baselineQuickInfo(); \ No newline at end of file