Skip to content

Commit 91633cd

Browse files
committed
Test JSDoc parsing using TS parser
1 parent bc69c7e commit 91633cd

8 files changed

Lines changed: 97 additions & 20 deletions

File tree

tests/cases/conformance/jsdoc/checkJsdocTypeTag1.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ x(1);
2323

2424
/** @type {function} */
2525
const y = (a) => a + 1;
26-
x(1);
26+
y(1);
2727

2828
/** @type {function (number)} */
2929
const x1 = (a) => a + 1;
@@ -41,4 +41,4 @@ var props = {};
4141
/**
4242
* @type {Object}
4343
*/
44-
var props = {};
44+
var props = {};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @noImplicitAny: true
5+
6+
// @Filename: functions.js
7+
8+
/**
9+
* @param {function(this: string, number): number} c is just passing on through
10+
* @return {function(this: string, number): number}
11+
*/
12+
function id1(c) {
13+
return c
14+
}
15+
16+
var x = id1(function (n) { return this.length + n });
17+
18+
/**
19+
* @param {function(new: { length: number }, number): number} c is just passing on through
20+
* @return {function(new: { length: number }, number): number}
21+
*/
22+
function id2(c) {
23+
return c
24+
}
25+
26+
class C {
27+
/** @param {number} n */
28+
constructor(n) {
29+
this.length = n;
30+
}
31+
}
32+
33+
var y = id2(C);
34+
var z = new y(12);
35+
z.length;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// @strict: true
2+
3+
// grammar error from checker
4+
var ara: Array.<number> = [1,2,3];
5+
6+
function f(x: ?number, y: Array.<number>) {
7+
return x ? x + y[1] : y[0];
8+
}
9+
function hof(ctor: function(new: number, string)) {
10+
return new ctor('hi');
11+
}
12+
function hof2(f: function(this: number, string): string) {
13+
return f(12, 'hullo');
14+
}
15+
var whatevs: * = 1001;
16+
var ques: ? = 'what';
17+
var g: function(number, number): number = (n,m) => n + m;
18+
var variadic: ...boolean = [true, false, true];
19+
var most: !string = 'definite';
20+
var weird1: new:string = {};
21+
var weird2: this:string = {};
22+
var postfixdef: number! = 101;
23+
var postfixopt: number? = undefined;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// parse error (blocks grammar errors from checker)
2+
function parse1(n: number=) { }
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// @allowJs: true
22
// @checkJs: true
33
// @noEmit: true
4+
// @Filename: forgot.js
45
/**
56
* @param {T} a
67
* @template T
78
*/
8-
function f<T>(a: T) {
9+
function f(a) {
910
return () => a
1011
}
1112
let n = f(1)()
@@ -15,7 +16,7 @@ let n = f(1)()
1516
* @template T
1617
* @returns {function(): T}
1718
*/
18-
function g<T>(a: T) {
19+
function g(a) {
1920
return () => a
2021
}
2122
let s = g('hi')()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @module: commonjs
5+
// @filename: node.d.ts
6+
// @noImplicitAny: true
7+
declare function require(id: string): any;
8+
declare var module: any, exports: any;
9+
10+
// @filename: f.js
11+
var F = function () {
12+
this.x = 1;
13+
};
14+
15+
function f(p: F) { p.x; }
16+
17+
// @filename: normal.ts
18+
class C { p: number }
19+
20+
/** @param {C} p */
21+
function g(c) { return c.p }
22+

tests/cases/conformance/jsdoc/syntaxErrors.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,13 @@
22
// @allowJs: true
33
// @noEmit: true
44

5-
// @Filename: foo.js
6-
/**
7-
* @param {(x)=>void} x
8-
* @param {typeof String} y
9-
* @param {string & number} z
10-
**/
11-
function foo(x, y, z) { }
5+
// @Filename: dummyType.d.ts
6+
declare class C<T> { t: T }
127

13-
// @Filename: skipped.js
14-
// @ts-nocheck
15-
/**
16-
* @param {(x)=>void} x
17-
* @param {typeof String} y
18-
* @param {string & number} z
19-
**/
20-
function bar(x, y, z) { }
8+
// @Filename: badTypeArguments.js
9+
/** @param {C.<>} x */
10+
/** @param {C.<number,>} y */
11+
function f(x, y) {
12+
return x.t + y.t;
13+
}
14+
var x = f({ t: 1000 }, { t: 3000 });

tests/cases/fourslash/formatEmptyParamList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
////function f( f: function){/*1*/
33
goTo.marker("1");
44
edit.insert("}");
5-
verify.currentLineContentIs("function f(f: function){ }")
5+
verify.currentLineContentIs("function f(f: function) { }")

0 commit comments

Comments
 (0)