Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use const enums #65

Merged
merged 1 commit into from
Jun 25, 2023
Merged

use const enums #65

merged 1 commit into from
Jun 25, 2023

Conversation

jeetiss
Copy link
Contributor

@jeetiss jeetiss commented Jun 25, 2023

const enums don't have any runtime

// Flag bitset
enum Flags {
  CHUNK_START = 1 << 0,
  CHUNK_END = 1 << 1,
  PARENT = 1 << 2,
  ROOT = 1 << 3,
  KEYED_HASH = 1 << 4,
  DERIVE_KEY_CONTEXT = 1 << 5,
  DERIVE_KEY_MATERIAL = 1 << 6,
}

export const example = [Flags.CHUNK_START, Flags.CHUNK_END]

compiled into:

// Flag bitset
var Flags;
(function (Flags) {
    Flags[Flags["CHUNK_START"] = 1] = "CHUNK_START";
    Flags[Flags["CHUNK_END"] = 2] = "CHUNK_END";
    Flags[Flags["PARENT"] = 4] = "PARENT";
    Flags[Flags["ROOT"] = 8] = "ROOT";
    Flags[Flags["KEYED_HASH"] = 16] = "KEYED_HASH";
    Flags[Flags["DERIVE_KEY_CONTEXT"] = 32] = "DERIVE_KEY_CONTEXT";
    Flags[Flags["DERIVE_KEY_MATERIAL"] = 64] = "DERIVE_KEY_MATERIAL";
})(Flags || (Flags = {}));
export const example = [Flags.CHUNK_START, Flags.CHUNK_END];

to support extending in runtime, when const enums just compiled to single values:

export const example = [1 /* Flags.CHUNK_START */, 2 /* Flags.CHUNK_END */];

this PR should decrease bundle size for entries that use enums

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants