luau2ts 0.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.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +107 -0
  3. package/dist/cli/args.d.ts +19 -0
  4. package/dist/cli/args.d.ts.map +1 -0
  5. package/dist/cli/args.js +130 -0
  6. package/dist/cli/args.js.map +1 -0
  7. package/dist/cli/bin.d.ts +3 -0
  8. package/dist/cli/bin.d.ts.map +1 -0
  9. package/dist/cli/bin.js +65 -0
  10. package/dist/cli/bin.js.map +1 -0
  11. package/dist/cli/modes.d.ts +17 -0
  12. package/dist/cli/modes.d.ts.map +1 -0
  13. package/dist/cli/modes.js +134 -0
  14. package/dist/cli/modes.js.map +1 -0
  15. package/dist/compile/class-shape.d.ts +31 -0
  16. package/dist/compile/class-shape.d.ts.map +1 -0
  17. package/dist/compile/class-shape.js +291 -0
  18. package/dist/compile/class-shape.js.map +1 -0
  19. package/dist/compile/context.d.ts +86 -0
  20. package/dist/compile/context.d.ts.map +1 -0
  21. package/dist/compile/context.js +144 -0
  22. package/dist/compile/context.js.map +1 -0
  23. package/dist/compile/index.d.ts +43 -0
  24. package/dist/compile/index.d.ts.map +1 -0
  25. package/dist/compile/index.js +2028 -0
  26. package/dist/compile/index.js.map +1 -0
  27. package/dist/compile/macros/datatypes.d.ts +2 -0
  28. package/dist/compile/macros/datatypes.d.ts.map +1 -0
  29. package/dist/compile/macros/datatypes.js +76 -0
  30. package/dist/compile/macros/datatypes.js.map +1 -0
  31. package/dist/compile/macros/index.d.ts +33 -0
  32. package/dist/compile/macros/index.d.ts.map +1 -0
  33. package/dist/compile/macros/index.js +71 -0
  34. package/dist/compile/macros/index.js.map +1 -0
  35. package/dist/compile/macros/instance.d.ts +2 -0
  36. package/dist/compile/macros/instance.d.ts.map +1 -0
  37. package/dist/compile/macros/instance.js +58 -0
  38. package/dist/compile/macros/instance.js.map +1 -0
  39. package/dist/compile/macros/stdlib.d.ts +2 -0
  40. package/dist/compile/macros/stdlib.d.ts.map +1 -0
  41. package/dist/compile/macros/stdlib.js +140 -0
  42. package/dist/compile/macros/stdlib.js.map +1 -0
  43. package/dist/compile/rbxts-runtime.d.ts +2 -0
  44. package/dist/compile/rbxts-runtime.d.ts.map +1 -0
  45. package/dist/compile/rbxts-runtime.js +163 -0
  46. package/dist/compile/rbxts-runtime.js.map +1 -0
  47. package/dist/compile/sourcemap.d.ts +25 -0
  48. package/dist/compile/sourcemap.d.ts.map +1 -0
  49. package/dist/compile/sourcemap.js +71 -0
  50. package/dist/compile/sourcemap.js.map +1 -0
  51. package/dist/compile/type.d.ts +6 -0
  52. package/dist/compile/type.d.ts.map +1 -0
  53. package/dist/compile/type.js +122 -0
  54. package/dist/compile/type.js.map +1 -0
  55. package/dist/compile/util.d.ts +38 -0
  56. package/dist/compile/util.d.ts.map +1 -0
  57. package/dist/compile/util.js +153 -0
  58. package/dist/compile/util.js.map +1 -0
  59. package/dist/index.d.ts +3 -0
  60. package/dist/index.d.ts.map +1 -0
  61. package/dist/index.js +7 -0
  62. package/dist/index.js.map +1 -0
  63. package/dist/parser/index.d.ts +4 -0
  64. package/dist/parser/index.d.ts.map +1 -0
  65. package/dist/parser/index.js +227 -0
  66. package/dist/parser/index.js.map +1 -0
  67. package/dist/parser/types.d.ts +430 -0
  68. package/dist/parser/types.d.ts.map +1 -0
  69. package/dist/parser/types.js +14 -0
  70. package/dist/parser/types.js.map +1 -0
  71. package/dist/parser/wasm/luau-parser.d.mts +21 -0
  72. package/dist/parser/wasm/luau-parser.mjs +2 -0
  73. package/dist/parser/wasm/luau-parser.wasm +0 -0
  74. package/dist/rojo/index.d.ts +4 -0
  75. package/dist/rojo/index.d.ts.map +1 -0
  76. package/dist/rojo/index.js +3 -0
  77. package/dist/rojo/index.js.map +1 -0
  78. package/dist/rojo/load-project.d.ts +12 -0
  79. package/dist/rojo/load-project.d.ts.map +1 -0
  80. package/dist/rojo/load-project.js +35 -0
  81. package/dist/rojo/load-project.js.map +1 -0
  82. package/dist/rojo/types.d.ts +39 -0
  83. package/dist/rojo/types.d.ts.map +1 -0
  84. package/dist/rojo/types.js +2 -0
  85. package/dist/rojo/types.js.map +1 -0
  86. package/dist/rojo/walk-tree.d.ts +40 -0
  87. package/dist/rojo/walk-tree.d.ts.map +1 -0
  88. package/dist/rojo/walk-tree.js +164 -0
  89. package/dist/rojo/walk-tree.js.map +1 -0
  90. package/dist/runtime/arith.d.ts +13 -0
  91. package/dist/runtime/arith.d.ts.map +1 -0
  92. package/dist/runtime/arith.js +151 -0
  93. package/dist/runtime/arith.js.map +1 -0
  94. package/dist/runtime/index-helper.d.ts +3 -0
  95. package/dist/runtime/index-helper.d.ts.map +1 -0
  96. package/dist/runtime/index-helper.js +40 -0
  97. package/dist/runtime/index-helper.js.map +1 -0
  98. package/dist/runtime/index.d.ts +13 -0
  99. package/dist/runtime/index.d.ts.map +1 -0
  100. package/dist/runtime/index.js +13 -0
  101. package/dist/runtime/index.js.map +1 -0
  102. package/dist/runtime/iterator.d.ts +58 -0
  103. package/dist/runtime/iterator.d.ts.map +1 -0
  104. package/dist/runtime/iterator.js +181 -0
  105. package/dist/runtime/iterator.js.map +1 -0
  106. package/dist/runtime/length.d.ts +2 -0
  107. package/dist/runtime/length.d.ts.map +1 -0
  108. package/dist/runtime/length.js +15 -0
  109. package/dist/runtime/length.js.map +1 -0
  110. package/dist/runtime/lua-stdlib.d.ts +186 -0
  111. package/dist/runtime/lua-stdlib.d.ts.map +1 -0
  112. package/dist/runtime/lua-stdlib.js +502 -0
  113. package/dist/runtime/lua-stdlib.js.map +1 -0
  114. package/dist/runtime/metatable.d.ts +16 -0
  115. package/dist/runtime/metatable.d.ts.map +1 -0
  116. package/dist/runtime/metatable.js +129 -0
  117. package/dist/runtime/metatable.js.map +1 -0
  118. package/dist/runtime/pattern.d.ts +21 -0
  119. package/dist/runtime/pattern.d.ts.map +1 -0
  120. package/dist/runtime/pattern.js +375 -0
  121. package/dist/runtime/pattern.js.map +1 -0
  122. package/dist/runtime/pcall.d.ts +12 -0
  123. package/dist/runtime/pcall.d.ts.map +1 -0
  124. package/dist/runtime/pcall.js +54 -0
  125. package/dist/runtime/pcall.js.map +1 -0
  126. package/dist/runtime/string-lib.d.ts +31 -0
  127. package/dist/runtime/string-lib.d.ts.map +1 -0
  128. package/dist/runtime/string-lib.js +296 -0
  129. package/dist/runtime/string-lib.js.map +1 -0
  130. package/dist/runtime/table-lib.d.ts +18 -0
  131. package/dist/runtime/table-lib.d.ts.map +1 -0
  132. package/dist/runtime/table-lib.js +133 -0
  133. package/dist/runtime/table-lib.js.map +1 -0
  134. package/dist/runtime/tostring.d.ts +3 -0
  135. package/dist/runtime/tostring.d.ts.map +1 -0
  136. package/dist/runtime/tostring.js +82 -0
  137. package/dist/runtime/tostring.js.map +1 -0
  138. package/dist/runtime/truthy.d.ts +13 -0
  139. package/dist/runtime/truthy.d.ts.map +1 -0
  140. package/dist/runtime/truthy.js +26 -0
  141. package/dist/runtime/truthy.js.map +1 -0
  142. package/package.json +70 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tony Bolivar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,107 @@
