mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-20 05:40:17 +08:00
32 lines
871 B
TypeScript
32 lines
871 B
TypeScript
// The enum fences: everything that does NOT fold to a compile-time
|
|
// constant is a pointed, named rejection — never a silently-wrong value.
|
|
// (Constant-member enums themselves lower; see the 183x corpus programs.)
|
|
|
|
// A computed member's initializer is a runtime expression Node evaluates
|
|
// when the declaration executes — the declaration fences on the member.
|
|
enum Computed {
|
|
Ok = 1,
|
|
Len = "abc".length,
|
|
}
|
|
|
|
// Reads of the computed member fence at the use site too.
|
|
console.log(Computed.Len);
|
|
|
|
enum E {
|
|
A,
|
|
B,
|
|
}
|
|
|
|
// The enum OBJECT as a value: no runtime representation exists.
|
|
const grabbed = E;
|
|
console.log(grabbed.A);
|
|
|
|
// Reverse lookups through a runtime index.
|
|
let i = 0;
|
|
i += 1;
|
|
console.log(E[i]);
|
|
|
|
// A constant reverse index no member carries: Node answers undefined,
|
|
// which the reverse mapping's `string` type cannot carry.
|
|
console.log(E[42]);
|