Skip to content

Commit

Permalink
convert numerical segments to numbers in parser vs during BindingInst…
Browse files Browse the repository at this point in the history
…ance creation
  • Loading branch information
KetanReddy committed Nov 4, 2024
1 parent 5bc1177 commit 6b2aa5c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion core/player/src/binding-grammar/custom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const parse: Parser = (path) => {
return;
}

let value = ch;
let value: string | number = ch;

while (next()) {
if (!isIdentifierChar(ch)) {
Expand All @@ -93,6 +93,8 @@ export const parse: Parser = (path) => {
}

if (value) {
const maybeNumber = Number(value);
value = isNaN(maybeNumber) ? value : maybeNumber;
return toValue(value);
}
};
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6b2aa5c

Please sign in to comment.