luau2ts 0.2.2 → 0.2.3

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.
Files changed (140) hide show
  1. package/dist/cli/args.d.ts +23 -0
  2. package/dist/cli/args.d.ts.map +1 -0
  3. package/dist/cli/args.js +177 -0
  4. package/dist/cli/args.js.map +1 -0
  5. package/dist/cli/bin.d.ts +3 -0
  6. package/dist/cli/bin.d.ts.map +1 -0
  7. package/dist/cli/bin.js +71 -0
  8. package/dist/cli/bin.js.map +1 -0
  9. package/dist/cli/modes.d.ts +20 -0
  10. package/dist/cli/modes.d.ts.map +1 -0
  11. package/dist/cli/modes.js +145 -0
  12. package/dist/cli/modes.js.map +1 -0
  13. package/dist/compile/class-shape.d.ts +31 -0
  14. package/dist/compile/class-shape.d.ts.map +1 -0
  15. package/dist/compile/class-shape.js +291 -0
  16. package/dist/compile/class-shape.js.map +1 -0
  17. package/dist/compile/context.d.ts +86 -0
  18. package/dist/compile/context.d.ts.map +1 -0
  19. package/dist/compile/context.js +144 -0
  20. package/dist/compile/context.js.map +1 -0
  21. package/dist/compile/index.d.ts +58 -0
  22. package/dist/compile/index.d.ts.map +1 -0
  23. package/dist/compile/index.js +2155 -0
  24. package/dist/compile/index.js.map +1 -0
  25. package/dist/compile/macros/datatypes.d.ts +2 -0
  26. package/dist/compile/macros/datatypes.d.ts.map +1 -0
  27. package/dist/compile/macros/datatypes.js +76 -0
  28. package/dist/compile/macros/datatypes.js.map +1 -0
  29. package/dist/compile/macros/index.d.ts +33 -0
  30. package/dist/compile/macros/index.d.ts.map +1 -0
  31. package/dist/compile/macros/index.js +71 -0
  32. package/dist/compile/macros/index.js.map +1 -0
  33. package/dist/compile/macros/instance.d.ts +2 -0
  34. package/dist/compile/macros/instance.d.ts.map +1 -0
  35. package/dist/compile/macros/instance.js +58 -0
  36. package/dist/compile/macros/instance.js.map +1 -0
  37. package/dist/compile/macros/stdlib.d.ts +2 -0
  38. package/dist/compile/macros/stdlib.d.ts.map +1 -0
  39. package/dist/compile/macros/stdlib.js +140 -0
  40. package/dist/compile/macros/stdlib.js.map +1 -0
  41. package/dist/compile/rbxts-runtime.d.ts +2 -0
  42. package/dist/compile/rbxts-runtime.d.ts.map +1 -0
  43. package/dist/compile/rbxts-runtime.js +163 -0
  44. package/dist/compile/rbxts-runtime.js.map +1 -0
  45. package/dist/compile/sourcemap.d.ts +25 -0
  46. package/dist/compile/sourcemap.d.ts.map +1 -0
  47. package/dist/compile/sourcemap.js +71 -0
  48. package/dist/compile/sourcemap.js.map +1 -0
  49. package/dist/compile/type.d.ts +6 -0
  50. package/dist/compile/type.d.ts.map +1 -0
  51. package/dist/compile/type.js +122 -0
  52. package/dist/compile/type.js.map +1 -0
  53. package/dist/compile/util.d.ts +38 -0
  54. package/dist/compile/util.d.ts.map +1 -0
  55. package/dist/compile/util.js +153 -0
  56. package/dist/compile/util.js.map +1 -0
  57. package/dist/index.d.ts +3 -0
  58. package/dist/index.d.ts.map +1 -0
  59. package/dist/index.js +7 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/parser/index.d.ts +4 -0
  62. package/dist/parser/index.d.ts.map +1 -0
  63. package/dist/parser/index.js +227 -0
  64. package/dist/parser/index.js.map +1 -0
  65. package/dist/parser/types.d.ts +430 -0
  66. package/dist/parser/types.d.ts.map +1 -0
  67. package/dist/parser/types.js +14 -0
  68. package/dist/parser/types.js.map +1 -0
  69. package/dist/parser/wasm/luau-parser.d.mts +21 -0
  70. package/dist/parser/wasm/luau-parser.mjs +2 -0
  71. package/dist/parser/wasm/luau-parser.wasm +0 -0
  72. package/dist/rojo/index.d.ts +4 -0
  73. package/dist/rojo/index.d.ts.map +1 -0
  74. package/dist/rojo/index.js +3 -0
  75. package/dist/rojo/index.js.map +1 -0
  76. package/dist/rojo/load-project.d.ts +12 -0
  77. package/dist/rojo/load-project.d.ts.map +1 -0
  78. package/dist/rojo/load-project.js +35 -0
  79. package/dist/rojo/load-project.js.map +1 -0
  80. package/dist/rojo/types.d.ts +39 -0
  81. package/dist/rojo/types.d.ts.map +1 -0
  82. package/dist/rojo/types.js +2 -0
  83. package/dist/rojo/types.js.map +1 -0
  84. package/dist/rojo/walk-tree.d.ts +40 -0
  85. package/dist/rojo/walk-tree.d.ts.map +1 -0
  86. package/dist/rojo/walk-tree.js +164 -0
  87. package/dist/rojo/walk-tree.js.map +1 -0
  88. package/dist/runtime/arith.d.ts +13 -0
  89. package/dist/runtime/arith.d.ts.map +1 -0
  90. package/dist/runtime/arith.js +151 -0
  91. package/dist/runtime/arith.js.map +1 -0
  92. package/dist/runtime/index-helper.d.ts +3 -0
  93. package/dist/runtime/index-helper.d.ts.map +1 -0
  94. package/dist/runtime/index-helper.js +40 -0
  95. package/dist/runtime/index-helper.js.map +1 -0
  96. package/dist/runtime/index.d.ts +13 -0
  97. package/dist/runtime/index.d.ts.map +1 -0
  98. package/dist/runtime/index.js +13 -0
  99. package/dist/runtime/index.js.map +1 -0
  100. package/dist/runtime/iterator.d.ts +58 -0
  101. package/dist/runtime/iterator.d.ts.map +1 -0
  102. package/dist/runtime/iterator.js +181 -0
  103. package/dist/runtime/iterator.js.map +1 -0
  104. package/dist/runtime/length.d.ts +2 -0
  105. package/dist/runtime/length.d.ts.map +1 -0
  106. package/dist/runtime/length.js +15 -0
  107. package/dist/runtime/length.js.map +1 -0
  108. package/dist/runtime/lua-stdlib.d.ts +186 -0
  109. package/dist/runtime/lua-stdlib.d.ts.map +1 -0
  110. package/dist/runtime/lua-stdlib.js +502 -0
  111. package/dist/runtime/lua-stdlib.js.map +1 -0
  112. package/dist/runtime/metatable.d.ts +16 -0
  113. package/dist/runtime/metatable.d.ts.map +1 -0
  114. package/dist/runtime/metatable.js +129 -0
  115. package/dist/runtime/metatable.js.map +1 -0
  116. package/dist/runtime/pattern.d.ts +21 -0
  117. package/dist/runtime/pattern.d.ts.map +1 -0
  118. package/dist/runtime/pattern.js +375 -0
  119. package/dist/runtime/pattern.js.map +1 -0
  120. package/dist/runtime/pcall.d.ts +12 -0
  121. package/dist/runtime/pcall.d.ts.map +1 -0
  122. package/dist/runtime/pcall.js +54 -0
  123. package/dist/runtime/pcall.js.map +1 -0
  124. package/dist/runtime/string-lib.d.ts +31 -0
  125. package/dist/runtime/string-lib.d.ts.map +1 -0
  126. package/dist/runtime/string-lib.js +296 -0
  127. package/dist/runtime/string-lib.js.map +1 -0
  128. package/dist/runtime/table-lib.d.ts +18 -0
  129. package/dist/runtime/table-lib.d.ts.map +1 -0
  130. package/dist/runtime/table-lib.js +133 -0
  131. package/dist/runtime/table-lib.js.map +1 -0
  132. package/dist/runtime/tostring.d.ts +3 -0
  133. package/dist/runtime/tostring.d.ts.map +1 -0
  134. package/dist/runtime/tostring.js +82 -0
  135. package/dist/runtime/tostring.js.map +1 -0
  136. package/dist/runtime/truthy.d.ts +13 -0
  137. package/dist/runtime/truthy.d.ts.map +1 -0
  138. package/dist/runtime/truthy.js +26 -0
  139. package/dist/runtime/truthy.js.map +1 -0
  140. package/package.json +1 -1
