Test JSDoc parsing using TS parser

This commit is contained in:
Nathan Shively-Sanders
2017-07-13 11:33:12 -07:00
parent bc69c7e6d1
commit 91633cde5f
8 changed files with 97 additions and 20 deletions

View File

@@ -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 = {};

View 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;

View 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;

View File

@@ -0,0 +1,2 @@
// parse error (blocks grammar errors from checker)
function parse1(n: number=) { }

View File

@@ -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')()

View 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 }

View File

@@ -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 });

View File

@@ -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) { }")