Skip to content

Commit

Permalink
Merge pull request #565 from player-ui/bugfix/quoted-bindings
Browse files Browse the repository at this point in the history
Fix Binding Instantiation of Escaped Numerical Bindings
  • Loading branch information
KetanReddy authored Jan 3, 2025
2 parents 271d910 + 852e47f commit 19ff47d
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 214 deletions.
6 changes: 0 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@
- Jeremiah Zucker ([@sugarmanz](https://github.com/sugarmanz))
- Ketan Reddy ([@KetanReddy](https://github.com/KetanReddy))

---

# 0.10.2 (Wed Dec 04 2024)



---

# 0.10.0 (Wed Dec 04 2024)
Expand Down
10 changes: 10 additions & 0 deletions core/player/src/binding/__tests__/binding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,13 @@ describe("descendent binding", () => {
]);
});
});

describe("Edge cases", () => {
it("Bindings with escaped numbers", () => {
expect(new BindingInstance("foo.01.bar").asArray()).toStrictEqual([
"foo",
"01",
"bar",
]);
});
});
22 changes: 21 additions & 1 deletion core/player/src/binding/__tests__/parser.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bench, describe } from "vitest";
import get from "dlv";
import { getBindingSegments } from "..";
import { BindingInstance, getBindingSegments } from "..";
import { testCases, testModel } from "./resolver.test";
import { parseCustom, ParserSuccessResult } from "../../binding-grammar";
import { resolveBindingAST } from "../resolver";
Expand All @@ -20,3 +20,23 @@ describe("parser benchmarks", () => {
{ iterations: 10000 },
);
});

describe("binding creation benchmarks", () => {
testCases.map(
([input, expectedOutput]) => {
bench(`Resolving binding: ${input}`, () => {
const parsedBinding = parseCustom(input);
const result = resolveBindingAST(
(parsedBinding as ParserSuccessResult).path,
{
getValue: (path) => get(testModel, getBindingSegments(path) as any),
convertToPath: (p) => p,
evaluate: () => undefined,
},
);
const bi = new BindingInstance(result.path);
});
},
{ iterations: 10000 },
);
});
4 changes: 3 additions & 1 deletion core/player/src/binding/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export class BindingInstance {
}

const tryNum = Number(segment);
return isNaN(tryNum) ? segment : tryNum;
// test to make sure turning a numerical string to a number doesn't change
// the actual value of the string by getting rid of a leading zero
return isNaN(tryNum) || String(tryNum) !== segment ? segment : tryNum;
});
Object.freeze(this.split);
this.joined = this.split.join(".");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"ts-node": "^10.9.2",
"tsconfig-paths-webpack-plugin": "^4.1.0",
"tslib": "^2.6.2",
"tsup": "^8.0.1",
"tsup": "^8.3.5",
"typescript": "5.5.3",
"unist-util-visit": "^5.0.0",
"uuid": "^8.3.2",
Expand Down
526 changes: 325 additions & 201 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions scripts/next-changelogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* eslint-disable no-await-in-loop */
const { execSync } = require("child_process");

const getLatestReleaseTag = () => {
const getLatestReleaseTags = () => {
const tags = execSync("git tag --sort=-creatordate", { encoding: "utf8" });
return tags
.split("\n")
Expand All @@ -12,21 +12,25 @@ const getLatestReleaseTag = () => {
(tag) =>
tag.includes("-next.") ||
tag.match(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/),
)[0];
);
};

class NextChangelogsPlugin {
name = "next-changelogs";

apply(auto) {
auto.hooks.next.tapPromise(this.name, async ({ dryRun }) => {
const latestRelease = getLatestReleaseTag();
const [latest, second] = getLatestReleaseTags();
if (dryRun) {
auto.logger.log.info(
`Dry run: making changelog from last release: ${latestRelease}`,
);
} else {
await auto.changelog({ from: latestRelease });
await auto.changelog({
from: second,
to: latest,
title: `${latest} ${new Date().toDateString()}`,
});
execSync(`git push ${auto.remote} ${auto.baseBranch}`);
}
});
Expand Down

0 comments on commit 19ff47d

Please sign in to comment.