@tilua/parser 1.1.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -326,8 +326,8 @@ interface FunctionSignature extends BaseNode {
326
326
  name?: Identifier;
327
327
  generics: GenericTypeParameter[];
328
328
  params: FunctionParameter[];
329
+ /** The last parameter is a rest parameter (`...rest: T[]`). */
329
330
  hasVarargs: boolean;
330
- varargTypeAnnotation?: TypeNode;
331
331
  returnType?: TypeNode;
332
332
  /** `: v is T` / `: asserts v` instead of a plain return type. */
333
333
  predicate?: TypePredicateNode;
@@ -360,6 +360,12 @@ interface ClassDeclaration extends BaseNode {
360
360
  superclass?: Identifier;
361
361
  /** The arguments `extends Box<number>` was written with. */
362
362
  superArguments?: TypeNode[];
363
+ /** `implements Shape, Named` — shapes the instances are checked against.
364
+ * Nothing at run time. */
365
+ implements?: TypeNode[];
366
+ /** `abstract class` — has no `new`; a class extending it does, once it
367
+ * has written every `abstract` member. */
368
+ isAbstract?: boolean;
363
369
  members: ClassMember[];
364
370
  }
365
371
  /** `class ... end` written where a value goes: `const Counter = class ... end`,
@@ -371,15 +377,18 @@ interface ClassExpression extends BaseNode {
371
377
  name?: Identifier;
372
378
  superclass?: Identifier;
373
379
  superArguments?: TypeNode[];
380
+ implements?: TypeNode[];
381
+ isAbstract?: boolean;
374
382
  members: ClassMember[];
375
383
  }
376
384
  type ClassMember = ClassField | ClassMethod | ClassAccessor | ClassConstructor;
377
385
  /** The two ways a class is written. Everything after parsing treats them
378
386
  * alike: only the name and the type parameters differ. */
379
387
  type ClassLike = ClassDeclaration | ClassExpression;
380
- /** `public` / `private` written before a member. Only the type checker reads
381
- * it: a private member is still an ordinary key at runtime. */
382
- type ClassAccessibility = "public" | "private";
388
+ /** `public` / `private` / `protected` written before a member. Only the type
389
+ * checker reads it: a private member is still an ordinary key at runtime.
390
+ * `protected` is reachable from the class and the classes extending it. */
391
+ type ClassAccessibility = "public" | "private" | "protected";
383
392
  /** `x: number` / `x = 1` / `static count = 0`. An instance field is assigned
384
393
  * when the instance is built, before the constructor body runs; a `static`
385
394
  * one is assigned on the class table, once. */
@@ -389,6 +398,11 @@ interface ClassField extends BaseNode {
389
398
  accessibility?: ClassAccessibility;
390
399
  name: Identifier;
391
400
  isStatic: boolean;
401
+ /** `readonly` — assigned where it is declared or in the constructor of
402
+ * its own class, and nowhere else. */
403
+ isReadonly?: boolean;
404
+ /** `override` — the class it extends has a member of this name. */
405
+ isOverride?: boolean;
392
406
  typeAnnotation?: TypeNode;
393
407
  init?: Expression;
394
408
  }
@@ -403,6 +417,11 @@ interface ClassMethod extends BaseNode {
403
417
  func: FunctionBody;
404
418
  /** TS-style overload signatures preceding the implementation. */
405
419
  signatures?: FunctionSignature[];
420
+ /** `abstract function area(): number` — a head with no body, which every
421
+ * class extending this one that is not abstract itself has to write. */
422
+ isAbstract?: boolean;
423
+ /** `override` — the class it extends has a member of this name. */
424
+ isOverride?: boolean;
406
425
  }
407
426
  /** `get name(): T ... end` / `set name(v: T) ... end` — read and written as a
408
427
  * property, run as a function. */
@@ -414,6 +433,8 @@ interface ClassAccessor extends BaseNode {
414
433
  name: Identifier;
415
434
  isStatic: boolean;
416
435
  func: FunctionBody;
436
+ /** `override` — the class it extends has a member of this name. */
437
+ isOverride?: boolean;
417
438
  }
418
439
  /** `constructor(...) ... end` — runs on a fresh instance. A class that
419
440
  * extends another must call `super(...)` before touching `this`. */
@@ -421,14 +442,6 @@ interface ClassConstructor extends BaseNode {
421
442
  type: "ClassConstructor";
422
443
  func: FunctionBody;
423
444
  }
424
- /** `new Name(args)` — builds an instance. Lowers to the class's own
425
- * `Name.new(args)`, which is also callable by hand. */
426
- interface NewExpression extends BaseNode {
427
- type: "NewExpression";
428
- callee: Expression;
429
- arguments: Expression[];
430
- typeArguments?: (TypeNode | TypePackNode)[];
431
- }
432
445
  /** `super` — only inside a class that extends another: `super(...)` in the
433
446
  * constructor runs the base's on this instance, and `super.method(...)` in a
434
447
  * method calls the base's version of it. */
@@ -448,7 +461,7 @@ interface CompoundAssignmentStatement extends BaseNode {
448
461
  }
449
462
  interface CallStatement extends BaseNode {
450
463
  type: "CallStatement";
451
- expression: CallExpression | MethodCallExpression | NewExpression;
464
+ expression: CallExpression | MethodCallExpression;
452
465
  }
453
466
  /** An expression written as a statement, where Lua would want a call or an
454
467
  * assignment: `value` on a line of its own.
@@ -494,15 +507,21 @@ interface NumericForStatement extends BaseNode {
494
507
  step?: Expression;
495
508
  body: Block;
496
509
  }
510
+ /** `for (const item in source)`. One value each time — several are an
511
+ * array, taken apart with a pattern: `for (const [k, v] in pairs(t))`.
512
+ * `let` instead of `const` when the body assigns to the name. */
497
513
  interface GenericForStatement extends BaseNode {
498
514
  type: "GenericForStatement";
499
- variables: BindingTarget[];
500
- iterators: Expression[];
515
+ kind: "const" | "let";
516
+ variable: BindingTarget;
517
+ iterator: Expression;
501
518
  body: Block;
502
519
  }
520
+ /** `return` / `return value`. A function gives back one value; several are
521
+ * an array — `return [a, b]`, a table. */
503
522
  interface ReturnStatement extends BaseNode {
504
523
  type: "ReturnStatement";
505
- arguments: Expression[];
524
+ argument?: Expression;
506
525
  }
507
526
  interface BreakStatement extends BaseNode {
508
527
  type: "BreakStatement";
@@ -525,15 +544,14 @@ interface GenericTypeParameter extends BaseNode {
525
544
  name: string;
526
545
  /** The name as a node. Absent on parameters the analyzer synthesizes. */
527
546
  id?: Identifier;
528
- isPack?: boolean;
529
547
  /** `<const T>` — infer the argument at its narrowest instead of widening
530
548
  * it: literals stay literal and array literals become tuples. */
531
549
  isConst?: boolean;
532
550
  /** `<T extends C>` upper bound (TS style). */
533
551
  constraint?: TypeNode;
534
- default?: TypeNode | TypePackNode;
552
+ default?: TypeNode;
535
553
  }
536
- type Expression = Identifier | NilLiteral | BooleanLiteral | NumberLiteral | StringLiteral | InterpolatedStringExpression | VarargExpression | FunctionExpression | TableExpression | ArrayExpression | BinaryExpression | UnaryExpression | MemberExpression | IndexExpression | CallExpression | MethodCallExpression | NewExpression | SuperExpression | ClassExpression | SpreadElement | ParenthesizedExpression | TypeAssertionExpression | SatisfiesExpression | AsConstExpression | IfElseExpression | ErrorExpression;
554
+ type Expression = Identifier | NilLiteral | BooleanLiteral | NumberLiteral | StringLiteral | InterpolatedStringExpression | FunctionExpression | TableExpression | ArrayExpression | BinaryExpression | UnaryExpression | MemberExpression | IndexExpression | CallExpression | MethodCallExpression | SuperExpression | ClassExpression | SpreadElement | ParenthesizedExpression | TypeAssertionExpression | SatisfiesExpression | AsConstExpression | IfElseExpression | ErrorExpression;
537
555
  /** An expression that could not be parsed. Only produced in recovery mode
538
556
  * (`parseWithRecovery`), where a broken initializer, condition, field value or
539
557
  * argument keeps its place in the tree; its span covers the skipped tokens
@@ -580,15 +598,12 @@ interface InterpolatedStringExpression extends BaseNode {
580
598
  type: "InterpolatedStringExpression";
581
599
  parts: InterpolatedStringPart[];
582
600
  }
583
- interface VarargExpression extends BaseNode {
584
- type: "VarargExpression";
585
- }
586
601
  interface FunctionParameter extends BaseNode {
587
602
  type: "FunctionParameter";
588
603
  /** `...rest: T[]` — every argument from this position on, as an array,
589
- * the way JavaScript's rest parameter collects them. It is always last,
590
- * and the function is a vararg function: `...` still means Lua's pack
591
- * (`const a, b = ...`), and this is the array of it. */
604
+ * the way JavaScript's rest parameter collects them. It is always last.
605
+ * It is the only way a function takes a varying number of arguments:
606
+ * tilua has no bare `...`. */
592
607
  rest?: boolean;
593
608
  /** `name?: T` — the argument may be omitted, and its type admits `nil`. */
594
609
  optional?: boolean;
@@ -604,8 +619,9 @@ interface FunctionBody extends BaseNode {
604
619
  type: "FunctionBody";
605
620
  generics: GenericTypeParameter[];
606
621
  params: FunctionParameter[];
622
+ /** The last parameter is a rest parameter (`...rest: T[]`): the Lua
623
+ * function takes varargs, and the body sees them as that array. */
607
624
  hasVarargs: boolean;
608
- varargTypeAnnotation?: TypeNode;
609
625
  returnType?: TypeNode;
610
626
  /** `: v is T` / `: asserts v` instead of a plain return type. */
611
627
  predicate?: TypePredicateNode;
@@ -694,7 +710,7 @@ interface CallExpression extends BaseNode {
694
710
  callee: Expression;
695
711
  arguments: Expression[];
696
712
  /** `f<T>(x)` — type arguments written out rather than inferred. */
697
- typeArguments?: (TypeNode | TypePackNode)[];
713
+ typeArguments?: TypeNode[];
698
714
  /** `f?.(...)` — see `MemberExpression.optional`. The call does not happen,
699
715
  * and the arguments are not evaluated, when `callee` is nil. */
700
716
  optional?: boolean;
@@ -714,7 +730,7 @@ interface MethodCallExpression extends BaseNode {
714
730
  method: Identifier;
715
731
  arguments: Expression[];
716
732
  /** `obj:m<T>(x)` — see `CallExpression.typeArguments`. */
717
- typeArguments?: (TypeNode | TypePackNode)[];
733
+ typeArguments?: TypeNode[];
718
734
  /** `object?:method(...)` — see `MemberExpression.optional`. The
719
735
  * arguments are not evaluated when `object` is nil. */
720
736
  optional?: boolean;
@@ -753,7 +769,7 @@ interface IfElseExpression extends BaseNode {
753
769
  }[];
754
770
  alternate: Expression;
755
771
  }
756
- type TypeNode = TypeReference | TypeLiteralString | TypeLiteralBoolean | TypeLiteralNumber | TableTypeNode | ArrayTypeNode | TupleTypeNode | FunctionTypeNode | UnionTypeNode | IntersectionTypeNode | ParenthesizedTypeNode | TypeofTypeNode | VariadicTypeNode | TypePackNode | KeyofTypeNode | IndexedAccessTypeNode | ConditionalTypeNode | InferTypeNode | MappedTypeNode | TemplateLiteralTypeNode | DifferenceTypeNode;
772
+ type TypeNode = TypeReference | TypeLiteralString | TypeLiteralBoolean | TypeLiteralNumber | TableTypeNode | ArrayTypeNode | TupleTypeNode | FunctionTypeNode | UnionTypeNode | IntersectionTypeNode | ParenthesizedTypeNode | TypeofTypeNode | KeyofTypeNode | IndexedAccessTypeNode | ConditionalTypeNode | InferTypeNode | MappedTypeNode | TemplateLiteralTypeNode | DifferenceTypeNode;
757
773
  /** `A - B` — every value of `A` that is not a `B`. Binds tighter than `|`
758
774
  * and looser than `&`, so `A | B - C` is `A | (B - C)`.
759
775
  *
@@ -842,17 +858,11 @@ interface TypePredicateNode extends BaseNode {
842
858
  /** Absent for a bare `asserts x` (a truthiness assertion). */
843
859
  typeAnnotation?: TypeNode;
844
860
  }
845
- interface TypePackNode extends BaseNode {
846
- type: "TypePackNode";
847
- types: TypeNode[];
848
- hasVarargs: boolean;
849
- varargType?: TypeNode;
850
- }
851
861
  interface TypeReference extends BaseNode {
852
862
  type: "TypeReference";
853
863
  base: string;
854
864
  namespace?: string;
855
- typeArguments: (TypeNode | TypePackNode)[];
865
+ typeArguments: TypeNode[];
856
866
  }
857
867
  interface TypeLiteralString extends BaseNode {
858
868
  type: "TypeLiteralString";
@@ -893,10 +903,13 @@ interface ArrayTypeNode extends BaseNode {
893
903
  type: "ArrayTypeNode";
894
904
  element: TypeNode;
895
905
  }
896
- /** `[number, string]` — fixed-length tuple type. */
906
+ /** `[number, string]` — a tuple type; `[string, ...number[]]` ends in a rest
907
+ * of as many more as there are. */
897
908
  interface TupleTypeNode extends BaseNode {
898
909
  type: "TupleTypeNode";
899
910
  elements: TypeNode[];
911
+ /** `...number[]` at the end: the array type the rest of it is. */
912
+ rest?: TypeNode;
900
913
  }
901
914
  interface FunctionTypeParameter extends BaseNode {
902
915
  type: "FunctionTypeParameter";
@@ -913,8 +926,6 @@ interface FunctionTypeNode extends BaseNode {
913
926
  type: "FunctionTypeNode";
914
927
  generics: GenericTypeParameter[];
915
928
  params: FunctionTypeParameter[];
916
- hasVarargs: boolean;
917
- varargType?: TypeNode;
918
929
  returnType: TypeNode;
919
930
  /** `(v: unknown) -> v is string` — a guard written as a function *type*. */
920
931
  predicate?: TypePredicateNode;
@@ -937,10 +948,6 @@ interface TypeofTypeNode extends BaseNode {
937
948
  type: "TypeofTypeNode";
938
949
  expression: Expression;
939
950
  }
940
- interface VariadicTypeNode extends BaseNode {
941
- type: "VariadicTypeNode";
942
- typeAnnotation: TypeNode;
943
- }
944
951
  type Node = Program | Block | Statement | Expression | TypeNode | FunctionBody | FunctionParameter | FunctionName | IfClause | TypedIdentifier | GenericTypeParameter | FunctionSignature | TypePredicateNode | TableField | SpreadElement | FunctionTypeParameter | TableTypeProperty | BindingTarget | ObjectPatternProperty | ArrayPatternElement;
945
952
 
946
953
  declare class ParseError extends Error {
@@ -1067,6 +1074,10 @@ declare function isGlobal(binding: Binding): boolean;
1067
1074
  * undeclared, which is almost always a typo rather than an intentional
1068
1075
  * implicit global. Handy for a "possibly undefined global" diagnostic. */
1069
1076
  declare function isUnassignedGlobal(binding: Binding): boolean;
1077
+ /** Globals tilua itself declares, whatever the type libraries do:
1078
+ * `scriptArgs` is the arguments the script was started with — Lua's
1079
+ * top-level `...` — as an array. */
1080
+ declare const LANGUAGE_GLOBALS: readonly string[];
1070
1081
  declare function analyzeScopes(program: Program, options?: AnalyzeScopesOptions): ScopeAnalysis;
1071
1082
 
1072
1083
  type Type = AnyType | UnknownType | NeverType | PrimitiveType | LiteralType | ArrayType | TupleType | ObjectType | FunctionType | UnionType | IntersectionType | TypeParamType | GenericRefType | KeyofType | IndexedAccessType | ConditionalType | InferType | MappedType | TemplateLiteralType | DifferenceType;
@@ -1109,17 +1120,13 @@ interface ArrayType {
1109
1120
  element: Type;
1110
1121
  alias?: string;
1111
1122
  }
1112
- /** `[A, B, C]` — fixed length.
1113
- *
1114
- * `isPack` marks the other thing this shape is used for: a *type pack*, the
1115
- * several values a Lua function returns (`(number, string)`). The two are
1116
- * structurally identical but behave differently in an expression list — a
1117
- * pack spreads across several names, a tuple is one value — so they have to
1118
- * be told apart. */
1123
+ /** `[A, B, C]` — fixed length; `[A, ...B[]]` — at least that, then any
1124
+ * number of `B`. `rest` is the element type of that tail. A tuple is an
1125
+ * array, a table like any other: several results are one of these. */
1119
1126
  interface TupleType {
1120
1127
  kind: "tuple";
1121
1128
  elements: Type[];
1122
- isPack?: boolean;
1129
+ rest?: Type;
1123
1130
  alias?: string;
1124
1131
  }
1125
1132
  interface ObjectProperty {
@@ -1128,11 +1135,16 @@ interface ObjectProperty {
1128
1135
  readonly?: boolean;
1129
1136
  /** A class member written `private`: reachable only from inside the class
1130
1137
  * that declared it. `owner` is that class's node, compared by identity;
1131
- * `className` is how a diagnostic names it. Checked, never lowered. */
1138
+ * `className` is how a diagnostic names it. Checked, never lowered.
1139
+ * `protected` widens that to the classes extending it. */
1132
1140
  private?: {
1133
1141
  owner: object;
1134
1142
  className: string;
1143
+ protected?: boolean;
1135
1144
  };
1145
+ /** An `abstract` class member: declared, with nothing behind it until a
1146
+ * class extending this one writes it. */
1147
+ abstract?: boolean;
1136
1148
  }
1137
1149
  interface ObjectType {
1138
1150
  kind: "object";
@@ -1194,8 +1206,14 @@ interface TypePredicate {
1194
1206
  interface FunctionType {
1195
1207
  kind: "function";
1196
1208
  params: FunctionParam[];
1209
+ /** The type of each argument a rest parameter (`...args: T[]`) collects —
1210
+ * or, with `restIsWhole`, the rest parameter's own type. */
1197
1211
  varargs?: Type;
1198
- /** A tuple when the function returns multiple values. */
1212
+ /** `...args: A` where `A` is a tuple, or a type parameter standing for
1213
+ * one (`<A extends unknown[]>`): `varargs` is `A` itself, and once `A`
1214
+ * is known its elements are the parameters. */
1215
+ restIsWhole?: boolean;
1216
+ /** What the function returns: one value — several are an array. */
1199
1217
  returns: Type;
1200
1218
  /** Names of the function's own generic parameters (`function f<T>(...)`).
1201
1219
  * `params` / `returns` may contain `typeParam` nodes for these. */
@@ -1344,7 +1362,9 @@ declare const bufferType: PrimitiveType;
1344
1362
  declare function primitive(name: PrimitiveName): PrimitiveType;
1345
1363
  declare function literal(value: string | number | boolean): LiteralType;
1346
1364
  declare function arrayOf(element: Type): ArrayType;
1347
- declare function tuple(elements: Type[], isPack?: boolean): TupleType;
1365
+ declare function tuple(elements: Type[], rest?: Type): TupleType;
1366
+ /** Every element type a tuple can hold, the rest's included. */
1367
+ declare function tupleMembers(t: TupleType): Type[];
1348
1368
  declare function objectType(entries: Iterable<[string, ObjectProperty]>, indexer?: ObjectType["indexer"], frozen?: boolean): ObjectType;
1349
1369
  declare function fn(params: FunctionParam[], returns: Type, varargs?: Type, typeParams?: string[], predicate?: TypePredicate): FunctionType;
1350
1370
  declare function substitute(t: Type, subst: Map<string, Type>): Type;
@@ -1409,6 +1429,20 @@ interface TypeDiagnostic {
1409
1429
  node: Expression | Statement | TypeNode | Block | ClassMember;
1410
1430
  message: string;
1411
1431
  }
1432
+ /** How a `for (const item in source)` walks its source — what lowering needs,
1433
+ * decided with the item's type so the two cannot drift apart.
1434
+ * - `values`: an array or a table, walked directly; the item is each value.
1435
+ * - `function`: an iterator function, called until it answers nil; the item
1436
+ * is each answer.
1437
+ * - `iteration`: `[step, state, first]`, as `pairs(t)` answers: `step` is
1438
+ * called with the state and the item before (`first` the first time) until
1439
+ * it answers nil.
1440
+ * `viaIter`: the source is an object whose `__iter` method gives the function
1441
+ * or the iteration. */
1442
+ interface LoopForm {
1443
+ readonly walks: "values" | "function" | "iteration";
1444
+ readonly viaIter: boolean;
1445
+ }
1412
1446
  interface TypeAnalysis {
1413
1447
  /** Inferred type of every expression node. */
1414
1448
  readonly typeOf: Map<Expression, Type>;
@@ -1420,7 +1454,7 @@ interface TypeAnalysis {
1420
1454
  /** What every type annotation node resolves to — `number`, `Shape`,
1421
1455
  * `typeof x`, a property's type inside `{ ... }`. Inside a generic alias or
1422
1456
  * function its parameters stay unresolved (`T`). */
1423
- readonly typeOfTypeNode: Map<TypeNode | TypePackNode, Type>;
1457
+ readonly typeOfTypeNode: Map<TypeNode, Type>;
1424
1458
  /** What each call argument is expected to be: the parameter it lands on,
1425
1459
  * with the signature's type parameters replaced by their constraints — a
1426
1460
  * union when an overload set disagrees. Recorded even for a call that does
@@ -1430,13 +1464,9 @@ interface TypeAnalysis {
1430
1464
  /** Top-level type aliases, resolved — and the type names this module
1431
1465
  * imports, so tooling treats both alike. */
1432
1466
  readonly aliases: Map<string, Type>;
1433
- /** The `for x in t` loops that walk a table directly, where tilua's one
1434
- * variable takes the *value* — not an iterator such as `pairs(t)` or
1435
- * `string.gmatch(s, p)`, whose variables are bound as written. Luau hands
1436
- * the key over first, so lowering these needs a key variable in front.
1437
- * Deciding that here keeps it next to the types the same choice produces:
1438
- * the variable's type and the code bound to it cannot drift apart. */
1439
- readonly iteratesValues: ReadonlySet<GenericForStatement>;
1467
+ /** How each `for (const item in source)` walks its source; see
1468
+ * `LoopForm`. A loop missing here walks values. */
1469
+ readonly loops: ReadonlyMap<GenericForStatement, LoopForm>;
1440
1470
  readonly diagnostics: TypeDiagnostic[];
1441
1471
  }
1442
1472
  /** A type a module exports: the resolved type, plus the parameter names of a
@@ -1507,11 +1537,15 @@ resolveModule?: (specifier: string) => ModuleExports | undefined): ModuleExports
1507
1537
  * (`tilua.methods` in its package.json). Nothing about `filter` is written
1508
1538
  * into the analyzer.
1509
1539
  */
1510
- declare const PRELUDE_SOURCE = "\n-- In Luau only `nil` and `false` are falsy: `0` and `\"\"` are truthy.\n-- These are what truthiness narrowing computes, made available to write down.\ntype Falsy = nil | false\ntype Truthy<T> = T - Falsy\n\n-- `-` is set difference. Over a union it drops members; over a concrete type\n-- it simplifies away; over an opaque type (`unknown`, an unresolved parameter)\n-- it is kept, so `Exclude<unknown, 1>` stays `unknown - 1`.\ntype Exclude<T, U> = T - U\ntype Extract<T, U> = T extends U ? T : never\ntype NonNullable<T> = T - nil\n\ntype ReturnType<T> = T extends (...unknown) => infer R ? R : never\ntype Parameters<T> = T extends (...infer P) => unknown ? P : never\n\ntype Partial<T> = { [K in keyof T]?: T[K] }\ntype Required<T> = { [K in keyof T]-?: T[K] }\ntype Readonly<T> = { readonly [K in keyof T]: T[K] }\ntype Mutable<T> = { -readonly [K in keyof T]: T[K] }\n\ntype Pick<T, K> = { [P in K]: T[P] }\ntype Omit<T, K> = Pick<T, Exclude<keyof T, K>>\ntype Record<K, V> = { [P in K]: V }\n";
1540
+ declare const PRELUDE_SOURCE = "\n-- In Luau only `nil` and `false` are falsy: `0` and `\"\"` are truthy.\n-- These are what truthiness narrowing computes, made available to write down.\ntype Falsy = nil | false\ntype Truthy<T> = T - Falsy\n\n-- `-` is set difference. Over a union it drops members; over a concrete type\n-- it simplifies away; over an opaque type (`unknown`, an unresolved parameter)\n-- it is kept, so `Exclude<unknown, 1>` stays `unknown - 1`.\ntype Exclude<T, U> = T - U\ntype Extract<T, U> = T extends U ? T : never\ntype NonNullable<T> = T - nil\n\ntype ReturnType<T> = T extends (...args: unknown[]) => infer R ? R : never\ntype Parameters<T> = T extends (...args: infer P) => unknown ? P : never\n\ntype Partial<T> = { [K in keyof T]?: T[K] }\ntype Required<T> = { [K in keyof T]-?: T[K] }\ntype Readonly<T> = { readonly [K in keyof T]: T[K] }\ntype Mutable<T> = { -readonly [K in keyof T]: T[K] }\n\ntype Pick<T, K> = { [P in K]: T[P] }\ntype Omit<T, K> = Pick<T, Exclude<keyof T, K>>\ntype Record<K, V> = { [P in K]: V }\n";
1511
1541
 
1512
1542
  interface ProjectHost {
1513
1543
  /** A file's text, or `undefined` when there is no such file. */
1514
1544
  readFile(path: string): string | undefined;
1545
+ /** The names of the folders in a folder, or `undefined` when there is no
1546
+ * such folder. Only a `types` entry with a `*` in it lists anything; a
1547
+ * host without this cannot load one. */
1548
+ readDirectory?(path: string): string[] | undefined;
1515
1549
  }
1516
1550
  declare const nodeHost: ProjectHost;
1517
1551
 
@@ -1775,4 +1809,4 @@ declare const tilua: {
1775
1809
  readonly analyzeTypes: typeof analyzeTypes;
1776
1810
  };
1777
1811
 
1778
- export { type AnalyzeTypesOptions, type AnyType, type ArgumentInfo, type ArrayExpression, type ArrayPattern, type ArrayPatternElement, type ArrayType, type ArrayTypeNode, type AsConstExpression, type AssignmentStatement, type BaseNode, type BaseToken, type BinaryExpression, BinaryOperators, type Binding, type BindingId, type BindingKind, type BindingTarget, type Block, type BooleanLiteral, type BreakStatement, type BuildTarget, CONFIG_FILE_NAMES, type CallExpression, type CallLowering, type CallSite, type CallStatement, type ClassAccessibility, type ClassAccessor, type ClassConstructor, type ClassDeclaration, type ClassExpression, type ClassField, type ClassInfo, type ClassLike, type ClassMember, type ClassMethod, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ConfigLookup, type ConfigProblem, type ContinueStatement, type DeclareClassStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type Directive, type DirectiveKind, type DirectiveOutcome, type Directives, type DoStatement, type EOFToken, type ErrorExpression, type ErrorStatement, type ExportAllStatement, type ExportDefaultStatement, type ExportNamedStatement, type ExportSpecifier, type ExportStatement, type ExportTypeAliasStatement, type ExportedType, type Expression, type ExpressionStatement, type FunctionBody, type FunctionDeclaration, type FunctionDeclarationStatement, type FunctionExpression, type FunctionName, type FunctionParam, type FunctionParameter, type FunctionSignature, type FunctionType, type FunctionTypeNode, type FunctionTypeParameter, type GenericForStatement, type GenericRefType, type GenericTypeParameter, type GlobalCall, type GlobalValue, type Identifier, type IdentifierPattern, type IdentifierToken, type IfClause, type IfElseExpression, type IfStatement, type ImportSpecifier, type ImportStatement, type IndexExpression, type IndexedAccessType, type IndexedAccessTypeNode, type InferType, type InferTypeNode, type InterpolatedStringExpression, type InterpolatedStringPart, type InterpolatedStringPart_Expression, type InterpolatedStringPart_String, type InterpolatedStringToken, type IntersectionType, type IntersectionTypeNode, type KeyofType, type KeyofTypeNode, type KeywordToken, Keywords, LexError, type LiteralToken, type LiteralType, type LoweringModule, type LoweringPlugin, type MappedType, type MappedTypeNode, type MemberExpression, type MethodCall, type MethodCallExpression, type MethodLowering, type ModuleExports, type NeverType, type NewExpression, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, PRELUDE_SOURCE, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type ProjectHost, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SourceComment, type SourceMapNode, type SourceMapOptions, type SourceMapTypes, type SpreadElement, type Statement, type StringLiteral, type SuperExpression, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type TiluaConfig, type Token, type TokenizeOptions, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLibraries, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypeOrigin, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, UNUSED_EXPECT_ERROR, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, aliasNameOf, analyzeScopes, analyzeTypes, anyType, applyDirectives, arrayOf, booleanType, bufferType, containsTypeParam, declaredUnknownType, tilua as default, difference, directivesOf, equalTypes, falsyType, findConfig, fn, formatType, getBinding, intersection, isAssignable, isClassType, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, readDirectives, resolveModulePath, resolveTypeLibraries, setAliasExpander, setDeferredBound, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tilua, tokenize, tuple, typeParam, unify, union, unknownType, widen, withAliasName, withoutAliasName };
1812
+ export { type AnalyzeTypesOptions, type AnyType, type ArgumentInfo, type ArrayExpression, type ArrayPattern, type ArrayPatternElement, type ArrayType, type ArrayTypeNode, type AsConstExpression, type AssignmentStatement, type BaseNode, type BaseToken, type BinaryExpression, BinaryOperators, type Binding, type BindingId, type BindingKind, type BindingTarget, type Block, type BooleanLiteral, type BreakStatement, type BuildTarget, CONFIG_FILE_NAMES, type CallExpression, type CallLowering, type CallSite, type CallStatement, type ClassAccessibility, type ClassAccessor, type ClassConstructor, type ClassDeclaration, type ClassExpression, type ClassField, type ClassInfo, type ClassLike, type ClassMember, type ClassMethod, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ConfigLookup, type ConfigProblem, type ContinueStatement, type DeclareClassStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type Directive, type DirectiveKind, type DirectiveOutcome, type Directives, type DoStatement, type EOFToken, type ErrorExpression, type ErrorStatement, type ExportAllStatement, type ExportDefaultStatement, type ExportNamedStatement, type ExportSpecifier, type ExportStatement, type ExportTypeAliasStatement, type ExportedType, type Expression, type ExpressionStatement, type FunctionBody, type FunctionDeclaration, type FunctionDeclarationStatement, type FunctionExpression, type FunctionName, type FunctionParam, type FunctionParameter, type FunctionSignature, type FunctionType, type FunctionTypeNode, type FunctionTypeParameter, type GenericForStatement, type GenericRefType, type GenericTypeParameter, type GlobalCall, type GlobalValue, type Identifier, type IdentifierPattern, type IdentifierToken, type IfClause, type IfElseExpression, type IfStatement, type ImportSpecifier, type ImportStatement, type IndexExpression, type IndexedAccessType, type IndexedAccessTypeNode, type InferType, type InferTypeNode, type InterpolatedStringExpression, type InterpolatedStringPart, type InterpolatedStringPart_Expression, type InterpolatedStringPart_String, type InterpolatedStringToken, type IntersectionType, type IntersectionTypeNode, type KeyofType, type KeyofTypeNode, type KeywordToken, Keywords, LANGUAGE_GLOBALS, LexError, type LiteralToken, type LiteralType, type LoweringModule, type LoweringPlugin, type MappedType, type MappedTypeNode, type MemberExpression, type MethodCall, type MethodCallExpression, type MethodLowering, type ModuleExports, type NeverType, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, PRELUDE_SOURCE, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type ProjectHost, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SourceComment, type SourceMapNode, type SourceMapOptions, type SourceMapTypes, type SpreadElement, type Statement, type StringLiteral, type SuperExpression, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type TiluaConfig, type Token, type TokenizeOptions, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLibraries, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypeOrigin, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, UNUSED_EXPECT_ERROR, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VariableDeclaration, type WhileStatement, aliasNameOf, analyzeScopes, analyzeTypes, anyType, applyDirectives, arrayOf, booleanType, bufferType, containsTypeParam, declaredUnknownType, tilua as default, difference, directivesOf, equalTypes, falsyType, findConfig, fn, formatType, getBinding, intersection, isAssignable, isClassType, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, readDirectives, resolveModulePath, resolveTypeLibraries, setAliasExpander, setDeferredBound, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tilua, tokenize, tuple, tupleMembers, typeParam, unify, union, unknownType, widen, withAliasName, withoutAliasName };