From 6b2aa5c37bb7d8bcc272edaf31b0000ec4b52dc1 Mon Sep 17 00:00:00 2001 From: Ketan Reddy Date: Mon, 4 Nov 2024 11:37:34 -0800 Subject: [PATCH] convert numerical segments to numbers in parser vs during BindingInstance creation --- core/player/src/binding-grammar/custom/index.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/player/src/binding-grammar/custom/index.ts b/core/player/src/binding-grammar/custom/index.ts index c51adbfc0..d9c843b84 100644 --- a/core/player/src/binding-grammar/custom/index.ts +++ b/core/player/src/binding-grammar/custom/index.ts @@ -82,7 +82,7 @@ export const parse: Parser = (path) => { return; } - let value = ch; + let value: string | number = ch; while (next()) { if (!isIdentifierChar(ch)) { @@ -93,6 +93,8 @@ export const parse: Parser = (path) => { } if (value) { + const maybeNumber = Number(value); + value = isNaN(maybeNumber) ? value : maybeNumber; return toValue(value); } }; @@ -260,6 +262,14 @@ export const parse: Parser = (path) => { let bracketSegment = parseBracket(); + if (bracketSegment?.name === "Value") { + const maybeNumber = Number(bracketSegment.value); + bracketSegment.value = + isNaN(maybeNumber) || String(maybeNumber) !== bracketSegment.value + ? bracketSegment.value + : maybeNumber; + } + while (bracketSegment !== undefined) { parsed.push(bracketSegment); bracketSegment = parseBracket();