mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-04 08:28:17 +08:00
Refactor jsdoc types (#16)
* WIP * Fix type 1 * Missing types info * Some fixes * Several types refactoring and fixes * WIP * Fix grammar
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import IEntity from "./IEntity.js"
|
||||
|
||||
/** @typedef {import("./ObjectEntity.js").default} ObjectEntity */
|
||||
|
||||
export default class Base64ObjectsEncoded extends IEntity {
|
||||
|
||||
static attributes = {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
/** @typedef {import("./IEntity.js").default} IEntity */
|
||||
|
||||
export default class ComputedType {
|
||||
|
||||
#f
|
||||
|
||||
@@ -5,44 +5,6 @@ import SerializerFactory from "../serialization/SerializerFactory.js"
|
||||
import Union from "./Union.js"
|
||||
import Utility from "../Utility.js"
|
||||
|
||||
/**
|
||||
* @template {AnyValue} T
|
||||
* @typedef {(new (...any) => T) | StringConstructor | NumberConstructor | BigIntConstructor | BooleanConstructor
|
||||
* | ArrayConstructor} AnyValueConstructor
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {IEntity | MirroredEntity | String | Number | BigInt | Boolean} AnySimpleValue
|
||||
* @typedef {AnySimpleValue | AnySimpleValue[]} AnyValue
|
||||
* @typedef {(entity: IEntity) => AnyValue} ValueSupplier
|
||||
* @typedef {AnyValueConstructor<AnyValue> | AnyValueConstructor<AnyValue>[] | Union | Union[] | ComputedType | MirroredEntity} AttributeType
|
||||
* @typedef {{
|
||||
* type?: AttributeType,
|
||||
* default?: AnyValue | ValueSupplier,
|
||||
* nullable?: Boolean,
|
||||
* ignored?: Boolean,
|
||||
* serialized?: Boolean,
|
||||
* expected?: Boolean,
|
||||
* inlined?: Boolean,
|
||||
* quoted?: Boolean,
|
||||
* predicate?: (value: AnyValue) => Boolean,
|
||||
* }} AttributeInformation
|
||||
* @typedef {{
|
||||
* [key: String]: AttributeInformation
|
||||
* }} AttributeDeclarations
|
||||
* @typedef {typeof IEntity} EntityConstructor
|
||||
*/
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {{
|
||||
* (value: Boolean): BooleanConstructor,
|
||||
* (value: Number): NumberConstructor,
|
||||
* (value: String): StringConstructor,
|
||||
* (value: BigInt): BigIntConstructor,
|
||||
* (value: T): typeof value.constructor,
|
||||
* }} TypeGetter
|
||||
*/
|
||||
|
||||
export default class IEntity extends Serializable {
|
||||
|
||||
/** @type {String | Union<String[]>} */
|
||||
@@ -65,7 +27,7 @@ export default class IEntity extends Serializable {
|
||||
constructor(values = {}, suppressWarns = false) {
|
||||
super()
|
||||
/** @type {String} */ this.lookbehind
|
||||
const Self = /** @type {EntityConstructor} */(this.constructor)
|
||||
const Self = /** @type {typeof IEntity} */(this.constructor)
|
||||
let attributes = Self.attributes
|
||||
if (values.attributes) {
|
||||
attributes = { ...Self.attributes }
|
||||
@@ -166,7 +128,7 @@ export default class IEntity extends Serializable {
|
||||
.getSerializer(defaultType)
|
||||
.read(/** @type {String} */(value))
|
||||
}
|
||||
assignAttribute(Utility.sanitize(value, /** @type {AnyValueConstructor<*>} */(defaultType)))
|
||||
assignAttribute(Utility.sanitize(value, /** @type {AnyConstructor<*>} */(defaultType)))
|
||||
continue // We have a value, need nothing more
|
||||
}
|
||||
if (Object.hasOwn(attribute, "default")) { // Accept also explicit undefined
|
||||
|
||||
@@ -19,14 +19,14 @@ export default class IntegerEntity extends IEntity {
|
||||
return Grammar.integer.map(v => new this(v))
|
||||
}
|
||||
|
||||
/** @param {Number | AttributeInformation} value */
|
||||
constructor(value = 0) {
|
||||
if (value.constructor !== Object) {
|
||||
// @ts-expect-error
|
||||
value = {
|
||||
super(value.constructor === Object
|
||||
? value
|
||||
: {
|
||||
value: value,
|
||||
}
|
||||
}
|
||||
super(value)
|
||||
)
|
||||
/** @type {Number} */ this.value
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,3 @@
|
||||
|
||||
/**
|
||||
* @typedef {import("./IEntity.js").default} IEntity
|
||||
* @typedef {import("./IEntity.js").EntityConstructor} EntityConstructor
|
||||
*/
|
||||
|
||||
export default class MirroredEntity {
|
||||
|
||||
static attributes = {
|
||||
|
||||
@@ -18,8 +18,6 @@ import UnknownPinEntity from "./UnknownPinEntity.js"
|
||||
import Utility from "../Utility.js"
|
||||
import VariableReferenceEntity from "./VariableReferenceEntity.js"
|
||||
|
||||
/** @typedef {import("./VectorEntity.js").default} VectorEntity */
|
||||
|
||||
export default class ObjectEntity extends IEntity {
|
||||
|
||||
static #keyName = {
|
||||
@@ -305,7 +303,7 @@ export default class ObjectEntity extends IEntity {
|
||||
},
|
||||
CustomProperties: {
|
||||
type: [new Union(PinEntity, UnknownPinEntity)],
|
||||
},
|
||||
}
|
||||
}
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
@@ -316,7 +314,7 @@ export default class ObjectEntity extends IEntity {
|
||||
Parsimmon.regex(/CustomProperties\s+/),
|
||||
Grammar.grammarFor(
|
||||
undefined,
|
||||
(this.attributes.CustomProperties ?? ObjectEntity.attributes.CustomProperties).type[0]
|
||||
this.attributes.CustomProperties.type[0]
|
||||
),
|
||||
).map(([_0, pin]) => values => {
|
||||
if (!values.CustomProperties) {
|
||||
@@ -382,7 +380,7 @@ export default class ObjectEntity extends IEntity {
|
||||
Parsimmon.regex(/\s+End\s+Object/),
|
||||
)
|
||||
.map(([_0, attributes, _2]) => {
|
||||
let values = {}
|
||||
const values = {}
|
||||
attributes.forEach(attributeSetter => attributeSetter(values))
|
||||
return new this(values)
|
||||
})
|
||||
@@ -390,6 +388,7 @@ export default class ObjectEntity extends IEntity {
|
||||
|
||||
/** @param {String} value */
|
||||
static keyName(value) {
|
||||
/** @type {String} */
|
||||
let result = ObjectEntity.#keyName[value]
|
||||
if (result) {
|
||||
return result
|
||||
@@ -400,7 +399,7 @@ export default class ObjectEntity extends IEntity {
|
||||
}
|
||||
const match = value.match(/NumPad([a-zA-Z]+)/)
|
||||
if (match) {
|
||||
result = Utility.numberFromText(match[1])
|
||||
result = Utility.numberFromText(match[1]).toString()
|
||||
if (result) {
|
||||
return "Num " + result
|
||||
}
|
||||
@@ -410,10 +409,10 @@ export default class ObjectEntity extends IEntity {
|
||||
static getMultipleObjectsGrammar() {
|
||||
return Parsimmon.seq(
|
||||
Parsimmon.optWhitespace,
|
||||
this.grammar,
|
||||
this.createGrammar(),
|
||||
Parsimmon.seq(
|
||||
Parsimmon.whitespace,
|
||||
this.grammar,
|
||||
this.createGrammar(),
|
||||
)
|
||||
.map(([_0, object]) => object)
|
||||
.many(),
|
||||
|
||||
@@ -12,10 +12,10 @@ export default class PathSymbolEntity extends IEntity {
|
||||
static {
|
||||
this.cleanupAttributes(this.attributes)
|
||||
}
|
||||
static #grammar = Grammar.symbol.map(v => new PathSymbolEntity(v))
|
||||
static grammar = this.createGrammar()
|
||||
|
||||
static createGrammar() {
|
||||
return PathSymbolEntity.#grammar
|
||||
return Grammar.symbol.map(v => new this(v))
|
||||
}
|
||||
|
||||
constructor(values) {
|
||||
|
||||
@@ -23,12 +23,6 @@ import Utility from "../Utility.js"
|
||||
import Vector2DEntity from "./Vector2DEntity.js"
|
||||
import VectorEntity from "./VectorEntity.js"
|
||||
|
||||
/**
|
||||
* @typedef {import("./IEntity.js").AnyValue} AnyValue
|
||||
* @typedef {import("./ObjectEntity.js").default} ObjectEntity
|
||||
* @typedef {import("lit").CSSResult} CSSResult
|
||||
*/
|
||||
|
||||
/** @template {AnyValue} T */
|
||||
export default class PinEntity extends IEntity {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user