mozilla / pluotsorbet

[ARCHIVED] PluotSorbet is a J2ME-compatible virtual machine written in JavaScript.
GNU General Public License v2.0
238 stars 46 forks source link

Omit enum reverse lookup code in TS. #1454

Open mbebenita opened 9 years ago

mbebenita commented 9 years ago

TS emits a bit of extra code for enum definitions. For instance:

enum A {
    x, y, z
}

var a = A.x;

is compiled to:

var A;
(function (A) {
    A[A["x"] = 0] = "x";
    A[A["y"] = 1] = "y";
    A[A["z"] = 2] = "z";
})(A || (A = {}));
var a = 0 /* x */;

We don't really need to do reverse lookups on enums. Perhaps we could add a compiler option to the TS compiler that omits this code.

marco-c commented 9 years ago

Should we file an issue in the TypeScript repo to ask them to add this option?

mbebenita commented 9 years ago

Looks like this feature already exists in TS:

http://stackoverflow.com/questions/28818849/how-do-the-different-enum-variants-work-in-typescript/28818850#28818850

declare enum

marco-c commented 9 years ago

In some cases we might simply use const enum