diff --git a/packages/assembly/index.ts b/packages/assembly/index.ts index 9e39480..65a22c2 100644 --- a/packages/assembly/index.ts +++ b/packages/assembly/index.ts @@ -102,7 +102,7 @@ export namespace ASON { // @ts-ignore inside isDefined() if (isDefined(ASON_TRACE)) { // @ts-ignore interface added at runtime - // trace(`serializing ${(value as InternalTransformInterface).__asonNameof()}`); + trace(`serializing ${(value as InternalTransformInterface).__asonNameof()}`); } } } @@ -148,7 +148,7 @@ export namespace ASON { if (isManaged(value) && !isFunction(value)) { if (isDefined(ASON_TRACE)) { // @ts-ignore interface added at runtime - // trace(`putting ${(value as InternalTransformInterface).__asonNameof()}`); + trace(`putting ${(value as InternalTransformInterface).__asonNameof()}`); } } } @@ -878,7 +878,7 @@ export namespace ASON { if (!success) { // @ts-ignore inside isDefined() if (isDefined(ASON_TRACE)) { - assert(false, `Deserialize: expected ${nameof()} (${idof()}), received ${getObjectType(entry0)}`); + assert(false, `Deserialize: expected ${nameof()}, received ${changetype(entry0).__asonNameof()}`); } else { assert(false, `Deserialize: received invalid type`); } @@ -1175,8 +1175,14 @@ export namespace ASON { } interface InternalTransformInterface { + __asonNameof(): string __asonPut(ser: U, entryId: u32): void __asonAlignofValueofParameter(): usize __asonLength(): i32 } + + function __asonNameofID(id: u32): string { + // Ensure __asonNameof() is compiled if __asonNameofID is used. + return changetype clazz.addInterface(resolvedInternalInterface)); } + + afterCompile(module: unknown): void { + createAsonNameofIDFunction(module as binaryen.Module); + } }; function traverseStatements(statements: Statement[]): void { @@ -105,6 +112,7 @@ function traverseStatements(statements: Statement[]): void { const classDeclaration = statement; createAsonPutMethod(classDeclaration); createAsonInstanceOfMethod(classDeclaration); + createAsonNameofMethod(classDeclaration); createAsonAlignofValueofMethod(classDeclaration); createAsonLengthMethod(classDeclaration); } else if (statement.kind === NodeKind.InterfaceDeclaration) { @@ -113,6 +121,7 @@ function traverseStatements(statements: Statement[]): void { // Don't declare methods on the internal interface if (interfaceDeclaration.name.text === INTERNAL_TRANSFORM_NAME) continue; + createAsonNameofMethod(interfaceDeclaration); createAsonAlignofValueofMethod(interfaceDeclaration); createAsonLengthMethod(interfaceDeclaration); } else if (statement.kind === NodeKind.NamespaceDeclaration) {