@polymer/gen-typescript-declarations
Advanced tools
Comparing version 0.3.3 to 0.3.4
@@ -9,2 +9,5 @@ # Changelog | ||
## [0.3.4] - 2017-12-20 | ||
- Handle optional and rest parameters in function type expressions. | ||
## [0.3.3] - 2017-12-18 | ||
@@ -11,0 +14,0 @@ - Pin Analyzer version for upcoming major refactor. |
import * as ts from './ts-ast'; | ||
/** | ||
* Convert from a type annotation in Closure syntax to a TypeScript type | ||
* expression AST (e.g `Array` => `Array<any>|null`). | ||
* Convert a Closure type expression string to its equivalent TypeScript AST | ||
* node. | ||
* | ||
* Note that function and method parameters should instead use | ||
* `closureParamToTypeScript`. | ||
*/ | ||
export declare function closureTypeToTypeScript(closureType: (string | null | undefined), templateTypes?: string[]): ts.Type; | ||
export declare function closureTypeToTypeScript(closureType: string | null | undefined, templateTypes?: string[]): ts.Type; | ||
/** | ||
* Convert from a parameter type annotation in Closure syntax to a TypeScript | ||
* type expression AST | ||
* (e.g `Array=` => `{type: 'Array<any>|null', optional: true}`). | ||
* Convert a Closure function or method parameter type expression string to its | ||
* equivalent TypeScript AST node. | ||
* | ||
* This differs from `closureTypeToTypeScript` in that it always returns a | ||
* `ParamType`, and can parse the optional (`foo=`) and rest (`...foo`) | ||
* syntaxes, which only apply when parsing an expression in the context of a | ||
* parameter. | ||
*/ | ||
export declare function closureParamToTypeScript(closureType: (string | null | undefined), templateTypes?: string[]): { | ||
type: ts.Type; | ||
optional: boolean; | ||
rest: boolean; | ||
}; | ||
export declare function closureParamToTypeScript(name: string, closureType: string | null | undefined, templateTypes?: string[]): ts.ParamType; |
@@ -16,4 +16,7 @@ "use strict"; | ||
/** | ||
* Convert from a type annotation in Closure syntax to a TypeScript type | ||
* expression AST (e.g `Array` => `Array<any>|null`). | ||
* Convert a Closure type expression string to its equivalent TypeScript AST | ||
* node. | ||
* | ||
* Note that function and method parameters should instead use | ||
* `closureParamToTypeScript`. | ||
*/ | ||
@@ -35,9 +38,18 @@ function closureTypeToTypeScript(closureType, templateTypes = []) { | ||
/** | ||
* Convert from a parameter type annotation in Closure syntax to a TypeScript | ||
* type expression AST | ||
* (e.g `Array=` => `{type: 'Array<any>|null', optional: true}`). | ||
* Convert a Closure function or method parameter type expression string to its | ||
* equivalent TypeScript AST node. | ||
* | ||
* This differs from `closureTypeToTypeScript` in that it always returns a | ||
* `ParamType`, and can parse the optional (`foo=`) and rest (`...foo`) | ||
* syntaxes, which only apply when parsing an expression in the context of a | ||
* parameter. | ||
*/ | ||
function closureParamToTypeScript(closureType, templateTypes = []) { | ||
function closureParamToTypeScript(name, closureType, templateTypes = []) { | ||
if (!closureType) { | ||
return { type: ts.anyType, optional: false, rest: false }; | ||
return new ts.ParamType({ | ||
name, | ||
type: ts.anyType, | ||
optional: false, | ||
rest: false, | ||
}); | ||
} | ||
@@ -49,3 +61,4 @@ let ast; | ||
catch (_a) { | ||
return { | ||
return new ts.ParamType({ | ||
name, | ||
type: ts.anyType, | ||
@@ -57,33 +70,43 @@ // It's important we try to get optional right even if we can't parse | ||
rest: false, | ||
}; | ||
}); | ||
} | ||
// Optional and Rest types are always the top-level node. | ||
switch (ast.type) { | ||
return convertParam(name, ast, templateTypes); | ||
} | ||
exports.closureParamToTypeScript = closureParamToTypeScript; | ||
/** | ||
* Convert a doctrine function or method parameter AST node to its equivalent | ||
* TypeScript parameter AST node. | ||
*/ | ||
function convertParam(name, node, templateTypes) { | ||
switch (node.type) { | ||
case 'OptionalType': | ||
return { | ||
type: convert(ast.expression, templateTypes), | ||
return new ts.ParamType({ | ||
name, | ||
type: convert(node.expression, templateTypes), | ||
optional: true, | ||
rest: false, | ||
}; | ||
}); | ||
case 'RestType': | ||
return { | ||
return new ts.ParamType({ | ||
name, | ||
// The Closure type annotation for a rest parameter looks like | ||
// `...foo`, where `foo` is implicitly an array. The TypeScript | ||
// equivalent is explicitly an array, so we wrap it in one here. | ||
type: new ts.ArrayType(convert(ast.expression, templateTypes)), | ||
type: new ts.ArrayType(node.expression !== undefined ? | ||
convert(node.expression, templateTypes) : | ||
ts.anyType), | ||
optional: false, | ||
rest: true, | ||
}; | ||
}); | ||
default: | ||
return { | ||
type: convert(ast, templateTypes), | ||
return new ts.ParamType({ | ||
name, | ||
type: convert(node, templateTypes), | ||
optional: false, | ||
rest: false, | ||
}; | ||
}); | ||
} | ||
} | ||
exports.closureParamToTypeScript = closureParamToTypeScript; | ||
/** | ||
* Format the given Closure type expression AST node as a TypeScript type | ||
* annotation string. | ||
* Convert a doctrine AST node to its equivalent TypeScript AST node. | ||
*/ | ||
@@ -200,5 +223,5 @@ function convert(node, templateTypes) { | ||
function convertFunction(node, templateTypes) { | ||
const params = node.params.map((param, idx) => new ts.ParamType( | ||
const params = node.params.map((param, idx) => convertParam( | ||
// TypeScript wants named parameters, but we don't have names. | ||
'p' + idx, convert(param, templateTypes))); | ||
'p' + idx, param, templateTypes)); | ||
if (node.new) { | ||
@@ -241,3 +264,3 @@ return new ts.ConstructorType(params, | ||
} | ||
fields.push(new ts.ParamType(field.key, fieldType, optional)); | ||
fields.push(new ts.ParamType({ name: field.key, type: fieldType, optional })); | ||
} | ||
@@ -244,0 +267,0 @@ return new ts.RecordType(fields); |
@@ -273,3 +273,3 @@ "use strict"; | ||
params: [ | ||
new ts.Param({ name: 'base', type: new ts.NameType('T') }), | ||
new ts.ParamType({ name: 'base', type: new ts.NameType('T') }), | ||
], | ||
@@ -291,3 +291,3 @@ returns: new ts.IntersectionType([ | ||
params: [ | ||
new ts.Param({ | ||
new ts.ParamType({ | ||
name: 'args', | ||
@@ -345,4 +345,3 @@ type: new ts.ArrayType(ts.anyType), | ||
// which only handles this for class method parameters currently. | ||
const { type, optional, rest } = closure_types_1.closureParamToTypeScript(param.type, feature.templateTypes); | ||
f.params.push(new ts.Param({ name: param.name, type, optional, rest })); | ||
f.params.push(closure_types_1.closureParamToTypeScript(param.name, param.type, feature.templateTypes)); | ||
} | ||
@@ -391,3 +390,4 @@ findOrCreateNamespace(root, namespacePath).members.push(f); | ||
for (const param of reverseIter(method.params || [])) { | ||
let { type, optional, rest } = closure_types_1.closureParamToTypeScript(param.type); | ||
const tsParam = closure_types_1.closureParamToTypeScript(param.name, param.type); | ||
tsParam.description = param.description || ''; | ||
if (param.defaultValue !== undefined) { | ||
@@ -399,9 +399,9 @@ // Parameters with default values generally behave like optional | ||
if (!requiredAhead) { | ||
optional = true; | ||
tsParam.optional = true; | ||
} | ||
else { | ||
type = new ts.UnionType([type, ts.undefinedType]); | ||
tsParam.type = new ts.UnionType([tsParam.type, ts.undefinedType]); | ||
} | ||
} | ||
else if (!optional) { | ||
else if (!tsParam.optional) { | ||
requiredAhead = true; | ||
@@ -411,15 +411,9 @@ } | ||
// JSDoc type annotation (or if it was wrong). | ||
rest = rest || !!param.rest; | ||
if (rest && type.kind !== 'array') { | ||
tsParam.rest = tsParam.rest || !!param.rest; | ||
if (tsParam.rest && tsParam.type.kind !== 'array') { | ||
// Closure rest parameter types are written without the Array syntax, | ||
// but in TypeScript they must be explicitly arrays. | ||
type = new ts.ArrayType(type); | ||
tsParam.type = new ts.ArrayType(tsParam.type); | ||
} | ||
m.params.unshift(new ts.Param({ | ||
name: param.name, | ||
description: param.description, | ||
type, | ||
optional, | ||
rest | ||
})); | ||
m.params.unshift(tsParam); | ||
} | ||
@@ -426,0 +420,0 @@ tsMethods.push(m); |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
export declare type Node = Document | Namespace | Class | Interface | Function | Method | Type | ParamType | Property; | ||
export declare type Node = Document | Namespace | Class | Interface | Function | Method | Type | Property; | ||
export declare class Document { | ||
@@ -89,3 +89,3 @@ readonly kind: string; | ||
description: string; | ||
params: Param[]; | ||
params: ParamType[]; | ||
templateTypes: string[]; | ||
@@ -98,3 +98,3 @@ returns: Type; | ||
description?: string; | ||
params?: Param[]; | ||
params?: ParamType[]; | ||
templateTypes?: string[]; | ||
@@ -128,20 +128,3 @@ returns?: Type; | ||
} | ||
export declare class Param { | ||
readonly kind: string; | ||
name: string; | ||
type: Type; | ||
optional: boolean; | ||
rest: boolean; | ||
description: string; | ||
constructor(data: { | ||
name: string; | ||
type: Type; | ||
optional?: boolean; | ||
rest?: boolean; | ||
description?: string; | ||
}); | ||
traverse(): Iterable<Node>; | ||
serialize(): string; | ||
} | ||
export declare type Type = NameType | UnionType | ArrayType | FunctionType | ConstructorType | RecordType | IntersectionType | IndexableObjectType; | ||
export declare type Type = NameType | UnionType | ArrayType | FunctionType | ConstructorType | RecordType | IntersectionType | IndexableObjectType | ParamType; | ||
export declare class NameType { | ||
@@ -196,4 +179,12 @@ readonly kind: string; | ||
optional: boolean; | ||
rest: boolean; | ||
description: string; | ||
constructor(data: { | ||
name: string; | ||
type: Type; | ||
optional?: boolean; | ||
rest?: boolean; | ||
description?: string; | ||
}); | ||
traverse(): Iterable<Node>; | ||
constructor(name: string, type: Type, optional?: boolean); | ||
serialize(): string; | ||
@@ -200,0 +191,0 @@ } |
@@ -293,29 +293,2 @@ "use strict"; | ||
exports.Property = Property; | ||
class Param { | ||
constructor(data) { | ||
this.kind = 'param'; | ||
this.name = data.name; | ||
this.type = data.type || exports.anyType; | ||
this.optional = data.optional || false; | ||
this.rest = data.rest || false; | ||
this.description = data.description || ''; | ||
} | ||
*traverse() { | ||
yield* this.type.traverse(); | ||
yield this; | ||
} | ||
serialize() { | ||
let out = ''; | ||
if (this.rest) { | ||
out += '...'; | ||
} | ||
out += this.name; | ||
if (this.optional) { | ||
out += '?'; | ||
} | ||
out += ': ' + this.type.serialize(); | ||
return out; | ||
} | ||
} | ||
exports.Param = Param; | ||
// string, MyClass, null, undefined, any | ||
@@ -480,7 +453,9 @@ class NameType { | ||
class ParamType { | ||
constructor(name, type, optional = false) { | ||
constructor(data) { | ||
this.kind = 'param'; | ||
this.name = name; | ||
this.type = type; | ||
this.optional = optional; | ||
this.name = data.name; | ||
this.type = data.type || exports.anyType; | ||
this.optional = data.optional || false; | ||
this.rest = data.rest || false; | ||
this.description = data.description || ''; | ||
} | ||
@@ -492,3 +467,12 @@ *traverse() { | ||
serialize() { | ||
return `${this.name}${this.optional ? '?' : ''}: ${this.type.serialize()}`; | ||
let out = ''; | ||
if (this.rest) { | ||
out += '...'; | ||
} | ||
out += this.name; | ||
if (this.optional) { | ||
out += '?'; | ||
} | ||
out += ': ' + this.type.serialize(); | ||
return out; | ||
} | ||
@@ -503,4 +487,4 @@ } | ||
*traverse() { | ||
for (const m of this.fields) { | ||
yield* m.traverse(); | ||
for (const f of this.fields) { | ||
yield* f.traverse(); | ||
} | ||
@@ -538,4 +522,4 @@ yield this; | ||
*traverse() { | ||
yield this.keyType; | ||
yield this.valueType; | ||
yield* this.keyType.traverse(); | ||
yield* this.valueType.traverse(); | ||
yield this; | ||
@@ -542,0 +526,0 @@ } |
{ | ||
"name": "@polymer/gen-typescript-declarations", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "Generate TypeScript type declarations for Polymer components.", | ||
@@ -5,0 +5,0 @@ "main": "lib/gen-ts.js", |
@@ -13,7 +13,9 @@ # gen-typescript-declarations | ||
Typings for the Polymer 2.0 library will be included in future releases on | ||
Bower in the `types/` directory ([pending | ||
PR](https://github.com/Polymer/polymer/pull/4928)). | ||
Typings for Polymer 2 are planned for regular release starting with version | ||
2.4, and are available in the | ||
[`types/`](https://github.com/Polymer/polymer/tree/master/types) directory on | ||
the `master` branch now. | ||
Install Polymer normally from Bower, and add a [triple-slash | ||
Once Polymer 2.4 is released, to use the typings, install Polymer normally from | ||
Bower, and add a [triple-slash | ||
directive](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) | ||
@@ -32,2 +34,5 @@ anywhere in your TypeScript project for the typings you require. Each HTML | ||
Typings for Polymer 3 are planned but not yet available (see | ||
[#18](https://github.com/Polymer/gen-typescript-declarations/issues/18)). | ||
You may also be interested in the [Polymer | ||
@@ -87,2 +92,9 @@ decorators](https://github.com/Polymer/polymer-decorators). | ||
* **`renameTypes`**`: {[name: string]: string}` | ||
Whenever a type with a name in this map is encountered, replace it with | ||
the given name. Note this only applies to named types found in places like | ||
function/method parameters and return types. It does not currently rename | ||
e.g. entire generated classes. | ||
## Using as a module | ||
@@ -97,3 +109,3 @@ | ||
"exclude": [ | ||
"test/", | ||
"test/**", | ||
], | ||
@@ -107,2 +119,5 @@ "removeReferences": [ | ||
] | ||
}, | ||
"renameTypes": { | ||
"Polymer_PropertyEffects": "Polymer.PropertyEffects" | ||
} | ||
@@ -109,0 +124,0 @@ } |
@@ -23,8 +23,10 @@ /** | ||
/** | ||
* Convert from a type annotation in Closure syntax to a TypeScript type | ||
* expression AST (e.g `Array` => `Array<any>|null`). | ||
* Convert a Closure type expression string to its equivalent TypeScript AST | ||
* node. | ||
* | ||
* Note that function and method parameters should instead use | ||
* `closureParamToTypeScript`. | ||
*/ | ||
export function closureTypeToTypeScript( | ||
closureType: (string|null|undefined), | ||
templateTypes: string[] = []): ts.Type { | ||
closureType: string|null|undefined, templateTypes: string[] = []): ts.Type { | ||
if (!closureType) { | ||
@@ -43,12 +45,22 @@ return ts.anyType; | ||
/** | ||
* Convert from a parameter type annotation in Closure syntax to a TypeScript | ||
* type expression AST | ||
* (e.g `Array=` => `{type: 'Array<any>|null', optional: true}`). | ||
* Convert a Closure function or method parameter type expression string to its | ||
* equivalent TypeScript AST node. | ||
* | ||
* This differs from `closureTypeToTypeScript` in that it always returns a | ||
* `ParamType`, and can parse the optional (`foo=`) and rest (`...foo`) | ||
* syntaxes, which only apply when parsing an expression in the context of a | ||
* parameter. | ||
*/ | ||
export function closureParamToTypeScript( | ||
closureType: (string|null|undefined), | ||
name: string, | ||
closureType: string|null|undefined, | ||
templateTypes: string[] = [], | ||
): {type: ts.Type, optional: boolean, rest: boolean} { | ||
): ts.ParamType { | ||
if (!closureType) { | ||
return {type: ts.anyType, optional: false, rest: false}; | ||
return new ts.ParamType({ | ||
name, | ||
type: ts.anyType, | ||
optional: false, | ||
rest: false, | ||
}); | ||
} | ||
@@ -60,3 +72,4 @@ | ||
} catch { | ||
return { | ||
return new ts.ParamType({ | ||
name, | ||
type: ts.anyType, | ||
@@ -68,28 +81,44 @@ // It's important we try to get optional right even if we can't parse | ||
rest: false, | ||
}; | ||
}); | ||
} | ||
// Optional and Rest types are always the top-level node. | ||
switch (ast.type) { | ||
return convertParam(name, ast, templateTypes); | ||
} | ||
/** | ||
* Convert a doctrine function or method parameter AST node to its equivalent | ||
* TypeScript parameter AST node. | ||
*/ | ||
function convertParam( | ||
name: string, node: doctrine.Type, templateTypes: string[]): ts.ParamType { | ||
switch (node.type) { | ||
case 'OptionalType': | ||
return { | ||
type: convert(ast.expression, templateTypes), | ||
return new ts.ParamType({ | ||
name, | ||
type: convert(node.expression, templateTypes), | ||
optional: true, | ||
rest: false, | ||
}; | ||
}); | ||
case 'RestType': | ||
return { | ||
return new ts.ParamType({ | ||
name, | ||
// The Closure type annotation for a rest parameter looks like | ||
// `...foo`, where `foo` is implicitly an array. The TypeScript | ||
// equivalent is explicitly an array, so we wrap it in one here. | ||
type: new ts.ArrayType(convert(ast.expression, templateTypes)), | ||
type: new ts.ArrayType( | ||
node.expression !== undefined ? | ||
convert(node.expression, templateTypes) : | ||
ts.anyType), | ||
optional: false, | ||
rest: true, | ||
}; | ||
}); | ||
default: | ||
return { | ||
type: convert(ast, templateTypes), | ||
return new ts.ParamType({ | ||
name, | ||
type: convert(node, templateTypes), | ||
optional: false, | ||
rest: false, | ||
}; | ||
}); | ||
} | ||
@@ -99,4 +128,3 @@ } | ||
/** | ||
* Format the given Closure type expression AST node as a TypeScript type | ||
* annotation string. | ||
* Convert a doctrine AST node to its equivalent TypeScript AST node. | ||
*/ | ||
@@ -219,6 +247,7 @@ function convert(node: doctrine.Type, templateTypes: string[]): ts.Type { | ||
const params = node.params.map( | ||
(param, idx) => new ts.ParamType( | ||
(param, idx) => convertParam( | ||
// TypeScript wants named parameters, but we don't have names. | ||
'p' + idx, | ||
convert(param, templateTypes))); | ||
param, | ||
templateTypes)); | ||
if (node.new) { | ||
@@ -268,3 +297,3 @@ return new ts.ConstructorType( | ||
fields.push(new ts.ParamType(field.key, fieldType, optional)); | ||
fields.push(new ts.ParamType({name: field.key, type: fieldType, optional})); | ||
} | ||
@@ -271,0 +300,0 @@ return new ts.RecordType(fields); |
@@ -315,3 +315,3 @@ /** | ||
params: [ | ||
new ts.Param({name: 'base', type: new ts.NameType('T')}), | ||
new ts.ParamType({name: 'base', type: new ts.NameType('T')}), | ||
], | ||
@@ -335,3 +335,3 @@ returns: new ts.IntersectionType([ | ||
params: [ | ||
new ts.Param({ | ||
new ts.ParamType({ | ||
name: 'args', | ||
@@ -397,5 +397,4 @@ type: new ts.ArrayType(ts.anyType), | ||
// which only handles this for class method parameters currently. | ||
const {type, optional, rest} = | ||
closureParamToTypeScript(param.type, feature.templateTypes); | ||
f.params.push(new ts.Param({name: param.name, type, optional, rest})); | ||
f.params.push(closureParamToTypeScript( | ||
param.name, param.type, feature.templateTypes)); | ||
} | ||
@@ -452,3 +451,4 @@ | ||
for (const param of reverseIter(method.params || [])) { | ||
let {type, optional, rest} = closureParamToTypeScript(param.type); | ||
const tsParam = closureParamToTypeScript(param.name, param.type); | ||
tsParam.description = param.description || ''; | ||
@@ -461,7 +461,7 @@ if (param.defaultValue !== undefined) { | ||
if (!requiredAhead) { | ||
optional = true; | ||
tsParam.optional = true; | ||
} else { | ||
type = new ts.UnionType([type, ts.undefinedType]); | ||
tsParam.type = new ts.UnionType([tsParam.type, ts.undefinedType]); | ||
} | ||
} else if (!optional) { | ||
} else if (!tsParam.optional) { | ||
requiredAhead = true; | ||
@@ -472,16 +472,10 @@ } | ||
// JSDoc type annotation (or if it was wrong). | ||
rest = rest || !!param.rest; | ||
if (rest && type.kind !== 'array') { | ||
tsParam.rest = tsParam.rest || !!param.rest; | ||
if (tsParam.rest && tsParam.type.kind !== 'array') { | ||
// Closure rest parameter types are written without the Array syntax, | ||
// but in TypeScript they must be explicitly arrays. | ||
type = new ts.ArrayType(type); | ||
tsParam.type = new ts.ArrayType(tsParam.type); | ||
} | ||
m.params.unshift(new ts.Param({ | ||
name: param.name, | ||
description: param.description, | ||
type, | ||
optional, | ||
rest | ||
})); | ||
m.params.unshift(tsParam); | ||
} | ||
@@ -488,0 +482,0 @@ |
@@ -16,3 +16,3 @@ /** | ||
export type Node = | ||
Document|Namespace|Class|Interface|Function|Method|Type|ParamType|Property; | ||
Document|Namespace|Class|Interface|Function|Method|Type|Property; | ||
@@ -255,3 +255,3 @@ export class Document { | ||
description: string; | ||
params: Param[]; | ||
params: ParamType[]; | ||
templateTypes: string[]; | ||
@@ -265,3 +265,3 @@ returns: Type; | ||
description?: string, | ||
params?: Param[], | ||
params?: ParamType[], | ||
templateTypes?: string[], | ||
@@ -379,46 +379,5 @@ returns?: Type, | ||
export class Param { | ||
readonly kind = 'param'; | ||
name: string; | ||
type: Type; | ||
optional: boolean; | ||
rest: boolean; | ||
description: string; | ||
constructor(data: { | ||
name: string, | ||
type: Type, | ||
optional?: boolean, | ||
rest?: boolean, | ||
description?: string | ||
}) { | ||
this.name = data.name; | ||
this.type = data.type || anyType; | ||
this.optional = data.optional || false; | ||
this.rest = data.rest || false; | ||
this.description = data.description || ''; | ||
} | ||
* traverse(): Iterable<Node> { | ||
yield* this.type.traverse(); | ||
yield this; | ||
} | ||
serialize(): string { | ||
let out = ''; | ||
if (this.rest) { | ||
out += '...'; | ||
} | ||
out += this.name; | ||
if (this.optional) { | ||
out += '?'; | ||
} | ||
out += ': ' + this.type.serialize(); | ||
return out; | ||
} | ||
} | ||
// A TypeScript type expression. | ||
export type Type = NameType|UnionType|ArrayType|FunctionType|ConstructorType| | ||
RecordType|IntersectionType|IndexableObjectType; | ||
RecordType|IntersectionType|IndexableObjectType|ParamType; | ||
@@ -606,3 +565,19 @@ // string, MyClass, null, undefined, any | ||
optional: boolean; | ||
rest: boolean; | ||
description: string; | ||
constructor(data: { | ||
name: string, | ||
type: Type, | ||
optional?: boolean, | ||
rest?: boolean, | ||
description?: string | ||
}) { | ||
this.name = data.name; | ||
this.type = data.type || anyType; | ||
this.optional = data.optional || false; | ||
this.rest = data.rest || false; | ||
this.description = data.description || ''; | ||
} | ||
* traverse(): Iterable<Node> { | ||
@@ -613,11 +588,14 @@ yield* this.type.traverse(); | ||
constructor(name: string, type: Type, optional: boolean = false) { | ||
this.name = name; | ||
this.type = type; | ||
this.optional = optional; | ||
serialize(): string { | ||
let out = ''; | ||
if (this.rest) { | ||
out += '...'; | ||
} | ||
out += this.name; | ||
if (this.optional) { | ||
out += '?'; | ||
} | ||
out += ': ' + this.type.serialize(); | ||
return out; | ||
} | ||
serialize() { | ||
return `${this.name}${this.optional ? '?' : ''}: ${this.type.serialize()}`; | ||
} | ||
} | ||
@@ -634,4 +612,4 @@ | ||
* traverse(): Iterable<Node> { | ||
for (const m of this.fields) { | ||
yield* m.traverse(); | ||
for (const f of this.fields) { | ||
yield* f.traverse(); | ||
} | ||
@@ -678,4 +656,4 @@ yield this; | ||
* traverse(): Iterable<Node> { | ||
yield this.keyType; | ||
yield this.valueType; | ||
yield* this.keyType.traverse(); | ||
yield* this.valueType.traverse(); | ||
yield this; | ||
@@ -682,0 +660,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
164847
135
3353