@tilua/compiler 6.1.0 → 7.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,8 +1,111 @@
1
1
  import * as T from '@tilua/parser';
2
- import { LoweringPlugin, BuildTarget, TypeAnalysis, ScopeAnalysis, OutputMode, TiluaConfig, ConfigProblem } from '@tilua/parser';
3
- export { LoweringPlugin, MethodCall, MethodLowering } from '@tilua/parser';
2
+ import { OutputMode, TiluaConfig, ConfigProblem, LoweringPlugin, TypeAnalysis, ScopeAnalysis } from '@tilua/parser';
3
+ export { LoweringPlugin, LuaSyntax, MethodCall, MethodLowering } from '@tilua/parser';
4
4
  import * as L from 'luau-parser';
5
5
 
6
+ /** What `tilua.config.json` holds. */
7
+ interface TiluaConfigJson {
8
+ /** Type libraries to check against: `["roblox"]` loads `@tilua-types/roblox`. */
9
+ types?: string[];
10
+ /** Import path aliases, as in tsconfig: `{ "@shared/*": ["src/shared/*"] }`. */
11
+ paths?: Record<string, string[]>;
12
+ /** Where `paths` targets resolve from. Default: the config's folder. */
13
+ baseUrl?: string;
14
+ /** A Rojo sourcemap, or `null`. */
15
+ sourceMap?: string | null;
16
+ /** How many files the output is. `"single"` (the default) is one file;
17
+ * `"chunks"` also writes a file for what only an `import()` reaches,
18
+ * loaded when it is first asked for; `"modules"` writes one per module. */
19
+ output?: OutputMode;
20
+ /** Leave out Lua's standard library — `print`, `string`, `pcall` — which
21
+ * is otherwise there for every file, as JavaScript's is in TypeScript. */
22
+ noLib?: boolean;
23
+ /** Leave out of the bundle what the entry never reaches (`treeShake`). */
24
+ treeShaking?: boolean;
25
+ }
26
+ /** A config file's path, or the config itself. Relative paths — to a config
27
+ * file, and inside an inline config — resolve from `cwd`. */
28
+ type ConfigInput = string | TiluaConfigJson;
29
+ interface ResolvedConfig {
30
+ readonly config?: TiluaConfig;
31
+ readonly problems: readonly ConfigProblem[];
32
+ }
33
+ /** The config for a build of `entry`: the one given, or else the nearest
34
+ * `tilua.config.json` above the entry. */
35
+ declare function resolveConfig(input: ConfigInput | undefined, entry: string, cwd?: string): ResolvedConfig;
36
+
37
+ interface BundleOptions {
38
+ /** The file the bundle runs. */
39
+ readonly entry: string;
40
+ /** A `tilua.config.json` path or contents. Default: the nearest config above the entry. */
41
+ readonly config?: ConfigInput;
42
+ /** The project folder. Modules are named by their path from it, and an
43
+ * inline config's relative paths resolve from it. Default: the config
44
+ * file's folder, or else the entry's. */
45
+ readonly root?: string;
46
+ /** Check types against the config's `types` too. Default: true. */
47
+ readonly typeCheck?: boolean;
48
+ /** How many files to make. Overrides the config's `output`; `"single"`
49
+ * without either. */
50
+ readonly output?: OutputMode;
51
+ /** Leave out what the entry never reaches. Overrides the config's
52
+ * `treeShaking`; off without either. */
53
+ readonly treeShaking?: boolean;
54
+ /** What the entry's file is called: `main.luau`. The other files of
55
+ * `"chunks"` are named after it (`main_shop.luau`), and every file takes
56
+ * its extension. Default: the entry's own name, with `.luau`. */
57
+ readonly outFile?: string;
58
+ }
59
+ /** One file of the output. */
60
+ interface BundleFile {
61
+ /** Where it goes, from the folder the output is written to: `main.luau`,
62
+ * `src/shop/buy.luau`. Files find each other by these, so they have to be
63
+ * written as they are named. */
64
+ readonly path: string;
65
+ readonly code: string;
66
+ /** The modules in it, by name. */
67
+ readonly modules: string[];
68
+ }
69
+ interface BundleDiagnostic {
70
+ /** Absolute path of the file it is about. */
71
+ readonly file: string;
72
+ readonly message: string;
73
+ readonly line: number;
74
+ readonly column: number;
75
+ /** `type` and `config` problems are reported without stopping the build;
76
+ * `syntax`, `scope` (such as assigning to an import) and `module`
77
+ * problems leave no bundle. */
78
+ readonly category: "syntax" | "scope" | "module" | "type" | "config";
79
+ /** A test that always comes out the same, and the like: said, and no
80
+ * reason for the build to fail. */
81
+ readonly severity?: "warning";
82
+ }
83
+ interface BundleResult {
84
+ /** The bundle — the entry's file, when there are several — or `undefined`
85
+ * when a module could not be compiled. Type errors are reported but do
86
+ * not stop it. */
87
+ readonly code?: string;
88
+ /** Every file of the output, the entry's first. Empty when there is no
89
+ * bundle. */
90
+ readonly files: BundleFile[];
91
+ /** The bundled modules' names, entry first. */
92
+ readonly modules: string[];
93
+ readonly diagnostics: BundleDiagnostic[];
94
+ }
95
+ declare function bundle(options: BundleOptions): Promise<BundleResult>;
96
+
97
+ interface Diagnostic {
98
+ readonly message: string;
99
+ readonly line: number;
100
+ readonly column: number;
101
+ }
102
+ interface CompileResult {
103
+ /** The Luau source, or `undefined` when the file has errors. */
104
+ readonly code?: string;
105
+ readonly diagnostics: Diagnostic[];
106
+ }
107
+ declare function compile(source: string, config?: ConfigInput): Promise<CompileResult>;
108
+
6
109
  /**
7
110
  * Fresh local names for what lowering introduces — a destructuring temporary,
8
111
  * a required module, a helper function.
@@ -21,6 +124,8 @@ declare class Names {
21
124
  /** A copy that goes on to take names independently — one per module, each
22
125
  * starting from what the whole bundle already takes. */
