From 323272671890bc4e4b2bf96e8f992885dd1fa4fb Mon Sep 17 00:00:00 2001 From: Alexander Drozdov Date: Tue, 27 Jul 2021 19:42:11 +0300 Subject: [PATCH] fix: virtualfn is not called if there is no sections left to parse --- src/parser/Parser.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/parser/Parser.ts b/src/parser/Parser.ts index ad2f4377..aa3979d0 100644 --- a/src/parser/Parser.ts +++ b/src/parser/Parser.ts @@ -22,13 +22,14 @@ type SectionParseResult = typeof PARSER_SKIPPED type ParserFn = (section: string[], item: ParsedItem) => SectionParseResult +type VirtualParserFn = (item: ParsedItem) => void -const parsers: ParserFn[] = [ +const parsers: Array = [ parseUnidentified, - parseSuperior, + { virtual: parseSuperior }, parseSynthesised, parseCategoryByHelpText, - normalizeName, + { virtual: normalizeName }, // ----------- parseItemLevel, parseTalismanTier, @@ -48,7 +49,7 @@ const parsers: ParserFn[] = [ parseModifiers, parseModifiers, parseModifiers, - transformToLegacyModifiers + { virtual: transformToLegacyModifiers } ] export function parseClipboard (clipboard: string) { @@ -83,6 +84,11 @@ export function parseClipboard (clipboard: string) { // each section can be parsed at most by one parser for (const parser of parsers) { + if (typeof parser === 'object') { + parser.virtual(parsed) + continue + } + for (const section of sections) { const result = parser(section, parsed) if (result === SECTION_PARSED) { @@ -97,7 +103,7 @@ export function parseClipboard (clipboard: string) { return Object.freeze(parsed) } -function normalizeName (_: string[], item: ParsedItem) { +function normalizeName (item: ParsedItem) { if (item.rarity === ItemRarity.Magic) { const baseType = magicBasetype(item.name) if (baseType) { @@ -129,8 +135,6 @@ function normalizeName (_: string[], item: ParsedItem) { item.category = baseType?.category item.icon = baseType?.icon } - - return PARSER_SKIPPED as SectionParseResult // fake parser } function parseMap (section: string[], item: ParsedItem) { @@ -545,7 +549,7 @@ function parseSynthesised (section: string[], item: ParsedItem) { return SECTION_SKIPPED } -function parseSuperior (_: string[], item: ParsedItem) { +function parseSuperior (item: ParsedItem) { if ( (item.rarity === ItemRarity.Normal) || (item.rarity === ItemRarity.Magic && item.isUnidentified) || @@ -556,8 +560,6 @@ function parseSuperior (_: string[], item: ParsedItem) { item.name = _$[C.ITEM_SUPERIOR].exec(item.name)![1] } } - - return PARSER_SKIPPED as SectionParseResult // fake parser } function parseCategoryByHelpText (section: string[], item: ParsedItem) { @@ -673,9 +675,8 @@ function parseStatsFromMod (lines: string[], item: ParsedItem, modifier: ParsedM /** * @deprecated */ -function transformToLegacyModifiers (_: string[], item: ParsedItem) { +function transformToLegacyModifiers (item: ParsedItem) { item.modifiers = sumStatsFromMods(item.newMods) - return PARSER_SKIPPED as SectionParseResult // fake parser } export function removeLinesEnding (