fork of hey-api/openapi-ts because I need some additional things
1import { keywords } from './keywords';
2
3type List = ReadonlyArray<string>;
4
5export class ReservedList {
6 private _array: List;
7 private _set: Set<string>;
8
9 constructor(values: List) {
10 this._array = values;
11 this._set = new Set(values);
12 }
13
14 get '~values'() {
15 return this._set;
16 }
17
18 /**
19 * Updates the reserved list with new values.
20 *
21 * @param values New reserved values or a function that receives the previous
22 * reserved values and returns the new ones.
23 */
24 set(values: List | ((prev: List) => List)): void {
25 const vals = typeof values === 'function' ? values(this._array) : values;
26 this._array = vals;
27 this._set = new Set(vals);
28 }
29}
30
31const runtimeReserved = new ReservedList([...keywords.pythonKeywords, ...keywords.pythonBuiltins]);
32
33/**
34 * Reserved names for identifiers. These names will not be used
35 * for variables, functions, classes, or other identifiers in generated code.
36 */
37export const reserved = {
38 /**
39 * Reserved names for runtime identifiers. These names will not be used
40 * for variables, functions, classes, or other runtime identifiers in
41 * generated code.
42 */
43 runtime: runtimeReserved,
44};