luaut-parser 1.0.0 → 1.2.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 +18 -4
- package/dist/index.cjs +468 -35
- package/dist/index.d.cts +79 -7
- package/dist/index.d.ts +79 -7
- package/dist/index.js +467 -35
- package/dist/luau.d.luaut +245 -244
- package/dist/roblox.d.luaut +503 -503
- package/package.json +40 -40
package/dist/index.d.cts
CHANGED
|
@@ -115,13 +115,35 @@ interface ExportDefaultStatement extends BaseNode {
|
|
|
115
115
|
type: "ExportDefaultStatement";
|
|
116
116
|
declaration: Expression;
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
interface ExportSpecifier extends BaseNode {
|
|
119
|
+
type: "ExportSpecifier";
|
|
120
|
+
/** The name in this module — or, with `from`, in the other module. */
|
|
121
|
+
local: Identifier;
|
|
122
|
+
/** The name it is exported as — same as `local` unless renamed with `as`. */
|
|
123
|
+
exported: Identifier;
|
|
124
|
+
}
|
|
125
|
+
/** `export { a, b as c }` exports names declared elsewhere in the module;
|
|
126
|
+
* `export { a, b as c } from "./x"` re-exports another module's names. */
|
|
127
|
+
interface ExportNamedStatement extends BaseNode {
|
|
128
|
+
type: "ExportNamedStatement";
|
|
129
|
+
specifiers: ExportSpecifier[];
|
|
130
|
+
source?: StringLiteral;
|
|
131
|
+
}
|
|
132
|
+
/** `export * from "./x"` — every named export of another module (not its
|
|
133
|
+
* default), except names this module exports itself. */
|
|
134
|
+
interface ExportAllStatement extends BaseNode {
|
|
135
|
+
type: "ExportAllStatement";
|
|
136
|
+
source: StringLiteral;
|
|
137
|
+
}
|
|
138
|
+
type Statement = VariableDeclaration | FunctionDeclaration | FunctionDeclarationStatement | AssignmentStatement | CompoundAssignmentStatement | CallStatement | DoStatement | WhileStatement | RepeatStatement | IfStatement | NumericForStatement | GenericForStatement | ReturnStatement | BreakStatement | ContinueStatement | TypeAliasStatement | ExportTypeAliasStatement | ImportStatement | ExportStatement | ExportDefaultStatement | ExportNamedStatement | ExportAllStatement | DeclareStatement | ErrorStatement;
|
|
119
139
|
/** `declare game: DataModel` / `declare function require(m: string): unknown`
|
|
120
140
|
* — an ambient value/function declaration for a definitions file (`.d.luaut`).
|
|
121
141
|
* Contributes a global type; emits no runtime code. */
|
|
122
142
|
interface DeclareStatement extends BaseNode {
|
|
123
143
|
type: "DeclareStatement";
|
|
124
144
|
name: string;
|
|
145
|
+
/** The name as a node, so tools can point at it — `name` has no span. */
|
|
146
|
+
id: Identifier;
|
|
125
147
|
/** the declared value's type (function form is lowered to a FunctionTypeNode) */
|
|
126
148
|
valueType: TypeNode;
|
|
127
149
|
}
|
|
@@ -295,6 +317,8 @@ interface ExportTypeAliasStatement extends BaseNode {
|
|
|
295
317
|
interface GenericTypeParameter extends BaseNode {
|
|
296
318
|
type: "GenericTypeParameter";
|
|
297
319
|
name: string;
|
|
320
|
+
/** The name as a node. Absent on parameters the analyzer synthesizes. */
|
|
321
|
+
id?: Identifier;
|
|
298
322
|
isPack?: boolean;
|
|
299
323
|
/** `<const T>` — infer the argument at its narrowest instead of widening
|
|
300
324
|
* it: literals stay literal and array literals become tuples. */
|
|
@@ -532,6 +556,8 @@ interface ConditionalTypeNode extends BaseNode {
|
|
|
532
556
|
interface InferTypeNode extends BaseNode {
|
|
533
557
|
type: "InferTypeNode";
|
|
534
558
|
name: string;
|
|
559
|
+
/** The bound name as a node. */
|
|
560
|
+
id?: Identifier;
|
|
535
561
|
}
|
|
536
562
|
/** `{ [K in C]: V }` — a mapped type. `optional` / `readonly` carry the
|
|
537
563
|
* modifier as written: `true` adds it (`?`), `false` removes it (`-?`),
|
|
@@ -540,6 +566,8 @@ interface MappedTypeNode extends BaseNode {
|
|
|
540
566
|
type: "MappedTypeNode";
|
|
541
567
|
/** The name bound to each key in turn (`K`). */
|
|
542
568
|
parameter: string;
|
|
569
|
+
/** `parameter` as a node. */
|
|
570
|
+
parameterId?: Identifier;
|
|
543
571
|
/** The union of keys to map over (`C`). */
|
|
544
572
|
constraint: TypeNode;
|
|
545
573
|
/** `[K in C as R]` — remaps each key through `R`. */
|
|
@@ -592,21 +620,22 @@ interface TypeLiteralNumber extends BaseNode {
|
|
|
592
620
|
type: "TypeLiteralNumber";
|
|
593
621
|
value: number;
|
|
594
622
|
}
|
|
595
|
-
type TableTypeProperty = {
|
|
623
|
+
type TableTypeProperty = ({
|
|
596
624
|
type: "TableTypeIndexer";
|
|
597
625
|
keyType: TypeNode;
|
|
598
626
|
valueType: TypeNode;
|
|
599
|
-
}
|
|
627
|
+
} & BaseNode)
|
|
600
628
|
/** `name: T` (required) or `name?: T` (optional — TS style, the property
|
|
601
629
|
* may be absent). `optional` reflects the `?` after the name only;
|
|
602
630
|
* `name: T | nil` is a required property whose value may be nil. */
|
|
603
|
-
| {
|
|
631
|
+
| ({
|
|
604
632
|
type: "TableTypeProperty";
|
|
605
633
|
name: string;
|
|
634
|
+
key: Identifier;
|
|
606
635
|
valueType: TypeNode;
|
|
607
636
|
optional: boolean;
|
|
608
637
|
readonly?: boolean;
|
|
609
|
-
};
|
|
638
|
+
} & BaseNode);
|
|
610
639
|
interface TableTypeNode extends BaseNode {
|
|
611
640
|
type: "TableTypeNode";
|
|
612
641
|
properties: TableTypeProperty[];
|
|
@@ -626,6 +655,8 @@ interface FunctionTypeParameter extends BaseNode {
|
|
|
626
655
|
/** `name?: T` — the argument may be omitted, and its type admits `nil`. */
|
|
627
656
|
optional?: boolean;
|
|
628
657
|
name?: string;
|
|
658
|
+
/** The name as a node (absent for an unnamed parameter). */
|
|
659
|
+
id?: Identifier;
|
|
629
660
|
typeAnnotation: TypeNode;
|
|
630
661
|
}
|
|
631
662
|
interface FunctionTypeNode extends BaseNode {
|
|
@@ -650,6 +681,8 @@ interface ParenthesizedTypeNode extends BaseNode {
|
|
|
650
681
|
type: "ParenthesizedTypeNode";
|
|
651
682
|
typeAnnotation: TypeNode;
|
|
652
683
|
}
|
|
684
|
+
/** `typeof x` / `typeof x.y` (TypeScript's type query) or `typeof(expr)`
|
|
685
|
+
* (Luau's spelling): the type of a value. */
|
|
653
686
|
interface TypeofTypeNode extends BaseNode {
|
|
654
687
|
type: "TypeofTypeNode";
|
|
655
688
|
expression: Expression;
|
|
@@ -1043,10 +1076,39 @@ interface TypeAnalysis {
|
|
|
1043
1076
|
/** Type of a specific variable *reference*, after flow narrowing at that
|
|
1044
1077
|
* point. For an un-narrowed reference this equals `bindingType`. */
|
|
1045
1078
|
readonly narrowedTypeOf: Map<Identifier, Type>;
|
|
1046
|
-
/**
|
|
1079
|
+
/** What every type annotation node resolves to — `number`, `Shape`,
|
|
1080
|
+
* `typeof x`, a property's type inside `{ ... }`. Inside a generic alias or
|
|
1081
|
+
* function its parameters stay unresolved (`T`). */
|
|
1082
|
+
readonly typeOfTypeNode: Map<TypeNode | TypePackNode, Type>;
|
|
1083
|
+
/** What each call argument is expected to be: the parameter it lands on,
|
|
1084
|
+
* with the signature's type parameters replaced by their constraints — a
|
|
1085
|
+
* union when an overload set disagrees. Recorded even for a call that does
|
|
1086
|
+
* not type-check, since that is exactly when an editor wants to offer the
|
|
1087
|
+
* values that would. */
|
|
1088
|
+
readonly expectedTypeOf: Map<Expression, Type>;
|
|
1089
|
+
/** Top-level type aliases, resolved — and the type names this module
|
|
1090
|
+
* imports, so tooling treats both alike. */
|
|
1047
1091
|
readonly aliases: Map<string, Type>;
|
|
1048
1092
|
readonly diagnostics: TypeDiagnostic[];
|
|
1049
1093
|
}
|
|
1094
|
+
/** A type a module exports: the resolved type, plus the parameter names of a
|
|
1095
|
+
* generic alias so an importer can instantiate it (`Box<number>`). */
|
|
1096
|
+
interface ExportedType {
|
|
1097
|
+
readonly type: Type;
|
|
1098
|
+
readonly params: readonly string[];
|
|
1099
|
+
}
|
|
1100
|
+
/** What a module makes available to `import`. See `moduleExports`. */
|
|
1101
|
+
interface ModuleExports {
|
|
1102
|
+
/** `export const` / `export let` / `export const function` names. */
|
|
1103
|
+
readonly values: ReadonlyMap<string, Type>;
|
|
1104
|
+
/** `export type` names. */
|
|
1105
|
+
readonly types: ReadonlyMap<string, ExportedType>;
|
|
1106
|
+
/** `export default <expr>`. */
|
|
1107
|
+
readonly default?: Type;
|
|
1108
|
+
/** The module is still being analyzed further up an import cycle. Its
|
|
1109
|
+
* names read as `any`, and nothing about them is reported. */
|
|
1110
|
+
readonly partial?: boolean;
|
|
1111
|
+
}
|
|
1050
1112
|
interface AnalyzeTypesOptions {
|
|
1051
1113
|
/** Types for pre-registered globals (`analyzeScopes`'s `builtinGlobals`).
|
|
1052
1114
|
* Anything not listed is treated as `any`. Overrides `libs`. */
|
|
@@ -1057,10 +1119,20 @@ interface AnalyzeTypesOptions {
|
|
|
1057
1119
|
* available to annotations and their `declare` statements seed global
|
|
1058
1120
|
* types. See `robloxLib`. */
|
|
1059
1121
|
libs?: readonly Program[];
|
|
1122
|
+
/** Resolve an `import`'s module path to what that module exports. Called
|
|
1123
|
+
* once per distinct path. Return `undefined` when there is no such module:
|
|
1124
|
+
* the import is reported and its names are `any`. Without this option
|
|
1125
|
+
* every import is `any` — a single file cannot know better. */
|
|
1126
|
+
resolveModule?: (specifier: string) => ModuleExports | undefined;
|
|
1060
1127
|
/** Emit assignability diagnostics (default: true). */
|
|
1061
1128
|
diagnostics?: boolean;
|
|
1062
1129
|
}
|
|
1063
1130
|
declare function analyzeTypes(program: Program, scopes: ScopeAnalysis, options?: AnalyzeTypesOptions): TypeAnalysis;
|
|
1131
|
+
/** The exports of an analyzed module, in the shape another module's
|
|
1132
|
+
* `resolveModule` returns. */
|
|
1133
|
+
declare function moduleExports(program: Program, scopes: ScopeAnalysis, types: TypeAnalysis,
|
|
1134
|
+
/** For `export ... from`: the same resolver the module was analyzed with. */
|
|
1135
|
+
resolveModule?: (specifier: string) => ModuleExports | undefined): ModuleExports;
|
|
1064
1136
|
|
|
1065
1137
|
/** Absolute path to the shipped `luau.d.luaut`. */
|
|
1066
1138
|
declare const luauDefsPath: string;
|
|
@@ -1099,4 +1171,4 @@ declare const luautparser: {
|
|
|
1099
1171
|
readonly analyzeTypes: typeof analyzeTypes;
|
|
1100
1172
|
};
|
|
1101
1173
|
|
|
1102
|
-
export { type AnalyzeTypesOptions, type AnyType, 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 CallExpression, type CallStatement, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ContinueStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type DoStatement, type EOFToken, type ErrorStatement, type ExportDefaultStatement, type ExportStatement, type ExportTypeAliasStatement, type Expression, 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 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 MappedType, type MappedTypeNode, type MemberExpression, type MethodCallExpression, type NeverType, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SpreadElement, type Statement, type StringLiteral, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type Token, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, analyzeScopes, analyzeTypes, anyType, arrayOf, booleanType, bufferType, containsTypeParam, luautparser as default, defaultLibs, difference, equalTypes, falsyType, fn, formatType, getBinding, intersection, isAssignable, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, luauDefs, luauDefsPath, luauLib, luautparser, matchInfer, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, robloxDefs, robloxDefsPath, robloxLib, setAliasExpander, stringType, substitute, templateMatches, threadType, tokenize, tuple, typeParam, unify, union, unknownType, widen };
|
|
1174
|
+
export { type AnalyzeTypesOptions, type AnyType, 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 CallExpression, type CallStatement, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ContinueStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type DoStatement, type EOFToken, type ErrorStatement, type ExportAllStatement, type ExportDefaultStatement, type ExportNamedStatement, type ExportSpecifier, type ExportStatement, type ExportTypeAliasStatement, type ExportedType, type Expression, 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 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 MappedType, type MappedTypeNode, type MemberExpression, type MethodCallExpression, type ModuleExports, type NeverType, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SpreadElement, type Statement, type StringLiteral, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type Token, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, analyzeScopes, analyzeTypes, anyType, arrayOf, booleanType, bufferType, containsTypeParam, luautparser as default, defaultLibs, difference, equalTypes, falsyType, fn, formatType, getBinding, intersection, isAssignable, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, luauDefs, luauDefsPath, luauLib, luautparser, matchInfer, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, robloxDefs, robloxDefsPath, robloxLib, setAliasExpander, stringType, substitute, templateMatches, threadType, tokenize, tuple, typeParam, unify, union, unknownType, widen };
|
package/dist/index.d.ts
CHANGED
|
@@ -115,13 +115,35 @@ interface ExportDefaultStatement extends BaseNode {
|
|
|
115
115
|
type: "ExportDefaultStatement";
|
|
116
116
|
declaration: Expression;
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
interface ExportSpecifier extends BaseNode {
|
|
119
|
+
type: "ExportSpecifier";
|
|
120
|
+
/** The name in this module — or, with `from`, in the other module. */
|
|
121
|
+
local: Identifier;
|
|
122
|
+
/** The name it is exported as — same as `local` unless renamed with `as`. */
|
|
123
|
+
exported: Identifier;
|
|
124
|
+
}
|
|
125
|
+
/** `export { a, b as c }` exports names declared elsewhere in the module;
|
|
126
|
+
* `export { a, b as c } from "./x"` re-exports another module's names. */
|
|
127
|
+
interface ExportNamedStatement extends BaseNode {
|
|
128
|
+
type: "ExportNamedStatement";
|
|
129
|
+
specifiers: ExportSpecifier[];
|
|
130
|
+
source?: StringLiteral;
|
|
131
|
+
}
|
|
132
|
+
/** `export * from "./x"` — every named export of another module (not its
|
|
133
|
+
* default), except names this module exports itself. */
|
|
134
|
+
interface ExportAllStatement extends BaseNode {
|
|
135
|
+
type: "ExportAllStatement";
|
|
136
|
+
source: StringLiteral;
|
|
137
|
+
}
|
|
138
|
+
type Statement = VariableDeclaration | FunctionDeclaration | FunctionDeclarationStatement | AssignmentStatement | CompoundAssignmentStatement | CallStatement | DoStatement | WhileStatement | RepeatStatement | IfStatement | NumericForStatement | GenericForStatement | ReturnStatement | BreakStatement | ContinueStatement | TypeAliasStatement | ExportTypeAliasStatement | ImportStatement | ExportStatement | ExportDefaultStatement | ExportNamedStatement | ExportAllStatement | DeclareStatement | ErrorStatement;
|
|
119
139
|
/** `declare game: DataModel` / `declare function require(m: string): unknown`
|
|
120
140
|
* — an ambient value/function declaration for a definitions file (`.d.luaut`).
|
|
121
141
|
* Contributes a global type; emits no runtime code. */
|
|
122
142
|
interface DeclareStatement extends BaseNode {
|
|
123
143
|
type: "DeclareStatement";
|
|
124
144
|
name: string;
|
|
145
|
+
/** The name as a node, so tools can point at it — `name` has no span. */
|
|
146
|
+
id: Identifier;
|
|
125
147
|
/** the declared value's type (function form is lowered to a FunctionTypeNode) */
|
|
126
148
|
valueType: TypeNode;
|
|
127
149
|
}
|
|
@@ -295,6 +317,8 @@ interface ExportTypeAliasStatement extends BaseNode {
|
|
|
295
317
|
interface GenericTypeParameter extends BaseNode {
|
|
296
318
|
type: "GenericTypeParameter";
|
|
297
319
|
name: string;
|
|
320
|
+
/** The name as a node. Absent on parameters the analyzer synthesizes. */
|
|
321
|
+
id?: Identifier;
|
|
298
322
|
isPack?: boolean;
|
|
299
323
|
/** `<const T>` — infer the argument at its narrowest instead of widening
|
|
300
324
|
* it: literals stay literal and array literals become tuples. */
|
|
@@ -532,6 +556,8 @@ interface ConditionalTypeNode extends BaseNode {
|
|
|
532
556
|
interface InferTypeNode extends BaseNode {
|
|
533
557
|
type: "InferTypeNode";
|
|
534
558
|
name: string;
|
|
559
|
+
/** The bound name as a node. */
|
|
560
|
+
id?: Identifier;
|
|
535
561
|
}
|
|
536
562
|
/** `{ [K in C]: V }` — a mapped type. `optional` / `readonly` carry the
|
|
537
563
|
* modifier as written: `true` adds it (`?`), `false` removes it (`-?`),
|
|
@@ -540,6 +566,8 @@ interface MappedTypeNode extends BaseNode {
|
|
|
540
566
|
type: "MappedTypeNode";
|
|
541
567
|
/** The name bound to each key in turn (`K`). */
|
|
542
568
|
parameter: string;
|
|
569
|
+
/** `parameter` as a node. */
|
|
570
|
+
parameterId?: Identifier;
|
|
543
571
|
/** The union of keys to map over (`C`). */
|
|
544
572
|
constraint: TypeNode;
|
|
545
573
|
/** `[K in C as R]` — remaps each key through `R`. */
|
|
@@ -592,21 +620,22 @@ interface TypeLiteralNumber extends BaseNode {
|
|
|
592
620
|
type: "TypeLiteralNumber";
|
|
593
621
|
value: number;
|
|
594
622
|
}
|
|
595
|
-
type TableTypeProperty = {
|
|
623
|
+
type TableTypeProperty = ({
|
|
596
624
|
type: "TableTypeIndexer";
|
|
597
625
|
keyType: TypeNode;
|
|
598
626
|
valueType: TypeNode;
|
|
599
|
-
}
|
|
627
|
+
} & BaseNode)
|
|
600
628
|
/** `name: T` (required) or `name?: T` (optional — TS style, the property
|
|
601
629
|
* may be absent). `optional` reflects the `?` after the name only;
|
|
602
630
|
* `name: T | nil` is a required property whose value may be nil. */
|
|
603
|
-
| {
|
|
631
|
+
| ({
|
|
604
632
|
type: "TableTypeProperty";
|
|
605
633
|
name: string;
|
|
634
|
+
key: Identifier;
|
|
606
635
|
valueType: TypeNode;
|
|
607
636
|
optional: boolean;
|
|
608
637
|
readonly?: boolean;
|
|
609
|
-
};
|
|
638
|
+
} & BaseNode);
|
|
610
639
|
interface TableTypeNode extends BaseNode {
|
|
611
640
|
type: "TableTypeNode";
|
|
612
641
|
properties: TableTypeProperty[];
|
|
@@ -626,6 +655,8 @@ interface FunctionTypeParameter extends BaseNode {
|
|
|
626
655
|
/** `name?: T` — the argument may be omitted, and its type admits `nil`. */
|
|
627
656
|
optional?: boolean;
|
|
628
657
|
name?: string;
|
|
658
|
+
/** The name as a node (absent for an unnamed parameter). */
|
|
659
|
+
id?: Identifier;
|
|
629
660
|
typeAnnotation: TypeNode;
|
|
630
661
|
}
|
|
631
662
|
interface FunctionTypeNode extends BaseNode {
|
|
@@ -650,6 +681,8 @@ interface ParenthesizedTypeNode extends BaseNode {
|
|
|
650
681
|
type: "ParenthesizedTypeNode";
|
|
651
682
|
typeAnnotation: TypeNode;
|
|
652
683
|
}
|
|
684
|
+
/** `typeof x` / `typeof x.y` (TypeScript's type query) or `typeof(expr)`
|
|
685
|
+
* (Luau's spelling): the type of a value. */
|
|
653
686
|
interface TypeofTypeNode extends BaseNode {
|
|
654
687
|
type: "TypeofTypeNode";
|
|
655
688
|
expression: Expression;
|
|
@@ -1043,10 +1076,39 @@ interface TypeAnalysis {
|
|
|
1043
1076
|
/** Type of a specific variable *reference*, after flow narrowing at that
|
|
1044
1077
|
* point. For an un-narrowed reference this equals `bindingType`. */
|
|
1045
1078
|
readonly narrowedTypeOf: Map<Identifier, Type>;
|
|
1046
|
-
/**
|
|
1079
|
+
/** What every type annotation node resolves to — `number`, `Shape`,
|
|
1080
|
+
* `typeof x`, a property's type inside `{ ... }`. Inside a generic alias or
|
|
1081
|
+
* function its parameters stay unresolved (`T`). */
|
|
1082
|
+
readonly typeOfTypeNode: Map<TypeNode | TypePackNode, Type>;
|
|
1083
|
+
/** What each call argument is expected to be: the parameter it lands on,
|
|
1084
|
+
* with the signature's type parameters replaced by their constraints — a
|
|
1085
|
+
* union when an overload set disagrees. Recorded even for a call that does
|
|
1086
|
+
* not type-check, since that is exactly when an editor wants to offer the
|
|
1087
|
+
* values that would. */
|
|
1088
|
+
readonly expectedTypeOf: Map<Expression, Type>;
|
|
1089
|
+
/** Top-level type aliases, resolved — and the type names this module
|
|
1090
|
+
* imports, so tooling treats both alike. */
|
|
1047
1091
|
readonly aliases: Map<string, Type>;
|
|
1048
1092
|
readonly diagnostics: TypeDiagnostic[];
|
|
1049
1093
|
}
|
|
1094
|
+
/** A type a module exports: the resolved type, plus the parameter names of a
|
|
1095
|
+
* generic alias so an importer can instantiate it (`Box<number>`). */
|
|
1096
|
+
interface ExportedType {
|
|
1097
|
+
readonly type: Type;
|
|
1098
|
+
readonly params: readonly string[];
|
|
1099
|
+
}
|
|
1100
|
+
/** What a module makes available to `import`. See `moduleExports`. */
|
|
1101
|
+
interface ModuleExports {
|
|
1102
|
+
/** `export const` / `export let` / `export const function` names. */
|
|
1103
|
+
readonly values: ReadonlyMap<string, Type>;
|
|
1104
|
+
/** `export type` names. */
|
|
1105
|
+
readonly types: ReadonlyMap<string, ExportedType>;
|
|
1106
|
+
/** `export default <expr>`. */
|
|
1107
|
+
readonly default?: Type;
|
|
1108
|
+
/** The module is still being analyzed further up an import cycle. Its
|
|
1109
|
+
* names read as `any`, and nothing about them is reported. */
|
|
1110
|
+
readonly partial?: boolean;
|
|
1111
|
+
}
|
|
1050
1112
|
interface AnalyzeTypesOptions {
|
|
1051
1113
|
/** Types for pre-registered globals (`analyzeScopes`'s `builtinGlobals`).
|
|
1052
1114
|
* Anything not listed is treated as `any`. Overrides `libs`. */
|
|
@@ -1057,10 +1119,20 @@ interface AnalyzeTypesOptions {
|
|
|
1057
1119
|
* available to annotations and their `declare` statements seed global
|
|
1058
1120
|
* types. See `robloxLib`. */
|
|
1059
1121
|
libs?: readonly Program[];
|
|
1122
|
+
/** Resolve an `import`'s module path to what that module exports. Called
|
|
1123
|
+
* once per distinct path. Return `undefined` when there is no such module:
|
|
1124
|
+
* the import is reported and its names are `any`. Without this option
|
|
1125
|
+
* every import is `any` — a single file cannot know better. */
|
|
1126
|
+
resolveModule?: (specifier: string) => ModuleExports | undefined;
|
|
1060
1127
|
/** Emit assignability diagnostics (default: true). */
|
|
1061
1128
|
diagnostics?: boolean;
|
|
1062
1129
|
}
|
|
1063
1130
|
declare function analyzeTypes(program: Program, scopes: ScopeAnalysis, options?: AnalyzeTypesOptions): TypeAnalysis;
|
|
1131
|
+
/** The exports of an analyzed module, in the shape another module's
|
|
1132
|
+
* `resolveModule` returns. */
|
|
1133
|
+
declare function moduleExports(program: Program, scopes: ScopeAnalysis, types: TypeAnalysis,
|
|
1134
|
+
/** For `export ... from`: the same resolver the module was analyzed with. */
|
|
1135
|
+
resolveModule?: (specifier: string) => ModuleExports | undefined): ModuleExports;
|
|
1064
1136
|
|
|
1065
1137
|
/** Absolute path to the shipped `luau.d.luaut`. */
|
|
1066
1138
|
declare const luauDefsPath: string;
|
|
@@ -1099,4 +1171,4 @@ declare const luautparser: {
|
|
|
1099
1171
|
readonly analyzeTypes: typeof analyzeTypes;
|
|
1100
1172
|
};
|
|
1101
1173
|
|
|
1102
|
-
export { type AnalyzeTypesOptions, type AnyType, 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 CallExpression, type CallStatement, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ContinueStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type DoStatement, type EOFToken, type ErrorStatement, type ExportDefaultStatement, type ExportStatement, type ExportTypeAliasStatement, type Expression, 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 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 MappedType, type MappedTypeNode, type MemberExpression, type MethodCallExpression, type NeverType, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SpreadElement, type Statement, type StringLiteral, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type Token, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, analyzeScopes, analyzeTypes, anyType, arrayOf, booleanType, bufferType, containsTypeParam, luautparser as default, defaultLibs, difference, equalTypes, falsyType, fn, formatType, getBinding, intersection, isAssignable, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, luauDefs, luauDefsPath, luauLib, luautparser, matchInfer, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, robloxDefs, robloxDefsPath, robloxLib, setAliasExpander, stringType, substitute, templateMatches, threadType, tokenize, tuple, typeParam, unify, union, unknownType, widen };
|
|
1174
|
+
export { type AnalyzeTypesOptions, type AnyType, 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 CallExpression, type CallStatement, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ContinueStatement, type DeclareStatement, type DifferenceType, type DifferenceTypeNode, type DoStatement, type EOFToken, type ErrorStatement, type ExportAllStatement, type ExportDefaultStatement, type ExportNamedStatement, type ExportSpecifier, type ExportStatement, type ExportTypeAliasStatement, type ExportedType, type Expression, 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 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 MappedType, type MappedTypeNode, type MemberExpression, type MethodCallExpression, type ModuleExports, type NeverType, type NilLiteral, type Node, type NumberLiteral, type NumericForStatement, type ObjectPattern, type ObjectPatternProperty, type ObjectProperty, type ObjectType, type OperatorToken, Operators, type ParenthesizedExpression, type ParenthesizedTypeNode, ParseError, type ParserOptions, type PrimitiveName, type PrimitiveType, type Program, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SpreadElement, type Statement, type StringLiteral, type TableExpression, type TableField, type TableTypeNode, type TableTypeProperty, type TemplateLiteralType, type TemplateLiteralTypeNode, type Token, type TupleType, type TupleTypeNode, type Type, type TypeAliasStatement, type TypeAnalysis, type TypeAssertionExpression, type TypeDiagnostic, type TypeLiteralBoolean, type TypeLiteralNumber, type TypeLiteralString, type TypeNode, type TypePackNode, type TypeParamType, type TypePredicate, type TypePredicateNode, type TypeReference, type TypedIdentifier, type TypeofTypeNode, type UnaryExpression, UnaryOperators, type UnionType, type UnionTypeNode, type UnknownType, type VarargExpression, type VariableDeclaration, type VariadicTypeNode, type WhileStatement, analyzeScopes, analyzeTypes, anyType, arrayOf, booleanType, bufferType, containsTypeParam, luautparser as default, defaultLibs, difference, equalTypes, falsyType, fn, formatType, getBinding, intersection, isAssignable, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, luauDefs, luauDefsPath, luauLib, luautparser, matchInfer, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, robloxDefs, robloxDefsPath, robloxLib, setAliasExpander, stringType, substitute, templateMatches, threadType, tokenize, tuple, typeParam, unify, union, unknownType, widen };
|