BREAKING CHANGE(Smartjson): Require TC39 Stage 3 decorators for @foldDec (use accessor), switch foldDec to initializer-based implementation, improve buffer encode/decode handling, bump dependencies and update docs/tests.

This commit is contained in:
2025-12-10 00:16:00 +00:00
parent acf8cea099
commit 6fe5112bfb
10 changed files with 1889 additions and 1020 deletions

View File

@@ -207,14 +207,23 @@ export class Smartjson {
}
/**
* Decorator that marks a property as foldable
* Decorator that marks a property as foldable (TC39 Stage 3 decorator)
* Use with the `accessor` keyword: @foldDec() accessor myProp: string;
*/
export const foldDec = () => {
return (target: any, key: string) => {
if (!target.saveableProperties) {
target.saveableProperties = [];
}
target.saveableProperties.push(key);
return <This extends Smartjson, Value>(
_value: ClassAccessorDecoratorTarget<This, Value>,
context: ClassAccessorDecoratorContext<This, Value>
): ClassAccessorDecoratorResult<This, Value> | void => {
const propertyName = String(context.name);
context.addInitializer(function (this: This) {
if (!this.saveableProperties) {
this.saveableProperties = [];
}
if (!this.saveableProperties.includes(propertyName)) {
this.saveableProperties.push(propertyName);
}
});
};
};