Type system fixes

This commit is contained in:
barsdeveloper
2022-04-11 23:35:28 +02:00
parent 4b045b4c70
commit f71edf1a3c
7 changed files with 55 additions and 57 deletions

View File

@@ -20,8 +20,7 @@ export default class GeneralSerializer extends ISerializer {
let grammar = Grammar.getGrammarForType(ISerializer.grammar, this.entityType)
const parseResult = grammar.parse(value)
if (!parseResult.status) {
console.error("Error when trying to parse the entity " + this.entityType.prototype.constructor.name)
return parseResult
throw new Error(`Error when trying to parse the entity ${this.entityType.prototype.constructor.name}.`)
}
return parseResult.value
}

View File

@@ -102,7 +102,8 @@ export default class Grammar {
let result = new entityType()
attributes.forEach(attributeSetter => attributeSetter(result))
return result
})
}
)
/* --- General --- */
@@ -194,7 +195,8 @@ export default class Grammar {
r.String,
r.Guid,
r.Reference,
r.LocalizedText)
r.LocalizedText
)
PinReference = r => P.seqMap(
r.PathSymbol, // Goes into objectNAme
@@ -239,9 +241,9 @@ export default class Grammar {
.sepBy1(P.whitespace),
P.seq(r.MultilineWhitespace, P.string("End"), P.whitespace, P.string("Object")),
(_, attributes, __) => {
let result = new ObjectEntity()
attributes.forEach(attributeSetter => attributeSetter(result))
return result
let values = {}
attributes.forEach(attributeSetter => attributeSetter(values))
return new ObjectEntity(values)
}
)

View File

@@ -25,8 +25,7 @@ export default class ObjectSerializer extends ISerializer {
read(value) {
const parseResult = ISerializer.grammar.Object.parse(value)
if (!parseResult.status) {
console.error("Error when trying to parse the object.")
return parseResult
throw new Error("Error when trying to parse the object.")
}
return parseResult.value
}