@player-ui/player 0.10.0-next.3 → 0.10.0-next.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Player.native.js +6 -0
- package/dist/Player.native.js.map +1 -1
- package/dist/cjs/index.cjs +6 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +6 -0
- package/dist/index.mjs +6 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/binding/__tests__/parser.bench.ts +22 -0
- package/src/binding/__tests__/resolver.test.ts +6 -3
- package/src/binding-grammar/custom/index.ts +11 -1
package/package.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"types"
|
|
7
7
|
],
|
|
8
8
|
"name": "@player-ui/player",
|
|
9
|
-
"version": "0.10.0-next.
|
|
9
|
+
"version": "0.10.0-next.5",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-ui/partial-match-registry": "0.10.0-next.
|
|
13
|
-
"@player-ui/make-flow": "0.10.0-next.
|
|
14
|
-
"@player-ui/types": "0.10.0-next.
|
|
12
|
+
"@player-ui/partial-match-registry": "0.10.0-next.5",
|
|
13
|
+
"@player-ui/make-flow": "0.10.0-next.5",
|
|
14
|
+
"@player-ui/types": "0.10.0-next.5",
|
|
15
15
|
"@types/dlv": "^1.1.4",
|
|
16
16
|
"dequal": "^2.0.2",
|
|
17
17
|
"dlv": "^1.1.3",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { bench, describe } from "vitest";
|
|
2
|
+
import get from "dlv";
|
|
3
|
+
import { getBindingSegments } from "..";
|
|
4
|
+
import { testCases, testModel } from "./resolver.test";
|
|
5
|
+
import { parseCustom, ParserSuccessResult } from "../../binding-grammar";
|
|
6
|
+
import { resolveBindingAST } from "../resolver";
|
|
7
|
+
|
|
8
|
+
describe("parser benchmarks", () => {
|
|
9
|
+
testCases.map(
|
|
10
|
+
([input, expectedOutput]) => {
|
|
11
|
+
bench(`Resolving binding: ${input}`, () => {
|
|
12
|
+
const parsedBinding = parseCustom(input);
|
|
13
|
+
resolveBindingAST((parsedBinding as ParserSuccessResult).path, {
|
|
14
|
+
getValue: (path) => get(testModel, getBindingSegments(path) as any),
|
|
15
|
+
convertToPath: (p) => p,
|
|
16
|
+
evaluate: () => undefined,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
{ iterations: 10000 },
|
|
21
|
+
);
|
|
22
|
+
});
|
|
@@ -5,7 +5,7 @@ import { parseCustom } from "../../binding-grammar";
|
|
|
5
5
|
import { resolveBindingAST } from "../resolver";
|
|
6
6
|
import { getBindingSegments } from "../utils";
|
|
7
7
|
|
|
8
|
-
const testModel = {
|
|
8
|
+
export const testModel = {
|
|
9
9
|
foo: {
|
|
10
10
|
pets: [
|
|
11
11
|
{
|
|
@@ -23,11 +23,14 @@ const testModel = {
|
|
|
23
23
|
"other",
|
|
24
24
|
],
|
|
25
25
|
},
|
|
26
|
-
};
|
|
26
|
+
} as const;
|
|
27
27
|
|
|
28
|
-
const testCases: Array<[string, string]> = [
|
|
28
|
+
export const testCases: Array<[string, string]> = [
|
|
29
29
|
["foo.bar", "foo.bar"],
|
|
30
30
|
["foo.pets.1.name", "foo.pets.1.name"],
|
|
31
|
+
["foo.pets.01.name", "foo.pets.1.name"],
|
|
32
|
+
["foo.pets['01'].name", "foo.pets.01.name"],
|
|
33
|
+
["foo.pets[01].name", "foo.pets.1.name"],
|
|
31
34
|
['foo.pets[name = "frodo"].type', "foo.pets.2.type"],
|
|
32
35
|
['foo.pets["name" = "sprinkles"].type', "foo.pets.4.type"],
|
|
33
36
|
];
|
|
@@ -82,7 +82,7 @@ export const parse: Parser = (path) => {
|
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
let value = ch;
|
|
85
|
+
let value: string | number = ch;
|
|
86
86
|
|
|
87
87
|
while (next()) {
|
|
88
88
|
if (!isIdentifierChar(ch)) {
|
|
@@ -93,6 +93,8 @@ export const parse: Parser = (path) => {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
if (value) {
|
|
96
|
+
const maybeNumber = Number(value);
|
|
97
|
+
value = isNaN(maybeNumber) ? value : maybeNumber;
|
|
96
98
|
return toValue(value);
|
|
97
99
|
}
|
|
98
100
|
};
|
|
@@ -260,6 +262,14 @@ export const parse: Parser = (path) => {
|
|
|
260
262
|
|
|
261
263
|
let bracketSegment = parseBracket();
|
|
262
264
|
|
|
265
|
+
if (bracketSegment?.name === "Value") {
|
|
266
|
+
const maybeNumber = Number(bracketSegment.value);
|
|
267
|
+
bracketSegment.value =
|
|
268
|
+
isNaN(maybeNumber) || String(maybeNumber) !== bracketSegment.value
|
|
269
|
+
? bracketSegment.value
|
|
270
|
+
: maybeNumber;
|
|
271
|
+
}
|
|
272
|
+
|
|
263
273
|
while (bracketSegment !== undefined) {
|
|
264
274
|
parsed.push(bracketSegment);
|
|
265
275
|
bracketSegment = parseBracket();
|