23
126
  fork(): Names;
127
+ /** `name`, chosen elsewhere, is not to be chosen again here. */
128
+ take(name: string): void;
24
129
  /** `base`, or `base2`, `base3`, ... — whichever is free first. */
25
130
  fresh(base: string): string;
26
131
  }
@@ -129,18 +234,24 @@ interface LowerOptions {
129
234
  /** The file as a library's runtime names it — `src/shop/buy.tilua` —
130
235
  * in the call sites it is handed. */
131
236
  readonly file?: string;
132
- /** Which Lua the output has to run on. Default `"luau"`. `"lua51"` also
133
- * lowers what Luau adds to Lua and 5.1 has no syntax for — `a += b`,
134
- * `continue`, `if c then a else b` as an expression, `//`. */
135
- readonly target?: Target;
136
237
  /** The project leaves Lua's standard library out (`"noLib": true`), so
137
238
  * nothing of it is lowered either. */
138
239
  readonly noLib?: boolean;
240
+ /** A bundle's helpers, shared by its modules: each module names the ones
241
+ * it uses, and the bundle defines each once. Without it a file defines
242
+ * its own. */
243
+ readonly shared?: SharedRuntime;
244
+ /** Tree shaking (`treeShake`): what of the module is left out, and which
245
+ * of the modules it imports do something as they run. */
246
+ readonly shaken?: {
247
+ readonly removed: ReadonlySet<object>;
248
+ readonly dead: ReadonlySet<object>;
249
+ /** Does the module `specifier` names run anything as it loads? */
250
+ runs(specifier: string): boolean;
251
+ /** Is the module `specifier` names needed at all? */
252
+ needed(specifier: string): boolean;
253
+ };
139
254
  }
