@tilua/compiler 1.0.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.
@@ -0,0 +1,233 @@
1
+ import * as T from '@tilua/parser';
2
+ import { LoweringPlugin, BuildTarget, TypeAnalysis, ScopeAnalysis, TiluaConfig, ConfigProblem } from '@tilua/parser';
3
+ export { LoweringPlugin, MethodCall, MethodLowering } from '@tilua/parser';
4
+ import * as L from 'luau-parser';
5
+
6
+ /**
7
+ * Fresh local names for what lowering introduces — a destructuring temporary,
8
+ * a required module, a helper function.
9
+ *
10
+ * A generated name must not capture or shadow anything the source means, so
11
+ * every name the file mentions anywhere is taken up front. A name is only
12
+ * reused by coincidence of a different spelling, never by accident.
13
+ */
14
+
15
+ declare class Names {
16
+ private readonly taken;
17
+ private constructor();
18
+ /** The names `programs` mention — a bundle takes every module's, so that
19
+ * a name shared across modules (the module table) collides with none. */
20
+ static from(...programs: T.Program[]): Names;
21
+ /** A copy that goes on to take names independently — one per module, each
22
+ * starting from what the whole bundle already takes. */
23
+ fork(): Names;
24
+ /** `base`, or `base2`, `base3`, ... — whichever is free first. */
25
+ fresh(base: string): string;
26
+ }
27
+
28
+ interface LoadedLowering {
29
+ readonly plugin: LoweringPlugin;
30
+ /** The package it came from, for reporting. */
31
+ readonly from: string;
32
+ }
33
+ interface LoweringProblem {
34
+ readonly file: string;
35
+ readonly message: string;
36
+ }
37
+ /** Load what the project's type libraries lower. A module that will not load,
38
+ * or exports the wrong shape, is reported and skipped: the rest of the build
39
+ * is still worth having. */
40
+ declare function loadLowerings(modules: readonly {
41
+ file: string;
42
+ from: string;
43
+ }[]): Promise<{
44
+ lowerings: LoadedLowering[];
45
+ problems: LoweringProblem[];
46
+ }>;
47
+
48
+ /**
49
+ * tilua AST -> Luau AST.
50
+ *
51
+ * Everything tilua adds over Luau is rewritten into plain Luau here; the
52
+ * result is an ordinary luau-parser tree, printed by luau-parser's printer.
53
+ *
54
+ * const { a, b } = value local a, b = value.a, value.b
55
+ * const [x, y] = list local x, y = list[1], list[2]
56
+ * { name: "n", count } { name = "n", count = count }
57
+ * [...xs, 1] concat(xs, { 1 })
58
+ * `${a} any` ("%s any"):format(tostring(a))
59
+ * function f(n = 1) ... end function f(n) if n == nil then n = 1 end ... end
60
+ * x as T / x satisfies T x
61
+ *
62
+ * Types have no runtime meaning, so every annotation, alias and `declare` is
63
+ * dropped: the output is untyped Luau.
64
+ *
65
+ * ## Modules
66
+ *
67
+ * In a bundle each file becomes a function that fills in its `exports` table
68
+ * (see `bundle.ts`), and modules behave the way ES modules do:
69
+ *
70
+ * - **Live bindings.** An exported binding lives on `exports` itself, so
71
+ * every read and write of it goes through `exports.name`. An imported name
72
+ * is read through the imported module's table (`util.clamp`), never
73
+ * copied — a value the other module sets later is still seen.
74
+ * - **Hoisting.** Every top-level name is declared before any code runs, and
75
+ * every top-level function is defined then too, ahead of the imports. In a
76
+ * cycle — `a` imports `b`, which imports `a` while `a` is still loading —
77
+ * `b` receives `a`'s partly filled table, and can already call its
78
+ * functions.
79
+ */
80
+
81
+ /** What lowering a file as a module of a bundle needs. */
82
+ interface ModuleContext {
83
+ /** The bundle's name for this module. */
84
+ readonly name: string;
85
+ /** The bundle's name for the module `specifier` imports, or `undefined`
86
+ * when there is no such module (reported). */
87
+ resolve(specifier: string): string | undefined;
88
+ /** The bundle's `require`: an expression that, called with a module's
89
+ * name, returns its exports table. */
90
+ readonly require: L.Expression;
91
+ /** Luau reaching the bundle's line map — what `console:error` reads to
92
+ * name the file a frame was written in. */
93
+ readonly lines?: string;
94
+ }
95
+ interface LowerOptions {
96
+ /** Lower the file as a module of a bundle. Without it, `import` and
97
+ * `export` are errors. */
98
+ readonly module?: ModuleContext;
99
+ /** Names already taken beyond the file's own — a bundle's. */
100
+ readonly names?: Names;
101
+ /** The file's types. They decide what `for x in t` means: over a table
102
+ * it yields the values, which in Luau needs a key variable before `x`.
103
+ * They also say what a method call is called on, which decides whether
104
+ * `methods` claims it. */
105
+ readonly types?: TypeAnalysis;
106
+ /** What the project's type libraries lower, already loaded (see
107
+ * `loadLowerings`). The compiler lowers the language; a call written
108
+ * against a library's types is the library's to explain. */
109
+ readonly lowerings?: readonly LoadedLowering[];
110
+ /** The file's own text, so `console:log` can show a function as the code it
111
+ * was written as. Without it a function shows only its type. */
112
+ readonly source?: string;
113
+ /** Which Lua the output has to run on. Default `"luau"`. `"lua51"` also
114
+ * lowers what Luau adds to Lua and 5.1 has no syntax for — `a += b`,
115
+ * `continue`, `if c then a else b` as an expression, `//`. */
116
+ readonly target?: Target;
117
+ }
118
+ /** `"luau"` is Roblox's Lua. `"lua51"` is stock Lua 5.1, which has none of
119
+ * Luau's additions — and no `goto` either, so `continue` has to be built out
120
+ * of the loops 5.1 does have. */
121
+ type Target = BuildTarget;
122
+ interface LowerDiagnostic {
123
+ readonly message: string;
124
+ readonly line: number;
125
+ readonly column: number;
126
+ }
127
+ interface LowerResult {
128
+ readonly statements: L.Statement[];
129
+ /** In a module: the parameter the statements fill in with the exports. */
130
+ readonly exportsName: string;
131
+ /** In a module: what the bundle's `require` needs to know about it. */
132
+ readonly module: ModuleInfo;
133
+ readonly diagnostics: LowerDiagnostic[];
134
+ /** The line of the *source* file each emitted statement came from. With the
135
+ * file it was lowered from, this is what turns a line of the bundle back
136
+ * into a place someone can open. */
137
+ readonly origins: WeakMap<L.Statement, number>;
138
+ }
139
+ /** How a module's exports behave at runtime, beyond what its code assigns. */
140
+ interface ModuleInfo {
141
+ /** Names the module itself exports. Reading one before the module has
142
+ * initialized it is an error, as in ES modules. */
143
+ readonly names: string[];
144
+ /** Names re-exported from another module — `export { x as y } from` —
145
+ * read from that module on every access, so they stay live.
146
+ * `imported` is `undefined` for the whole module (`import * as M; export { M }`). */
147
+ readonly links: {
148
+ name: string;
149
+ module: string;
150
+ imported?: string;
151
+ }[];
152
+ /** `export * from` modules, consulted live for any other name. */
153
+ readonly stars: string[];
154
+ /** Whether the module exports anything. */
155
+ exports: boolean;
156
+ }
157
+ declare function lower(program: T.Program, scopes: ScopeAnalysis, options?: LowerOptions): LowerResult;
158
+
159
+ /** What `tilua.config.json` holds. */
160
+ interface TiluaConfigJson {
161
+ /** Type libraries to check against: `["roblox"]` loads `@tilua-types/roblox`. */
162
+ types?: string[];
163
+ /** Import path aliases, as in tsconfig: `{ "@shared/*": ["src/shared/*"] }`. */
164
+ paths?: Record<string, string[]>;
165
+ /** Where `paths` targets resolve from. Default: the config's folder. */
166
+ baseUrl?: string;
167
+ /** A Rojo sourcemap, or `null`. */
168
+ sourceMap?: string | null;
169
+ /** Which Lua the output must run on. `"luau"` (the default) keeps Luau's
170
+ * own syntax; `"lua51"` also lowers what stock Lua 5.1 cannot parse —
171
+ * `a += b`, `continue`, `if c then a else b` as an expression, `//`,
172
+ * digit separators and binary literals. */
173
+ target?: Target;
174
+ }
175
+ /** A config file's path, or the config itself. Relative paths — to a config
176
+ * file, and inside an inline config — resolve from `cwd`. */
177
+ type ConfigInput = string | TiluaConfigJson;
178
+ interface ResolvedConfig {
179
+ readonly config?: TiluaConfig;
180
+ readonly problems: readonly ConfigProblem[];
181
+ }
182
+ /** The config for a build of `entry`: the one given, or else the nearest
183
+ * `tilua.config.json` above the entry. */
184
+ declare function resolveConfig(input: ConfigInput | undefined, entry: string, cwd?: string): ResolvedConfig;
185
+
186
+ interface BundleOptions {
187
+ /** The file the bundle runs. */
188
+ readonly entry: string;
189
+ /** A `tilua.config.json` path or contents. Default: the nearest config above the entry. */
190
+ readonly config?: ConfigInput;
191
+ /** The project folder. Modules are named by their path from it, and an
192
+ * inline config's relative paths resolve from it. Default: the config
193
+ * file's folder, or else the entry's. */
194
+ readonly root?: string;
195
+ /** Check types against the config's `types` too. Default: true. */
196
+ readonly typeCheck?: boolean;
197
+ /** Which Lua the output must run on. Overrides the config's `target`. */
198
+ readonly target?: Target;
199
+ }
200
+ interface BundleDiagnostic {
201
+ /** Absolute path of the file it is about. */
202
+ readonly file: string;
203
+ readonly message: string;
204
+ readonly line: number;
205
+ readonly column: number;
206
+ /** `type` and `config` problems are reported without stopping the build;
207
+ * `syntax`, `scope` (such as assigning to an import) and `module`
208
+ * problems leave no bundle. */
209
+ readonly category: "syntax" | "scope" | "module" | "type" | "config";
210
+ }
211
+ interface BundleResult {
212
+ /** The bundle, or `undefined` when a module could not be compiled. Type
213
+ * errors are reported but do not stop it. */
214
+ readonly code?: string;
215
+ /** The bundled modules' names, entry first. */
216
+ readonly modules: string[];
217
+ readonly diagnostics: BundleDiagnostic[];
218
+ }
219
+ declare function bundle(options: BundleOptions): Promise<BundleResult>;
220
+
221
+ interface Diagnostic {
222
+ readonly message: string;
223
+ readonly line: number;
224
+ readonly column: number;
225
+ }
226
+ interface CompileResult {
227
+ /** The Luau source, or `undefined` when the file has errors. */
228
+ readonly code?: string;
229
+ readonly diagnostics: Diagnostic[];
230
+ }
231
+ declare function compile(source: string, config?: ConfigInput): Promise<CompileResult>;
232
+
233
+ export { type BundleDiagnostic, 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 };
@@ -0,0 +1,233 @@
1
+ import * as T from '@tilua/parser';
2
+ import { LoweringPlugin, BuildTarget, TypeAnalysis, ScopeAnalysis, TiluaConfig, ConfigProblem } from '@tilua/parser';
3
+ export { LoweringPlugin, MethodCall, MethodLowering } from '@tilua/parser';
4
+ import * as L from 'luau-parser';
5
+
6
+ /**
7
+ * Fresh local names for what lowering introduces — a destructuring temporary,
8
+ * a required module, a helper function.
9
+ *
10
+ * A generated name must not capture or shadow anything the source means, so
11
+ * every name the file mentions anywhere is taken up front. A name is only
12
+ * reused by coincidence of a different spelling, never by accident.
13
+ */
14
+
15
+ declare class Names {
16
+ private readonly taken;
17
+ private constructor();
18
+ /** The names `programs` mention — a bundle takes every module's, so that
19
+ * a name shared across modules (the module table) collides with none. */
20
+ static from(...programs: T.Program[]): Names;
21
+ /** A copy that goes on to take names independently — one per module, each
22
+ * starting from what the whole bundle already takes. */
23
+ fork(): Names;
24
+ /** `base`, or `base2`, `base3`, ... — whichever is free first. */
25
+ fresh(base: string): string;
26
+ }
27
+
28
+ interface LoadedLowering {
29
+ readonly plugin: LoweringPlugin;
30
+ /** The package it came from, for reporting. */
31
+ readonly from: string;
32
+ }
33
+ interface LoweringProblem {
34
+ readonly file: string;
35
+ readonly message: string;
36
+ }
37
+ /** Load what the project's type libraries lower. A module that will not load,
38
+ * or exports the wrong shape, is reported and skipped: the rest of the build
39
+ * is still worth having. */
40
+ declare function loadLowerings(modules: readonly {
41
+ file: string;
42
+ from: string;
43
+ }[]): Promise<{
44
+ lowerings: LoadedLowering[];
45
+ problems: LoweringProblem[];
46
+ }>;
47
+
48
+ /**
49
+ * tilua AST -> Luau AST.
50
+ *
51
+ * Everything tilua adds over Luau is rewritten into plain Luau here; the
52
+ * result is an ordinary luau-parser tree, printed by luau-parser's printer.
53
+ *
54
+ * const { a, b } = value local a, b = value.a, value.b
55
+ * const [x, y] = list local x, y = list[1], list[2]
56
+ * { name: "n", count } { name = "n", count = count }
57
+ * [...xs, 1] concat(xs, { 1 })
58
+ * `${a} any` ("%s any"):format(tostring(a))
59
+ * function f(n = 1) ... end function f(n) if n == nil then n = 1 end ... end
60
+ * x as T / x satisfies T x
61
+ *
62
+ * Types have no runtime meaning, so every annotation, alias and `declare` is
63
+ * dropped: the output is untyped Luau.
64
+ *
65
+ * ## Modules
66
+ *
67
+ * In a bundle each file becomes a function that fills in its `exports` table
68
+ * (see `bundle.ts`), and modules behave the way ES modules do:
69
+ *
70
+ * - **Live bindings.** An exported binding lives on `exports` itself, so
71
+ * every read and write of it goes through `exports.name`. An imported name
72
+ * is read through the imported module's table (`util.clamp`), never
73
+ * copied — a value the other module sets later is still seen.
74
+ * - **Hoisting.** Every top-level name is declared before any code runs, and
75
+ * every top-level function is defined then too, ahead of the imports. In a
76
+ * cycle — `a` imports `b`, which imports `a` while `a` is still loading —
77
+ * `b` receives `a`'s partly filled table, and can already call its
78
+ * functions.
79
+ */
80
+
81
+ /** What lowering a file as a module of a bundle needs. */
82
+ interface ModuleContext {
83
+ /** The bundle's name for this module. */
84
+ readonly name: string;
85
+ /** The bundle's name for the module `specifier` imports, or `undefined`
86
+ * when there is no such module (reported). */
87
+ resolve(specifier: string): string | undefined;
88
+ /** The bundle's `require`: an expression that, called with a module's
89
+ * name, returns its exports table. */
90
+ readonly require: L.Expression;
91
+ /** Luau reaching the bundle's line map — what `console:error` reads to
92
+ * name the file a frame was written in. */
93
+ readonly lines?: string;
94
+ }
95
+ interface LowerOptions {
96
+ /** Lower the file as a module of a bundle. Without it, `import` and
97
+ * `export` are errors. */
98
+ readonly module?: ModuleContext;
99
+ /** Names already taken beyond the file's own — a bundle's. */
100
+ readonly names?: Names;
101
+ /** The file's types. They decide what `for x in t` means: over a table
102
+ * it yields the values, which in Luau needs a key variable before `x`.
103
+ * They also say what a method call is called on, which decides whether
104
+ * `methods` claims it. */
105
+ readonly types?: TypeAnalysis;
106
+ /** What the project's type libraries lower, already loaded (see
107
+ * `loadLowerings`). The compiler lowers the language; a call written
108
+ * against a library's types is the library's to explain. */
109
+ readonly lowerings?: readonly LoadedLowering[];
110
+ /** The file's own text, so `console:log` can show a function as the code it
111
+ * was written as. Without it a function shows only its type. */
112
+ readonly source?: string;
113
+ /** Which Lua the output has to run on. Default `"luau"`. `"lua51"` also
114
+ * lowers what Luau adds to Lua and 5.1 has no syntax for — `a += b`,
115
+ * `continue`, `if c then a else b` as an expression, `//`. */
116
+ readonly target?: Target;
117
+ }
118
+ /** `"luau"` is Roblox's Lua. `"lua51"` is stock Lua 5.1, which has none of
119
+ * Luau's additions — and no `goto` either, so `continue` has to be built out
120
+ * of the loops 5.1 does have. */
121
+ type Target = BuildTarget;
122
+ interface LowerDiagnostic {
123
+ readonly message: string;
124
+ readonly line: number;
125
+ readonly column: number;
126
+ }
127
+ interface LowerResult {
128
+ readonly statements: L.Statement[];
129
+ /** In a module: the parameter the statements fill in with the exports. */
130
+ readonly exportsName: string;
131
+ /** In a module: what the bundle's `require` needs to know about it. */
132
+ readonly module: ModuleInfo;
133
+ readonly diagnostics: LowerDiagnostic[];
134
+ /** The line of the *source* file each emitted statement came from. With the
135
+ * file it was lowered from, this is what turns a line of the bundle back
136
+ * into a place someone can open. */
137
+ readonly origins: WeakMap<L.Statement, number>;
138
+ }
139
+ /** How a module's exports behave at runtime, beyond what its code assigns. */
140
+ interface ModuleInfo {
141
+ /** Names the module itself exports. Reading one before the module has
142
+ * initialized it is an error, as in ES modules. */
143
+ readonly names: string[];
144
+ /** Names re-exported from another module — `export { x as y } from` —
145
+ * read from that module on every access, so they stay live.
146
+ * `imported` is `undefined` for the whole module (`import * as M; export { M }`). */
147
+ readonly links: {
148
+ name: string;
149
+ module: string;
150
+ imported?: string;
151
+ }[];
152
+ /** `export * from` modules, consulted live for any other name. */
153
+ readonly stars: string[];
154
+ /** Whether the module exports anything. */
155
+ exports: boolean;
156
+ }
157
+ declare function lower(program: T.Program, scopes: ScopeAnalysis, options?: LowerOptions): LowerResult;
158
+
159
+ /** What `tilua.config.json` holds. */
160
+ interface TiluaConfigJson {
161
+ /** Type libraries to check against: `["roblox"]` loads `@tilua-types/roblox`. */
162
+ types?: string[];
163
+ /** Import path aliases, as in tsconfig: `{ "@shared/*": ["src/shared/*"] }`. */
164
+ paths?: Record<string, string[]>;
165
+ /** Where `paths` targets resolve from. Default: the config's folder. */
166
+ baseUrl?: string;
167
+ /** A Rojo sourcemap, or `null`. */
168
+ sourceMap?: string | null;
169
+ /** Which Lua the output must run on. `"luau"` (the default) keeps Luau's
170
+ * own syntax; `"lua51"` also lowers what stock Lua 5.1 cannot parse —
171
+ * `a += b`, `continue`, `if c then a else b` as an expression, `//`,
172
+ * digit separators and binary literals. */
173
+ target?: Target;
174
+ }
175
+ /** A config file's path, or the config itself. Relative paths — to a config
176
+ * file, and inside an inline config — resolve from `cwd`. */
177
+ type ConfigInput = string | TiluaConfigJson;
178
+ interface ResolvedConfig {
179
+ readonly config?: TiluaConfig;
180
+ readonly problems: readonly ConfigProblem[];
181
+ }
182
+ /** The config for a build of `entry`: the one given, or else the nearest
183
+ * `tilua.config.json` above the entry. */
184
+ declare function resolveConfig(input: ConfigInput | undefined, entry: string, cwd?: string): ResolvedConfig;
185
+
186
+ interface BundleOptions {
187
+ /** The file the bundle runs. */
188
+ readonly entry: string;
189
+ /** A `tilua.config.json` path or contents. Default: the nearest config above the entry. */
190
+ readonly config?: ConfigInput;
191
+ /** The project folder. Modules are named by their path from it, and an
192
+ * inline config's relative paths resolve from it. Default: the config
193
+ * file's folder, or else the entry's. */
194
+ readonly root?: string;
195
+ /** Check types against the config's `types` too. Default: true. */
196
+ readonly typeCheck?: boolean;
197
+ /** Which Lua the output must run on. Overrides the config's `target`. */
198
+ readonly target?: Target;
199
+ }
200
+ interface BundleDiagnostic {
201
+ /** Absolute path of the file it is about. */
202
+ readonly file: string;
203
+ readonly message: string;
204
+ readonly line: number;
205
+ readonly column: number;
206
+ /** `type` and `config` problems are reported without stopping the build;
207
+ * `syntax`, `scope` (such as assigning to an import) and `module`
208
+ * problems leave no bundle. */
209
+ readonly category: "syntax" | "scope" | "module" | "type" | "config";
210
+ }
211
+ interface BundleResult {
212
+ /** The bundle, or `undefined` when a module could not be compiled. Type
213
+ * errors are reported but do not stop it. */
214
+ readonly code?: string;
215
+ /** The bundled modules' names, entry first. */
216
+ readonly modules: string[];
217
+ readonly diagnostics: BundleDiagnostic[];
218
+ }
219
+ declare function bundle(options: BundleOptions): Promise<BundleResult>;
220
+
221
+ interface Diagnostic {
222
+ readonly message: string;
223
+ readonly line: number;
224
+ readonly column: number;
225
+ }
226
+ interface CompileResult {
227
+ /** The Luau source, or `undefined` when the file has errors. */
228
+ readonly code?: string;
229
+ readonly diagnostics: Diagnostic[];
230
+ }
231
+ declare function compile(source: string, config?: ConfigInput): Promise<CompileResult>;
232
+
233
+ export { type BundleDiagnostic, 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 ADDED
@@ -0,0 +1,55 @@
1
+ import {
2
+ bundle,
3
+ loadLowerings,
4
+ lower,
5
+ program,
6
+ resolveConfig
7
+ } from "./chunk-S5C4VH6A.js";
8
+
9
+ // src/compile.ts
10
+ import { readFileSync } from "fs";
11
+ import { resolve } from "path";
12
+ import { parse, analyzeScopes, analyzeTypes, resolveTypeLibraries, ParseError, LexError } from "@tilua/parser";
13
+ import { print } from "luau-parser";
14
+ async function compile(source, config) {
15
+ let program2;
16
+ try {
17
+ program2 = parse(source);
18
+ } catch (error) {
19
+ if (error instanceof ParseError || error instanceof LexError) {
20
+ const { line, column } = error;
21
+ return { diagnostics: [{ message: error.message, line, column }] };
22
+ }
23
+ throw error;
24
+ }
25
+ const scopes = analyzeScopes(program2);
26
+ const diagnostics = scopes.diagnostics.map((d) => ({
27
+ message: d.message,
28
+ line: d.node.line.start,
29
+ column: d.node.column.start
30
+ }));
31
+ const { config: resolved, problems } = resolveConfig(config, resolve("main.tilua"));
32
+ const libraries = resolved ? resolveTypeLibraries(resolved) : { files: [], lowerings: [], problems: [] };
33
+ const { lowerings, problems: loweringProblems } = await loadLowerings(libraries.lowerings);
34
+ for (const p of [...problems, ...libraries.problems]) {
35
+ diagnostics.push({ message: p.message, line: p.line ?? 1, column: p.column ?? 1 });
36
+ }
37
+ for (const p of loweringProblems) diagnostics.push({ message: p.message, line: 1, column: 1 });
38
+ const libs = libraries.files.map((file) => parse(readFileSync(file, "utf8")));
39
+ const lowered = lower(program2, scopes, {
40
+ types: analyzeTypes(program2, scopes, { libs, diagnostics: false }),
41
+ lowerings,
42
+ target: resolved?.target,
43
+ source
44
+ });
45
+ diagnostics.push(...lowered.diagnostics);
46
+ if (diagnostics.length) return { diagnostics };
47
+ return { code: print(program(lowered.statements)) + "\n", diagnostics };
48
+ }
49
+ export {
50
+ bundle,
51
+ compile,
52
+ loadLowerings,
53
+ lower,
54
+ resolveConfig
55
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@tilua/compiler",
3
+ "version": "1.0.0",
4
+ "description": "Compiles tilua to Luau: lowers the @tilua/parser AST to a luau-parser AST and prints it",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "bin": {
9
+ "tilua": "dist/cli.js"
10
+ },
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "types": {
17
+ "require": "./dist/index.d.cts",
18
+ "import": "./dist/index.d.ts"
19
+ },
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs"
22
+ }
23
+ },
24
+ "scripts": {
25
+ "test": "tsx scripts/test.ts",
26
+ "build": "tsup",
27
+ "typecheck": "tsc --noEmit"
28
+ },
29
+ "keywords": [
30
+ "tilua",
31
+ "luau",
32
+ "roblox",
33
+ "compiler"
34
+ ],
35
+ "author": "",
36
+ "license": "ISC",
37
+ "type": "module",
38
+ "dependencies": {
39
+ "luau-parser": "^1.0.3",
40
+ "@tilua/parser": "^1.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@types/node": "^22.20.2",
44
+ "tsup": "^8.5.1",
45
+ "tsx": "^4.23.13",
46
+ "typescript": "^5.9.3"
47
+ },
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/Uav3537/tilua-compiler.git"
51
+ },
52
+ "publishConfig": {
53
+ "access": "public"
54
+ }
55
+ }