edit tsgen to handle generic default types

This commit is contained in:
Chnapy 2020-01-02 21:51:38 +01:00
parent 74c5a373e8
commit bf09e4740a
3 changed files with 37 additions and 7 deletions

View file

@ -468,10 +468,21 @@ class Parser {
if (doclet.tags)
for (let tag of doclet.tags) {
if (tag.originalTitle === 'generic') {
let matches = tag.value.match(/(?:(?:{)([^}]+)(?:}))?\s?([^\s]+)(?:\s?-\s?(?:\[)(.+)(?:\]))?/);
let typeParam = dom.create.typeParameter(matches[2], matches[1] == null ? null : dom.create.typeParameter(matches[1]));
/**
* {string} K - [key]
* 1 = string | 2 = null | 3 = K | 4 = key
*
* {string=string} K - [key]
* 1 = string | 2 = string | 3 = K | 4 = key
*/
const matches = tag.value.match(/(?:(?:{)([^}=]+)(?:=)?([^}=]+)?(?:}))?\s?([^\s]+)(?:\s?-\s?(?:\[)(.+)(?:\]))?/);
const [_, _type, _defaultType, _name, _paramsNames] = matches;
const typeParam = dom.create.typeParameter(_name, _type == null ? null : dom.create.typeParameter(_type));
if (_defaultType != null) {
typeParam.defaultType = dom.create.typeParameter(_defaultType);
}
obj.typeParameters.push(typeParam);
handleOverrides(matches[3], matches[2]);
handleOverrides(_paramsNames, _name);
}
else if (tag.originalTitle === 'genericUse') {
let matches = tag.value.match(/(?:(?:{)([^}]+)(?:}))(?:\s?-\s?(?:\[)(.+)(?:\]))?/);

File diff suppressed because one or more lines are too long

View file

@ -554,10 +554,29 @@ export class Parser {
if (doclet.tags)
for (let tag of doclet.tags) {
if (tag.originalTitle === 'generic') {
let matches = (<string>tag.value).match(/(?:(?:{)([^}]+)(?:}))?\s?([^\s]+)(?:\s?-\s?(?:\[)(.+)(?:\]))?/);
let typeParam = dom.create.typeParameter(matches[2], matches[1] == null ? null : dom.create.typeParameter(matches[1]));
/**
* {string} K - [key]
* 1 = string | 2 = null | 3 = K | 4 = key
*
* {string=string} K - [key]
* 1 = string | 2 = string | 3 = K | 4 = key
*/
const matches = (<string>tag.value).match(/(?:(?:{)([^}=]+)(?:=)?([^}=]+)?(?:}))?\s?([^\s]+)(?:\s?-\s?(?:\[)(.+)(?:\]))?/);
const [_, _type, _defaultType, _name, _paramsNames] = matches;
const typeParam = dom.create.typeParameter(
_name,
_type == null ? null : dom.create.typeParameter(_type)
);
if(_defaultType != null) {
typeParam.defaultType = dom.create.typeParameter(_defaultType);
}
(<dom.ClassDeclaration | dom.FunctionDeclaration | dom.TypeAliasDeclaration>obj).typeParameters.push(typeParam);
handleOverrides(matches[3], matches[2]);
handleOverrides(_paramsNames, _name);
} else if (tag.originalTitle === 'genericUse') {
let matches = (<string>tag.value).match(/(?:(?:{)([^}]+)(?:}))(?:\s?-\s?(?:\[)(.+)(?:\]))?/);
let overrideType: string = this.prepareTypeName(matches[1]);