Use const enums in typescript since regular enums generate extremely bad code (#64486)
authorKatelyn Gadd <kg@luminance.org>
Sat, 29 Jan 2022 17:09:50 +0000 (09:09 -0800)
committerGitHub <noreply@github.com>
Sat, 29 Jan 2022 17:09:50 +0000 (09:09 -0800)
To get good behavior in typescript, your enums need to be 'const enum', otherwise it generates some really gross JS with runtime overhead.

src/mono/wasm/runtime/types.ts

index b208aee..cc0d1b2 100644 (file)
@@ -195,7 +195,7 @@ export function assert(condition: unknown, messsage: string): asserts condition
 }
 
 // see src/mono/wasm/driver.c MARSHAL_TYPE_xxx and Runtime.cs MarshalType
-export enum MarshalType {
+export const enum MarshalType {
     NULL = 0,
     INT = 1,
     FP64 = 2,
@@ -230,7 +230,7 @@ export enum MarshalType {
 }
 
 // see src/mono/wasm/driver.c MARSHAL_ERROR_xxx and Runtime.cs
-export enum MarshalError {
+export const enum MarshalError {
     BUFFER_TOO_SMALL = 512,
     NULL_CLASS_POINTER = 513,
     NULL_TYPE_POINTER = 514,