@tilua/parser 3.0.0 → 3.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/dist/index.cjs +423 -83
- package/dist/index.d.cts +73 -3
- package/dist/index.d.ts +73 -3
- package/dist/index.js +412 -82
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -639,6 +639,12 @@ interface FunctionParameter extends BaseNode {
|
|
|
639
639
|
typeAnnotation?: TypeNode;
|
|
640
640
|
/** default value (`function f(a = 1) end`) */
|
|
641
641
|
default?: Expression;
|
|
642
|
+
/** Not written in the source: the `this` a class method is given, or the
|
|
643
|
+
* `self` of `function T:m()`. It carries the span of what implies it
|
|
644
|
+
* (the method, the `T:m`) so a diagnostic has somewhere to point, but no
|
|
645
|
+
* text there is its name — an editor colours, hovers and renames none
|
|
646
|
+
* of it. */
|
|
647
|
+
implicit?: boolean;
|
|
642
648
|
}
|
|
643
649
|
interface FunctionBody extends BaseNode {
|
|
644
650
|
type: "FunctionBody";
|
|
@@ -1064,7 +1070,7 @@ interface ScopeDiagnostic {
|
|
|
1064
1070
|
};
|
|
1065
1071
|
};
|
|
1066
1072
|
message: string;
|
|
1067
|
-
kind: "redeclare" | "const-assign" | "type-only" | "undeclared" | "use-before-define";
|
|
1073
|
+
kind: "redeclare" | "const-assign" | "type-only" | "undeclared" | "use-before-define" | "outside-loop";
|
|
1068
1074
|
}
|
|
1069
1075
|
interface ScopeAnalysis {
|
|
1070
1076
|
/** Every Identifier that appears in a variable *usage* position (i.e.
|
|
@@ -1601,7 +1607,7 @@ resolveModule?: (specifier: string) => ModuleExports | undefined): ModuleExports
|
|
|
1601
1607
|
* `ObjectValues<T>` and `ObjectEntries<T>`, an object's members as tuples in
|
|
1602
1608
|
* the order they were written.
|
|
1603
1609
|
*/
|
|
1604
|
-
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\n-- ============================================================\n-- The metatables of the language's own values\n-- ============================================================\n\n-- A string's methods. The first group is Lua's string library, which a\n-- string really answers to; where Lua answers several values, tilua answers\n-- one, as the global functions do (`find` is an array, `gsub` the new\n-- string). The second group is written the way JavaScript writes it.\n--\n-- Positions are Lua's: `sub` and `slice` count from 1, and `indexOf` is\n-- `nil` when the text is not there.\ndeclare metatable string: {\n __index: {\n upper: (self: string) => string,\n lower: (self: string) => string,\n len: (self: string) => number,\n sub: (self: string, i: number, j?: number) => string,\n rep: (self: string, n: number, separator?: string) => string,\n reverse: (self: string) => string,\n format: (self: string, ...args: unknown[]) => string,\n byte: ((self: string, i?: number) => number) & ((self: string, i: number, j: number) => number[]),\n find: (self: string, pattern: string, init?: number, plain?: boolean) => [number, number, ...string[]] | nil,\n match: (self: string, pattern: string, init?: number) => [...string[]] | nil,\n gmatch: (self: string, pattern: string) => () => [string, ...string[]] | nil,\n gsub: (self: string, pattern: string, replacement: unknown, n?: number) => string,\n\n trim: (self: string) => string,\n trimStart: (self: string) => string,\n trimEnd: (self: string) => string,\n startsWith: (self: string, text: string) => boolean,\n endsWith: (self: string, text: string) => boolean,\n includes: (self: string, text: string) => boolean,\n indexOf: (self: string, text: string, start?: number) => number | nil,\n slice: (self: string, start?: number, stop?: number) => string,\n replace: (self: string, text: string, replacement: string) => string,\n replaceAll: (self: string, text: string, replacement: string) => string,\n padStart: (self: string, length: number, padding?: string) => string,\n padEnd: (self: string, length: number, padding?: string) => string,\n },\n}\n\n-- An array's methods. Lua gives an array no metatable: the compiler lowers\n-- each call to a plain function, so they work on any array, one a Lua\n-- library made included.\n--\n-- Indices are Lua's: the first element is 1, and `indexOf` / `findIndex`\n-- answer `nil` rather than JavaScript's -1. `sort` takes Lua's comparator\n-- (true when `a` comes first). `push`, `pop`, `shift`, `unshift`,\n-- `sort` and `reverse` change the array; everything else returns a new one.\ndeclare metatable<T> T[]: {\n __index: {\n find: (self: T[], test: (value: T, index: number) => boolean) => T | nil,\n findIndex: (self: T[], test: (value: T, index: number) => boolean) => number | nil,\n filter: (self: T[], test: (value: T, index: number) => boolean) => T[],\n map: <U>(self: T[], transform: (value: T, index: number) => U) => U[],\n forEach: (self: T[], visit: (value: T, index: number) => nil) => nil,\n some: (self: T[], test: (value: T, index: number) => boolean) => boolean,\n every: (self: T[], test: (value: T, index: number) => boolean) => boolean,\n reduce: <U>(self: T[], step: (total: U, value: T, index: number) => U, initial: U) => U,\n includes: (self: T[], value: T) => boolean,\n indexOf: (self: T[], value: T, start?: number) => number | nil,\n join: (self: T[], separator?: string) => string,\n concat: (self: T[], ...others: T[][]) => T[],\n slice: (self: T[], start?: number, stop?: number) => T[],\n flat: (self: T[]) => T[],\n reverse: (self: T[]) => T[],\n sort: (self: T[], compare?: (a: T, b: T) => boolean) => T[],\n push: (self: T[], ...args: T[]) => number,\n pop: (self: T[]) => T | nil,\n shift: (self: T[]) => T | nil,\n unshift: (self: T[], ...args: T[]) => number,\n },\n}\n\n-- A table's methods. Unlike JavaScript's `Object.keys`, they answer a\n-- tuple, in the order the table's type wrote its members:\n--\n-- const point = { x: 1, y: \"up\" }\n-- point:keys() -- [\"x\", \"y\"]\n-- point:values() -- [number, string]\n-- point:entries() -- [[\"x\", number], [\"y\", string]]\n--\n-- A Lua table has no order of its own, so the compiler hands its runtime the\n-- keys as the type lists them. An optional member keeps its place, holding\n-- `nil` when it is missing; an indexer's keys follow the named ones. A\n-- member of the table's own with one of these names is what a call reaches,\n-- and a class instance, which has a metatable of its own, has none of them.\ndeclare metatable<T extends {}> T: {\n __index: {\n keys: (self: T) => ObjectKeys<T>,\n values: (self: T) => ObjectValues<T>,\n entries: (self: T) => ObjectEntries<T>,\n },\n}\n";
|
|
1610
|
+
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\n-- ============================================================\n-- The metatables of the language's own values\n-- ============================================================\n\n-- A string's methods. The first group is Lua's string library, which a\n-- string really answers to; where Lua answers several values, tilua answers\n-- one, as the global functions do (`find` is an array, `gsub` the new\n-- string). The second group is written the way JavaScript writes it.\n--\n-- Positions are Lua's: `sub` and `slice` count from 1, and `indexOf` is\n-- `nil` when the text is not there.\ndeclare metatable string: {\n __index: {\n upper: (self: string) => string,\n lower: (self: string) => string,\n len: (self: string) => number,\n sub: (self: string, i: number, j?: number) => string,\n rep: (self: string, n: number, separator?: string) => string,\n reverse: (self: string) => string,\n format: (self: string, ...args: unknown[]) => string,\n byte: ((self: string, i?: number) => number) & ((self: string, i: number, j: number) => number[]),\n find: (self: string, pattern: string, init?: number, plain?: boolean) => [number, number, ...string[]] | nil,\n match: (self: string, pattern: string, init?: number) => [...string[]] | nil,\n gmatch: (self: string, pattern: string) => () => [string, ...string[]] | nil,\n gsub: (self: string, pattern: string, replacement: unknown, n?: number) => string,\n\n trim: (self: string) => string,\n trimStart: (self: string) => string,\n trimEnd: (self: string) => string,\n startsWith: (self: string, text: string) => boolean,\n endsWith: (self: string, text: string) => boolean,\n includes: (self: string, text: string) => boolean,\n indexOf: (self: string, text: string, start?: number) => number | nil,\n slice: (self: string, start?: number, stop?: number) => string,\n replace: (self: string, text: string, replacement: string) => string,\n replaceAll: (self: string, text: string, replacement: string) => string,\n padStart: (self: string, length: number, padding?: string) => string,\n padEnd: (self: string, length: number, padding?: string) => string,\n },\n}\n\n-- An array's methods. Lua gives an array no metatable: the compiler lowers\n-- each call to a plain function, so they work on any array, one a Lua\n-- library made included.\n--\n-- Indices are Lua's: the first element is 1, and `indexOf` / `findIndex`\n-- answer `nil` rather than JavaScript's -1. `sort` takes Lua's comparator\n-- (true when `a` comes first). `push`, `pop`, `shift`, `unshift`,\n-- `sort` and `reverse` change the array; everything else returns a new one.\n-- A `filter` whose test is a guard \u2014 `v is S`, or `v => v ~= nil` \u2014\n-- answers an array of what it let through.\ndeclare metatable<T> T[]: {\n __index: {\n find: (self: T[], test: (value: T, index: number) => boolean) => T | nil,\n findIndex: (self: T[], test: (value: T, index: number) => boolean) => number | nil,\n filter: (<S extends T>(self: T[], test: (value: T, index: number) => value is S) => S[])\n & ((self: T[], test: (value: T, index: number) => boolean) => T[]),\n map: <U>(self: T[], transform: (value: T, index: number) => U) => U[],\n forEach: (self: T[], visit: (value: T, index: number) => nil) => nil,\n some: (self: T[], test: (value: T, index: number) => boolean) => boolean,\n every: (self: T[], test: (value: T, index: number) => boolean) => boolean,\n reduce: <U>(self: T[], step: (total: U, value: T, index: number) => U, initial: U) => U,\n includes: (self: T[], value: T) => boolean,\n indexOf: (self: T[], value: T, start?: number) => number | nil,\n join: (self: T[], separator?: string) => string,\n concat: (self: T[], ...others: T[][]) => T[],\n slice: (self: T[], start?: number, stop?: number) => T[],\n flat: (self: T[]) => T[],\n reverse: (self: T[]) => T[],\n sort: (self: T[], compare?: (a: T, b: T) => boolean) => T[],\n push: (self: T[], ...args: T[]) => number,\n pop: (self: T[]) => T | nil,\n shift: (self: T[]) => T | nil,\n unshift: (self: T[], ...args: T[]) => number,\n },\n}\n\n-- A table's methods. Unlike JavaScript's `Object.keys`, they answer a\n-- tuple, in the order the table's type wrote its members:\n--\n-- const point = { x: 1, y: \"up\" }\n-- point:keys() -- [\"x\", \"y\"]\n-- point:values() -- [number, string]\n-- point:entries() -- [[\"x\", number], [\"y\", string]]\n--\n-- A Lua table has no order of its own, so the compiler hands its runtime the\n-- keys as the type lists them. An optional member keeps its place, holding\n-- `nil` when it is missing; an indexer's keys follow the named ones. A\n-- member of the table's own with one of these names is what a call reaches,\n-- and a class instance, which has a metatable of its own, has none of them.\n--\n-- The rest are JavaScript's `Object` functions, written as methods of the\n-- table they take first:\n--\n-- point:hasOwn(\"x\") -- Object.hasOwn(point, \"x\")\n-- point:assign({ z: 3 }) -- Object.assign(point, { z: 3 })\n-- point:freeze() -- Object.freeze(point)\n--\n-- `hasOwn` asks the table itself, not what its metatable's `__index`\n-- lends it. `assign` copies each source's members onto the table, later ones\n-- over earlier ones, skipping a `nil` source, and answers the table. `freeze`\n-- is Luau's `table.freeze`; under Lua 5.1, which cannot freeze a table, the\n-- table is answered as it is and `isFrozen` is false.\ndeclare metatable<T extends {}> T: {\n __index: {\n keys: (self: T) => ObjectKeys<T>,\n values: (self: T) => ObjectValues<T>,\n entries: (self: T) => ObjectEntries<T>,\n\n hasOwn: (self: T, key: unknown) => boolean,\n hasOwnProperty: (self: T, key: unknown) => boolean,\n assign: (<U>(self: T, source: U) => T & U)\n & (<U, V>(self: T, a: U, b: V) => T & U & V)\n & (<U, V, W>(self: T, a: U, b: V, c: W) => T & U & V & W)\n -- Generic like the rest: a plain signature would be tried first.\n & (<S extends {}>(self: T, ...sources: S[]) => T),\n freeze: (self: T) => Readonly<T>,\n isFrozen: (self: T) => boolean,\n },\n}\n";
|
|
1605
1611
|
|
|
1606
1612
|
interface ProjectHost {
|
|
1607
1613
|
/** A file's text, or `undefined` when there is no such file. */
|
|
@@ -1722,6 +1728,10 @@ declare function resolveTypeLibraries(config: TiluaConfig, host?: ProjectHost):
|
|
|
1722
1728
|
* },
|
|
1723
1729
|
* }
|
|
1724
1730
|
* export default plugin
|
|
1731
|
+
*
|
|
1732
|
+
* What a plugin runs to decide and to write — `luauString`, `isInstanceOf`,
|
|
1733
|
+
* `returnsTuple`, ... — is exported beside this contract (see `luau.ts` and
|
|
1734
|
+
* `loweringHelpers.ts`), so no plugin keeps a copy.
|
|
1725
1735
|
*/
|
|
1726
1736
|
|
|
1727
1737
|
interface LoweringPlugin {
|
|
@@ -1865,6 +1875,66 @@ declare function sourceMapTypes(text: string, path: string, options: SourceMapOp
|
|
|
1865
1875
|
problem?: string;
|
|
1866
1876
|
};
|
|
1867
1877
|
|
|
1878
|
+
/**
|
|
1879
|
+
* Writing Luau source as text: what a name may be and how a string is quoted.
|
|
1880
|
+
*
|
|
1881
|
+
* The compiler emits Luau, a lowering plugin hands back Luau expressions, and
|
|
1882
|
+
* a server filling placeholders into a bundle writes Luau strings. Each needs
|
|
1883
|
+
* the same few rules, and they live here so none of them keeps its own copy.
|
|
1884
|
+
* Nothing here parses or runs Luau.
|
|
1885
|
+
*/
|
|
1886
|
+
/** Luau's reserved words. tilua reserves most of them too — `local` is the
|
|
1887
|
+
* exception, so a tilua name can still be one of these. */
|
|
1888
|
+
declare const LUAU_KEYWORDS: ReadonlySet<string>;
|
|
1889
|
+
/** Is `name` shaped like a name — a letter or `_`, then letters, digits and
|
|
1890
|
+
* `_`? tilua's and Luau's names are both this shape; whether it is also a
|
|
1891
|
+
* keyword is another question (`isLuauName`). */
|
|
1892
|
+
declare function isIdentifier(name: string): boolean;
|
|
1893
|
+
/** Can `name` be written bare in Luau — as a variable, `t.name` or `{ name = v }`? */
|
|
1894
|
+
declare function isLuauName(name: string): boolean;
|
|
1895
|
+
/** `text` as the inside of a double-quoted Luau string, without the quotes:
|
|
1896
|
+
* for splicing into a `"..."` that is already written.
|
|
1897
|
+
*
|
|
1898
|
+
* Every control character is escaped, as `\n` where Luau has a name for it and
|
|
1899
|
+
* as three decimal digits otherwise — always three, so a digit that follows
|
|
1900
|
+
* (`"\1" .. "2"`) is never read as part of the escape. Not `JSON.stringify`:
|
|
1901
|
+
* its `\u0001` is not a Luau escape. Anything else, `é` or `한` included, is
|
|
1902
|
+
* written as it is; Luau source is UTF-8. */
|
|
1903
|
+
declare function escapeLuauString(text: string): string;
|
|
1904
|
+
/** `text` as a double-quoted Luau string literal: `"a\nb"`. */
|
|
1905
|
+
declare function luauString(text: string): string;
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* Questions a lowering plugin asks of a type, answered once here.
|
|
1909
|
+
*
|
|
1910
|
+
* A plugin decides how to lower a call from the receiver's or an argument's
|
|
1911
|
+
* type (see `LoweringPlugin`). The same few questions come up in every one —
|
|
1912
|
+
* is it a function, is it an instance of this class, what does this method
|
|
1913
|
+
* return — and a plugin imports these rather than walking the type model
|
|
1914
|
+
* itself:
|
|
1915
|
+
*
|
|
1916
|
+
* import { isInstanceOf } from "@tilua/parser"
|
|
1917
|
+
*
|
|
1918
|
+
* Each looks through a union with `nil` (`Part | nil`): whether the value may
|
|
1919
|
+
* be missing is a check the analyzer asked for elsewhere, not a reason to
|
|
1920
|
+
* lower differently.
|
|
1921
|
+
*/
|
|
1922
|
+
|
|
1923
|
+
/** The members of `type` that are not `nil`: `[A, B]` for `A | B | nil`,
|
|
1924
|
+
* `[T]` for any other `T`, and `[]` for `undefined` or `nil` alone. */
|
|
1925
|
+
declare function withoutNil(type: Type | undefined): Type[];
|
|
1926
|
+
/** A function, or an overloaded one (an intersection of functions). */
|
|
1927
|
+
declare function isFunctionType(type: Type | undefined): boolean;
|
|
1928
|
+
/** An instance of `className` or of a class extending it: a `Part` is an
|
|
1929
|
+
* instance of `BasePart` and of `Instance`. */
|
|
1930
|
+
declare function isInstanceOf(type: Type | undefined, className: string): boolean;
|
|
1931
|
+
/** Has every one of `names` as a member — a structural check, for a type
|
|
1932
|
+
* known by its shape rather than its class. */
|
|
1933
|
+
declare function hasMembers(type: Type | undefined, names: readonly string[]): boolean;
|
|
1934
|
+
/** Does every signature of `receiver`'s `method` return a tuple — several
|
|
1935
|
+
* values, as tilua has them in one array? False when the method is missing. */
|
|
1936
|
+
declare function returnsTuple(receiver: Type | undefined, method: string): boolean;
|
|
1937
|
+
|
|
1868
1938
|
declare const tilua: {
|
|
1869
1939
|
readonly tokenize: typeof tokenize;
|
|
1870
1940
|
readonly parseTokens: typeof parseTokens;
|
|
@@ -1878,4 +1948,4 @@ declare const tilua: {
|
|
|
1878
1948
|
readonly analyzeTypes: typeof analyzeTypes;
|
|
1879
1949
|
};
|
|
1880
1950
|
|
|
1881
|
-
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 DeclareMetatableStatement, 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 Unification, 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 };
|
|
1951
|
+
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 DeclareMetatableStatement, 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, LUAU_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 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 Unification, 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, escapeLuauString, falsyType, findConfig, fn, formatType, getBinding, hasMembers, intersection, isAssignable, isClassType, isFunctionType, isGlobal, isIdentifier, isInstanceOf, isLuauName, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, luauString, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, readDirectives, resolveModulePath, resolveTypeLibraries, returnsTuple, setAliasExpander, setDeferredBound, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tilua, tokenize, tuple, tupleMembers, typeParam, unify, union, unknownType, widen, withAliasName, withoutAliasName, withoutNil };
|
package/dist/index.d.ts
CHANGED
|
@@ -639,6 +639,12 @@ interface FunctionParameter extends BaseNode {
|
|
|
639
639
|
typeAnnotation?: TypeNode;
|
|
640
640
|
/** default value (`function f(a = 1) end`) */
|
|
641
641
|
default?: Expression;
|
|
642
|
+
/** Not written in the source: the `this` a class method is given, or the
|
|
643
|
+
* `self` of `function T:m()`. It carries the span of what implies it
|
|
644
|
+
* (the method, the `T:m`) so a diagnostic has somewhere to point, but no
|
|
645
|
+
* text there is its name — an editor colours, hovers and renames none
|
|
646
|
+
* of it. */
|
|
647
|
+
implicit?: boolean;
|
|
642
648
|
}
|
|
643
649
|
interface FunctionBody extends BaseNode {
|
|
644
650
|
type: "FunctionBody";
|
|
@@ -1064,7 +1070,7 @@ interface ScopeDiagnostic {
|
|
|
1064
1070
|
};
|
|
1065
1071
|
};
|
|
1066
1072
|
message: string;
|
|
1067
|
-
kind: "redeclare" | "const-assign" | "type-only" | "undeclared" | "use-before-define";
|
|
1073
|
+
kind: "redeclare" | "const-assign" | "type-only" | "undeclared" | "use-before-define" | "outside-loop";
|
|
1068
1074
|
}
|
|
1069
1075
|
interface ScopeAnalysis {
|
|
1070
1076
|
/** Every Identifier that appears in a variable *usage* position (i.e.
|
|
@@ -1601,7 +1607,7 @@ resolveModule?: (specifier: string) => ModuleExports | undefined): ModuleExports
|
|
|
1601
1607
|
* `ObjectValues<T>` and `ObjectEntries<T>`, an object's members as tuples in
|
|
1602
1608
|
* the order they were written.
|
|
1603
1609
|
*/
|
|
1604
|
-
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\n-- ============================================================\n-- The metatables of the language's own values\n-- ============================================================\n\n-- A string's methods. The first group is Lua's string library, which a\n-- string really answers to; where Lua answers several values, tilua answers\n-- one, as the global functions do (`find` is an array, `gsub` the new\n-- string). The second group is written the way JavaScript writes it.\n--\n-- Positions are Lua's: `sub` and `slice` count from 1, and `indexOf` is\n-- `nil` when the text is not there.\ndeclare metatable string: {\n __index: {\n upper: (self: string) => string,\n lower: (self: string) => string,\n len: (self: string) => number,\n sub: (self: string, i: number, j?: number) => string,\n rep: (self: string, n: number, separator?: string) => string,\n reverse: (self: string) => string,\n format: (self: string, ...args: unknown[]) => string,\n byte: ((self: string, i?: number) => number) & ((self: string, i: number, j: number) => number[]),\n find: (self: string, pattern: string, init?: number, plain?: boolean) => [number, number, ...string[]] | nil,\n match: (self: string, pattern: string, init?: number) => [...string[]] | nil,\n gmatch: (self: string, pattern: string) => () => [string, ...string[]] | nil,\n gsub: (self: string, pattern: string, replacement: unknown, n?: number) => string,\n\n trim: (self: string) => string,\n trimStart: (self: string) => string,\n trimEnd: (self: string) => string,\n startsWith: (self: string, text: string) => boolean,\n endsWith: (self: string, text: string) => boolean,\n includes: (self: string, text: string) => boolean,\n indexOf: (self: string, text: string, start?: number) => number | nil,\n slice: (self: string, start?: number, stop?: number) => string,\n replace: (self: string, text: string, replacement: string) => string,\n replaceAll: (self: string, text: string, replacement: string) => string,\n padStart: (self: string, length: number, padding?: string) => string,\n padEnd: (self: string, length: number, padding?: string) => string,\n },\n}\n\n-- An array's methods. Lua gives an array no metatable: the compiler lowers\n-- each call to a plain function, so they work on any array, one a Lua\n-- library made included.\n--\n-- Indices are Lua's: the first element is 1, and `indexOf` / `findIndex`\n-- answer `nil` rather than JavaScript's -1. `sort` takes Lua's comparator\n-- (true when `a` comes first). `push`, `pop`, `shift`, `unshift`,\n-- `sort` and `reverse` change the array; everything else returns a new one.\ndeclare metatable<T> T[]: {\n __index: {\n find: (self: T[], test: (value: T, index: number) => boolean) => T | nil,\n findIndex: (self: T[], test: (value: T, index: number) => boolean) => number | nil,\n filter: (self: T[], test: (value: T, index: number) => boolean) => T[],\n map: <U>(self: T[], transform: (value: T, index: number) => U) => U[],\n forEach: (self: T[], visit: (value: T, index: number) => nil) => nil,\n some: (self: T[], test: (value: T, index: number) => boolean) => boolean,\n every: (self: T[], test: (value: T, index: number) => boolean) => boolean,\n reduce: <U>(self: T[], step: (total: U, value: T, index: number) => U, initial: U) => U,\n includes: (self: T[], value: T) => boolean,\n indexOf: (self: T[], value: T, start?: number) => number | nil,\n join: (self: T[], separator?: string) => string,\n concat: (self: T[], ...others: T[][]) => T[],\n slice: (self: T[], start?: number, stop?: number) => T[],\n flat: (self: T[]) => T[],\n reverse: (self: T[]) => T[],\n sort: (self: T[], compare?: (a: T, b: T) => boolean) => T[],\n push: (self: T[], ...args: T[]) => number,\n pop: (self: T[]) => T | nil,\n shift: (self: T[]) => T | nil,\n unshift: (self: T[], ...args: T[]) => number,\n },\n}\n\n-- A table's methods. Unlike JavaScript's `Object.keys`, they answer a\n-- tuple, in the order the table's type wrote its members:\n--\n-- const point = { x: 1, y: \"up\" }\n-- point:keys() -- [\"x\", \"y\"]\n-- point:values() -- [number, string]\n-- point:entries() -- [[\"x\", number], [\"y\", string]]\n--\n-- A Lua table has no order of its own, so the compiler hands its runtime the\n-- keys as the type lists them. An optional member keeps its place, holding\n-- `nil` when it is missing; an indexer's keys follow the named ones. A\n-- member of the table's own with one of these names is what a call reaches,\n-- and a class instance, which has a metatable of its own, has none of them.\ndeclare metatable<T extends {}> T: {\n __index: {\n keys: (self: T) => ObjectKeys<T>,\n values: (self: T) => ObjectValues<T>,\n entries: (self: T) => ObjectEntries<T>,\n },\n}\n";
|
|
1610
|
+
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\n-- ============================================================\n-- The metatables of the language's own values\n-- ============================================================\n\n-- A string's methods. The first group is Lua's string library, which a\n-- string really answers to; where Lua answers several values, tilua answers\n-- one, as the global functions do (`find` is an array, `gsub` the new\n-- string). The second group is written the way JavaScript writes it.\n--\n-- Positions are Lua's: `sub` and `slice` count from 1, and `indexOf` is\n-- `nil` when the text is not there.\ndeclare metatable string: {\n __index: {\n upper: (self: string) => string,\n lower: (self: string) => string,\n len: (self: string) => number,\n sub: (self: string, i: number, j?: number) => string,\n rep: (self: string, n: number, separator?: string) => string,\n reverse: (self: string) => string,\n format: (self: string, ...args: unknown[]) => string,\n byte: ((self: string, i?: number) => number) & ((self: string, i: number, j: number) => number[]),\n find: (self: string, pattern: string, init?: number, plain?: boolean) => [number, number, ...string[]] | nil,\n match: (self: string, pattern: string, init?: number) => [...string[]] | nil,\n gmatch: (self: string, pattern: string) => () => [string, ...string[]] | nil,\n gsub: (self: string, pattern: string, replacement: unknown, n?: number) => string,\n\n trim: (self: string) => string,\n trimStart: (self: string) => string,\n trimEnd: (self: string) => string,\n startsWith: (self: string, text: string) => boolean,\n endsWith: (self: string, text: string) => boolean,\n includes: (self: string, text: string) => boolean,\n indexOf: (self: string, text: string, start?: number) => number | nil,\n slice: (self: string, start?: number, stop?: number) => string,\n replace: (self: string, text: string, replacement: string) => string,\n replaceAll: (self: string, text: string, replacement: string) => string,\n padStart: (self: string, length: number, padding?: string) => string,\n padEnd: (self: string, length: number, padding?: string) => string,\n },\n}\n\n-- An array's methods. Lua gives an array no metatable: the compiler lowers\n-- each call to a plain function, so they work on any array, one a Lua\n-- library made included.\n--\n-- Indices are Lua's: the first element is 1, and `indexOf` / `findIndex`\n-- answer `nil` rather than JavaScript's -1. `sort` takes Lua's comparator\n-- (true when `a` comes first). `push`, `pop`, `shift`, `unshift`,\n-- `sort` and `reverse` change the array; everything else returns a new one.\n-- A `filter` whose test is a guard \u2014 `v is S`, or `v => v ~= nil` \u2014\n-- answers an array of what it let through.\ndeclare metatable<T> T[]: {\n __index: {\n find: (self: T[], test: (value: T, index: number) => boolean) => T | nil,\n findIndex: (self: T[], test: (value: T, index: number) => boolean) => number | nil,\n filter: (<S extends T>(self: T[], test: (value: T, index: number) => value is S) => S[])\n & ((self: T[], test: (value: T, index: number) => boolean) => T[]),\n map: <U>(self: T[], transform: (value: T, index: number) => U) => U[],\n forEach: (self: T[], visit: (value: T, index: number) => nil) => nil,\n some: (self: T[], test: (value: T, index: number) => boolean) => boolean,\n every: (self: T[], test: (value: T, index: number) => boolean) => boolean,\n reduce: <U>(self: T[], step: (total: U, value: T, index: number) => U, initial: U) => U,\n includes: (self: T[], value: T) => boolean,\n indexOf: (self: T[], value: T, start?: number) => number | nil,\n join: (self: T[], separator?: string) => string,\n concat: (self: T[], ...others: T[][]) => T[],\n slice: (self: T[], start?: number, stop?: number) => T[],\n flat: (self: T[]) => T[],\n reverse: (self: T[]) => T[],\n sort: (self: T[], compare?: (a: T, b: T) => boolean) => T[],\n push: (self: T[], ...args: T[]) => number,\n pop: (self: T[]) => T | nil,\n shift: (self: T[]) => T | nil,\n unshift: (self: T[], ...args: T[]) => number,\n },\n}\n\n-- A table's methods. Unlike JavaScript's `Object.keys`, they answer a\n-- tuple, in the order the table's type wrote its members:\n--\n-- const point = { x: 1, y: \"up\" }\n-- point:keys() -- [\"x\", \"y\"]\n-- point:values() -- [number, string]\n-- point:entries() -- [[\"x\", number], [\"y\", string]]\n--\n-- A Lua table has no order of its own, so the compiler hands its runtime the\n-- keys as the type lists them. An optional member keeps its place, holding\n-- `nil` when it is missing; an indexer's keys follow the named ones. A\n-- member of the table's own with one of these names is what a call reaches,\n-- and a class instance, which has a metatable of its own, has none of them.\n--\n-- The rest are JavaScript's `Object` functions, written as methods of the\n-- table they take first:\n--\n-- point:hasOwn(\"x\") -- Object.hasOwn(point, \"x\")\n-- point:assign({ z: 3 }) -- Object.assign(point, { z: 3 })\n-- point:freeze() -- Object.freeze(point)\n--\n-- `hasOwn` asks the table itself, not what its metatable's `__index`\n-- lends it. `assign` copies each source's members onto the table, later ones\n-- over earlier ones, skipping a `nil` source, and answers the table. `freeze`\n-- is Luau's `table.freeze`; under Lua 5.1, which cannot freeze a table, the\n-- table is answered as it is and `isFrozen` is false.\ndeclare metatable<T extends {}> T: {\n __index: {\n keys: (self: T) => ObjectKeys<T>,\n values: (self: T) => ObjectValues<T>,\n entries: (self: T) => ObjectEntries<T>,\n\n hasOwn: (self: T, key: unknown) => boolean,\n hasOwnProperty: (self: T, key: unknown) => boolean,\n assign: (<U>(self: T, source: U) => T & U)\n & (<U, V>(self: T, a: U, b: V) => T & U & V)\n & (<U, V, W>(self: T, a: U, b: V, c: W) => T & U & V & W)\n -- Generic like the rest: a plain signature would be tried first.\n & (<S extends {}>(self: T, ...sources: S[]) => T),\n freeze: (self: T) => Readonly<T>,\n isFrozen: (self: T) => boolean,\n },\n}\n";
|
|
1605
1611
|
|
|
1606
1612
|
interface ProjectHost {
|
|
1607
1613
|
/** A file's text, or `undefined` when there is no such file. */
|
|
@@ -1722,6 +1728,10 @@ declare function resolveTypeLibraries(config: TiluaConfig, host?: ProjectHost):
|
|
|
1722
1728
|
* },
|
|
1723
1729
|
* }
|
|
1724
1730
|
* export default plugin
|
|
1731
|
+
*
|
|
1732
|
+
* What a plugin runs to decide and to write — `luauString`, `isInstanceOf`,
|
|
1733
|
+
* `returnsTuple`, ... — is exported beside this contract (see `luau.ts` and
|
|
1734
|
+
* `loweringHelpers.ts`), so no plugin keeps a copy.
|
|
1725
1735
|
*/
|
|
1726
1736
|
|
|
1727
1737
|
interface LoweringPlugin {
|
|
@@ -1865,6 +1875,66 @@ declare function sourceMapTypes(text: string, path: string, options: SourceMapOp
|
|
|
1865
1875
|
problem?: string;
|
|
1866
1876
|
};
|
|
1867
1877
|
|
|
1878
|
+
/**
|
|
1879
|
+
* Writing Luau source as text: what a name may be and how a string is quoted.
|
|
1880
|
+
*
|
|
1881
|
+
* The compiler emits Luau, a lowering plugin hands back Luau expressions, and
|
|
1882
|
+
* a server filling placeholders into a bundle writes Luau strings. Each needs
|
|
1883
|
+
* the same few rules, and they live here so none of them keeps its own copy.
|
|
1884
|
+
* Nothing here parses or runs Luau.
|
|
1885
|
+
*/
|
|
1886
|
+
/** Luau's reserved words. tilua reserves most of them too — `local` is the
|
|
1887
|
+
* exception, so a tilua name can still be one of these. */
|
|
1888
|
+
declare const LUAU_KEYWORDS: ReadonlySet<string>;
|
|
1889
|
+
/** Is `name` shaped like a name — a letter or `_`, then letters, digits and
|
|
1890
|
+
* `_`? tilua's and Luau's names are both this shape; whether it is also a
|
|
1891
|
+
* keyword is another question (`isLuauName`). */
|
|
1892
|
+
declare function isIdentifier(name: string): boolean;
|
|
1893
|
+
/** Can `name` be written bare in Luau — as a variable, `t.name` or `{ name = v }`? */
|
|
1894
|
+
declare function isLuauName(name: string): boolean;
|
|
1895
|
+
/** `text` as the inside of a double-quoted Luau string, without the quotes:
|
|
1896
|
+
* for splicing into a `"..."` that is already written.
|
|
1897
|
+
*
|
|
1898
|
+
* Every control character is escaped, as `\n` where Luau has a name for it and
|
|
1899
|
+
* as three decimal digits otherwise — always three, so a digit that follows
|
|
1900
|
+
* (`"\1" .. "2"`) is never read as part of the escape. Not `JSON.stringify`:
|
|
1901
|
+
* its `\u0001` is not a Luau escape. Anything else, `é` or `한` included, is
|
|
1902
|
+
* written as it is; Luau source is UTF-8. */
|
|
1903
|
+
declare function escapeLuauString(text: string): string;
|
|
1904
|
+
/** `text` as a double-quoted Luau string literal: `"a\nb"`. */
|
|
1905
|
+
declare function luauString(text: string): string;
|
|
1906
|
+
|
|
1907
|
+
/**
|
|
1908
|
+
* Questions a lowering plugin asks of a type, answered once here.
|
|
1909
|
+
*
|
|
1910
|
+
* A plugin decides how to lower a call from the receiver's or an argument's
|
|
1911
|
+
* type (see `LoweringPlugin`). The same few questions come up in every one —
|
|
1912
|
+
* is it a function, is it an instance of this class, what does this method
|
|
1913
|
+
* return — and a plugin imports these rather than walking the type model
|
|
1914
|
+
* itself:
|
|
1915
|
+
*
|
|
1916
|
+
* import { isInstanceOf } from "@tilua/parser"
|
|
1917
|
+
*
|
|
1918
|
+
* Each looks through a union with `nil` (`Part | nil`): whether the value may
|
|
1919
|
+
* be missing is a check the analyzer asked for elsewhere, not a reason to
|
|
1920
|
+
* lower differently.
|
|
1921
|
+
*/
|
|
1922
|
+
|
|
1923
|
+
/** The members of `type` that are not `nil`: `[A, B]` for `A | B | nil`,
|
|
1924
|
+
* `[T]` for any other `T`, and `[]` for `undefined` or `nil` alone. */
|
|
1925
|
+
declare function withoutNil(type: Type | undefined): Type[];
|
|
1926
|
+
/** A function, or an overloaded one (an intersection of functions). */
|
|
1927
|
+
declare function isFunctionType(type: Type | undefined): boolean;
|
|
1928
|
+
/** An instance of `className` or of a class extending it: a `Part` is an
|
|
1929
|
+
* instance of `BasePart` and of `Instance`. */
|
|
1930
|
+
declare function isInstanceOf(type: Type | undefined, className: string): boolean;
|
|
1931
|
+
/** Has every one of `names` as a member — a structural check, for a type
|
|
1932
|
+
* known by its shape rather than its class. */
|
|
1933
|
+
declare function hasMembers(type: Type | undefined, names: readonly string[]): boolean;
|
|
1934
|
+
/** Does every signature of `receiver`'s `method` return a tuple — several
|
|
1935
|
+
* values, as tilua has them in one array? False when the method is missing. */
|
|
1936
|
+
declare function returnsTuple(receiver: Type | undefined, method: string): boolean;
|
|
1937
|
+
|
|
1868
1938
|
declare const tilua: {
|
|
1869
1939
|
readonly tokenize: typeof tokenize;
|
|
1870
1940
|
readonly parseTokens: typeof parseTokens;
|
|
@@ -1878,4 +1948,4 @@ declare const tilua: {
|
|
|
1878
1948
|
readonly analyzeTypes: typeof analyzeTypes;
|
|
1879
1949
|
};
|
|
1880
1950
|
|
|
1881
|
-
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 DeclareMetatableStatement, 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 Unification, 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 };
|
|
1951
|
+
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 DeclareMetatableStatement, 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, LUAU_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 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 Unification, 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, escapeLuauString, falsyType, findConfig, fn, formatType, getBinding, hasMembers, intersection, isAssignable, isClassType, isFunctionType, isGlobal, isIdentifier, isInstanceOf, isLuauName, isPossiblyFalsy, isPossiblyTruthy, isUnassignedGlobal, literal, loadConfig, luauString, matchInfer, moduleCandidates, moduleExports, narrowExclude, narrowFalsy, narrowTo, narrowTruthy, neverType, nilType, nodeHost, numberType, objectType, optional, overlaps, parse, parseExpressionFromSource, parseTokens, parseWithRecovery, primitive, readDirectives, resolveModulePath, resolveTypeLibraries, returnsTuple, setAliasExpander, setDeferredBound, sourceMapTypes, stringType, stripJsonComments, substitute, templateMatches, threadType, tilua, tokenize, tuple, tupleMembers, typeParam, unify, union, unknownType, widen, withAliasName, withoutAliasName, withoutNil };
|