From b963fc75dd4e45e7841a0fab9362bff7befc0a49 Mon Sep 17 00:00:00 2001 From: isaacs Date: Sat, 29 Apr 2023 13:36:24 -0700 Subject: [PATCH] chore: code style Updates from PR review --- src/compose/compose-collection.ts | 7 ++----- src/compose/resolve-flow-collection.ts | 10 ++++------ src/schema/yaml-1.1/timestamp.ts | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/compose/compose-collection.ts b/src/compose/compose-collection.ts index 3c21b44d..a287bf1a 100644 --- a/src/compose/compose-collection.ts +++ b/src/compose/compose-collection.ts @@ -38,10 +38,8 @@ function resolveCollection( if (tagName === '!' || tagName === Coll.tagName) { coll.tag = Coll.tagName return coll - } else if (tagName) { - coll.tag = tagName } - + if (tagName) coll.tag = tagName return coll } @@ -58,7 +56,6 @@ export function composeCollection( onError(tagToken, 'TAG_RESOLVE_FAILED', msg) ) - let coll: YAMLMap.Parsed | YAMLSeq.Parsed let expType: 'map' | 'seq' | undefined = token.type === 'block-map' ? 'map' @@ -133,7 +130,7 @@ export function composeCollection( } } - coll = resolveCollection(CN, ctx, token, onError, tagName, tag) + const coll = resolveCollection(CN, ctx, token, onError, tagName, tag) const res = tag.resolve?.( diff --git a/src/compose/resolve-flow-collection.ts b/src/compose/resolve-flow-collection.ts index 10377ac9..33f7b2ba 100644 --- a/src/compose/resolve-flow-collection.ts +++ b/src/compose/resolve-flow-collection.ts @@ -24,12 +24,10 @@ export function resolveFlowCollection( ) { const isMap = fc.start.source === '{' const fcName = isMap ? 'flow map' : 'flow sequence' - let NodeClass = tag?.nodeClass - const MapClass = NodeClass || YAMLMap - const SeqClass = NodeClass || YAMLSeq - const coll = isMap - ? (new MapClass(ctx.schema) as YAMLMap.Parsed) - : (new SeqClass(ctx.schema) as YAMLSeq.Parsed) + let NodeClass = (tag?.nodeClass ?? (isMap ? YAMLMap : YAMLSeq)) as { + new (ctx: ComposeContext['schema']): YAMLMap.Parsed | YAMLSeq.Parsed + } + const coll = new NodeClass(ctx.schema) coll.flow = true const atRoot = ctx.atRoot if (atRoot) ctx.atRoot = false diff --git a/src/schema/yaml-1.1/timestamp.ts b/src/schema/yaml-1.1/timestamp.ts index 026c9efb..2093f3ae 100644 --- a/src/schema/yaml-1.1/timestamp.ts +++ b/src/schema/yaml-1.1/timestamp.ts @@ -47,7 +47,7 @@ function stringifySexagesimal(node: Scalar) { return ( sign + parts - .map(n => String(n).padStart(2, '0')) //(n < 10 ? '0' + String(n) : String(n))) + .map(n => String(n).padStart(2, '0')) .join(':') .replace(/000000\d*$/, '') // % 60 may introduce error )