Permalink
Browse files

CLI: Added variable arguments support to tsd-jsdoc

  • Loading branch information...
dcodeIO committed Dec 30, 2016
1 parent 40074bb commit 20d8a2dd93d3bbb6990594286f992e703fc4e334
@@ -1,5 +1,5 @@
// $> pbts --name protobuf --out index.d.ts src
// Generated Fri, 30 Dec 2016 16:29:57 UTC
// Generated Fri, 30 Dec 2016 20:40:44 UTC
export = protobuf;
export as namespace protobuf;
@@ -1851,7 +1851,7 @@ declare namespace protobuf {
* @property {function(string=):string} str Stringifies the so far generated function source.
* @property {function(string=, Object=):function} eof Ends generation and builds the function whilst applying a scope.
*/
type Codegen = (format: string, args: any) => Codegen;
type Codegen = (format: string, ...args: any[]) => Codegen;
/**
* Node-style callback as used by {@link util.fetch}.
@@ -1911,7 +1911,7 @@ declare namespace protobuf {
* @param {...*} params Function arguments
* @returns {Promise<*>} Promisified function
*/
function asPromise(fn: () => any, ctx: any, params: any): Promise<any>;
function asPromise(fn: () => any, ctx: any, ...params: any[]): Promise<any>;
/**
* A minimal base64 implementation for number arrays.
@@ -1957,7 +1957,7 @@ declare namespace protobuf {
* @property {boolean} supported Whether code generation is supported by the environment.
* @property {boolean} verbose=false When set to true, codegen will log generated code to console. Useful for debugging.
*/
function codegen(params: string): Codegen;
function codegen(...params: string[]): Codegen;
/**
* Constructs a new event emitter instance.
@@ -1998,7 +1998,7 @@ declare namespace protobuf {
* @param {...*} args Arguments
* @returns {util.EventEmitter} `this`
*/
emit(evt: string, args: any): util.EventEmitter;
emit(evt: string, ...args: any[]): util.EventEmitter;
}
/**
@@ -219,9 +219,9 @@ function getTypeOf(element) {
}
// begins writing the definition of the specified element
function begin(element) {
function begin(element, noDeclare) {
writeComment(element.comment);
if (element.scope === "global" && !options.module)
if (element.scope === "global" && !options.module && !noDeclare)
write("declare ");
}
@@ -240,11 +240,12 @@ function writeFunctionSignature(element, isConstructor, isTypeDef) {
// parameter types
if (element.params)
element.params.forEach(function(param, i) {
element.params.forEach(function(param) {
var path = param.name.split(/\./g);
if (path.length === 1)
params[param.name] = {
type: getTypeOf(param),
variable: param.variable === true,
optional: param.optional === true,
defaultValue: param.defaultvalue // TODO
};
@@ -254,8 +255,13 @@ function writeFunctionSignature(element, isConstructor, isTypeDef) {
var paramNames = Object.keys(params);
paramNames.forEach(function(name, i) {
var param = params[name];
write(name, param.optional ? "?: " : ": ", param.type);
var param = params[name];
var type = param.type;
if (param.variable) {
name = "..." + name;
type = param.type.charAt(0) === "(" ? "any[]" : param.type + "[]";
}
write(name, param.optional ? "?: " : ": ", type);
if (i < paramNames.length - 1)
write(", ");
});
@@ -332,8 +338,9 @@ function notAModuleReference(ref) {
// handles a class or class-like
function handleClass(element, parent) {
begin(element);
if (isInterface(element))
var is_interface = isInterface(element);
begin(element, is_interface);
if (is_interface)
write("interface ");
else {
if (element.virtual)
@@ -363,7 +370,7 @@ function handleClass(element, parent) {
++indent;
// constructor
if (!isInterface(element) && !element.virtual)
if (!is_interface && !element.virtual)
handleFunction(element, parent, true);
// members except inner classes
@@ -467,7 +474,7 @@ function handleTypeDef(element, parent) {
writeInterface(element);
}
} else {
begin(element);
begin(element, true);
if (element.access)
write(element.access, " ");
write("type ", element.name, " = ");
@@ -8,4 +8,4 @@ export = asPromise;
* @param {...*} params Function arguments
* @returns {Promise<*>} Promisified function
*/
declare function asPromise(fn: () => any, ctx: any, params: any): Promise<any>;
function asPromise(fn: () => any, ctx: any, ...params: any[]): Promise<any>;
@@ -10,7 +10,7 @@ export = codegen;
* @property {function(string=):string} str Stringifies the so far generated function source.
* @property {function(string=, Object=):function} eof Ends generation and builds the function whilst applying a scope.
*/
type Codegen = (format: string, args: any) => Codegen;
type Codegen = (format: string, ...args: any[]) => Codegen;
/**
* A closure for generating functions programmatically.
@@ -22,4 +22,4 @@ type Codegen = (format: string, args: any) => Codegen;
* @property {boolean} supported Whether code generation is supported by the environment.
* @property {boolean} verbose=false When set to true, codegen will log generated code to console. Useful for debugging.
*/
declare function codegen(params: string): Codegen;
declare function codegen(...params: string[]): Codegen;
@@ -0,0 +1,4 @@
import codegen from ".";
var cg = codegen("f", "a")
("s", "a");
@@ -39,5 +39,5 @@ declare class EventEmitter {
* @param {...*} args Arguments
* @returns {util.EventEmitter} `this`
*/
emit(evt: string, args: any): EventEmitter;
emit(evt: string, ...args: any[]): EventEmitter;
}

0 comments on commit 20d8a2d

Please sign in to comment.