140
- /** `"luau"` is Roblox's Lua. `"lua51"` is stock Lua 5.1, which has none of
141
- * Luau's additions — and no `goto` either, so `continue` has to be built out
142
- * of the loops 5.1 does have. */
143
- type Target = BuildTarget;
144
255
  interface LowerDiagnostic {
145
256
  readonly message: string;
146
257
  readonly line: number;
@@ -160,6 +271,50 @@ interface LowerResult {
160
271
  /** The file reads `scriptArgs`: whatever runs it has to set it up, from
161
272
  * the chunk's own `...` — this file, compiled alone, does it itself. */
162
273
  readonly usesScriptArgs: boolean;
274
+ /** With `shared`: the shared helpers the statements name. */
275
+ readonly shared: readonly string[];
276
+ }
277
+ /**
278
+ * The helpers of a bundle — `tilua_asArray`, the array methods, a library's
279
+ * runtime — defined once for every module rather than once in each. A
280
+ * project of forty files that all map over a list would otherwise carry the
281
+ * array runtime forty times.
282
+ *
283
+ * A helper is shared by what it is: the same kind, or a runtime whose Luau
284
+ * reads the same, gets the same name in every module. One whose Luau differs
285
+ * from module to module — a runtime reading its own module's line map — is a
286
+ * helper of its own in each.
287
+ */
288
+ declare class SharedRuntime {
289
+ private readonly names;
290
+ private readonly byKey;
291
+ /** Each group of names and the statements that declare them as locals,
292
+ * in the order they were first defined: each after what it uses. */
293
+ private readonly definitions;
294
+ private readonly defined;
295
+ constructor(names: Names);
296
+ /** The name the helper `key` goes by, in every module. */
297
+ name(key: string, base: string): string;
298
+ /** `statements` declare `names`. Only the first module to say so is heard:
299
+ * the others' are the same. */
300
+ define(names: string[], statements: L.Statement[]): void;
301
+ /** Tree shaking: leave out of each runtime table the members nothing
302
+ * reads. `code` is everything else the output holds — the modules —
303
+ * and a member is read when it, or a member read already, names it:
304
+ * `tilua_array.filter(xs, f)` keeps `filter`, and whatever `filter`
305
+ * itself calls. A table used as anything but `table.member` — handed
306
+ * on, walked, indexed by what only the running program knows — keeps
307
+ * every member. */
308
+ shake(code: readonly L.Statement[]): void;
309
+ /** Luau setting up the helpers `used` for a chunk whose code names them:
310
+ * `declare` goes before that code, which reads each as an upvalue, and
311
+ * `define` after it — before any of it runs, and after what a helper
312
+ * reads as it is set up (the line map). Each definition runs in a
313
+ * function of its own, so what it keeps to itself stays there. */
314
+ chunk(used: ReadonlySet<string>): {
315
+ declare: L.Statement[];
316
+ define: L.Statement[];
317
+ };
163
318
  }
164
319
  /** How a module's exports behave at runtime, beyond what its code assigns. */
165
320
  interface ModuleInfo {
@@ -181,109 +336,4 @@ interface ModuleInfo {
181
336
  }
182
337
  declare function lower(program: T.Program, scopes: ScopeAnalysis, options?: LowerOptions): LowerResult;
183
338
 
184
- /** What `tilua.config.json` holds. */
185
- interface TiluaConfigJson {
186
- /** Type libraries to check against: `["roblox"]` loads `@tilua-types/roblox`. */
187
- types?: string[];
188
- /** Import path aliases, as in tsconfig: `{ "@shared/*": ["src/shared/*"] }`. */
189
- paths?: Record<string, string[]>;
190
- /** Where `paths` targets resolve from. Default: the config's folder. */
191
- baseUrl?: string;
192
- /** A Rojo sourcemap, or `null`. */
193
- sourceMap?: string | null;
194
- /** Which Lua the output must run on. `"luau"` (the default) keeps Luau's
195
- * own syntax; `"lua51"` also lowers what stock Lua 5.1 cannot parse —
196
- * `a += b`, `continue`, `if c then a else b` as an expression, `//`,
197
- * digit separators and binary literals. */
198
- target?: Target;
199
- /** How many files the output is. `"single"` (the default) is one file;
200
- * `"chunks"` also writes a file for what only an `import()` reaches,
201
- * loaded when it is first asked for; `"modules"` writes one per module. */
202
- output?: OutputMode;
203
- /** Leave out Lua's standard library — `print`, `string`, `pcall` — which
204
- * is otherwise there for every file, as JavaScript's is in TypeScript. */
205
- noLib?: boolean;
206
- }
207
- /** A config file's path, or the config itself. Relative paths — to a config
208
- * file, and inside an inline config — resolve from `cwd`. */
209
- type ConfigInput = string | TiluaConfigJson;
210
- interface ResolvedConfig {
211
- readonly config?: TiluaConfig;
212
- readonly problems: readonly ConfigProblem[];
213
- }
214
- /** The config for a build of `entry`: the one given, or else the nearest
215
- * `tilua.config.json` above the entry. */
216
- declare function resolveConfig(input: ConfigInput | undefined, entry: string, cwd?: string): ResolvedConfig;
217
-
218
- interface BundleOptions {
219
- /** The file the bundle runs. */
220
- readonly entry: string;
221
- /** A `tilua.config.json` path or contents. Default: the nearest config above the entry. */
222
- readonly config?: ConfigInput;
223
- /** The project folder. Modules are named by their path from it, and an
224
- * inline config's relative paths resolve from it. Default: the config
225
- * file's folder, or else the entry's. */
226
- readonly root?: string;
227
- /** Check types against the config's `types` too. Default: true. */
228
- readonly typeCheck?: boolean;
229
- /** Which Lua the output must run on. Overrides the config's `target`. */
230
- readonly target?: Target;
231
- /** How many files to make. Overrides the config's `output`; `"single"`
232
- * without either. */
233
- readonly output?: OutputMode;
234
- /** What the entry's file is called: `main.luau`. The other files of
235
- * `"chunks"` are named after it (`main_shop.luau`), and every file takes
236
- * its extension. Default: the entry's own name, with `.luau`. */
237
- readonly outFile?: string;
238
- }
239
- /** One file of the output. */
240
- interface BundleFile {
241
- /** Where it goes, from the folder the output is written to: `main.luau`,
242
- * `src/shop/buy.luau`. Files find each other by these, so they have to be
243
- * written as they are named. */
244
- readonly path: string;
245
- readonly code: string;
246
- /** The modules in it, by name. */
247
- readonly modules: string[];
248
- }
249
- interface BundleDiagnostic {
250
- /** Absolute path of the file it is about. */
251
- readonly file: string;
252
- readonly message: string;
253
- readonly line: number;
254
- readonly column: number;
255
- /** `type` and `config` problems are reported without stopping the build;
256
- * `syntax`, `scope` (such as assigning to an import) and `module`
257
- * problems leave no bundle. */
258
- readonly category: "syntax" | "scope" | "module" | "type" | "config";
259
- /** A test that always comes out the same, and the like: said, and no
260
- * reason for the build to fail. */
261
- readonly severity?: "warning";
262
- }
263
- interface BundleResult {
264
- /** The bundle — the entry's file, when there are several — or `undefined`
265
- * when a module could not be compiled. Type errors are reported but do
266
- * not stop it. */
267
- readonly code?: string;
268
- /** Every file of the output, the entry's first. Empty when there is no
269
- * bundle. */
270
- readonly files: BundleFile[];
271
- /** The bundled modules' names, entry first. */
272
- readonly modules: string[];
273
- readonly diagnostics: BundleDiagnostic[];
274
- }
275
- declare function bundle(options: BundleOptions): Promise<BundleResult>;
276
-
277
- interface Diagnostic {
278
- readonly message: string;
279
- readonly line: number;
280
- readonly column: number;
281
- }
282
- interface CompileResult {
283
- /** The Luau source, or `undefined` when the file has errors. */
284
- readonly code?: string;
285
- readonly diagnostics: Diagnostic[];
286
- }
287
- declare function compile(source: string, config?: ConfigInput): Promise<CompileResult>;
288
-
289
339
  export { type BundleDiagnostic, type BundleFile, type BundleOptions, type BundleResult, type CompileResult, type ConfigInput, type Diagnostic, type LoadedLowering, type LowerDiagnostic, type LowerOptions, type LowerResult, type LoweringProblem, type ModuleContext, type ResolvedConfig, type TiluaConfigJson, bundle, compile, loadLowerings, lower, resolveConfig };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,111 @@
1
1
  import * as T from '@tilua/parser';
2
- import { LoweringPlugin, BuildTarget, TypeAnalysis, ScopeAnalysis, OutputMode, TiluaConfig, ConfigProblem } from '@tilua/parser';
3
- export { LoweringPlugin, MethodCall, MethodLowering } from '@tilua/parser';
2
+ import { OutputMode, TiluaConfig, ConfigProblem, LoweringPlugin, TypeAnalysis, ScopeAnalysis } from '@tilua/parser';
3
+ export { LoweringPlugin, LuaSyntax, MethodCall, MethodLowering } from '@tilua/parser';
4
4
  import * as L from 'luau-parser';
5
5
 
6
+ /** What `tilua.config.json` holds. */
7
+ interface TiluaConfigJson {
8
+ /** Type libraries to check against: `["roblox"]` loads `@tilua-types/roblox`. */
9
+ types?: string[];
10
+ /** Import path aliases, as in tsconfig: `{ "@shared/*": ["src/shared/*"] }`. */
11
+ paths?: Record<string, string[]>;
12
+ /** Where `paths` targets resolve from. Default: the config's folder. */
13
+ baseUrl?: string;
14
+ /** A Rojo sourcemap, or `null`. */
15
+ sourceMap?: string | null;
16
+ /** How many files the output is. `"single"` (the default) is one file;
17
+ * `"chunks"` also writes a file for what only an `import()` reaches,
18
+ * loaded when it is first asked for; `"modules"` writes one per module. */
19
+ output?: OutputMode;
20
+ /** Leave out Lua's standard library — `print`, `string`, `pcall` — which
21
+ * is otherwise there for every file, as JavaScript's is in TypeScript. */
22
+ noLib?: boolean;
23
+ /** Leave out of the bundle what the entry never reaches (`treeShake`). */
24
+ treeShaking?: boolean;
25
+ }
26
+ /** A config file's path, or the config itself. Relative paths — to a config
27
+ * file, and inside an inline config — resolve from `cwd`. */
28
+ type ConfigInput = string | TiluaConfigJson;
29
+ interface ResolvedConfig {
30
+ readonly config?: TiluaConfig;
31
+ readonly problems: readonly ConfigProblem[];
32
+ }
33
+ /** The config for a build of `entry`: the one given, or else the nearest
34
+ * `tilua.config.json` above the entry. */
35
+ declare function resolveConfig(input: ConfigInput | undefined, entry: string, cwd?: string): ResolvedConfig;
36
+
37
+ interface BundleOptions {
38
+ /** The file the bundle runs. */
39
+ readonly entry: string;
40
+ /** A `tilua.config.json` path or contents. Default: the nearest config above the entry. */
41
+ readonly config?: ConfigInput;
42
+ /** The project folder. Modules are named by their path from it, and an
43
+ * inline config's relative paths resolve from it. Default: the config
44
+ * file's folder, or else the entry's. */
45
+ readonly root?: string;
46
+ /** Check types against the config's `types` too. Default: true. */
47
+ readonly typeCheck?: boolean;
48
+ /** How many files to make. Overrides the config's `output`; `"single"`
49
+ * without either. */
50
+ readonly output?: OutputMode;
51
+ /** Leave out what the entry never reaches. Overrides the config's
52
+ * `treeShaking`; off without either. */
53
+ readonly treeShaking?: boolean;
54
+ /** What the entry's file is called: `main.luau`. The other files of
55
+ * `"chunks"` are named after it (`main_shop.luau`), and every file takes
56
+ * its extension. Default: the entry's own name, with `.luau`. */
57
+ readonly outFile?: string;
58
+ }
59
+ /** One file of the output. */
60
+ interface BundleFile {
61
+ /** Where it goes, from the folder the output is written to: `main.luau`,
62
+ * `src/shop/buy.luau`. Files find each other by these, so they have to be
63
+ * written as they are named. */
64
+ readonly path: string;
65
+ readonly code: string;
66
+ /** The modules in it, by name. */
67
+ readonly modules: string[];
68
+ }
69
+ interface BundleDiagnostic {
70
+ /** Absolute path of the file it is about. */
71
+ readonly file: string;
72
+ readonly message: string;
73
+ readonly line: number;
74
+ readonly column: number;
75
+ /** `type` and `config` problems are reported without stopping the build;
76
+ * `syntax`, `scope` (such as assigning to an import) and `module`
77
+ * problems leave no bundle. */
78
+ readonly category: "syntax" | "scope" | "module" | "type" | "config";
79
+ /** A test that always comes out the same, and the like: said, and no
80
+ * reason for the build to fail. */
81
+ readonly severity?: "warning";
82
+ }
83
+ interface BundleResult {
84
+ /** The bundle — the entry's file, when there are several — or `undefined`
85
+ * when a module could not be compiled. Type errors are reported but do
86
+ * not stop it. */
87
+ readonly code?: string;
88
+ /** Every file of the output, the entry's first. Empty when there is no
89
+ * bundle. */
90
+ readonly files: BundleFile[];
91
+ /** The bundled modules' names, entry first. */
92
+ readonly modules: string[];
93
+ readonly diagnostics: BundleDiagnostic[];
94
+ }
95
+ declare function bundle(options: BundleOptions): Promise<BundleResult>;
96
+
97
+ interface Diagnostic {
98
+ readonly message: string;
99
+ readonly line: number;
100
+ readonly column: number;
101
+ }
102
+ interface CompileResult {
103
+ /** The Luau source, or `undefined` when the file has errors. */
104
+ readonly code?: string;
105
+ readonly diagnostics: Diagnostic[];
106
+ }
107
+ declare function compile(source: string, config?: ConfigInput): Promise<CompileResult>;
108
+
6
109
  /**
7
110
  * Fresh local names for what lowering introduces — a destructuring temporary,
8
111
  * a required module, a helper function.
@@ -21,6 +124,8 @@ declare class Names {
21
124
  /** A copy that goes on to take names independently — one per module, each
22
125
  * starting from what the whole bundle already takes. */
23
126
  fork(): Names;
127
+ /** `name`, chosen elsewhere, is not to be chosen again here. */
128
+ take(name: string): void;
24
129
  /** `base`, or `base2`, `base3`, ... — whichever is free first. */
25
130
  fresh(base: string): string;
26
131
  }
@@ -129,18 +234,24 @@ interface LowerOptions {
129
234
  /** The file as a library's runtime names it — `src/shop/buy.tilua` —
130
235
  * in the call sites it is handed. */
131
236
  readonly file?: string;
132
- /** Which Lua the output has to run on. Default `"luau"`. `"lua51"` also
133
- * lowers what Luau adds to Lua and 5.1 has no syntax for — `a += b`,
134
- * `continue`, `if c then a else b` as an expression, `//`. */
135
- readonly target?: Target;
136
237
  /** The project leaves Lua's standard library out (`"noLib": true`), so
137
238
  * nothing of it is lowered either. */
138
239
  readonly noLib?: boolean;
240
+ /** A bundle's helpers, shared by its modules: each module names the ones
241
+ * it uses, and the bundle defines each once. Without it a file defines
242
+ * its own. */
243
+ readonly shared?: SharedRuntime;
244
+ /** Tree shaking (`treeShake`): what of the module is left out, and which
245
+ * of the modules it imports do something as they run. */
246
+ readonly shaken?: {
247
+ readonly removed: ReadonlySet<object>;
248
+ readonly dead: ReadonlySet<object>;
249
+ /** Does the module `specifier` names run anything as it loads? */
250
+ runs(specifier: string): boolean;
251
+ /** Is the module `specifier` names needed at all? */
252
+ needed(specifier: string): boolean;
253
+ };
139
254
  }
140
- /** `"luau"` is Roblox's Lua. `"lua51"` is stock Lua 5.1, which has none of
141
- * Luau's additions — and no `goto` either, so `continue` has to be built out
142
- * of the loops 5.1 does have. */
143
- type Target = BuildTarget;
144
255
  interface LowerDiagnostic {
145
256
  readonly message: string;
146
257
  readonly line: number;
@@ -160,6 +271,50 @@ interface LowerResult {
160
271
  /** The file reads `scriptArgs`: whatever runs it has to set it up, from
161
272
  * the chunk's own `...` — this file, compiled alone, does it itself. */
162
273
  readonly usesScriptArgs: boolean;
274
+ /** With `shared`: the shared helpers the statements name. */
275
+ readonly shared: readonly string[];
276
+ }
277
+ /**
278
+ * The helpers of a bundle — `tilua_asArray`, the array methods, a library's
279
+ * runtime — defined once for every module rather than once in each. A
280
+ * project of forty files that all map over a list would otherwise carry the
281
+ * array runtime forty times.
282
+ *
283
+ * A helper is shared by what it is: the same kind, or a runtime whose Luau
284
+ * reads the same, gets the same name in every module. One whose Luau differs
285
+ * from module to module — a runtime reading its own module's line map — is a
286
+ * helper of its own in each.
287
+ */
288
+ declare class SharedRuntime {
289
+ private readonly names;
290
+ private readonly byKey;
291
+ /** Each group of names and the statements that declare them as locals,
292
+ * in the order they were first defined: each after what it uses. */
293
+ private readonly definitions;
294
+ private readonly defined;
295
+ constructor(names: Names);
296
+ /** The name the helper `key` goes by, in every module. */
297
+ name(key: string, base: string): string;
298
+ /** `statements` declare `names`. Only the first module to say so is heard:
299
+ * the others' are the same. */
300
+ define(names: string[], statements: L.Statement[]): void;
301
+ /** Tree shaking: leave out of each runtime table the members nothing
302
+ * reads. `code` is everything else the output holds — the modules —
303
+ * and a member is read when it, or a member read already, names it:
304
+ * `tilua_array.filter(xs, f)` keeps `filter`, and whatever `filter`
305
+ * itself calls. A table used as anything but `table.member` — handed
306
+ * on, walked, indexed by what only the running program knows — keeps
307
+ * every member. */
308
+ shake(code: readonly L.Statement[]): void;
309
+ /** Luau setting up the helpers `used` for a chunk whose code names them:
310
+ * `declare` goes before that code, which reads each as an upvalue, and
311
+ * `define` after it — before any of it runs, and after what a helper
312
+ * reads as it is set up (the line map). Each definition runs in a
313
+ * function of its own, so what it keeps to itself stays there. */
314
+ chunk(used: ReadonlySet<string>): {
315
+ declare: L.Statement[];
316
+ define: L.Statement[];
317
+ };
163
318
  }
164
319
  /** How a module's exports behave at runtime, beyond what its code assigns. */
165
320
  interface ModuleInfo {
@@ -181,109 +336,4 @@ interface ModuleInfo {
181
336
  }
182
337
  declare function lower(program: T.Program, scopes: ScopeAnalysis, options?: LowerOptions): LowerResult;
183
338
 
184
- /** What `tilua.config.json` holds. */
185
- interface TiluaConfigJson {
186
- /** Type libraries to check against: `["roblox"]` loads `@tilua-types/roblox`. */
187
- types?: string[];
188
- /** Import path aliases, as in tsconfig: `{ "@shared/*": ["src/shared/*"] }`. */
189
- paths?: Record<string, string[]>;
190
- /** Where `paths` targets resolve from. Default: the config's folder. */
191
- baseUrl?: string;
192
- /** A Rojo sourcemap, or `null`. */
193
- sourceMap?: string | null;
194
- /** Which Lua the output must run on. `"luau"` (the default) keeps Luau's
195
- * own syntax; `"lua51"` also lowers what stock Lua 5.1 cannot parse —
196
- * `a += b`, `continue`, `if c then a else b` as an expression, `//`,
197
- * digit separators and binary literals. */
198
- target?: Target;
199
- /** How many files the output is. `"single"` (the default) is one file;
200
- * `"chunks"` also writes a file for what only an `import()` reaches,
201
- * loaded when it is first asked for; `"modules"` writes one per module. */
202
- output?: OutputMode;
203
- /** Leave out Lua's standard library — `print`, `string`, `pcall` — which
204
- * is otherwise there for every file, as JavaScript's is in TypeScript. */
205
- noLib?: boolean;
206
- }
207
- /** A config file's path, or the config itself. Relative paths — to a config
208
- * file, and inside an inline config — resolve from `cwd`. */
209
- type ConfigInput = string | TiluaConfigJson;
210
- interface ResolvedConfig {
211
- readonly config?: TiluaConfig;
212
- readonly problems: readonly ConfigProblem[];
213
- }
214
- /** The config for a build of `entry`: the one given, or else the nearest
215
- * `tilua.config.json` above the entry. */
216
- declare function resolveConfig(input: ConfigInput | undefined, entry: string, cwd?: string): ResolvedConfig;
217
-
218
- interface BundleOptions {
219
- /** The file the bundle runs. */
220
- readonly entry: string;
221
- /** A `tilua.config.json` path or contents. Default: the nearest config above the entry. */
222
- readonly config?: ConfigInput;
223
- /** The project folder. Modules are named by their path from it, and an
224
- * inline config's relative paths resolve from it. Default: the config
225
- * file's folder, or else the entry's. */
226
- readonly root?: string;
227
- /** Check types against the config's `types` too. Default: true. */
228
- readonly typeCheck?: boolean;
229
- /** Which Lua the output must run on. Overrides the config's `target`. */
230
- readonly target?: Target;
231
- /** How many files to make. Overrides the config's `output`; `"single"`
232
- * without either. */
233
- readonly output?: OutputMode;
234
- /** What the entry's file is called: `main.luau`. The other files of
235
- * `"chunks"` are named after it (`main_shop.luau`), and every file takes
236
- * its extension. Default: the entry's own name, with `.luau`. */
237
- readonly outFile?: string;
238
- }
239
- /** One file of the output. */
240
- interface BundleFile {
241
- /** Where it goes, from the folder the output is written to: `main.luau`,
242
- * `src/shop/buy.luau`. Files find each other by these, so they have to be
243
- * written as they are named. */
244
- readonly path: string;
245
- readonly code: string;
246
- /** The modules in it, by name. */
247
- readonly modules: string[];
248
- }
249
- interface BundleDiagnostic {
250
- /** Absolute path of the file it is about. */
251
- readonly file: string;
252
- readonly message: string;
253
- readonly line: number;
254
- readonly column: number;
255
- /** `type` and `config` problems are reported without stopping the build;
256
- * `syntax`, `scope` (such as assigning to an import) and `module`
257
- * problems leave no bundle. */
258
- readonly category: "syntax" | "scope" | "module" | "type" | "config";
259
- /** A test that always comes out the same, and the like: said, and no
260
- * reason for the build to fail. */
261
- readonly severity?: "warning";
262
- }
263
- interface BundleResult {
264
- /** The bundle — the entry's file, when there are several — or `undefined`
265
- * when a module could not be compiled. Type errors are reported but do
266
- * not stop it. */
267
- readonly code?: string;
268
- /** Every file of the output, the entry's first. Empty when there is no
269
- * bundle. */
270
- readonly files: BundleFile[];
271
- /** The bundled modules' names, entry first. */
272
- readonly modules: string[];
273
- readonly diagnostics: BundleDiagnostic[];
274
- }
275
- declare function bundle(options: BundleOptions): Promise<BundleResult>;
276
-
277
- interface Diagnostic {
278
- readonly message: string;
279
- readonly line: number;
280
- readonly column: number;
281
- }
282
- interface CompileResult {
283
- /** The Luau source, or `undefined` when the file has errors. */
284
- readonly code?: string;
285
- readonly diagnostics: Diagnostic[];
286
- }
287
- declare function compile(source: string, config?: ConfigInput): Promise<CompileResult>;
288
-
289
339
  export { type BundleDiagnostic, type BundleFile, type BundleOptions, type BundleResult, type CompileResult, type ConfigInput, type Diagnostic, type LoadedLowering, type LowerDiagnostic, type LowerOptions, type LowerResult, type LoweringProblem, type ModuleContext, type ResolvedConfig, type TiluaConfigJson, bundle, compile, loadLowerings, lower, resolveConfig };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  lower,
5
5
  program,
6
6
  resolveConfig
7
- } from "./chunk-574KDV5W.js";
7
+ } from "./chunk-WGXXYKEU.js";
8
8
 
9
9
  // src/compile.ts
10
10
  import { readFileSync } from "fs";
@@ -41,7 +41,6 @@ async function compile(source, config) {
41
41
  types: analyzeTypes(program2, scopes, { libs, noLib, diagnostics: false }),
42
42
  noLib,
43
43
  lowerings,
44
- target: resolved?.target,
45
44
  source
46
45
  });
47
46
  diagnostics.push(...lowered.diagnostics);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tilua/compiler",
3
- "version": "6.1.0",
3
+ "version": "7.0.1",
4
4
  "description": "Compiles tilua to Luau: lowers the @tilua/parser AST to a luau-parser AST and prints it",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -38,7 +38,7 @@
38
38
  "type": "module",
39
39
  "dependencies": {
40
40
  "luau-parser": "^1.0.3",
41
- "@tilua/parser": "^6.1.0"
41
+ "@tilua/parser": "^7.0.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^22.20.2",