mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-29 16:29:19 -05:00
Test JSDoc parsing using TS parser
This commit is contained in:
@@ -23,7 +23,7 @@ x(1);
|
||||
|
||||
/** @type {function} */
|
||||
const y = (a) => a + 1;
|
||||
x(1);
|
||||
y(1);
|
||||
|
||||
/** @type {function (number)} */
|
||||
const x1 = (a) => a + 1;
|
||||
@@ -41,4 +41,4 @@ var props = {};
|
||||
/**
|
||||
* @type {Object}
|
||||
*/
|
||||
var props = {};
|
||||
var props = {};
|
||||
|
||||
35
tests/cases/conformance/jsdoc/jsdocFunctionType.ts
Normal file
35
tests/cases/conformance/jsdoc/jsdocFunctionType.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @noImplicitAny: true
|
||||
|
||||
// @Filename: functions.js
|
||||
|
||||
/**
|
||||
* @param {function(this: string, number): number} c is just passing on through
|
||||
* @return {function(this: string, number): number}
|
||||
*/
|
||||
function id1(c) {
|
||||
return c
|
||||
}
|
||||
|
||||
var x = id1(function (n) { return this.length + n });
|
||||
|
||||
/**
|
||||
* @param {function(new: { length: number }, number): number} c is just passing on through
|
||||
* @return {function(new: { length: number }, number): number}
|
||||
*/
|
||||
function id2(c) {
|
||||
return c
|
||||
}
|
||||
|
||||
class C {
|
||||
/** @param {number} n */
|
||||
constructor(n) {
|
||||
this.length = n;
|
||||
}
|
||||
}
|
||||
|
||||
var y = id2(C);
|
||||
var z = new y(12);
|
||||
z.length;
|
||||
23
tests/cases/conformance/jsdoc/jsdocInTypescript.ts
Normal file
23
tests/cases/conformance/jsdoc/jsdocInTypescript.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
// @strict: true
|
||||
|
||||
// grammar error from checker
|
||||
var ara: Array.<number> = [1,2,3];
|
||||
|
||||
function f(x: ?number, y: Array.<number>) {
|
||||
return x ? x + y[1] : y[0];
|
||||
}
|
||||
function hof(ctor: function(new: number, string)) {
|
||||
return new ctor('hi');
|
||||
}
|
||||
function hof2(f: function(this: number, string): string) {
|
||||
return f(12, 'hullo');
|
||||
}
|
||||
var whatevs: * = 1001;
|
||||
var ques: ? = 'what';
|
||||
var g: function(number, number): number = (n,m) => n + m;
|
||||
var variadic: ...boolean = [true, false, true];
|
||||
var most: !string = 'definite';
|
||||
var weird1: new:string = {};
|
||||
var weird2: this:string = {};
|
||||
var postfixdef: number! = 101;
|
||||
var postfixopt: number? = undefined;
|
||||
2
tests/cases/conformance/jsdoc/jsdocInTypescript2.ts
Normal file
2
tests/cases/conformance/jsdoc/jsdocInTypescript2.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
// parse error (blocks grammar errors from checker)
|
||||
function parse1(n: number=) { }
|
||||
@@ -1,11 +1,12 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @Filename: forgot.js
|
||||
/**
|
||||
* @param {T} a
|
||||
* @template T
|
||||
*/
|
||||
function f<T>(a: T) {
|
||||
function f(a) {
|
||||
return () => a
|
||||
}
|
||||
let n = f(1)()
|
||||
@@ -15,7 +16,7 @@ let n = f(1)()
|
||||
* @template T
|
||||
* @returns {function(): T}
|
||||
*/
|
||||
function g<T>(a: T) {
|
||||
function g(a) {
|
||||
return () => a
|
||||
}
|
||||
let s = g('hi')()
|
||||
|
||||
22
tests/cases/conformance/jsdoc/jsdocTypesInTypeAnnotations.ts
Normal file
22
tests/cases/conformance/jsdoc/jsdocTypesInTypeAnnotations.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @noEmit: true
|
||||
// @module: commonjs
|
||||
// @filename: node.d.ts
|
||||
// @noImplicitAny: true
|
||||
declare function require(id: string): any;
|
||||
declare var module: any, exports: any;
|
||||
|
||||
// @filename: f.js
|
||||
var F = function () {
|
||||
this.x = 1;
|
||||
};
|
||||
|
||||
function f(p: F) { p.x; }
|
||||
|
||||
// @filename: normal.ts
|
||||
class C { p: number }
|
||||
|
||||
/** @param {C} p */
|
||||
function g(c) { return c.p }
|
||||
|
||||
@@ -2,19 +2,13 @@
|
||||
// @allowJs: true
|
||||
// @noEmit: true
|
||||
|
||||
// @Filename: foo.js
|
||||
/**
|
||||
* @param {(x)=>void} x
|
||||
* @param {typeof String} y
|
||||
* @param {string & number} z
|
||||
**/
|
||||
function foo(x, y, z) { }
|
||||
// @Filename: dummyType.d.ts
|
||||
declare class C<T> { t: T }
|
||||
|
||||
// @Filename: skipped.js
|
||||
// @ts-nocheck
|
||||
/**
|
||||
* @param {(x)=>void} x
|
||||
* @param {typeof String} y
|
||||
* @param {string & number} z
|
||||
**/
|
||||
function bar(x, y, z) { }
|
||||
// @Filename: badTypeArguments.js
|
||||
/** @param {C.<>} x */
|
||||
/** @param {C.<number,>} y */
|
||||
function f(x, y) {
|
||||
return x.t + y.t;
|
||||
}
|
||||
var x = f({ t: 1000 }, { t: 3000 });
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
////function f( f: function){/*1*/
|
||||
goTo.marker("1");
|
||||
edit.insert("}");
|
||||
verify.currentLineContentIs("function f(f: function){ }")
|
||||
verify.currentLineContentIs("function f(f: function) { }")
|
||||
|
||||
Reference in New Issue
Block a user