@tilua/parser 1.1.0 → 2.1.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/README.md +186 -47
- package/dist/index.cjs +1405 -455
- package/dist/index.d.cts +107 -64
- package/dist/index.d.ts +107 -64
- package/dist/index.js +1404 -456
- package/package.json +1 -1
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
|
|
381
|
-
* it: a private member is still an ordinary key at runtime.
|
|
382
|
-
|
|
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
|
|
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
|
-
|
|
500
|
-
|
|
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
|
-
|
|
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
|
|
552
|
+
default?: TypeNode;
|
|
535
553
|
}
|
|
536
|
-
type Expression = Identifier | NilLiteral | BooleanLiteral | NumberLiteral | StringLiteral | InterpolatedStringExpression |
|
|
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
|
-
*
|
|
591
|
-
*
|
|
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;
|
|
@@ -688,13 +704,16 @@ interface IndexExpression extends BaseNode {
|
|
|
688
704
|
type: "IndexExpression";
|
|
689
705
|
object: Expression;
|
|
690
706
|
index: Expression;
|
|
707
|
+
/** `object?.[key]` — when `object` is nil, the whole chain this link
|
|
708
|
+
* belongs to is nil and the key is not evaluated. */
|
|
709
|
+
optional?: boolean;
|
|
691
710
|
}
|
|
692
711
|
interface CallExpression extends BaseNode {
|
|
693
712
|
type: "CallExpression";
|
|
694
713
|
callee: Expression;
|
|
695
714
|
arguments: Expression[];
|
|
696
715
|
/** `f<T>(x)` — type arguments written out rather than inferred. */
|
|
697
|
-
typeArguments?:
|
|
716
|
+
typeArguments?: TypeNode[];
|
|
698
717
|
/** `f?.(...)` — see `MemberExpression.optional`. The call does not happen,
|
|
699
718
|
* and the arguments are not evaluated, when `callee` is nil. */
|
|
700
719
|
optional?: boolean;
|
|
@@ -714,7 +733,7 @@ interface MethodCallExpression extends BaseNode {
|
|
|
714
733
|
method: Identifier;
|
|
715
734
|
arguments: Expression[];
|
|
716
735
|
/** `obj:m<T>(x)` — see `CallExpression.typeArguments`. */
|
|
717
|
-
typeArguments?:
|
|
736
|
+
typeArguments?: TypeNode[];
|
|
718
737
|
/** `object?:method(...)` — see `MemberExpression.optional`. The
|
|
719
738
|
* arguments are not evaluated when `object` is nil. */
|
|
720
739
|
optional?: boolean;
|
|
@@ -753,7 +772,7 @@ interface IfElseExpression extends BaseNode {
|
|
|
753
772
|
}[];
|
|
754
773
|
alternate: Expression;
|
|
755
774
|
}
|
|
756
|
-
type TypeNode = TypeReference | TypeLiteralString | TypeLiteralBoolean | TypeLiteralNumber | TableTypeNode | ArrayTypeNode | TupleTypeNode | FunctionTypeNode | UnionTypeNode | IntersectionTypeNode | ParenthesizedTypeNode | TypeofTypeNode |
|
|
775
|
+
type TypeNode = TypeReference | TypeLiteralString | TypeLiteralBoolean | TypeLiteralNumber | TableTypeNode | ArrayTypeNode | TupleTypeNode | FunctionTypeNode | UnionTypeNode | IntersectionTypeNode | ParenthesizedTypeNode | TypeofTypeNode | KeyofTypeNode | IndexedAccessTypeNode | ConditionalTypeNode | InferTypeNode | MappedTypeNode | TemplateLiteralTypeNode | DifferenceTypeNode;
|
|
757
776
|
/** `A - B` — every value of `A` that is not a `B`. Binds tighter than `|`
|
|
758
777
|
* and looser than `&`, so `A | B - C` is `A | (B - C)`.
|
|
759
778
|
*
|
|
@@ -842,17 +861,11 @@ interface TypePredicateNode extends BaseNode {
|
|
|
842
861
|
/** Absent for a bare `asserts x` (a truthiness assertion). */
|
|
843
862
|
typeAnnotation?: TypeNode;
|
|
844
863
|
}
|
|
845
|
-
interface TypePackNode extends BaseNode {
|
|
846
|
-
type: "TypePackNode";
|
|
847
|
-
types: TypeNode[];
|
|
848
|
-
hasVarargs: boolean;
|
|
849
|
-
varargType?: TypeNode;
|
|
850
|
-
}
|
|
851
864
|
interface TypeReference extends BaseNode {
|
|
852
865
|
type: "TypeReference";
|
|
853
866
|
base: string;
|
|
854
867
|
namespace?: string;
|
|
855
|
-
typeArguments:
|
|
868
|
+
typeArguments: TypeNode[];
|
|
856
869
|
}
|
|
857
870
|
interface TypeLiteralString extends BaseNode {
|
|
858
871
|
type: "TypeLiteralString";
|
|
@@ -892,11 +905,18 @@ interface TableTypeNode extends BaseNode {
|
|
|
892
905
|
interface ArrayTypeNode extends BaseNode {
|
|
893
906
|
type: "ArrayTypeNode";
|
|
894
907
|
element: TypeNode;
|
|
908
|
+
/** `readonly T[]` — the list may be read, not written to. */
|
|
909
|
+
isReadonly?: boolean;
|
|
895
910
|
}
|
|
896
|
-
/** `[number, string]` —
|
|
911
|
+
/** `[number, string]` — a tuple type; `[string, ...number[]]` ends in a rest
|
|
912
|
+
* of as many more as there are. */
|
|
897
913
|
interface TupleTypeNode extends BaseNode {
|
|
898
914
|
type: "TupleTypeNode";
|
|
899
915
|
elements: TypeNode[];
|
|
916
|
+
/** `...number[]` at the end: the array type the rest of it is. */
|
|
917
|
+
rest?: TypeNode;
|
|
918
|
+
/** `readonly [A, B]` — see `ArrayTypeNode.isReadonly`. */
|
|
919
|
+
isReadonly?: boolean;
|
|
900
920
|
}
|
|
901
921
|
interface FunctionTypeParameter extends BaseNode {
|
|
902
922
|
type: "FunctionTypeParameter";
|
|
@@ -913,8 +933,6 @@ interface FunctionTypeNode extends BaseNode {
|
|
|
913
933
|
type: "FunctionTypeNode";
|
|
914
934
|
generics: GenericTypeParameter[];
|
|
915
935
|
params: FunctionTypeParameter[];
|
|
916
|
-
hasVarargs: boolean;
|
|
917
|
-
varargType?: TypeNode;
|
|
918
936
|
returnType: TypeNode;
|
|
919
937
|
/** `(v: unknown) -> v is string` — a guard written as a function *type*. */
|
|
920
938
|
predicate?: TypePredicateNode;
|
|
@@ -937,10 +955,6 @@ interface TypeofTypeNode extends BaseNode {
|
|
|
937
955
|
type: "TypeofTypeNode";
|
|
938
956
|
expression: Expression;
|
|
939
957
|
}
|
|
940
|
-
interface VariadicTypeNode extends BaseNode {
|
|
941
|
-
type: "VariadicTypeNode";
|
|
942
|
-
typeAnnotation: TypeNode;
|
|
943
|
-
}
|
|
944
958
|
type Node = Program | Block | Statement | Expression | TypeNode | FunctionBody | FunctionParameter | FunctionName | IfClause | TypedIdentifier | GenericTypeParameter | FunctionSignature | TypePredicateNode | TableField | SpreadElement | FunctionTypeParameter | TableTypeProperty | BindingTarget | ObjectPatternProperty | ArrayPatternElement;
|
|
945
959
|
|
|
946
960
|
declare class ParseError extends Error {
|
|
@@ -1067,6 +1081,10 @@ declare function isGlobal(binding: Binding): boolean;
|
|
|
1067
1081
|
* undeclared, which is almost always a typo rather than an intentional
|
|
1068
1082
|
* implicit global. Handy for a "possibly undefined global" diagnostic. */
|
|
1069
1083
|
declare function isUnassignedGlobal(binding: Binding): boolean;
|
|
1084
|
+
/** Globals tilua itself declares, whatever the type libraries do:
|
|
1085
|
+
* `scriptArgs` is the arguments the script was started with — Lua's
|
|
1086
|
+
* top-level `...` — as an array. */
|
|
1087
|
+
declare const LANGUAGE_GLOBALS: readonly string[];
|
|
1070
1088
|
declare function analyzeScopes(program: Program, options?: AnalyzeScopesOptions): ScopeAnalysis;
|
|
1071
1089
|
|
|
1072
1090
|
type Type = AnyType | UnknownType | NeverType | PrimitiveType | LiteralType | ArrayType | TupleType | ObjectType | FunctionType | UnionType | IntersectionType | TypeParamType | GenericRefType | KeyofType | IndexedAccessType | ConditionalType | InferType | MappedType | TemplateLiteralType | DifferenceType;
|
|
@@ -1108,19 +1126,17 @@ interface ArrayType {
|
|
|
1108
1126
|
kind: "array";
|
|
1109
1127
|
element: Type;
|
|
1110
1128
|
alias?: string;
|
|
1129
|
+
readonly?: boolean;
|
|
1111
1130
|
}
|
|
1112
|
-
/** `[A, B, C]` — fixed length
|
|
1113
|
-
*
|
|
1114
|
-
*
|
|
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. */
|
|
1131
|
+
/** `[A, B, C]` — fixed length; `[A, ...B[]]` — at least that, then any
|
|
1132
|
+
* number of `B`. `rest` is the element type of that tail. A tuple is an
|
|
1133
|
+
* array, a table like any other: several results are one of these. */
|
|
1119
1134
|
interface TupleType {
|
|
1120
1135
|
kind: "tuple";
|
|
1121
1136
|
elements: Type[];
|
|
1122
|
-
|
|
1137
|
+
rest?: Type;
|
|
1123
1138
|
alias?: string;
|
|
1139
|
+
readonly?: boolean;
|
|
1124
1140
|
}
|
|
1125
1141
|
interface ObjectProperty {
|
|
1126
1142
|
type: Type;
|
|
@@ -1128,11 +1144,16 @@ interface ObjectProperty {
|
|
|
1128
1144
|
readonly?: boolean;
|
|
1129
1145
|
/** A class member written `private`: reachable only from inside the class
|
|
1130
1146
|
* that declared it. `owner` is that class's node, compared by identity;
|
|
1131
|
-
* `className` is how a diagnostic names it. Checked, never lowered.
|
|
1147
|
+
* `className` is how a diagnostic names it. Checked, never lowered.
|
|
1148
|
+
* `protected` widens that to the classes extending it. */
|
|
1132
1149
|
private?: {
|
|
1133
1150
|
owner: object;
|
|
1134
1151
|
className: string;
|
|
1152
|
+
protected?: boolean;
|
|
1135
1153
|
};
|
|
1154
|
+
/** An `abstract` class member: declared, with nothing behind it until a
|
|
1155
|
+
* class extending this one writes it. */
|
|
1156
|
+
abstract?: boolean;
|
|
1136
1157
|
}
|
|
1137
1158
|
interface ObjectType {
|
|
1138
1159
|
kind: "object";
|
|
@@ -1194,8 +1215,14 @@ interface TypePredicate {
|
|
|
1194
1215
|
interface FunctionType {
|
|
1195
1216
|
kind: "function";
|
|
1196
1217
|
params: FunctionParam[];
|
|
1218
|
+
/** The type of each argument a rest parameter (`...args: T[]`) collects —
|
|
1219
|
+
* or, with `restIsWhole`, the rest parameter's own type. */
|
|
1197
1220
|
varargs?: Type;
|
|
1198
|
-
/** A tuple
|
|
1221
|
+
/** `...args: A` where `A` is a tuple, or a type parameter standing for
|
|
1222
|
+
* one (`<A extends unknown[]>`): `varargs` is `A` itself, and once `A`
|
|
1223
|
+
* is known its elements are the parameters. */
|
|
1224
|
+
restIsWhole?: boolean;
|
|
1225
|
+
/** What the function returns: one value — several are an array. */
|
|
1199
1226
|
returns: Type;
|
|
1200
1227
|
/** Names of the function's own generic parameters (`function f<T>(...)`).
|
|
1201
1228
|
* `params` / `returns` may contain `typeParam` nodes for these. */
|
|
@@ -1344,7 +1371,9 @@ declare const bufferType: PrimitiveType;
|
|
|
1344
1371
|
declare function primitive(name: PrimitiveName): PrimitiveType;
|
|
1345
1372
|
declare function literal(value: string | number | boolean): LiteralType;
|
|
1346
1373
|
declare function arrayOf(element: Type): ArrayType;
|
|
1347
|
-
declare function tuple(elements: Type[],
|
|
1374
|
+
declare function tuple(elements: Type[], rest?: Type): TupleType;
|
|
1375
|
+
/** Every element type a tuple can hold, the rest's included. */
|
|
1376
|
+
declare function tupleMembers(t: TupleType): Type[];
|
|
1348
1377
|
declare function objectType(entries: Iterable<[string, ObjectProperty]>, indexer?: ObjectType["indexer"], frozen?: boolean): ObjectType;
|
|
1349
1378
|
declare function fn(params: FunctionParam[], returns: Type, varargs?: Type, typeParams?: string[], predicate?: TypePredicate): FunctionType;
|
|
1350
1379
|
declare function substitute(t: Type, subst: Map<string, Type>): Type;
|
|
@@ -1409,6 +1438,20 @@ interface TypeDiagnostic {
|
|
|
1409
1438
|
node: Expression | Statement | TypeNode | Block | ClassMember;
|
|
1410
1439
|
message: string;
|
|
1411
1440
|
}
|
|
1441
|
+
/** How a `for (const item in source)` walks its source — what lowering needs,
|
|
1442
|
+
* decided with the item's type so the two cannot drift apart.
|
|
1443
|
+
* - `values`: an array or a table, walked directly; the item is each value.
|
|
1444
|
+
* - `function`: an iterator function, called until it answers nil; the item
|
|
1445
|
+
* is each answer.
|
|
1446
|
+
* - `iteration`: `[step, state, first]`, as `pairs(t)` answers: `step` is
|
|
1447
|
+
* called with the state and the item before (`first` the first time) until
|
|
1448
|
+
* it answers nil.
|
|
1449
|
+
* `viaIter`: the source is an object whose `__iter` method gives the function
|
|
1450
|
+
* or the iteration. */
|
|
1451
|
+
interface LoopForm {
|
|
1452
|
+
readonly walks: "values" | "function" | "iteration";
|
|
1453
|
+
readonly viaIter: boolean;
|
|
1454
|
+
}
|
|
1412
1455
|
interface TypeAnalysis {
|
|
1413
1456
|
/** Inferred type of every expression node. */
|
|
1414
1457
|
readonly typeOf: Map<Expression, Type>;
|
|
@@ -1420,7 +1463,7 @@ interface TypeAnalysis {
|
|
|
1420
1463
|
/** What every type annotation node resolves to — `number`, `Shape`,
|
|
1421
1464
|
* `typeof x`, a property's type inside `{ ... }`. Inside a generic alias or
|
|
1422
1465
|
* function its parameters stay unresolved (`T`). */
|
|
1423
|
-
readonly typeOfTypeNode: Map<TypeNode
|
|
1466
|
+
readonly typeOfTypeNode: Map<TypeNode, Type>;
|
|
1424
1467
|
/** What each call argument is expected to be: the parameter it lands on,
|
|
1425
1468
|
* with the signature's type parameters replaced by their constraints — a
|
|
1426
1469
|
* union when an overload set disagrees. Recorded even for a call that does
|
|
@@ -1430,13 +1473,9 @@ interface TypeAnalysis {
|
|
|
1430
1473
|
/** Top-level type aliases, resolved — and the type names this module
|
|
1431
1474
|
* imports, so tooling treats both alike. */
|
|
1432
1475
|
readonly aliases: Map<string, Type>;
|
|
1433
|
-
/**
|
|
1434
|
-
*
|
|
1435
|
-
|
|
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>;
|
|
1476
|
+
/** How each `for (const item in source)` walks its source; see
|
|
1477
|
+
* `LoopForm`. A loop missing here walks values. */
|
|
1478
|
+
readonly loops: ReadonlyMap<GenericForStatement, LoopForm>;
|
|
1440
1479
|
readonly diagnostics: TypeDiagnostic[];
|
|
1441
1480
|
}
|
|
1442
1481
|
/** A type a module exports: the resolved type, plus the parameter names of a
|
|
@@ -1507,11 +1546,15 @@ resolveModule?: (specifier: string) => ModuleExports | undefined): ModuleExports
|
|
|
1507
1546
|
* (`tilua.methods` in its package.json). Nothing about `filter` is written
|
|
1508
1547
|
* into the analyzer.
|
|
1509
1548
|
*/
|
|
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";
|
|
1549
|
+
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
1550
|
|
|
1512
1551
|
interface ProjectHost {
|
|
1513
1552
|
/** A file's text, or `undefined` when there is no such file. */
|
|
1514
1553
|
readFile(path: string): string | undefined;
|
|
1554
|
+
/** The names of the folders in a folder, or `undefined` when there is no
|
|
1555
|
+
* such folder. Only a `types` entry with a `*` in it lists anything; a
|
|
1556
|
+
* host without this cannot load one. */
|
|
1557
|
+
readDirectory?(path: string): string[] | undefined;
|
|
1515
1558
|
}
|
|
1516
1559
|
declare const nodeHost: ProjectHost;
|
|
1517
1560
|
|
|
@@ -1775,4 +1818,4 @@ declare const tilua: {
|
|
|
1775
1818
|
readonly analyzeTypes: typeof analyzeTypes;
|
|
1776
1819
|
};
|
|
1777
1820
|
|
|
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
|
|
1821
|
+
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 };
|