@@ -0,0 +1,23 @@
1
+ import type { CompatMode } from '../compile/context.js';
2
+ export interface ParsedArgs {
3
+ /** Positional input: a `.luau`/`.lua` file, a directory, or undefined when `-p` is set. */
4
+ input: string | undefined;
5
+ /** Project file path, set by `-p` / `--project`. Mutually exclusive with `input`. */
6
+ project: string | undefined;
7
+ /** Output target. For single-file input: a file path (or `-` for stdout, the default).
8
+ * For directory or project input: an output directory. */
9
+ output: string | undefined;
10
+ mode: CompatMode;
11
+ sourcemap: boolean;
12
+ /** undefined = use default (on); true / false = explicit override. */
13
+ checkLuau: boolean | undefined;
14
+ checkTs: boolean | undefined;
15
+ typeCheck: boolean | undefined;
16
+ help: boolean;
17
+ version: boolean;
18
+ }
19
+ export declare class ArgError extends Error {
20
+ }
21
+ export declare function parseArgs(argv: string[]): ParsedArgs;
22
+ export declare const HELP_TEXT = "luau2ts: A Luau-to-TypeScript compiler for Roblox.\n\nUsage:\n luau2ts <file.luau> Compile one file. Writes to stdout.\n luau2ts <file.luau> -o <file.ts> Compile one file. Writes to a file.\n luau2ts <dir/> -o <out/> Compile every .luau/.lua under <dir/>.\n Mirrors the input tree into <out/>.\n luau2ts -p <default.project.json> -o <out/>\n Walk a Rojo project file, compile\n every script it references, and\n emit a roblox-ts-shaped tree.\n\nFlags:\n -o, --output <path> Output file or directory. Default: stdout for\n single-file input; required for dir/project.\n -p, --project <path> Path to a Rojo *.project.json file, or a directory\n containing default.project.json.\n --mode <name> Emit compatibility mode. One of:\n rbxts (default) emits TS that imports from\n @rbxts/types, @rbxts/services,\n etc. Pairs with roblox-ts.\n native emits TS that imports stdlib\n helpers from 'luau2ts/runtime'.\n Pairs with a host runtime that\n provides Roblox's Luau API.\n --sourcemap Emit a .ts.map next to each .ts.\n --check-ts Run TypeScript's type checker over the emitted\n .ts source (default: ON). Diagnostics print\n with [ts:CODE] prefix; non-zero exit on errors.\n --no-check-ts Skip the TypeScript post-emit check (faster\n batch compiles).\n --check-luau Run Luau's type checker (Luau.Analysis) over\n the input via @luau2ts/analyzer (default: ON\n when the analyzer package is installed).\n --no-check-luau Skip the Luau pre-emit check.\n --typecheck Force both layers on (errors if @luau2ts/analyzer\n is requested but not installed).\n --no-typecheck Skip both layers.\n -h, --help Show this help text.\n -v, --version Print the installed luau2ts version.\n";
23
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../src/cli/args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,WAAW,UAAU;IACzB,2FAA2F;IAC3F,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,qFAAqF;IACrF,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B;+DAC2D;IAC3D,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,sEAAsE;IACtE,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,QAAS,SAAQ,KAAK;CAAG;AAEtC,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,CAqIpD;AAED,eAAO,MAAM,SAAS,+8EAwCrB,CAAC"}
@@ -0,0 +1,177 @@
1
+ export class ArgError extends Error {
2
+ }
3
+ export function parseArgs(argv) {
4
+ const result = {
5
+ input: undefined,
6
+ project: undefined,
7
+ output: undefined,
8
+ mode: 'rbxts',
9
+ sourcemap: false,
10
+ checkLuau: undefined,
11
+ checkTs: undefined,
12
+ typeCheck: undefined,
13
+ help: false,
14
+ version: false,
15
+ };
16
+ const positional = [];
17
+ let i = 0;
18
+ while (i < argv.length) {
19
+ const arg = argv[i];
20
+ if (arg === '--') {
21
+ // All remaining args are positional, mirroring POSIX convention.
22
+ for (let j = i + 1; j < argv.length; j += 1)
23
+ positional.push(argv[j]);
24
+ break;
25
+ }
26
+ if (arg === '-h' || arg === '--help') {
27
+ result.help = true;
28
+ i += 1;
29
+ continue;
30
+ }
31
+ if (arg === '-v' || arg === '--version') {
32
+ result.version = true;
33
+ i += 1;
34
+ continue;
35
+ }
36
+ if (arg === '--sourcemap') {
37
+ result.sourcemap = true;
38
+ i += 1;
39
+ continue;
40
+ }
41
+ if (arg === '--check-ts') {
42
+ result.checkTs = true;
43
+ i += 1;
44
+ continue;
45
+ }
46
+ if (arg === '--no-check-ts') {
47
+ result.checkTs = false;
48
+ i += 1;
49
+ continue;
50
+ }
51
+ if (arg === '--check-luau') {
52
+ result.checkLuau = true;
53
+ i += 1;
54
+ continue;
55
+ }
56
+ if (arg === '--no-check-luau') {
57
+ result.checkLuau = false;
58
+ i += 1;
59
+ continue;
60
+ }
61
+ if (arg === '--typecheck') {
62
+ result.typeCheck = true;
63
+ i += 1;
64
+ continue;
65
+ }
66
+ if (arg === '--no-typecheck') {
67
+ result.typeCheck = false;
68
+ result.checkTs = false;
69
+ result.checkLuau = false;
70
+ i += 1;
71
+ continue;
72
+ }
73
+ if (arg === '-o' || arg === '--output') {
74
+ const value = argv[i + 1];
75
+ if (value === undefined)
76
+ throw new ArgError(`Missing value for ${arg}`);
77
+ result.output = value;
78
+ i += 2;
79
+ continue;
80
+ }
81
+ if (arg.startsWith('--output=')) {
82
+ result.output = arg.slice('--output='.length);
83
+ i += 1;
84
+ continue;
85
+ }
86
+ if (arg === '-p' || arg === '--project') {
87
+ const value = argv[i + 1];
88
+ if (value === undefined)
89
+ throw new ArgError(`Missing value for ${arg}`);
90
+ result.project = value;
91
+ i += 2;
92
+ continue;
93
+ }
94
+ if (arg.startsWith('--project=')) {
95
+ result.project = arg.slice('--project='.length);
96
+ i += 1;
97
+ continue;
98
+ }
99
+ if (arg === '--mode') {
100
+ const value = argv[i + 1];
101
+ if (value === undefined)
102
+ throw new ArgError('Missing value for --mode');
103
+ if (value !== 'rbxts' && value !== 'native') {
104
+ throw new ArgError(`Invalid --mode value: ${value} (expected rbxts or native)`);
105
+ }
106
+ result.mode = value;
107
+ i += 2;
108
+ continue;
109
+ }
110
+ if (arg.startsWith('--mode=')) {
111
+ const value = arg.slice('--mode='.length);
112
+ if (value !== 'rbxts' && value !== 'native') {
113
+ throw new ArgError(`Invalid --mode value: ${value} (expected rbxts or native)`);
114
+ }
115
+ result.mode = value;
116
+ i += 1;
117
+ continue;
118
+ }
119
+ if (arg.startsWith('-')) {
120
+ throw new ArgError(`Unknown flag: ${arg}`);
121
+ }
122
+ positional.push(arg);
123
+ i += 1;
124
+ }
125
+ if (positional.length > 1) {
126
+ throw new ArgError(`Too many positional arguments (expected 0 or 1, got ${positional.length}). `
127
+ + `Use -o for the output target.`);
128
+ }
129
+ if (positional.length === 1)
130
+ result.input = positional[0];
131
+ if (result.input && result.project) {
132
+ throw new ArgError('Cannot use a positional input and -p / --project together.');
133
+ }
134
+ return result;
135
+ }
136
+ export const HELP_TEXT = `luau2ts: A Luau-to-TypeScript compiler for Roblox.
137
+
138
+ Usage:
139
+ luau2ts <file.luau> Compile one file. Writes to stdout.
140
+ luau2ts <file.luau> -o <file.ts> Compile one file. Writes to a file.
141
+ luau2ts <dir/> -o <out/> Compile every .luau/.lua under <dir/>.
142
+ Mirrors the input tree into <out/>.
143
+ luau2ts -p <default.project.json> -o <out/>
144
+ Walk a Rojo project file, compile
145
+ every script it references, and
146
+ emit a roblox-ts-shaped tree.
147
+
148
+ Flags:
149
+ -o, --output <path> Output file or directory. Default: stdout for
150
+ single-file input; required for dir/project.
151
+ -p, --project <path> Path to a Rojo *.project.json file, or a directory
152
+ containing default.project.json.
153
+ --mode <name> Emit compatibility mode. One of:
154
+ rbxts (default) emits TS that imports from
155
+ @rbxts/types, @rbxts/services,
156
+ etc. Pairs with roblox-ts.
157
+ native emits TS that imports stdlib
158
+ helpers from 'luau2ts/runtime'.
159
+ Pairs with a host runtime that
160
+ provides Roblox's Luau API.
161
+ --sourcemap Emit a .ts.map next to each .ts.
162
+ --check-ts Run TypeScript's type checker over the emitted
163
+ .ts source (default: ON). Diagnostics print
164
+ with [ts:CODE] prefix; non-zero exit on errors.
165
+ --no-check-ts Skip the TypeScript post-emit check (faster
166
+ batch compiles).
167
+ --check-luau Run Luau's type checker (Luau.Analysis) over
168
+ the input via @luau2ts/analyzer (default: ON
169
+ when the analyzer package is installed).
170
+ --no-check-luau Skip the Luau pre-emit check.
171
+ --typecheck Force both layers on (errors if @luau2ts/analyzer
172
+ is requested but not installed).
173
+ --no-typecheck Skip both layers.
174
+ -h, --help Show this help text.
175
+ -v, --version Print the installed luau2ts version.
176
+ `;
177
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/cli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""}
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+ import { stat } from 'node:fs/promises';
3
+ import { resolve } from 'node:path';
4
+ import process from 'node:process';
5
+ import pkgJson from '../../package.json' with { type: 'json' };
6
+ import { ArgError, HELP_TEXT, parseArgs } from './args.js';
7
+ import { compileDirMode, compileFileMode, compileProjectMode, } from './modes.js';
8
+ async function main() {
9
+ let args;
10
+ try {
11
+ args = parseArgs(process.argv.slice(2));
12
+ }
13
+ catch (err) {
14
+ if (err instanceof ArgError) {
15
+ process.stderr.write(`luau2ts: ${err.message}\n`);
16
+ process.stderr.write(`Run \`luau2ts --help\` for usage.\n`);
17
+ return 2;
18
+ }
19
+ throw err;
20
+ }
21
+ if (args.help) {
22
+ process.stdout.write(HELP_TEXT);
23
+ return 0;
24
+ }
25
+ if (args.version) {
26
+ const version = pkgJson.version;
27
+ process.stdout.write(`luau2ts ${version}\n`);
28
+ return 0;
29
+ }
30
+ const opts = {
31
+ mode: args.mode,
32
+ sourcemap: args.sourcemap,
33
+ checkTs: args.checkTs,
34
+ checkLuau: args.checkLuau,
35
+ typeCheck: args.typeCheck,
36
+ };
37
+ if (args.project !== undefined) {
38
+ if (!args.output) {
39
+ process.stderr.write(`luau2ts: -p/--project requires -o/--output\n`);
40
+ return 2;
41
+ }
42
+ return compileProjectMode(args.project, args.output, opts);
43
+ }
44
+ if (args.input === undefined) {
45
+ process.stdout.write(HELP_TEXT);
46
+ return 0;
47
+ }
48
+ const inputAbs = resolve(args.input);
49
+ let inputStat;
50
+ try {
51
+ inputStat = await stat(inputAbs);
52
+ }
53
+ catch (err) {
54
+ const msg = err instanceof Error ? err.message : String(err);
55
+ process.stderr.write(`luau2ts: cannot read ${args.input}: ${msg}\n`);
56
+ return 1;
57
+ }
58
+ if (inputStat.isDirectory()) {
59
+ if (!args.output) {
60
+ process.stderr.write(`luau2ts: directory input requires -o/--output\n`);
61
+ return 2;
62
+ }
63
+ return compileDirMode(args.input, args.output, opts);
64
+ }
65
+ return compileFileMode(args.input, args.output, opts);
66
+ }
67
+ main().then((code) => process.exit(code), (err) => {
68
+ process.stderr.write(`luau2ts: ${err instanceof Error ? err.stack ?? err.message : String(err)}\n`);
69
+ process.exit(1);
70
+ });
71
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,OAAO,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EACL,cAAc,EACd,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAC;AAEpB,KAAK,UAAU,IAAI;IACjB,IAAI,IAAI,CAAC;IACT,IAAI,CAAC;QACH,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAI,GAAG,YAAY,QAAQ,EAAE,CAAC;YAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC;YAClD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qCAAqC,CAAC,CAAC;YAC5D,OAAO,CAAC,CAAC;QACX,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACd,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAChC,OAAO,CAAC,CAAC;IACX,CAAC;IACD,IAAI,IAAI,CAAC,OAAO,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AAK,KAAK,GAAG,IAAI,CAAC,CAAC;QACrE,OAAO,CAAC,CAAC;IACX,CAAC;IAED,IAAI,SAAS,CAAC,WAAW,EAAE,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;YACxE,OAAO,CAAC,CAAC;QACX,CAAC;QACD,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,eAAe,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AACxD,CAAC;AAED,IAAI,EAAE,CAAC,IAAI,CACT,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAC5B,CAAC,GAAG,EAAE,EAAE;IACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CACF,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { extname } from 'node:path';
2
+ import type { CompatMode } from '../compile/context.js';
3
+ export interface ModeOptions {
4
+ mode: CompatMode;
5
+ sourcemap: boolean;
6
+ checkTs: boolean | undefined;
7
+ checkLuau: boolean | undefined;
8
+ typeCheck: boolean | undefined;
9
+ }
10
+ /** Single-file mode. If `outputArg` is undefined, writes to stdout. */
11
+ export declare function compileFileMode(inputArg: string, outputArg: string | undefined, opts: ModeOptions): Promise<number>;
12
+ /** Directory mode. Walks every `.luau`/`.lua` under `inputDir` and writes
13
+ * a mirrored tree under `outputDir`. */
14
+ export declare function compileDirMode(inputArg: string, outputArg: string, opts: ModeOptions): Promise<number>;
15
+ /** Rojo project mode. Walks `default.project.json` (or the given file)
16
+ * and emits one `.ts` per discovered Luau script, mirroring the project's
17
+ * on-disk layout under `outputDir`. */
18
+ export declare function compileProjectMode(projectArg: string, outputArg: string, opts: ModeOptions): Promise<number>;
19
+ export { extname };
20
+ //# sourceMappingURL=modes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modes.d.ts","sourceRoot":"","sources":["../../src/cli/modes.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,OAAO,EAA2B,MAAM,WAAW,CAAC;AAIhF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;IAC7B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AA0ED,uEAAuE;AACvE,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CAiBjB;AAED;yCACyC;AACzC,wBAAsB,cAAc,CAClC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CAuBjB;AAkBD;;wCAEwC;AACxC,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,MAAM,CAAC,CAkBjB;AAID,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,145 @@
1
+ import { mkdir, readdir, readFile, stat, writeFile } from 'node:fs/promises';
2
+ import { basename, dirname, extname, join, relative, resolve } from 'node:path';
3
+ import { compile } from '../compile/index.js';
4
+ import { loadProject } from '../rojo/index.js';
5
+ import { classifyFile } from '../rojo/walk-tree.js';
6
+ function compileOptionsFor(sourceFile, opts) {
7
+ const out = {
8
+ sourceFile,
9
+ compatMode: opts.mode,
10
+ };
11
+ if (opts.sourcemap)
12
+ out.sourceMap = true;
13
+ // Forward only EXPLICIT overrides; leave defaults to compile().
14
+ if (opts.checkTs !== undefined)
15
+ out.postEmitCheck = opts.checkTs;
16
+ if (opts.checkLuau !== undefined)
17
+ out.preEmitCheck = opts.checkLuau;
18
+ if (opts.typeCheck !== undefined)
19
+ out.typeCheck = opts.typeCheck;
20
+ return out;
21
+ }
22
+ function reportErrors(filePath, result) {
23
+ if (result.errors.length === 0)
24
+ return false;
25
+ for (const err of result.errors) {
26
+ // Parser/check errors carry a loc: { start: { line, col }, end }.
27
+ // Walk through both shapes defensively so a future error variant
28
+ // with a flat {line, col} still formats sensibly.
29
+ const e = err;
30
+ const line = e.loc?.start?.line ?? e.line ?? 0;
31
+ const col = e.loc?.start?.col ?? e.col ?? 0;
32
+ const msg = e.message ?? String(err);
33
+ process.stderr.write(`${filePath}:${line}:${col}: ${msg}\n`);
34
+ }
35
+ return true;
36
+ }
37
+ async function writeCompiled(outPath, result, sourcemap) {
38
+ await mkdir(dirname(outPath), { recursive: true });
39
+ let source = result.source;
40
+ if (sourcemap && result.sourceMap) {
41
+ const mapPath = `${outPath}.map`;
42
+ await writeFile(mapPath, JSON.stringify(result.sourceMap), 'utf8');
43
+ source += `//# sourceMappingURL=${basename(mapPath)}\n`;
44
+ }
45
+ await writeFile(outPath, source, 'utf8');
46
+ }
47
+ /** Translate a .luau source filename to its .ts counterpart, preserving
48
+ * Rojo-style `.server` / `.client` suffixes so the output still maps to
49
+ * the original instance kind. */
50
+ function tsCounterpart(filename) {
51
+ const lower = filename.toLowerCase();
52
+ const replacements = [
53
+ { from: '.server.luau', to: '.server.ts' },
54
+ { from: '.server.lua', to: '.server.ts' },
55
+ { from: '.client.luau', to: '.client.ts' },
56
+ { from: '.client.lua', to: '.client.ts' },
57
+ { from: '.luau', to: '.ts' },
58
+ { from: '.lua', to: '.ts' },
59
+ ];
60
+ for (const { from, to } of replacements) {
61
+ if (lower.endsWith(from)) {
62
+ return filename.slice(0, filename.length - from.length) + to;
63
+ }
64
+ }
65
+ return filename;
66
+ }
67
+ /** Single-file mode. If `outputArg` is undefined, writes to stdout. */
68
+ export async function compileFileMode(inputArg, outputArg, opts) {
69
+ const abs = resolve(inputArg);
70
+ const source = await readFile(abs, 'utf8');
71
+ const result = await compile(source, compileOptionsFor(abs, opts));
72
+ const hadErrors = reportErrors(abs, result);
73
+ if (outputArg === undefined || outputArg === '-') {
74
+ process.stdout.write(result.source);
75
+ if (opts.sourcemap && result.sourceMap) {
76
+ process.stderr.write(`[luau2ts] --sourcemap with stdout is a no-op; pass -o to emit a .ts.map.\n`);
77
+ }
78
+ }
79
+ else {
80
+ await writeCompiled(resolve(outputArg), result, opts.sourcemap);
81
+ }
82
+ return hadErrors ? 1 : 0;
83
+ }
84
+ /** Directory mode. Walks every `.luau`/`.lua` under `inputDir` and writes
85
+ * a mirrored tree under `outputDir`. */
86
+ export async function compileDirMode(inputArg, outputArg, opts) {
87
+ const inputRoot = resolve(inputArg);
88
+ const outputRoot = resolve(outputArg);
89
+ const inputStat = await stat(inputRoot);
90
+ if (!inputStat.isDirectory()) {
91
+ throw new Error(`Not a directory: ${inputArg}`);
92
+ }
93
+ let anyErrors = false;
94
+ let compiledCount = 0;
95
+ await walkDir(inputRoot, async (filePath) => {
96
+ if (!classifyFile(basename(filePath)))
97
+ return;
98
+ const source = await readFile(filePath, 'utf8');
99
+ const result = await compile(source, compileOptionsFor(filePath, opts));
100
+ if (reportErrors(filePath, result))
101
+ anyErrors = true;
102
+ const rel = relative(inputRoot, filePath);
103
+ const outRel = join(dirname(rel), tsCounterpart(basename(rel)));
104
+ await writeCompiled(join(outputRoot, outRel), result, opts.sourcemap);
105
+ compiledCount += 1;
106
+ });
107
+ process.stderr.write(`[luau2ts] compiled ${compiledCount} file(s) into ${outputRoot}\n`);
108
+ return anyErrors ? 1 : 0;
109
+ }
110
+ async function walkDir(dir, visit) {
111
+ const entries = await readdir(dir);
112
+ for (const entry of entries.sort()) {
113
+ const full = join(dir, entry);
114
+ const st = await stat(full);
115
+ if (st.isDirectory()) {
116
+ await walkDir(full, visit);
117
+ }
118
+ else if (st.isFile()) {
119
+ await visit(full);
120
+ }
121
+ }
122
+ }
123
+ /** Rojo project mode. Walks `default.project.json` (or the given file)
124
+ * and emits one `.ts` per discovered Luau script, mirroring the project's
125
+ * on-disk layout under `outputDir`. */
126
+ export async function compileProjectMode(projectArg, outputArg, opts) {
127
+ const project = await loadProject(projectArg);
128
+ const outputRoot = resolve(outputArg);
129
+ const projectDir = dirname(project.projectFile);
130
+ let anyErrors = false;
131
+ for (const entry of project.scripts) {
132
+ const result = await compile(entry.source, compileOptionsFor(entry.filePath, opts));
133
+ if (reportErrors(entry.filePath, result))
134
+ anyErrors = true;
135
+ const rel = relative(projectDir, entry.filePath);
136
+ const outRel = join(dirname(rel), tsCounterpart(basename(rel)));
137
+ await writeCompiled(join(outputRoot, outRel), result, opts.sourcemap);
138
+ }
139
+ process.stderr.write(`[luau2ts] compiled ${project.scripts.length} script(s) from ${project.name} into ${outputRoot}\n`);
140
+ return anyErrors ? 1 : 0;
141
+ }
142
+ // Surface extname so the v8 minifier doesn't drop it as unused; we keep
143
+ // the import explicit since it's used by tests of this module externally.
144
+ export { extname };
145
+ //# sourceMappingURL=modes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"modes.js","sourceRoot":"","sources":["../../src/cli/modes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,E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AE,IAAI,CAAC,CAAC,CAAC;QACpF,IAAI,YAAY,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,CAAC;YAAE,SAAS,GAAG,IAAI,CAAC;QAC3D,MAAM,GAAG,GAAG,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;QACjD,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChE,MAAM,aAAa,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACxE,CAAC;IAED,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,sBAAsB,OAAO,CAAC,OAAO,CAAC,MAAM,mBAAmB,OAAO,CAAC,IAAI,SAAS,UAAU,IAAI,CACnG,CAAC;IACF,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3B,CAAC;AAED,wEAAwE;AACxE,0EAA0E;AAC1E,OAAO,EAAE,OAAO,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ import ts from 'typescript';
2
+ import type { Expr, FunctionStat, Stat } from '../parser/index.js';
3
+ import type { CompileContext } from './context.js';
4
+ /** A detected class definition. The compiler will emit a single
5
+ * `ts.ClassDeclaration` covering every statement in `consumed`; the
6
+ * caller skips those statements when building its own output. */
7
+ export interface ClassPattern {
8
+ /** Class name. */
9
+ name: string;
10
+ /** Optional superclass identifier (from the metatable's `__index`). */
11
+ superclass: string | null;
12
+ /** Indexes (within the parent block's body) of every statement that
13
+ * contributes to the class — declaration, __index, .new factory,
14
+ * :constructor, and every :method. The block compiler skips these. */
15
+ consumed: Set<number>;
16
+ /** The .new factory statement (only used to harvest the constructor
17
+ * body if `:constructor` is missing). */
18
+ ctorFactory: FunctionStat | null;
19
+ /** The :constructor method statement, if any. */
20
+ constructor: FunctionStat | null;
21
+ /** All :method statements, in source order. */
22
+ methods: FunctionStat[];
23
+ }
24
+ /** Walk a flat list of statements and detect class patterns. Returns the
25
+ * detected classes plus the union of consumed indexes (so callers can
26
+ * skip them in the regular pipeline). */
27
+ export declare function detectClasses(stmts: Stat[]): ClassPattern[];
28
+ /** Compile a detected class pattern into a TS `class` declaration. The
29
+ * returned node replaces the consumed statements in the output. */
30
+ export declare function compileClassPattern(pattern: ClassPattern, ctx: CompileContext, compileBlockBody: (body: Stat, ctx: CompileContext) => ts.Statement[], compileExpr: (expr: Expr, ctx: CompileContext) => ts.Expression): ts.ClassDeclaration;
31
+ //# sourceMappingURL=class-shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class-shape.d.ts","sourceRoot":"","sources":["../../src/compile/class-shape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAEV,IAAI,EACJ,YAAY,EAEZ,IAAI,EACL,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAInD;;kEAEkE;AAClE,MAAM,WAAW,YAAY;IAC3B,kBAAkB;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,uEAAuE;IACvE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;2EAEuE;IACvE,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACtB;8CAC0C;IAC1C,WAAW,EAAE,YAAY,GAAG,IAAI,CAAC;IACjC,iDAAiD;IACjD,WAAW,EAAE,YAAY,GAAG,IAAI,CAAC;IACjC,+CAA+C;IAC/C,OAAO,EAAE,YAAY,EAAE,CAAC;CACzB;AAED;;0CAE0C;AAC1C,wBAAgB,aAAa,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,YAAY,EAAE,CAmD3D;AAkED;oEACoE;AACpE,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,YAAY,EACrB,GAAG,EAAE,cAAc,EACnB,gBAAgB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,KAAK,EAAE,CAAC,SAAS,EAAE,EACrE,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,KAAK,EAAE,CAAC,UAAU,GAC9D,EAAE,CAAC,gBAAgB,CAmErB"}