mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:50:33 +08:00
ArrayEntity parsing fixed
This commit is contained in:
11
dist/ueblueprint.js
vendored
11
dist/ueblueprint.js
vendored
@@ -4525,7 +4525,14 @@ class ArrayEntity extends IEntity {
|
||||
|
||||
/** @type {typeof IEntity} */
|
||||
static type
|
||||
static grammar = this.createGrammar()
|
||||
static #grammar
|
||||
static get grammar() {
|
||||
return this.#grammar ?? this.createGrammar()
|
||||
}
|
||||
static set grammar(value) {
|
||||
this.#grammar = value;
|
||||
}
|
||||
//static grammar = this.createGrammar()
|
||||
|
||||
/** @param {ExtractType<T>[]} values */
|
||||
constructor(values = []) {
|
||||
@@ -4560,7 +4567,7 @@ class ArrayEntity extends IEntity {
|
||||
this.asUniqueClass()
|
||||
);
|
||||
result.type = /** @type {ExtractType<T>} */(type);
|
||||
this.grammar = result.createGrammar();
|
||||
result.grammar = result.createGrammar();
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
4
dist/ueblueprint.min.js
vendored
4
dist/ueblueprint.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -42,7 +42,7 @@ export default class ArrayEntity extends IEntity {
|
||||
this.asUniqueClass()
|
||||
)
|
||||
result.type = /** @type {ExtractType<T>} */(type)
|
||||
this.grammar = result.createGrammar()
|
||||
result.grammar = result.createGrammar()
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ export default class IEntity {
|
||||
this.#keys = [... new Set(value)]
|
||||
}
|
||||
|
||||
/** @param {{ [key: String]: IEntity }} values */
|
||||
constructor(values = {}) {
|
||||
const keys = Utility.mergeArrays(Object.keys(values), Object.keys(this.Self().attributes))
|
||||
for (const key of keys) {
|
||||
|
||||
@@ -24,8 +24,4 @@ export default class UnknownKeysEntity extends IEntity {
|
||||
attributes.forEach(attributeSetter => attributeSetter(values))
|
||||
return new this(values)
|
||||
}).label("UnknownKeysEntity")
|
||||
|
||||
constructor(values = {}) {
|
||||
super(values)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,43 +57,69 @@ test("ArrayEntity", () => {
|
||||
123,
|
||||
3BEF2168446CAA32D5B54289FAB2F0BA,
|
||||
Some(a=1, b="2")
|
||||
)`)).toStrictEqual(new ArrayEntity([
|
||||
)`)).toEqual(new ArrayEntity([
|
||||
new StringEntity("alpha"),
|
||||
new StringEntity("beta"),
|
||||
new NumberEntity(123),
|
||||
new GuidEntity("3BEF2168446CAA32D5B54289FAB2F0BA"),
|
||||
new (UnknownKeysEntity.withLookbehind("Some"))({
|
||||
a: 1,
|
||||
b: "2",
|
||||
a: new NumberEntity(1),
|
||||
b: new StringEntity("2"),
|
||||
})
|
||||
]))
|
||||
expect(grammar.parse(`(
|
||||
A(first = (9,8,7,6,5), second = 00000000000000000000000000000000),
|
||||
B(key="hello"),
|
||||
)`)).toStrictEqual([
|
||||
)`)).toEqual(new ArrayEntity([
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: "A",
|
||||
first: [9, 8, 7, 6, 5],
|
||||
lookbehind: new StringEntity("A"),
|
||||
first: new ArrayEntity([
|
||||
new NumberEntity(9),
|
||||
new NumberEntity(8),
|
||||
new NumberEntity(7),
|
||||
new NumberEntity(6),
|
||||
new NumberEntity(5),
|
||||
]),
|
||||
second: new GuidEntity("00000000000000000000000000000000"),
|
||||
}),
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: "B",
|
||||
key: "hello",
|
||||
lookbehind: new StringEntity("B"),
|
||||
key: new StringEntity("hello"),
|
||||
})
|
||||
])
|
||||
]))
|
||||
|
||||
// Nested
|
||||
expect(grammar.parse("((1, 2), (3, 4))")).toStrictEqual([[1, 2], [3, 4]])
|
||||
expect(grammar.parse('(((1, 2), (3, 4)), 5)')).toStrictEqual([[[1, 2], [3, 4]], 5])
|
||||
expect(grammar.parse("((1, 2), (3, 4))")).toEqual(new ArrayEntity([
|
||||
new ArrayEntity([new NumberEntity(1), new NumberEntity(2)]),
|
||||
new ArrayEntity([new NumberEntity(3), new NumberEntity(4)]),
|
||||
]))
|
||||
expect(grammar.parse('(((1, 2), (3, 4)), 5)')).toEqual(new ArrayEntity([
|
||||
new ArrayEntity([
|
||||
new ArrayEntity([new NumberEntity(1), new NumberEntity(2)]),
|
||||
new ArrayEntity([new NumberEntity(3), new NumberEntity(4)])
|
||||
]),
|
||||
new NumberEntity(5)
|
||||
]))
|
||||
expect(grammar.parse(`(
|
||||
One(a = (1,(2,(3,(4)))), b = ()),
|
||||
)`)).toStrictEqual([
|
||||
)`)).toEqual(new ArrayEntity([
|
||||
new UnknownKeysEntity({
|
||||
lookbehind: "One",
|
||||
a: [1, [2, [3, [4]]]],
|
||||
a: new ArrayEntity([
|
||||
new NumberEntity(1),
|
||||
new ArrayEntity([
|
||||
new NumberEntity(2),
|
||||
new ArrayEntity([
|
||||
new NumberEntity(3),
|
||||
new ArrayEntity([
|
||||
new NumberEntity(4),
|
||||
])
|
||||
])
|
||||
])
|
||||
]),
|
||||
b: null,
|
||||
}),
|
||||
])
|
||||
]))
|
||||
})
|
||||
|
||||
test("Boolean", () => {
|
||||
|
||||
Reference in New Issue
Block a user