From 65cb36166fc9872b2892474eb3a9d14634053c83 Mon Sep 17 00:00:00 2001 From: iCrawl Date: Wed, 8 Jun 2022 13:27:41 +0200 Subject: [PATCH] fix(VarType): parsing type names --- packages/docgen/src/types/var-type.ts | 35 ++++++++++++++++++--------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/docgen/src/types/var-type.ts b/packages/docgen/src/types/var-type.ts index b18feadf5..40933216d 100644 --- a/packages/docgen/src/types/var-type.ts +++ b/packages/docgen/src/types/var-type.ts @@ -17,18 +17,31 @@ export class DocumentedVarType extends DocumentedItem { } private splitVarName(str: string) { - if (str === '*') return ['*']; - str = str.replace(/\./g, ''); - const matches = str.match(/([\w*]+)([^\w*]+)/g); - const output = []; - if (matches) { - for (const match of matches) { - const groups = /([\w*]+)([^\w*]+)/.exec(match); - output.push([groups![1], groups![2]]); + const res: string[][] = []; + let currGroup: string[] = []; + let currStr = ''; + + const isASymbol = (char: string) => '-!$%^&*()_+|~=`{}[]:;<>?, '.includes(char); + + for (const char of str) { + const currentlyInASymbolSection = isASymbol(currStr[0]!); + const charIsASymbol = isASymbol(char); + + if (currStr.length && currentlyInASymbolSection !== charIsASymbol) { + currGroup.push(currStr); + currStr = char; + + if (!charIsASymbol) { + res.push(currGroup); + currGroup = []; + } + } else { + currStr += char; } - } else { - output.push([str.match(/([\w*]+)/g)![0]]); } - return output; + currGroup.push(currStr); + res.push(currGroup); + + return res; } }