1
+ <div align="center">
2
+ <img src="static/img/logo.png" alt="luau2ts" width="200" />
3
+
4
+ # luau2ts
5
+
6
+ **A Luau-to-TypeScript compiler for Roblox.**
7
+
8
+ [![CI](https://github.com/luau2ts/luau2ts/actions/workflows/test.yml/badge.svg)](https://github.com/luau2ts/luau2ts/actions/workflows/test.yml)
9
+ [![codecov](https://codecov.io/gh/luau2ts/luau2ts/branch/main/graph/badge.svg)](https://codecov.io/gh/luau2ts/luau2ts)
10
+ [![npm](https://img.shields.io/npm/v/luau2ts.svg)](https://www.npmjs.com/package/luau2ts)
11
+ [![downloads](https://img.shields.io/npm/dm/luau2ts.svg)](https://www.npmjs.com/package/luau2ts)
12
+ [![license](https://img.shields.io/npm/l/luau2ts.svg)](./LICENSE)
13
+ [![node](https://img.shields.io/node/v/luau2ts.svg)](https://www.npmjs.com/package/luau2ts)
14
+ </div>
15
+
16
+ ## Why?
17
+
18
+ [`roblox-ts`](https://roblox-ts.com) compiles TypeScript to Luau so Roblox developers can write strongly-typed game code in TS.
19
+
20
+ `luau2ts` is the mirror: it compiles **Luau to TypeScript**. Use it to migrate an existing Luau codebase to TypeScript, to keep two parallel runtimes in sync, or to run authored Luau through TS-native tooling. Output is idiomatic, readable TS, with optional 1:1 line-mapped source maps and a roblox-ts-compatible emit mode.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ npm install -g luau2ts
26
+ ```
27
+
28
+ Or as a project dependency:
29
+
30
+ ```bash
31
+ npm install --save-dev luau2ts
32
+ ```
33
+
34
+ ## Quick start
35
+
36
+ Compile a single file:
37
+
38
+ ```bash
39
+ luau2ts foo.luau # → stdout
40
+ luau2ts foo.luau -o foo.ts # → foo.ts
41
+ ```
42
+
43
+ Compile every `.luau` and `.lua` file in a directory tree:
44
+
45
+ ```bash
46
+ luau2ts src/ -o out/
47
+ ```
48
+
49
+ Walk a Rojo project file and emit a parallel TypeScript tree:
50
+
51
+ ```bash
52
+ luau2ts -p default.project.json -o out/
53
+ ```
54
+
55
+ Use it as a library:
56
+
57
+ ```ts
58
+ import { compile } from 'luau2ts';
59
+
60
+ const result = await compile(`
61
+ local function greet(name)
62
+ print("Hello, " .. name)
63
+ end
64
+ `);
65
+
66
+ console.log(result.source);
67
+ // // Compiled by luau2ts v0.1.0 (do not edit).
68
+ // function greet(name) {
69
+ // print(`Hello, ${name}`);
70
+ // }
71
+ ```
72
+
73
+ ## Compatibility
74
+
75
+ `luau2ts` ships two emit modes. Switch with `--mode <name>` or `compatMode` in the library API.
76
+
77
+ | Mode | What it emits | Pairs with |
78
+ |---|---|---|
79
+ | `rbxts` (default) | TS that mirrors what [roblox-ts](https://roblox-ts.com) accepts as input: `new Vector3(...)`, `import { Workspace } from '@rbxts/services'`, 0-indexed arrays for statically-typed arrays. | [`@rbxts/types`](https://www.npmjs.com/package/@rbxts/types), [`@rbxts/services`](https://www.npmjs.com/package/@rbxts/services), [`@rbxts/promise`](https://www.npmjs.com/package/@rbxts/promise), the `roblox-ts` build pipeline. |
80
+ | `native` | TS that imports stdlib helpers from `luau2ts/runtime` (`luaIndex`, `lualen`, `pairKeys`, `multiret`, ...) and uses Roblox's native API surface (`Vector3.new(...)`, `game:GetService(...)`, 1-indexed arrays). | A host runtime that mirrors Roblox's Luau API surface. |
81
+
82
+ ## Status
83
+
84
+ | | |
85
+ |---|---|
86
+ | Luau conformance | **53 / 53** upstream conformance tests pass (100%) |
87
+ | Tests | **255 passing** across **9 test files** |
88
+ | Roblox API coverage (rbxts mode) | **4798 / 4798** members across **682 classes** (100%) |
89
+
90
+ ## Docs
91
+
92
+ Full guide and API reference at **[luau2ts.dev](https://luau2ts.com)**.
93
+
94
+ Highlights:
95
+ - [Quick start](https://luau2ts.com/docs/quick-start)
96
+ - [Setup guide](https://luau2ts.com/docs/setup-guide)
97
+ - [CLI usage](https://luau2ts.com/docs/usage)
98
+ - [Rojo project conversion](https://luau2ts.com/docs/guides/rojo-project-conversion)
99
+ - [Using with roblox-ts](https://luau2ts.com/docs/guides/using-with-roblox-ts)
100
+
101
+ ## Contributing
102
+
103
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for build / test / release workflow.
104
+
105
+ ## License
106
+
107
+ [MIT](./LICENSE) © Tony Bolivar
@@ -0,0 +1,19 @@
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
+ help: boolean;
13
+ version: boolean;
14
+ }
15
+ export declare class ArgError extends Error {
16
+ }
17
+ export declare function parseArgs(argv: string[]): ParsedArgs;
18
+ export declare const HELP_TEXT = "luau2ts \u2014 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) \u2014 emits TS that imports from\n @rbxts/types, @rbxts/services,\n etc. Pairs with roblox-ts.\n native \u2014 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 -h, --help Show this help text.\n -v, --version Print the installed luau2ts version.\n";
19
+ //# 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,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,CAkGpD;AAED,eAAO,MAAM,SAAS,+sDA4BrB,CAAC"}
@@ -0,0 +1,130 @@
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
+ help: false,
11
+ version: false,
12
+ };
13
+ const positional = [];
14
+ let i = 0;
15
+ while (i < argv.length) {
16
+ const arg = argv[i];
17
+ if (arg === '--') {
18
+ // All remaining args are positional, mirroring POSIX convention.
19
+ for (let j = i + 1; j < argv.length; j += 1)
20
+ positional.push(argv[j]);
21
+ break;
22
+ }
23
+ if (arg === '-h' || arg === '--help') {
24
+ result.help = true;
25
+ i += 1;
26
+ continue;
27
+ }
28
+ if (arg === '-v' || arg === '--version') {
29
+ result.version = true;
30
+ i += 1;
31
+ continue;
32
+ }
33
+ if (arg === '--sourcemap') {
34
+ result.sourcemap = true;
35
+ i += 1;
36
+ continue;
37
+ }
38
+ if (arg === '-o' || arg === '--output') {
39
+ const value = argv[i + 1];
40
+ if (value === undefined)
41
+ throw new ArgError(`Missing value for ${arg}`);
42
+ result.output = value;
43
+ i += 2;
44
+ continue;
45
+ }
46
+ if (arg.startsWith('--output=')) {
47
+ result.output = arg.slice('--output='.length);
48
+ i += 1;
49
+ continue;
50
+ }
51
+ if (arg === '-p' || arg === '--project') {
52
+ const value = argv[i + 1];
53
+ if (value === undefined)
54
+ throw new ArgError(`Missing value for ${arg}`);
55
+ result.project = value;
56
+ i += 2;
57
+ continue;
58
+ }
59
+ if (arg.startsWith('--project=')) {
60
+ result.project = arg.slice('--project='.length);
61
+ i += 1;
62
+ continue;
63
+ }
64
+ if (arg === '--mode') {
65
+ const value = argv[i + 1];
66
+ if (value === undefined)
67
+ throw new ArgError('Missing value for --mode');
68
+ if (value !== 'rbxts' && value !== 'native') {
69
+ throw new ArgError(`Invalid --mode value: ${value} (expected rbxts or native)`);
70
+ }
71
+ result.mode = value;
72
+ i += 2;
73
+ continue;
74
+ }
75
+ if (arg.startsWith('--mode=')) {
76
+ const value = arg.slice('--mode='.length);
77
+ if (value !== 'rbxts' && value !== 'native') {
78
+ throw new ArgError(`Invalid --mode value: ${value} (expected rbxts or native)`);
79
+ }
80
+ result.mode = value;
81
+ i += 1;
82
+ continue;
83
+ }
84
+ if (arg.startsWith('-')) {
85
+ throw new ArgError(`Unknown flag: ${arg}`);
86
+ }
87
+ positional.push(arg);
88
+ i += 1;
89
+ }
90
+ if (positional.length > 1) {
91
+ throw new ArgError(`Too many positional arguments (expected 0 or 1, got ${positional.length}). `
92
+ + `Use -o for the output target.`);
93
+ }
94
+ if (positional.length === 1)
95
+ result.input = positional[0];
96
+ if (result.input && result.project) {
97
+ throw new ArgError('Cannot use a positional input and -p / --project together.');
98
+ }
99
+ return result;
100
+ }
101
+ export const HELP_TEXT = `luau2ts — A Luau-to-TypeScript compiler for Roblox.
102
+
103
+ Usage:
104
+ luau2ts <file.luau> Compile one file. Writes to stdout.
105
+ luau2ts <file.luau> -o <file.ts> Compile one file. Writes to a file.
106
+ luau2ts <dir/> -o <out/> Compile every .luau/.lua under <dir/>.
107
+ Mirrors the input tree into <out/>.
108
+ luau2ts -p <default.project.json> -o <out/>
109
+ Walk a Rojo project file, compile
110
+ every script it references, and
111
+ emit a roblox-ts-shaped tree.
112
+
113
+ Flags:
114
+ -o, --output <path> Output file or directory. Default: stdout for
115
+ single-file input; required for dir/project.
116
+ -p, --project <path> Path to a Rojo *.project.json file, or a directory
117
+ containing default.project.json.
118
+ --mode <name> Emit compatibility mode. One of:
119
+ rbxts (default) — emits TS that imports from
120
+ @rbxts/types, @rbxts/services,
121
+ etc. Pairs with roblox-ts.
122
+ native — emits TS that imports stdlib
123
+ helpers from 'luau2ts/runtime'.
124
+ Pairs with a host runtime that
125
+ provides Roblox's Luau API.
126
+ --sourcemap Emit a .ts.map next to each .ts.
127
+ -h, --help Show this help text.
128
+ -v, --version Print the installed luau2ts version.
129
+ `;
130
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/cli/args.ts"],"names":[],"mappings":"AAgBA,MAAM,OAAO,QAAS,SAAQ,KAAK;CAAG;AAEtC,MAAM,UAAU,SAAS,CAAC,IAAc;IACtC,MAAM,MAAM,GAAe;QACzB,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,SAAS;QAClB,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,OAAO;QACb,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,KAAK;KACf,CAAC;IACF,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,CAAC,GAAG,IAAI,CAAC,MAA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M,IAAI,QAAQ,CAAC,yBAAyB,KAAK,6BAA6B,CAAC,CAAC;YAClF,CAAC;YACD,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC;YACpB,CAAC,IAAI,CAAC,CAAC;YACP,SAAS;QACX,CAAC;QACD,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACxB,MAAM,IAAI,QAAQ,CAAC,iBAAiB,GAAG,EAAE,CAAC,CAAC;QAC7C,CAAC;QACD,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC,IAAI,CAAC,CAAC;IACT,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,QAAQ,CAChB,uDAAuD,UAAU,CAAC,MAAM,KAAK;cACzE,+BAA+B,CACpC,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,CAAC,KAAK,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IAE1D,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnC,MAAM,IAAI,QAAQ,CAAC,4DAA4D,CAAC,CAAC;IACnF,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,SAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BxB,CAAC"}
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":""}
@@ -0,0 +1,65 @@
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 = { mode: args.mode, sourcemap: args.sourcemap };
31
+ if (args.project !== undefined) {
32
+ if (!args.output) {
33
+ process.stderr.write(`luau2ts: -p/--project requires -o/--output\n`);
34
+ return 2;
35
+ }
36
+ return compileProjectMode(args.project, args.output, opts);
37
+ }
38
+ if (args.input === undefined) {
39
+ process.stdout.write(HELP_TEXT);
40
+ return 0;
41
+ }
42
+ const inputAbs = resolve(args.input);
43
+ let inputStat;
44
+ try {
45
+ inputStat = await stat(inputAbs);
46
+ }
47
+ catch (err) {
48
+ const msg = err instanceof Error ? err.message : String(err);
49
+ process.stderr.write(`luau2ts: cannot read ${args.input}: ${msg}\n`);
50
+ return 1;
51
+ }
52
+ if (inputStat.isDirectory()) {
53
+ if (!args.output) {
54
+ process.stderr.write(`luau2ts: directory input requires -o/--output\n`);
55
+ return 2;
56
+ }
57
+ return compileDirMode(args.input, args.output, opts);
58
+ }
59
+ return compileFileMode(args.input, args.output, opts);
60
+ }
61
+ main().then((code) => process.exit(code), (err) => {
62
+ process.stderr.write(`luau2ts: ${err instanceof Error ? err.stack ?? err.message : String(err)}\n`);
63
+ process.exit(1);
64
+ });
65
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":";AACA,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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,17 @@
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
+ }
7
+ /** Single-file mode. If `outputArg` is undefined, writes to stdout. */
8
+ export declare function compileFileMode(inputArg: string, outputArg: string | undefined, opts: ModeOptions): Promise<number>;
9
+ /** Directory mode. Walks every `.luau`/`.lua` under `inputDir` and writes
10
+ * a mirrored tree under `outputDir`. */
11
+ export declare function compileDirMode(inputArg: string, outputArg: string, opts: ModeOptions): Promise<number>;
12
+ /** Rojo project mode. Walks `default.project.json` (or the given file)
13
+ * and emits one `.ts` per discovered Luau script, mirroring the project's
14
+ * on-disk layout under `outputDir`. */
15
+ export declare function compileProjectMode(projectArg: string, outputArg: string, opts: ModeOptions): Promise<number>;
16
+ export { extname };
17
+ //# 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;CACpB;AA6DD,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,134 @@
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
+ return out;
14
+ }
15
+ function reportErrors(filePath, result) {
16
+ if (result.errors.length === 0)
17
+ return false;
18
+ for (const err of result.errors) {
19
+ const line = err.line ?? 0;
20
+ const col = err.col ?? 0;
21
+ const msg = err.message ?? String(err);
22
+ process.stderr.write(`${filePath}:${line}:${col}: ${msg}\n`);
23
+ }
24
+ return true;
25
+ }
26
+ async function writeCompiled(outPath, result, sourcemap) {
27
+ await mkdir(dirname(outPath), { recursive: true });
28
+ let source = result.source;
29
+ if (sourcemap && result.sourceMap) {
30
+ const mapPath = `${outPath}.map`;
31
+ await writeFile(mapPath, JSON.stringify(result.sourceMap), 'utf8');
32
+ source += `//# sourceMappingURL=${basename(mapPath)}\n`;
33
+ }
34
+ await writeFile(outPath, source, 'utf8');
35
+ }
36
+ /** Translate a .luau source filename to its .ts counterpart, preserving
37
+ * Rojo-style `.server` / `.client` suffixes so the output still maps to
38
+ * the original instance kind. */
39
+ function tsCounterpart(filename) {
40
+ const lower = filename.toLowerCase();
41
+ const replacements = [
42
+ { from: '.server.luau', to: '.server.ts' },
43
+ { from: '.server.lua', to: '.server.ts' },
44
+ { from: '.client.luau', to: '.client.ts' },
45
+ { from: '.client.lua', to: '.client.ts' },
46
+ { from: '.luau', to: '.ts' },
47
+ { from: '.lua', to: '.ts' },
48
+ ];
49
+ for (const { from, to } of replacements) {
50
+ if (lower.endsWith(from)) {
51
+ return filename.slice(0, filename.length - from.length) + to;
52
+ }
53
+ }
54
+ return filename;
55
+ }
56
+ /** Single-file mode. If `outputArg` is undefined, writes to stdout. */
57
+ export async function compileFileMode(inputArg, outputArg, opts) {
58
+ const abs = resolve(inputArg);
59
+ const source = await readFile(abs, 'utf8');
60
+ const result = await compile(source, compileOptionsFor(abs, opts));
61
+ const hadErrors = reportErrors(abs, result);
62
+ if (outputArg === undefined || outputArg === '-') {
63
+ process.stdout.write(result.source);
64
+ if (opts.sourcemap && result.sourceMap) {
65
+ process.stderr.write(`[luau2ts] --sourcemap with stdout is a no-op; pass -o to emit a .ts.map.\n`);
66
+ }
67
+ }
68
+ else {
69
+ await writeCompiled(resolve(outputArg), result, opts.sourcemap);
70
+ }
71
+ return hadErrors ? 1 : 0;
72
+ }
73
+ /** Directory mode. Walks every `.luau`/`.lua` under `inputDir` and writes
74
+ * a mirrored tree under `outputDir`. */
75
+ export async function compileDirMode(inputArg, outputArg, opts) {
76
+ const inputRoot = resolve(inputArg);
77
+ const outputRoot = resolve(outputArg);
78
+ const inputStat = await stat(inputRoot);
79
+ if (!inputStat.isDirectory()) {
80
+ throw new Error(`Not a directory: ${inputArg}`);
81
+ }
82
+ let anyErrors = false;
83
+ let compiledCount = 0;
84
+ await walkDir(inputRoot, async (filePath) => {
85
+ if (!classifyFile(basename(filePath)))
86
+ return;
87
+ const source = await readFile(filePath, 'utf8');
88
+ const result = await compile(source, compileOptionsFor(filePath, opts));
89
+ if (reportErrors(filePath, result))
90
+ anyErrors = true;
91
+ const rel = relative(inputRoot, filePath);
92
+ const outRel = join(dirname(rel), tsCounterpart(basename(rel)));
93
+ await writeCompiled(join(outputRoot, outRel), result, opts.sourcemap);
94
+ compiledCount += 1;
95
+ });
96
+ process.stderr.write(`[luau2ts] compiled ${compiledCount} file(s) into ${outputRoot}\n`);
97
+ return anyErrors ? 1 : 0;
98
+ }
99
+ async function walkDir(dir, visit) {
100
+ const entries = await readdir(dir);
101
+ for (const entry of entries.sort()) {
102
+ const full = join(dir, entry);
103
+ const st = await stat(full);
104
+ if (st.isDirectory()) {
105
+ await walkDir(full, visit);
106
+ }
107
+ else if (st.isFile()) {
108
+ await visit(full);
109
+ }
110
+ }
111
+ }
112
+ /** Rojo project mode. Walks `default.project.json` (or the given file)
113
+ * and emits one `.ts` per discovered Luau script, mirroring the project's
114
+ * on-disk layout under `outputDir`. */
115
+ export async function compileProjectMode(projectArg, outputArg, opts) {
116
+ const project = await loadProject(projectArg);
117
+ const outputRoot = resolve(outputArg);
118
+ const projectDir = dirname(project.projectFile);
119
+ let anyErrors = false;
120
+ for (const entry of project.scripts) {
121
+ const result = await compile(entry.source, compileOptionsFor(entry.filePath, opts));
122
+ if (reportErrors(entry.filePath, result))
123
+ anyErrors = true;
124
+ const rel = relative(projectDir, entry.filePath);
125
+ const outRel = join(dirname(rel), tsCounterpart(basename(rel)));
126
+ await writeCompiled(join(outputRoot, outRel), result, opts.sourcemap);
127
+ }
128
+ process.stderr.write(`[luau2ts] compiled ${project.scripts.length} script(s) from ${project.name} into ${outputRoot}\n`);
129
+ return anyErrors ? 1 : 0;
130
+ }
131
+ // Surface extname so the v8 minifier doesn't drop it as unused; we keep
132
+ // the import explicit since it's used by tests of this module externally.
133
+ export { extname };
134
+ //# 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,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EAAE,OAAO,EAA2C,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD,SAAS,iBAAiB,CACxB,UAAkB,EAClB,IAAiB;IAEjB,MAAM,GAAG,GAAmB;QAC1B,UAAU;QACV,UAAU,EAAE,IAAI,CAAC,IAAI;KACtB,CAAC;IACF,IAAI,IAAI,CAAC,SAAS;QAAE,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;IACzC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,YAAY,CAAC,QAAgB,EAAE,MAAqB;IAC3D,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAChC,MAAM,IAAI,GAAI,GAAyB,CAAC,IAAI,IAAI,CAAC,CAAC;QAClD,MAAM,GAAG,GAAI,GAAwB,CAAC,GAAG,IAAI,CAAC,CAAC;QAC/C,MAAM,GAAG,GAAI,GAA4B,CAAC,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;QACjE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,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AAG,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"}