From a4c25fd19438586829195a936c40cf3c517f6cb6 Mon Sep 17 00:00:00 2001 From: "s.kozel" Date: Wed, 10 May 2023 18:18:45 +0200 Subject: [PATCH] fix: react-native property parse error in case of several "-" characters --- .../parsers/props.parser.ts | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/reactNative.parser/parsers/props.parser.ts b/src/reactNative.parser/parsers/props.parser.ts index 0a3ab78..d291b05 100644 --- a/src/reactNative.parser/parsers/props.parser.ts +++ b/src/reactNative.parser/parsers/props.parser.ts @@ -33,28 +33,25 @@ export class PropsParser { } private getDescription(prop: string): string { - const descriptionArray: string[] = prop.split('-'); - descriptionArray.shift(); - return descriptionArray.join('-'); + const propLined = prop.replace(/(?:\r\n|\r|\n)/g, ' '); + const result = propLined.match(/(?<=\})(?:[^-]*-)(.*)/); + if (result && result.length > 1) { + return result[1].trim(); + } + throw new Error("Property parse error. Please check the property string: \"" + prop + "\""); } private getType(prop: string): string { const type: string = prop.slice(prop.indexOf('{') + 1, prop.lastIndexOf('}')); - return type ? type : ''; } private getName(prop: string): string { - const splitted: string[] = prop.split('-'); - if (splitted.length > 1) { - const result = prop.match(/[^}]+(?=-[^-}]*$)/); - if (result) { - return result[0].trim(); - } - throw new Error(`Property parse error. Please check the property string: \"${prop}\"`); - } else { - return splitted[0].replace(/(\r\n|\n|\r)/gm, ''); + const propLined = prop.replace(/(?:\r\n|\r|\n)/g, ' '); + const result = propLined.match(/(?<=\})([^-]*)(?:.*)/); + if (result && result.length > 1) { + return result[1].trim(); } + throw new Error("Property parse error. Please check the property string: \"" + prop + "\""); } - }