luaut-parser 1.2.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 +103 -28
- package/dist/index.cjs +769 -59
- package/dist/index.d.cts +127 -25
- package/dist/index.d.ts +127 -25
- package/dist/index.js +760 -49
- package/package.json +2 -2
- package/dist/luau.d.luaut +0 -245
- package/dist/roblox.d.luaut +0 -503
package/dist/index.d.cts
CHANGED
|
@@ -135,7 +135,7 @@ interface ExportAllStatement extends BaseNode {
|
|
|
135
135
|
type: "ExportAllStatement";
|
|
136
136
|
source: StringLiteral;
|
|
137
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;
|
|
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 | DeclareClassStatement | ErrorStatement;
|
|
139
139
|
/** `declare game: DataModel` / `declare function require(m: string): unknown`
|
|
140
140
|
* — an ambient value/function declaration for a definitions file (`.d.luaut`).
|
|
141
141
|
* Contributes a global type; emits no runtime code. */
|
|
@@ -147,6 +147,18 @@ interface DeclareStatement extends BaseNode {
|
|
|
147
147
|
/** the declared value's type (function form is lowered to a FunctionTypeNode) */
|
|
148
148
|
valueType: TypeNode;
|
|
149
149
|
}
|
|
150
|
+
/** `declare class Part extends BasePart { Shape: EnumItem }` — a *nominal*
|
|
151
|
+
* type for a definitions file, the way Roblox's own classes are: a `Part` is
|
|
152
|
+
* an `Instance` because it extends one, not because it has the same members,
|
|
153
|
+
* and no table literal is ever a `Part`. The body lists the members the class
|
|
154
|
+
* adds; it inherits the rest. Declares a type only, no value. */
|
|
155
|
+
interface DeclareClassStatement extends BaseNode {
|
|
156
|
+
type: "DeclareClassStatement";
|
|
157
|
+
name: Identifier;
|
|
158
|
+
/** `extends Base` — another class. */
|
|
159
|
+
superclass?: TypeReference;
|
|
160
|
+
body: TableTypeNode;
|
|
161
|
+
}
|
|
150
162
|
/** A statement position that could not be parsed. Only produced when parsing
|
|
151
163
|
* in recovery mode (`parseWithRecovery`); its span covers the skipped tokens
|
|
152
164
|
* so tools can still map a cursor there. */
|
|
@@ -858,7 +870,26 @@ interface ObjectType {
|
|
|
858
870
|
/** The alias this object was resolved from — display only, ignored by
|
|
859
871
|
* `isAssignable` (the type is structural). Dropped on `widen`/`substitute`. */
|
|
860
872
|
name?: string;
|
|
873
|
+
/** Set on a `declare class` — the type is then *nominal*. See `ClassInfo`. */
|
|
874
|
+
class?: ClassInfo;
|
|
875
|
+
}
|
|
876
|
+
/** What makes an object a class instance. `properties` then holds every
|
|
877
|
+
* member, inherited ones included. Only the class itself and the classes
|
|
878
|
+
* extending it are assignable to it — no table literal, no structurally
|
|
879
|
+
* identical class. Going the other way, a class satisfies a shape naming
|
|
880
|
+
* members it has (`{ Name: string }`) but is not a table: never a
|
|
881
|
+
* `{ [K]: V }` or `{}`, which is what keeps `typeof(part)` from matching the
|
|
882
|
+
* `{ [unknown]: unknown }` overload. */
|
|
883
|
+
interface ClassInfo {
|
|
884
|
+
name: string;
|
|
885
|
+
/** The class it directly extends, if any. */
|
|
886
|
+
superclass?: string;
|
|
887
|
+
/** The class itself, then each class it extends, nearest first. */
|
|
888
|
+
ancestors: readonly string[];
|
|
861
889
|
}
|
|
890
|
+
declare function isClassType(t: Type): t is ObjectType & {
|
|
891
|
+
class: ClassInfo;
|
|
892
|
+
};
|
|
862
893
|
interface FunctionParam {
|
|
863
894
|
name?: string;
|
|
864
895
|
type: Type;
|
|
@@ -1065,7 +1096,9 @@ declare function overlaps(a: Type, b: Type): boolean;
|
|
|
1065
1096
|
declare function formatType(t: Type): string;
|
|
1066
1097
|
|
|
1067
1098
|
interface TypeDiagnostic {
|
|
1068
|
-
|
|
1099
|
+
/** Usually an expression or statement; a type where the type is wrong
|
|
1100
|
+
* (`declare class A extends NotAClass`). */
|
|
1101
|
+
node: Expression | Statement | TypeNode;
|
|
1069
1102
|
message: string;
|
|
1070
1103
|
}
|
|
1071
1104
|
interface TypeAnalysis {
|
|
@@ -1117,7 +1150,8 @@ interface AnalyzeTypesOptions {
|
|
|
1117
1150
|
libTypes?: Record<string, Type>;
|
|
1118
1151
|
/** Parsed definitions files (`.d.luaut`): their `type` aliases become
|
|
1119
1152
|
* available to annotations and their `declare` statements seed global
|
|
1120
|
-
* types.
|
|
1153
|
+
* types. A project lists them under `types` in `luaut.config.json`; see
|
|
1154
|
+
* `resolveTypeLibraries`. */
|
|
1121
1155
|
libs?: readonly Program[];
|
|
1122
1156
|
/** Resolve an `import`'s module path to what that module exports. Called
|
|
1123
1157
|
* once per distinct path. Return `undefined` when there is no such module:
|
|
@@ -1134,29 +1168,97 @@ declare function moduleExports(program: Program, scopes: ScopeAnalysis, types: T
|
|
|
1134
1168
|
/** For `export ... from`: the same resolver the module was analyzed with. */
|
|
1135
1169
|
resolveModule?: (specifier: string) => ModuleExports | undefined): ModuleExports;
|
|
1136
1170
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
declare const luauLib: Program;
|
|
1171
|
+
interface ProjectHost {
|
|
1172
|
+
/** A file's text, or `undefined` when there is no such file. */
|
|
1173
|
+
readFile(path: string): string | undefined;
|
|
1174
|
+
}
|
|
1175
|
+
declare const nodeHost: ProjectHost;
|
|
1143
1176
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
/**
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
|
|
1177
|
+
declare const CONFIG_FILE_NAMES: readonly ["luaut.config.json", "luaut.config.jsonc"];
|
|
1178
|
+
interface LuautConfig {
|
|
1179
|
+
/** Absolute path of the config file. */
|
|
1180
|
+
readonly path: string;
|
|
1181
|
+
/** The folder it sits in. Relative paths in it resolve from here. */
|
|
1182
|
+
readonly directory: string;
|
|
1183
|
+
/** The config file's text, for locating problems in it. */
|
|
1184
|
+
readonly source: string;
|
|
1185
|
+
/** Type libraries to load, in order: `"luau"`, `"@luaut/roblox"`, `"./types"`. */
|
|
1186
|
+
readonly types: readonly string[];
|
|
1187
|
+
/** Import path aliases, as in tsconfig: `{ "@shared/*": ["src/shared/*"] }`. */
|
|
1188
|
+
readonly paths: Readonly<Record<string, readonly string[]>>;
|
|
1189
|
+
/** Where `paths` targets resolve from, absolute. The config's folder unless set. */
|
|
1190
|
+
readonly baseUrl: string;
|
|
1191
|
+
/** Absolute path of a Rojo sourcemap, or `null` for none. */
|
|
1192
|
+
readonly sourceMap: string | null;
|
|
1193
|
+
}
|
|
1194
|
+
interface ConfigProblem {
|
|
1195
|
+
/** The file the problem is about: a config file, or a sourcemap it names. */
|
|
1196
|
+
readonly file: string;
|
|
1197
|
+
readonly message: string;
|
|
1198
|
+
/** 1-based position in `file`, when the problem has one. */
|
|
1199
|
+
readonly line?: number;
|
|
1200
|
+
readonly column?: number;
|
|
1201
|
+
}
|
|
1202
|
+
interface ConfigLookup {
|
|
1203
|
+
/** The config that applies, if one was found and could be read. */
|
|
1204
|
+
readonly config?: LuautConfig;
|
|
1205
|
+
readonly problems: readonly ConfigProblem[];
|
|
1206
|
+
/** Every config path looked at on the way up, found or not — what a cache
|
|
1207
|
+
* must watch, so that creating or deleting a config is noticed. */
|
|
1208
|
+
readonly searched: readonly string[];
|
|
1209
|
+
}
|
|
1210
|
+
/** The config that applies to `file`: the nearest one in its folder or above. */
|
|
1211
|
+
declare function findConfig(file: string, host?: ProjectHost): ConfigLookup;
|
|
1212
|
+
/** Read and check one config file. Problems do not stop the rest of it from
|
|
1213
|
+
* applying: an unknown option is reported and the known ones still work. */
|
|
1214
|
+
declare function loadConfig(path: string, host?: ProjectHost): {
|
|
1215
|
+
config?: LuautConfig;
|
|
1216
|
+
problems: ConfigProblem[];
|
|
1217
|
+
};
|
|
1218
|
+
/** Blank out `//` and `/* *\/` comments and trailing commas, keeping every
|
|
1219
|
+
* other character where it was — so a JSON error's position still points
|
|
1220
|
+
* into the original text. */
|
|
1221
|
+
declare function stripJsonComments(text: string): string;
|
|
1150
1222
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1223
|
+
interface TypeLibraries {
|
|
1224
|
+
/** Definitions files, dependencies before what depends on them. */
|
|
1225
|
+
readonly files: readonly string[];
|
|
1226
|
+
readonly problems: readonly ConfigProblem[];
|
|
1227
|
+
}
|
|
1228
|
+
declare function resolveTypeLibraries(config: LuautConfig, host?: ProjectHost): TypeLibraries;
|
|
1229
|
+
|
|
1230
|
+
/** Every file `specifier` could mean from `fromFile`, in the order they are
|
|
1231
|
+
* tried. A resolver that caches should watch all of them: creating an earlier
|
|
1232
|
+
* candidate changes what the import means. */
|
|
1233
|
+
declare function moduleCandidates(fromFile: string, specifier: string, config?: LuautConfig): string[];
|
|
1234
|
+
/** The file `specifier` names from `fromFile`, if it exists. */
|
|
1235
|
+
declare function resolveModulePath(fromFile: string, specifier: string, config?: LuautConfig, host?: ProjectHost): string | undefined;
|
|
1236
|
+
|
|
1237
|
+
interface SourceMapNode {
|
|
1238
|
+
name: string;
|
|
1239
|
+
className: string;
|
|
1240
|
+
filePaths?: string[];
|
|
1241
|
+
children?: SourceMapNode[];
|
|
1242
|
+
}
|
|
1243
|
+
interface SourceMapOptions {
|
|
1244
|
+
/** The type names the loaded libraries define. An instance of a class not
|
|
1245
|
+
* among them is typed as `Instance`. */
|
|
1246
|
+
readonly classes: ReadonlySet<string>;
|
|
1247
|
+
/** A class's own member names. A child whose name a member already takes
|
|
1248
|
+
* is left out — Roblox resolves the member first. Defaults to the members
|
|
1249
|
+
* every instance has. */
|
|
1250
|
+
readonly membersOf?: (className: string) => ReadonlySet<string>;
|
|
1251
|
+
}
|
|
1252
|
+
interface SourceMapTypes {
|
|
1253
|
+
/** The tree's classes, and `game` / `workspace` for a place. */
|
|
1254
|
+
readonly program: Program;
|
|
1255
|
+
/** `declare script: ...` for a file the tree maps, or `undefined`. */
|
|
1256
|
+
scriptFor(file: string): Program | undefined;
|
|
1257
|
+
}
|
|
1258
|
+
declare function sourceMapTypes(text: string, path: string, options: SourceMapOptions): {
|
|
1259
|
+
types?: SourceMapTypes;
|
|
1260
|
+
problem?: string;
|
|
1261
|
+
};
|
|
1160
1262
|
|
|
1161
1263
|
declare const luautparser: {
|
|
1162
1264
|
readonly tokenize: typeof tokenize;
|
|
@@ -1171,4 +1273,4 @@ declare const luautparser: {
|
|
|
1171
1273
|
readonly analyzeTypes: typeof analyzeTypes;
|
|
1172
1274
|
};
|
|
1173
1275
|
|
|
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,
|
|
1276
|
+
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, CONFIG_FILE_NAMES, type CallExpression, type CallStatement, type ClassInfo, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ConfigLookup, type ConfigProblem, type ContinueStatement, type DeclareClassStatement, 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 LuautConfig, 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 ProjectHost, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SourceMapNode, type SourceMapOptions, type SourceMapTypes, 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 TypeLibraries, 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, difference, equalTypes, falsyType, findConfig, fn, formatType, getBinding, intersection, isAssignable, isClassType, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, luautparser, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, resolveModulePath, resolveTypeLibraries, setAliasExpander, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tokenize, tuple, typeParam, unify, union, unknownType, widen };
|
package/dist/index.d.ts
CHANGED
|
@@ -135,7 +135,7 @@ interface ExportAllStatement extends BaseNode {
|
|
|
135
135
|
type: "ExportAllStatement";
|
|
136
136
|
source: StringLiteral;
|
|
137
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;
|
|
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 | DeclareClassStatement | ErrorStatement;
|
|
139
139
|
/** `declare game: DataModel` / `declare function require(m: string): unknown`
|
|
140
140
|
* — an ambient value/function declaration for a definitions file (`.d.luaut`).
|
|
141
141
|
* Contributes a global type; emits no runtime code. */
|
|
@@ -147,6 +147,18 @@ interface DeclareStatement extends BaseNode {
|
|
|
147
147
|
/** the declared value's type (function form is lowered to a FunctionTypeNode) */
|
|
148
148
|
valueType: TypeNode;
|
|
149
149
|
}
|
|
150
|
+
/** `declare class Part extends BasePart { Shape: EnumItem }` — a *nominal*
|
|
151
|
+
* type for a definitions file, the way Roblox's own classes are: a `Part` is
|
|
152
|
+
* an `Instance` because it extends one, not because it has the same members,
|
|
153
|
+
* and no table literal is ever a `Part`. The body lists the members the class
|
|
154
|
+
* adds; it inherits the rest. Declares a type only, no value. */
|
|
155
|
+
interface DeclareClassStatement extends BaseNode {
|
|
156
|
+
type: "DeclareClassStatement";
|
|
157
|
+
name: Identifier;
|
|
158
|
+
/** `extends Base` — another class. */
|
|
159
|
+
superclass?: TypeReference;
|
|
160
|
+
body: TableTypeNode;
|
|
161
|
+
}
|
|
150
162
|
/** A statement position that could not be parsed. Only produced when parsing
|
|
151
163
|
* in recovery mode (`parseWithRecovery`); its span covers the skipped tokens
|
|
152
164
|
* so tools can still map a cursor there. */
|
|
@@ -858,7 +870,26 @@ interface ObjectType {
|
|
|
858
870
|
/** The alias this object was resolved from — display only, ignored by
|
|
859
871
|
* `isAssignable` (the type is structural). Dropped on `widen`/`substitute`. */
|
|
860
872
|
name?: string;
|
|
873
|
+
/** Set on a `declare class` — the type is then *nominal*. See `ClassInfo`. */
|
|
874
|
+
class?: ClassInfo;
|
|
875
|
+
}
|
|
876
|
+
/** What makes an object a class instance. `properties` then holds every
|
|
877
|
+
* member, inherited ones included. Only the class itself and the classes
|
|
878
|
+
* extending it are assignable to it — no table literal, no structurally
|
|
879
|
+
* identical class. Going the other way, a class satisfies a shape naming
|
|
880
|
+
* members it has (`{ Name: string }`) but is not a table: never a
|
|
881
|
+
* `{ [K]: V }` or `{}`, which is what keeps `typeof(part)` from matching the
|
|
882
|
+
* `{ [unknown]: unknown }` overload. */
|
|
883
|
+
interface ClassInfo {
|
|
884
|
+
name: string;
|
|
885
|
+
/** The class it directly extends, if any. */
|
|
886
|
+
superclass?: string;
|
|
887
|
+
/** The class itself, then each class it extends, nearest first. */
|
|
888
|
+
ancestors: readonly string[];
|
|
861
889
|
}
|
|
890
|
+
declare function isClassType(t: Type): t is ObjectType & {
|
|
891
|
+
class: ClassInfo;
|
|
892
|
+
};
|
|
862
893
|
interface FunctionParam {
|
|
863
894
|
name?: string;
|
|
864
895
|
type: Type;
|
|
@@ -1065,7 +1096,9 @@ declare function overlaps(a: Type, b: Type): boolean;
|
|
|
1065
1096
|
declare function formatType(t: Type): string;
|
|
1066
1097
|
|
|
1067
1098
|
interface TypeDiagnostic {
|
|
1068
|
-
|
|
1099
|
+
/** Usually an expression or statement; a type where the type is wrong
|
|
1100
|
+
* (`declare class A extends NotAClass`). */
|
|
1101
|
+
node: Expression | Statement | TypeNode;
|
|
1069
1102
|
message: string;
|
|
1070
1103
|
}
|
|
1071
1104
|
interface TypeAnalysis {
|
|
@@ -1117,7 +1150,8 @@ interface AnalyzeTypesOptions {
|
|
|
1117
1150
|
libTypes?: Record<string, Type>;
|
|
1118
1151
|
/** Parsed definitions files (`.d.luaut`): their `type` aliases become
|
|
1119
1152
|
* available to annotations and their `declare` statements seed global
|
|
1120
|
-
* types.
|
|
1153
|
+
* types. A project lists them under `types` in `luaut.config.json`; see
|
|
1154
|
+
* `resolveTypeLibraries`. */
|
|
1121
1155
|
libs?: readonly Program[];
|
|
1122
1156
|
/** Resolve an `import`'s module path to what that module exports. Called
|
|
1123
1157
|
* once per distinct path. Return `undefined` when there is no such module:
|
|
@@ -1134,29 +1168,97 @@ declare function moduleExports(program: Program, scopes: ScopeAnalysis, types: T
|
|
|
1134
1168
|
/** For `export ... from`: the same resolver the module was analyzed with. */
|
|
1135
1169
|
resolveModule?: (specifier: string) => ModuleExports | undefined): ModuleExports;
|
|
1136
1170
|
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
declare const luauLib: Program;
|
|
1171
|
+
interface ProjectHost {
|
|
1172
|
+
/** A file's text, or `undefined` when there is no such file. */
|
|
1173
|
+
readFile(path: string): string | undefined;
|
|
1174
|
+
}
|
|
1175
|
+
declare const nodeHost: ProjectHost;
|
|
1143
1176
|
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
/**
|
|
1147
|
-
|
|
1148
|
-
/**
|
|
1149
|
-
|
|
1177
|
+
declare const CONFIG_FILE_NAMES: readonly ["luaut.config.json", "luaut.config.jsonc"];
|
|
1178
|
+
interface LuautConfig {
|
|
1179
|
+
/** Absolute path of the config file. */
|
|
1180
|
+
readonly path: string;
|
|
1181
|
+
/** The folder it sits in. Relative paths in it resolve from here. */
|
|
1182
|
+
readonly directory: string;
|
|
1183
|
+
/** The config file's text, for locating problems in it. */
|
|
1184
|
+
readonly source: string;
|
|
1185
|
+
/** Type libraries to load, in order: `"luau"`, `"@luaut/roblox"`, `"./types"`. */
|
|
1186
|
+
readonly types: readonly string[];
|
|
1187
|
+
/** Import path aliases, as in tsconfig: `{ "@shared/*": ["src/shared/*"] }`. */
|
|
1188
|
+
readonly paths: Readonly<Record<string, readonly string[]>>;
|
|
1189
|
+
/** Where `paths` targets resolve from, absolute. The config's folder unless set. */
|
|
1190
|
+
readonly baseUrl: string;
|
|
1191
|
+
/** Absolute path of a Rojo sourcemap, or `null` for none. */
|
|
1192
|
+
readonly sourceMap: string | null;
|
|
1193
|
+
}
|
|
1194
|
+
interface ConfigProblem {
|
|
1195
|
+
/** The file the problem is about: a config file, or a sourcemap it names. */
|
|
1196
|
+
readonly file: string;
|
|
1197
|
+
readonly message: string;
|
|
1198
|
+
/** 1-based position in `file`, when the problem has one. */
|
|
1199
|
+
readonly line?: number;
|
|
1200
|
+
readonly column?: number;
|
|
1201
|
+
}
|
|
1202
|
+
interface ConfigLookup {
|
|
1203
|
+
/** The config that applies, if one was found and could be read. */
|
|
1204
|
+
readonly config?: LuautConfig;
|
|
1205
|
+
readonly problems: readonly ConfigProblem[];
|
|
1206
|
+
/** Every config path looked at on the way up, found or not — what a cache
|
|
1207
|
+
* must watch, so that creating or deleting a config is noticed. */
|
|
1208
|
+
readonly searched: readonly string[];
|
|
1209
|
+
}
|
|
1210
|
+
/** The config that applies to `file`: the nearest one in its folder or above. */
|
|
1211
|
+
declare function findConfig(file: string, host?: ProjectHost): ConfigLookup;
|
|
1212
|
+
/** Read and check one config file. Problems do not stop the rest of it from
|
|
1213
|
+
* applying: an unknown option is reported and the known ones still work. */
|
|
1214
|
+
declare function loadConfig(path: string, host?: ProjectHost): {
|
|
1215
|
+
config?: LuautConfig;
|
|
1216
|
+
problems: ConfigProblem[];
|
|
1217
|
+
};
|
|
1218
|
+
/** Blank out `//` and `/* *\/` comments and trailing commas, keeping every
|
|
1219
|
+
* other character where it was — so a JSON error's position still points
|
|
1220
|
+
* into the original text. */
|
|
1221
|
+
declare function stripJsonComments(text: string): string;
|
|
1150
1222
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1223
|
+
interface TypeLibraries {
|
|
1224
|
+
/** Definitions files, dependencies before what depends on them. */
|
|
1225
|
+
readonly files: readonly string[];
|
|
1226
|
+
readonly problems: readonly ConfigProblem[];
|
|
1227
|
+
}
|
|
1228
|
+
declare function resolveTypeLibraries(config: LuautConfig, host?: ProjectHost): TypeLibraries;
|
|
1229
|
+
|
|
1230
|
+
/** Every file `specifier` could mean from `fromFile`, in the order they are
|
|
1231
|
+
* tried. A resolver that caches should watch all of them: creating an earlier
|
|
1232
|
+
* candidate changes what the import means. */
|
|
1233
|
+
declare function moduleCandidates(fromFile: string, specifier: string, config?: LuautConfig): string[];
|
|
1234
|
+
/** The file `specifier` names from `fromFile`, if it exists. */
|
|
1235
|
+
declare function resolveModulePath(fromFile: string, specifier: string, config?: LuautConfig, host?: ProjectHost): string | undefined;
|
|
1236
|
+
|
|
1237
|
+
interface SourceMapNode {
|
|
1238
|
+
name: string;
|
|
1239
|
+
className: string;
|
|
1240
|
+
filePaths?: string[];
|
|
1241
|
+
children?: SourceMapNode[];
|
|
1242
|
+
}
|
|
1243
|
+
interface SourceMapOptions {
|
|
1244
|
+
/** The type names the loaded libraries define. An instance of a class not
|
|
1245
|
+
* among them is typed as `Instance`. */
|
|
1246
|
+
readonly classes: ReadonlySet<string>;
|
|
1247
|
+
/** A class's own member names. A child whose name a member already takes
|
|
1248
|
+
* is left out — Roblox resolves the member first. Defaults to the members
|
|
1249
|
+
* every instance has. */
|
|
1250
|
+
readonly membersOf?: (className: string) => ReadonlySet<string>;
|
|
1251
|
+
}
|
|
1252
|
+
interface SourceMapTypes {
|
|
1253
|
+
/** The tree's classes, and `game` / `workspace` for a place. */
|
|
1254
|
+
readonly program: Program;
|
|
1255
|
+
/** `declare script: ...` for a file the tree maps, or `undefined`. */
|
|
1256
|
+
scriptFor(file: string): Program | undefined;
|
|
1257
|
+
}
|
|
1258
|
+
declare function sourceMapTypes(text: string, path: string, options: SourceMapOptions): {
|
|
1259
|
+
types?: SourceMapTypes;
|
|
1260
|
+
problem?: string;
|
|
1261
|
+
};
|
|
1160
1262
|
|
|
1161
1263
|
declare const luautparser: {
|
|
1162
1264
|
readonly tokenize: typeof tokenize;
|
|
@@ -1171,4 +1273,4 @@ declare const luautparser: {
|
|
|
1171
1273
|
readonly analyzeTypes: typeof analyzeTypes;
|
|
1172
1274
|
};
|
|
1173
1275
|
|
|
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,
|
|
1276
|
+
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, CONFIG_FILE_NAMES, type CallExpression, type CallStatement, type ClassInfo, type CompoundAssignmentStatement, type ConditionalType, type ConditionalTypeNode, type ConfigLookup, type ConfigProblem, type ContinueStatement, type DeclareClassStatement, 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 LuautConfig, 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 ProjectHost, type PunctuatorToken, Punctuators, type RecoverResult, type RepeatStatement, type ReturnStatement, type SatisfiesExpression, type ScopeAnalysis, type ScopeDiagnostic, type SourceMapNode, type SourceMapOptions, type SourceMapTypes, 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 TypeLibraries, 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, difference, equalTypes, falsyType, findConfig, fn, formatType, getBinding, intersection, isAssignable, isClassType, isGlobal, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, luautparser, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, resolveModulePath, resolveTypeLibraries, setAliasExpander, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tokenize, tuple, typeParam, unify, union, unknownType, widen };
|