Skip to content

Commit

Permalink
Decorator context metadata is assigned to if nullish
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Sep 14, 2024
1 parent 97d7d39 commit 08447e3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function align(value: number, alignment: number): number {
export function struct(options: Partial<Options> = {}) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
return function __decorateStruct<const T extends StaticLike>(target: T, context: ClassDecoratorContext & DecoratorContext): T {
context.metadata ??= {};
context.metadata[init] ||= [];
let size = 0;
const members = new Map();
Expand Down Expand Up @@ -91,6 +92,7 @@ export function member(type: primitive.Valid | ClassLike, length?: number) {
throw new ReferenceError('Invalid name for struct member');
}

context.metadata ??= {};
context.metadata[init] ||= [];
context.metadata[init].push({ name, type, length } satisfies MemberInit);
return value;
Expand Down

0 comments on commit 08447e3

Please sign in to comment.