|
| 1 | +//! Type ID constants for global types. |
| 2 | +//! |
| 3 | +//! TODO(tidefield): Implement a codegen for this file from TypeScript .d.ts files. |
| 4 | +
|
| 5 | +// use crate::define_global_type; |
| 6 | +use crate::{ResolvedTypeId, TypeId}; |
| 7 | + |
| 8 | +use super::globals::GLOBAL_LEVEL; |
| 9 | + |
| 10 | +// FIXME(tidefield): Get rid of the macro when implementing the codegen to improve compile time |
| 11 | +// Right now, I'm preserving the names so that the snapshot tests don't break the snapshot tests |
| 12 | +// to make sure I'm not breaking anything. |
| 13 | +#[macro_export] |
| 14 | +macro_rules! define_global_type { |
| 15 | + ($name:ident, $index:expr, $name_str:expr) => { |
| 16 | + pub const $name: TypeId = TypeId::new($index); |
| 17 | + paste::paste! { |
| 18 | + pub const [<$name _NAME>]: &str = $name_str; |
| 19 | + } |
| 20 | + }; |
| 21 | +} |
| 22 | +// define_global_type!(ARRAY_ID, 8, "Array"); // Creates ARRAY_ID and ARRAY_ID_NAME |
| 23 | + |
| 24 | +// Type ID constants with their names defined together |
| 25 | +define_global_type!(UNKNOWN_ID, 0, "unknown"); |
| 26 | +define_global_type!(UNDEFINED_ID, 1, "undefined"); |
| 27 | +define_global_type!(VOID_ID, 2, "void"); |
| 28 | +define_global_type!(CONDITIONAL_ID, 3, "conditional"); |
| 29 | +define_global_type!(NUMBER_ID, 4, "number"); |
| 30 | +define_global_type!(STRING_ID, 5, "string"); |
| 31 | +define_global_type!(INSTANCEOF_ARRAY_T_ID, 6, "instanceof Array<T>"); |
| 32 | +define_global_type!(INSTANCEOF_ARRAY_U_ID, 7, "instanceof Array<U>"); |
| 33 | +define_global_type!(ARRAY_ID, 8, "Array"); |
| 34 | +define_global_type!(ARRAY_FILTER_ID, 9, "Array.prototype.filter"); |
| 35 | +define_global_type!(ARRAY_FOREACH_ID, 10, "Array.prototype.forEach"); |
| 36 | +define_global_type!(ARRAY_MAP_ID, 11, "Array.prototype.map"); |
| 37 | +define_global_type!(GLOBAL_ID, 12, "globalThis"); |
| 38 | +define_global_type!(INSTANCEOF_PROMISE_ID, 13, "instanceof Promise"); |
| 39 | +define_global_type!(PROMISE_ID, 14, "Promise"); |
| 40 | +define_global_type!(PROMISE_CONSTRUCTOR_ID, 15, "Promise.constructor"); |
| 41 | +define_global_type!(PROMISE_CATCH_ID, 16, "Promise.prototype.catch"); |
| 42 | +define_global_type!(PROMISE_FINALLY_ID, 17, "Promise.prototype.finally"); |
| 43 | +define_global_type!(PROMISE_THEN_ID, 18, "Promise.prototype.then"); |
| 44 | +define_global_type!(PROMISE_ALL_ID, 19, "Promise.all"); |
| 45 | +define_global_type!(PROMISE_ALL_SETTLED_ID, 20, "Promise.allSettled"); |
| 46 | +define_global_type!(PROMISE_ANY_ID, 21, "Promise.any"); |
| 47 | +define_global_type!(PROMISE_RACE_ID, 22, "Promise.race"); |
| 48 | +define_global_type!(PROMISE_REJECT_ID, 23, "Promise.reject"); |
| 49 | +define_global_type!(PROMISE_RESOLVE_ID, 24, "Promise.resolve"); |
| 50 | +define_global_type!(PROMISE_TRY_ID, 25, "Promise.try"); |
| 51 | +define_global_type!(BIGINT_STRING_LITERAL_ID, 26, "\"bigint\""); |
| 52 | +define_global_type!(BOOLEAN_STRING_LITERAL_ID, 27, "\"boolean\""); |
| 53 | +define_global_type!(FUNCTION_STRING_LITERAL_ID, 28, "\"function\""); |
| 54 | +define_global_type!(NUMBER_STRING_LITERAL_ID, 29, "\"number\""); |
| 55 | +define_global_type!(OBJECT_STRING_LITERAL_ID, 30, "\"object\""); |
| 56 | +define_global_type!(STRING_STRING_LITERAL_ID, 31, "\"string\""); |
| 57 | +define_global_type!(SYMBOL_STRING_LITERAL_ID, 32, "\"symbol\""); |
| 58 | +define_global_type!(UNDEFINED_STRING_LITERAL_ID, 33, "\"undefined\""); |
| 59 | +define_global_type!( |
| 60 | + TYPEOF_OPERATOR_RETURN_UNION_ID, |
| 61 | + 34, |
| 62 | + "\"bigint\" | \"boolean\" | \"function\" | \"number\" | \"object\" | \"string\" | \"symbol\" | \"undefined\"" |
| 63 | +); |
| 64 | +define_global_type!(T_ID, 35, "T"); |
| 65 | +define_global_type!(U_ID, 36, "U"); |
| 66 | +define_global_type!(CONDITIONAL_CALLBACK_ID, 37, "() => conditional"); |
| 67 | +define_global_type!(MAP_CALLBACK_ID, 38, "<U>(item: T) => U"); |
| 68 | +define_global_type!(VOID_CALLBACK_ID, 39, "() => void"); |
| 69 | +define_global_type!(FETCH_ID, 40, "fetch"); |
| 70 | +define_global_type!(INSTANCEOF_REGEXP_ID, 41, "instanceof RegExp"); |
| 71 | +define_global_type!(REGEXP_ID, 42, "RegExp"); |
| 72 | +define_global_type!(REGEXP_EXEC_ID, 43, "RegExp.exec"); |
| 73 | + |
| 74 | +/// Total number of predefined types. |
| 75 | +/// Must be one more than the highest TypeId above. |
| 76 | +pub const NUM_PREDEFINED_TYPES: usize = 44; |
| 77 | + |
| 78 | +// Resolved type ID constants (TypeId wrapped with GlobalLevel) |
| 79 | +pub const GLOBAL_UNKNOWN_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, UNKNOWN_ID); |
| 80 | +pub const GLOBAL_UNDEFINED_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, UNDEFINED_ID); |
| 81 | +pub const GLOBAL_VOID_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, VOID_ID); |
| 82 | +pub const GLOBAL_CONDITIONAL_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, CONDITIONAL_ID); |
| 83 | +pub const GLOBAL_NUMBER_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, NUMBER_ID); |
| 84 | +pub const GLOBAL_STRING_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, STRING_ID); |
| 85 | +pub const GLOBAL_ARRAY_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, ARRAY_ID); |
| 86 | +pub const GLOBAL_GLOBAL_ID /* :smirk: */: ResolvedTypeId = |
| 87 | + ResolvedTypeId::new(GLOBAL_LEVEL, GLOBAL_ID); |
| 88 | +pub const GLOBAL_INSTANCEOF_PROMISE_ID: ResolvedTypeId = |
| 89 | + ResolvedTypeId::new(GLOBAL_LEVEL, INSTANCEOF_PROMISE_ID); |
| 90 | +pub const GLOBAL_PROMISE_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, PROMISE_ID); |
| 91 | +pub const GLOBAL_PROMISE_CONSTRUCTOR_ID: ResolvedTypeId = |
| 92 | + ResolvedTypeId::new(GLOBAL_LEVEL, PROMISE_CONSTRUCTOR_ID); |
| 93 | +pub const GLOBAL_BIGINT_STRING_LITERAL_ID: ResolvedTypeId = |
| 94 | + ResolvedTypeId::new(GLOBAL_LEVEL, BIGINT_STRING_LITERAL_ID); |
| 95 | +pub const GLOBAL_BOOLEAN_STRING_LITERAL_ID: ResolvedTypeId = |
| 96 | + ResolvedTypeId::new(GLOBAL_LEVEL, BOOLEAN_STRING_LITERAL_ID); |
| 97 | +pub const GLOBAL_FUNCTION_STRING_LITERAL_ID: ResolvedTypeId = |
| 98 | + ResolvedTypeId::new(GLOBAL_LEVEL, FUNCTION_STRING_LITERAL_ID); |
| 99 | +pub const GLOBAL_NUMBER_STRING_LITERAL_ID: ResolvedTypeId = |
| 100 | + ResolvedTypeId::new(GLOBAL_LEVEL, NUMBER_STRING_LITERAL_ID); |
| 101 | +pub const GLOBAL_OBJECT_STRING_LITERAL_ID: ResolvedTypeId = |
| 102 | + ResolvedTypeId::new(GLOBAL_LEVEL, OBJECT_STRING_LITERAL_ID); |
| 103 | +pub const GLOBAL_STRING_STRING_LITERAL_ID: ResolvedTypeId = |
| 104 | + ResolvedTypeId::new(GLOBAL_LEVEL, STRING_STRING_LITERAL_ID); |
| 105 | +pub const GLOBAL_SYMBOL_STRING_LITERAL_ID: ResolvedTypeId = |
| 106 | + ResolvedTypeId::new(GLOBAL_LEVEL, SYMBOL_STRING_LITERAL_ID); |
| 107 | +pub const GLOBAL_UNDEFINED_STRING_LITERAL_ID: ResolvedTypeId = |
| 108 | + ResolvedTypeId::new(GLOBAL_LEVEL, UNDEFINED_STRING_LITERAL_ID); |
| 109 | +pub const GLOBAL_TYPEOF_OPERATOR_RETURN_UNION_ID: ResolvedTypeId = |
| 110 | + ResolvedTypeId::new(GLOBAL_LEVEL, TYPEOF_OPERATOR_RETURN_UNION_ID); |
| 111 | +pub const GLOBAL_T_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, T_ID); |
| 112 | +pub const GLOBAL_U_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, U_ID); |
| 113 | +pub const GLOBAL_FETCH_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, FETCH_ID); |
| 114 | +pub const GLOBAL_INSTANCEOF_REGEXP_ID: ResolvedTypeId = |
| 115 | + ResolvedTypeId::new(GLOBAL_LEVEL, INSTANCEOF_REGEXP_ID); |
| 116 | +pub const GLOBAL_REGEXP_ID: ResolvedTypeId = ResolvedTypeId::new(GLOBAL_LEVEL, REGEXP_ID); |
0 commit comments