@data-vegle/rbxts-go 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +181 -2
  3. package/README.rbxtsgo.md +169 -0
  4. package/THIRD_PARTY_NOTICES.md +745 -0
  5. package/cli/cli.go +454 -0
  6. package/compile/compile.go +388 -0
  7. package/compile/declarations.go +221 -0
  8. package/compile/incremental.go +349 -0
  9. package/compile/times.go +9 -0
  10. package/docs/plugin-api.md +243 -0
  11. package/go.mod +20 -0
  12. package/go.sum +24 -0
  13. package/internal/difftest/difftest.go +530 -0
  14. package/internal/plugintest/plugintest.go +181 -0
  15. package/luau/create.go +351 -0
  16. package/luau/doc.go +71 -0
  17. package/luau/globals.go +178 -0
  18. package/luau/jsnum.go +188 -0
  19. package/luau/kinds.go +128 -0
  20. package/luau/list.go +227 -0
  21. package/luau/nodes.go +479 -0
  22. package/luau/operators.go +46 -0
  23. package/luau/render.go +134 -0
  24. package/luau/render_expressions.go +264 -0
  25. package/luau/render_fields.go +81 -0
  26. package/luau/render_indexable.go +81 -0
  27. package/luau/render_state.go +134 -0
  28. package/luau/render_statements.go +235 -0
  29. package/luau/render_util.go +296 -0
  30. package/luau/solve_temp_ids.go +212 -0
  31. package/luau/typeguards.go +175 -0
  32. package/luau/util.go +184 -0
  33. package/luau/visit.go +138 -0
  34. package/npm/index.d.ts +3 -0
  35. package/npm/rbxts-go.sh +187 -0
  36. package/package.json +45 -5
  37. package/patches/typescript/0001-checker-exports.patch +40 -0
  38. package/patches/typescript/0002-iterable-arity.patch +15 -0
  39. package/patches/typescript/0003-context-sensitive-this.patch +15 -0
  40. package/patches/typescript/0004-printer-keep-parse-tree-parentheses.patch +26 -0
  41. package/pluginapi/host.go +31 -0
  42. package/pluginapi/pluginapi.go +153 -0
  43. package/plugins/LICENSE-rbxts-transformer-setget +18 -0
  44. package/plugins/apply.go +342 -0
  45. package/plugins/config.go +431 -0
  46. package/plugins/fallback.go +84 -0
  47. package/plugins/fixemit.go +60 -0
  48. package/plugins/native.go +271 -0
  49. package/plugins/session.go +236 -0
  50. package/plugins/setget.go +478 -0
  51. package/project/copy.go +333 -0
  52. package/project/include/Promise.lua +2068 -0
  53. package/project/include/RuntimeLib.lua +260 -0
  54. package/project/nodepath/nodepath.go +917 -0
  55. package/project/pathtranslator/pathtranslator.go +214 -0
  56. package/project/project.go +498 -0
  57. package/project/rojoresolver/json.go +248 -0
  58. package/project/rojoresolver/rojoresolver.go +559 -0
  59. package/project/shared/constants.go +83 -0
  60. package/project/shared/diagnostic.go +238 -0
  61. package/project/shared/diagnostics.go +388 -0
  62. package/project/shared/elapsed.go +14 -0
  63. package/project/shared/eol_other.go +6 -0
  64. package/project/shared/eol_windows.go +4 -0
  65. package/project/shared/kleur.go +40 -0
  66. package/project/shared/util.go +183 -0
  67. package/scripts/build-with-plugins.sh +130 -0
  68. package/scripts/setup-third-party.sh +75 -0
  69. package/transformer/add_index_diagnostics.go +21 -0
  70. package/transformer/add_one_if_array_type.go +15 -0
  71. package/transformer/array_binding_pattern_contains_hoists.go +25 -0
  72. package/transformer/assert_never.go +24 -0
  73. package/transformer/assignment.go +64 -0
  74. package/transformer/call_macros.go +70 -0
  75. package/transformer/check_variable_hoist.go +125 -0
  76. package/transformer/clean_module_name.go +28 -0
  77. package/transformer/constructor_macros.go +122 -0
  78. package/transformer/convert_to_indexable_expression.go +12 -0
  79. package/transformer/create_binary_from_operator.go +86 -0
  80. package/transformer/create_continue_statements.go +68 -0
  81. package/transformer/create_get_service.go +15 -0
  82. package/transformer/create_hoist_declaration.go +27 -0
  83. package/transformer/create_import_expression.go +220 -0
  84. package/transformer/create_string_from_literal.go +195 -0
  85. package/transformer/create_truthiness_checks.go +63 -0
  86. package/transformer/create_type_check.go +9 -0
  87. package/transformer/ensure_transform_order.go +53 -0
  88. package/transformer/expression_chain.go +27 -0
  89. package/transformer/expression_might_mutate.go +60 -0
  90. package/transformer/find_constructor.go +15 -0
  91. package/transformer/fixup_whitespace_and_decode_entities.go +377 -0
  92. package/transformer/get_accessor_for_binding_type.go +160 -0
  93. package/transformer/get_add_iterable_to_array_builder.go +363 -0
  94. package/transformer/get_assignable_value.go +15 -0
  95. package/transformer/get_constant_value_literal.go +20 -0
  96. package/transformer/get_declared_variables.go +34 -0
  97. package/transformer/get_extends_node.go +23 -0
  98. package/transformer/get_flags.go +21 -0
  99. package/transformer/get_kind_name.go +18 -0
  100. package/transformer/get_original_symbol_of_node.go +16 -0
  101. package/transformer/get_source_file_from_module_specifier.go +68 -0
  102. package/transformer/get_statements.go +12 -0
  103. package/transformer/has_multiple_definitions.go +18 -0
  104. package/transformer/hoist_functions_past_final_statement.go +43 -0
  105. package/transformer/identifier_macros.go +17 -0
  106. package/transformer/is_blocked_by_try_statement.go +19 -0
  107. package/transformer/is_method.go +104 -0
  108. package/transformer/is_symbol_mutable.go +26 -0
  109. package/transformer/is_symbol_of_value.go +11 -0
  110. package/transformer/is_used_as_statement.go +25 -0
  111. package/transformer/is_valid_method_index_without_call.go +36 -0
  112. package/transformer/macro_manager.go +92 -0
  113. package/transformer/object_accessor.go +32 -0
  114. package/transformer/offset.go +58 -0
  115. package/transformer/pointer.go +53 -0
  116. package/transformer/property_call_macros.go +1035 -0
  117. package/transformer/state.go +606 -0
  118. package/transformer/transform_array_assignment_pattern.go +65 -0
  119. package/transformer/transform_array_binding_pattern.go +49 -0
  120. package/transformer/transform_array_literal_expression.go +97 -0
  121. package/transformer/transform_await_expression.go +12 -0
  122. package/transformer/transform_binary_expression.go +221 -0
  123. package/transformer/transform_binding_name.go +25 -0
  124. package/transformer/transform_block.go +14 -0
  125. package/transformer/transform_boolean_literal.go +13 -0
  126. package/transformer/transform_break_statement.go +26 -0
  127. package/transformer/transform_call_expression.go +266 -0
  128. package/transformer/transform_class_constructor.go +125 -0
  129. package/transformer/transform_class_declaration.go +12 -0
  130. package/transformer/transform_class_expression.go +14 -0
  131. package/transformer/transform_class_like_declaration.go +355 -0
  132. package/transformer/transform_conditional_expression.go +70 -0
  133. package/transformer/transform_continue_statement.go +30 -0
  134. package/transformer/transform_decorators.go +253 -0
  135. package/transformer/transform_delete_expression.go +17 -0
  136. package/transformer/transform_do_statement.go +39 -0
  137. package/transformer/transform_element_access_expression.go +114 -0
  138. package/transformer/transform_entity_name.go +21 -0
  139. package/transformer/transform_enum_declaration.go +135 -0
  140. package/transformer/transform_export_assignment.go +57 -0
  141. package/transformer/transform_export_declaration.go +150 -0
  142. package/transformer/transform_expression.go +120 -0
  143. package/transformer/transform_expression_statement.go +71 -0
  144. package/transformer/transform_for_of_statement.go +461 -0
  145. package/transformer/transform_for_statement.go +599 -0
  146. package/transformer/transform_function_declaration.go +84 -0
  147. package/transformer/transform_function_expression.go +48 -0
  148. package/transformer/transform_identifier.go +194 -0
  149. package/transformer/transform_if_statement.go +44 -0
  150. package/transformer/transform_import_declaration.go +146 -0
  151. package/transformer/transform_import_equals_declaration.go +46 -0
  152. package/transformer/transform_import_expression.go +36 -0
  153. package/transformer/transform_initializer.go +22 -0
  154. package/transformer/transform_interpolated_string_part.go +12 -0
  155. package/transformer/transform_jsx.go +41 -0
  156. package/transformer/transform_jsx_attributes.go +110 -0
  157. package/transformer/transform_jsx_children.go +50 -0
  158. package/transformer/transform_jsx_element.go +14 -0
  159. package/transformer/transform_jsx_expression.go +20 -0
  160. package/transformer/transform_jsx_fragment.go +42 -0
  161. package/transformer/transform_jsx_self_closing_element.go +13 -0
  162. package/transformer/transform_jsx_tag_name.go +53 -0
  163. package/transformer/transform_logical.go +160 -0
  164. package/transformer/transform_logical_or_coalescing_assignment_expression.go +103 -0
  165. package/transformer/transform_method_declaration.go +102 -0
  166. package/transformer/transform_module_declaration.go +143 -0
  167. package/transformer/transform_new_expression.go +27 -0
  168. package/transformer/transform_no_substitution_template_literal.go +16 -0
  169. package/transformer/transform_numeric_literal.go +15 -0
  170. package/transformer/transform_object_assignment_pattern.go +86 -0
  171. package/transformer/transform_object_binding_pattern.go +49 -0
  172. package/transformer/transform_object_literal_expression.go +107 -0
  173. package/transformer/transform_omitted_expression.go +9 -0
  174. package/transformer/transform_optional_chain.go +312 -0
  175. package/transformer/transform_parameters.go +124 -0
  176. package/transformer/transform_parenthesized_expression.go +17 -0
  177. package/transformer/transform_property_access_expression.go +37 -0
  178. package/transformer/transform_property_declaration.go +33 -0
  179. package/transformer/transform_property_name.go +20 -0
  180. package/transformer/transform_return_statement.go +83 -0
  181. package/transformer/transform_source_file.go +230 -0
  182. package/transformer/transform_spread_element.go +35 -0
  183. package/transformer/transform_statement.go +84 -0
  184. package/transformer/transform_statement_list.go +90 -0
  185. package/transformer/transform_string_literal.go +22 -0
  186. package/transformer/transform_super_keyword.go +9 -0
  187. package/transformer/transform_switch_statement.go +145 -0
  188. package/transformer/transform_tagged_template_expression.go +34 -0
  189. package/transformer/transform_template_expression.go +35 -0
  190. package/transformer/transform_this_expression.go +33 -0
  191. package/transformer/transform_throw_statement.go +18 -0
  192. package/transformer/transform_try_statement.go +192 -0
  193. package/transformer/transform_type_expression.go +12 -0
  194. package/transformer/transform_unary_expression.go +79 -0
  195. package/transformer/transform_variable_statement.go +178 -0
  196. package/transformer/transform_void_expression.go +13 -0
  197. package/transformer/transform_while_statement.go +34 -0
  198. package/transformer/transform_writable.go +69 -0
  199. package/transformer/transform_yield_expression.go +56 -0
  200. package/transformer/type_guards.go +30 -0
  201. package/transformer/types.go +381 -0
  202. package/transformer/validate_identifier.go +17 -0
  203. package/transformer/validate_method_assignment.go +106 -0
  204. package/transformer/validate_not_any.go +37 -0
  205. package/transformer/wrap_expression_statement.go +20 -0
  206. package/transformer/wrap_return_if_lua_tuple.go +63 -0
  207. package/transformer/wrap_statements_as_generator.go +22 -0
  208. package/tsbridge/affected.go +141 -0
  209. package/tsbridge/config.go +71 -0
  210. package/tsbridge/diagnostics.go +128 -0
  211. package/tsbridge/doc.go +16 -0
  212. package/tsbridge/macros.go +207 -0
  213. package/tsbridge/macrospec.go +30 -0
  214. package/tsbridge/pool.go +142 -0
  215. package/tsbridge/project.go +137 -0
  216. package/tsbridge/reprint.go +120 -0
  217. package/tsbridge/update.go +128 -0
  218. package/watch/poll.go +126 -0
  219. package/watch/session.go +651 -0
  220. package/watch/watch.go +180 -0
@@ -0,0 +1,40 @@
1
+ // Package shared is the port of src/Shared from roblox-ts 3.0.0: constants, project types, diagnostics
2
+ // definitions, and small utilities used by both the project layer and the transformer.
3
+ package shared
4
+
5
+ import (
6
+ "os"
7
+ "strings"
8
+
9
+ "golang.org/x/term"
10
+ )
11
+
12
+ // Kleur decides whether colors are applied, like the kleur package. Colors end up inside diagnostic message text,
13
+ // because upstream calls kleur.yellow while building the messages. So the same diagnostic has different bytes
14
+ // depending on the environment.
15
+ type Kleur struct {
16
+ Enabled bool
17
+ }
18
+
19
+ // DetectKleur follows kleur 4.1.5, which reads the environment once at load.
20
+ func DetectKleur() Kleur {
21
+ forceColor, hasForceColor := os.LookupEnv("FORCE_COLOR")
22
+ _, hasNoColor := os.LookupEnv("NO_COLOR")
23
+ enabled := os.Getenv("NODE_DISABLE_COLORS") == "" && !hasNoColor && os.Getenv("TERM") != "dumb" &&
24
+ ((hasForceColor && forceColor != "0") || term.IsTerminal(int(os.Stdout.Fd())))
25
+ return Kleur{Enabled: enabled}
26
+ }
27
+
28
+ func (k Kleur) wrap(open, close, text string) string {
29
+ if !k.Enabled {
30
+ return text
31
+ }
32
+ // kleur re-opens the color after any close sequence already in the text.
33
+ return open + strings.ReplaceAll(text, close, close+open) + close
34
+ }
35
+
36
+ // Yellow is kleur.yellow.
37
+ func (k Kleur) Yellow(text string) string { return k.wrap("\x1b[33m", "\x1b[39m", text) }
38
+
39
+ // Grey is kleur.grey.
40
+ func (k Kleur) Grey(text string) string { return k.wrap("\x1b[90m", "\x1b[39m", text) }
@@ -0,0 +1,183 @@
1
+ package shared
2
+
3
+ import (
4
+ "fmt"
5
+ "os"
6
+ "path/filepath"
7
+ "strings"
8
+ "sync"
9
+
10
+ "github.com/microsoft/TypeScript/tsc/internal/diagnostics"
11
+ "github.com/microsoft/TypeScript/tsc/internal/tspath"
12
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/project/nodepath"
13
+ )
14
+
15
+ // DiagnosticError is DiagnosticError from src/Shared/errors. ProjectError is this with one text diagnostic.
16
+ type DiagnosticError struct {
17
+ Diagnostics []*Diagnostic
18
+ }
19
+
20
+ func (e *DiagnosticError) Error() string {
21
+ return FormatDiagnostics(e.Diagnostics, ProcessCwd(), tspath.CaseSensitive, EOL)
22
+ }
23
+
24
+ // NewProjectError is `new ProjectError(message)`.
25
+ func NewProjectError(message string) *DiagnosticError {
26
+ return &DiagnosticError{Diagnostics: []*Diagnostic{TextDiagnostic(message, diagnostics.CategoryError)}}
27
+ }
28
+
29
+ // ProcessCwd is process.cwd() in the form diagnosticwriter takes.
30
+ func ProcessCwd() tspath.RootedDirectoryPath {
31
+ dir, err := os.Getwd()
32
+ if err != nil {
33
+ dir = "/"
34
+ }
35
+ return tspath.RootedDirectoryPathFromAbsolute(tspath.NormalizePath(filepath.ToSlash(dir)))
36
+ }
37
+
38
+ // IsPathDescendantOf is isPathDescendantOf.
39
+ func IsPathDescendantOf(filePath, dirPath string) bool {
40
+ if dirPath == filePath {
41
+ return true
42
+ }
43
+ if startsWithDotDot, ok := nodepath.Native.RelativeStartsWithDotDot(dirPath, filePath); ok {
44
+ return !startsWithDotDot
45
+ }
46
+ return !strings.HasPrefix(nodepath.Native.Relative(dirPath, filePath), "..")
47
+ }
48
+
49
+ // FindAncestorDir is findAncestorDir.
50
+ func FindAncestorDir(dirs []string) string {
51
+ path := nodepath.Native
52
+ normalized := make([]string, len(dirs))
53
+ for i, dir := range dirs {
54
+ dir = path.Normalize(dir)
55
+ if !strings.HasSuffix(dir, path.Sep) {
56
+ dir += path.Sep
57
+ }
58
+ normalized[i] = dir
59
+ }
60
+ current := normalized[0]
61
+ for {
62
+ all := true
63
+ for _, dir := range normalized {
64
+ if !strings.HasPrefix(dir, current) {
65
+ all = false
66
+ break
67
+ }
68
+ }
69
+ if all {
70
+ return current
71
+ }
72
+ current = path.Join(current, "..")
73
+ }
74
+ }
75
+
76
+ // RealPathExists is realPathExistsSync. ok is false where JS returns undefined.
77
+ func RealPathExists(fsPath string) (string, bool) {
78
+ if _, err := os.Stat(fsPath); err != nil {
79
+ return "", false
80
+ }
81
+ real, err := filepath.EvalSymlinks(fsPath)
82
+ if err != nil {
83
+ return "", false
84
+ }
85
+ return real, true
86
+ }
87
+
88
+ // DiagnosticService is TSTransformer/classes/DiagnosticService.ts as an instance, so each worker can have its own.
89
+ // Upstream's is a static class. The compile step collects each worker's list in file order at the end.
90
+ type DiagnosticService struct {
91
+ diagnostics []*Diagnostic
92
+ single bool
93
+ }
94
+
95
+ // AddSingleDiagnostic is addSingleDiagnostic. Upstream keys this by diagnostic.code, and every roblox-ts diagnostic
96
+ // has the same code, so only the first one between flushes gets through. That holds per service here.
97
+ func (s *DiagnosticService) AddSingleDiagnostic(d *Diagnostic) {
98
+ if !s.single {
99
+ s.single = true
100
+ s.AddDiagnostic(d)
101
+ }
102
+ }
103
+
104
+ // AddDiagnostic is addDiagnostic.
105
+ func (s *DiagnosticService) AddDiagnostic(d *Diagnostic) { s.diagnostics = append(s.diagnostics, d) }
106
+
107
+ // AddDiagnostics is addDiagnostics.
108
+ func (s *DiagnosticService) AddDiagnostics(list []*Diagnostic) {
109
+ s.diagnostics = append(s.diagnostics, list...)
110
+ }
111
+
112
+ // Flush is flush.
113
+ func (s *DiagnosticService) Flush() []*Diagnostic {
114
+ current := s.diagnostics
115
+ s.diagnostics = nil
116
+ s.single = false
117
+ return current
118
+ }
119
+
120
+ // HasErrors is hasErrors.
121
+ func (s *DiagnosticService) HasErrors() bool { return HasErrors(s.diagnostics) }
122
+
123
+ // AddDiagnosticWithCache is DiagnosticService.addDiagnosticWithCache. The cache lives in the worker's state.
124
+ func AddDiagnosticWithCache[T comparable](s *DiagnosticService, cacheBy T, d *Diagnostic, cache map[T]bool) {
125
+ if !cache[cacheBy] {
126
+ cache[cacheBy] = true
127
+ s.AddDiagnostic(d)
128
+ }
129
+ }
130
+
131
+ // LogServiceType is LogService. Writes are locked, because workers can log.
132
+ type LogServiceType struct {
133
+ Verbose bool
134
+ mu sync.Mutex
135
+ partial bool
136
+ }
137
+
138
+ // LogService is the process-wide logger, like the static class upstream.
139
+ var LogService = &LogServiceType{}
140
+
141
+ func (l *LogServiceType) write(message string) {
142
+ l.partial = !strings.HasSuffix(message, "\n")
143
+ fmt.Fprint(os.Stdout, message)
144
+ }
145
+
146
+ // Write is LogService.write.
147
+ func (l *LogServiceType) Write(message string) {
148
+ l.mu.Lock()
149
+ defer l.mu.Unlock()
150
+ l.write(message)
151
+ }
152
+
153
+ // WriteLine is LogService.writeLine.
154
+ func (l *LogServiceType) WriteLine(messages ...string) {
155
+ l.mu.Lock()
156
+ defer l.mu.Unlock()
157
+ if l.partial {
158
+ l.write("\n")
159
+ }
160
+ for _, message := range messages {
161
+ l.write(message + "\n")
162
+ }
163
+ }
164
+
165
+ // WriteLineIfVerbose is LogService.writeLineIfVerbose.
166
+ func (l *LogServiceType) WriteLineIfVerbose(messages ...string) {
167
+ if l.Verbose {
168
+ l.WriteLine(messages...)
169
+ }
170
+ }
171
+
172
+ // Warn is LogService.warn.
173
+ func (l *LogServiceType) Warn(message string) {
174
+ l.WriteLine(Color.Yellow("Compiler Warning:") + " " + message)
175
+ }
176
+
177
+ // CategoryError is the error category, so callers don't need the internal diagnostics import for it.
178
+ const CategoryError = diagnostics.CategoryError
179
+
180
+ // AssertionMessage is the text of assert(false, message).
181
+ func AssertionMessage(message string) string {
182
+ return "Assertion Failed! " + message + "\nThis is a compiler bug! Please submit a bug report here:\nhttps://github.com/roblox-ts/roblox-ts/issues"
183
+ }
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env bash
2
+ # Purpose: build rbxts-go with native plugins compiled in. See docs/plugin-api.md.
3
+ # Each plugin folder is a Go module: it has a go.mod whose module path is under
4
+ # github.com/microsoft/TypeScript/tsc/, and its package registers the plugin in an init function.
5
+ # The script writes a main package that imports every plugin and calls cli.Main, and a go.mod that
6
+ # points the TypeScript module, rbxts-go and each plugin at their folders. Both go into a temporary
7
+ # folder, which is removed afterwards. RBXTSGO_KEEP_BUILD_DIR=1 keeps it and prints where it is.
8
+ # Run: bash scripts/build-with-plugins.sh -o <output> [plugin folder...]
9
+ # Studio: not needed.
10
+ # Date: 2026-11-20, native plugin API.
11
+ set -euo pipefail
12
+
13
+ usage() {
14
+ echo "usage: $0 -o <output> <plugin folder>..." >&2
15
+ exit 2
16
+ }
17
+
18
+ repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
19
+ # RBXTSGO_TYPESCRIPT_DIR points at a patched TypeScript checkout kept somewhere else (the npm launcher keeps one
20
+ # per user, outside node_modules).
21
+ typescript="${RBXTSGO_TYPESCRIPT_DIR:-$repo/third_party/typescript/tsc}"
22
+ prefix="github.com/microsoft/TypeScript/tsc/"
23
+
24
+ output=""
25
+ plugins=()
26
+ while [ $# -gt 0 ]; do
27
+ case "$1" in
28
+ -o)
29
+ [ $# -ge 2 ] || usage
30
+ output="$2"
31
+ shift 2
32
+ ;;
33
+ -h | --help) usage ;;
34
+ -*)
35
+ echo "unknown option: $1" >&2
36
+ usage
37
+ ;;
38
+ *)
39
+ plugins+=("$1")
40
+ shift
41
+ ;;
42
+ esac
43
+ done
44
+ [ -n "$output" ] || usage
45
+
46
+ if [ ! -f "$typescript/go.mod" ]; then
47
+ echo "$typescript is missing: run scripts/setup-third-party.sh first" >&2
48
+ exit 1
49
+ fi
50
+
51
+ # The build runs in another folder, so the output path must not depend on the current one.
52
+ case "$output" in
53
+ /* | [A-Za-z]:[\\/]*) ;;
54
+ *) output="$PWD/$output" ;;
55
+ esac
56
+
57
+ work="$(mktemp -d "${TMPDIR:-/tmp}/rbxtsgo-plugins.XXXXXX")"
58
+ if [ "${RBXTSGO_KEEP_BUILD_DIR:-}" = "1" ]; then
59
+ echo "build folder: $work" >&2
60
+ else
61
+ trap 'rm -rf "$work"' EXIT
62
+ fi
63
+
64
+ imports=""
65
+ requires=""
66
+ replaces=""
67
+ for folder in ${plugins[@]+"${plugins[@]}"}; do
68
+ if [ ! -f "$folder/go.mod" ]; then
69
+ echo "$folder has no go.mod: a plugin folder is a Go module" >&2
70
+ exit 1
71
+ fi
72
+ folder="$(cd "$folder" && pwd)"
73
+ module="$(awk '$1 == "module" { gsub(/"/, "", $2); print $2; exit }' "$folder/go.mod")"
74
+ if [ -z "$module" ]; then
75
+ echo "$folder/go.mod has no module line" >&2
76
+ exit 1
77
+ fi
78
+ case "$module" in
79
+ "$prefix"rbxtsgo | "$prefix"rbxtsgo/* | "$prefix"internal | "$prefix"internal/*)
80
+ echo "$folder: the module path $module is taken by the compiler itself" >&2
81
+ exit 1
82
+ ;;
83
+ "$prefix"?*) ;;
84
+ *)
85
+ echo "$folder: the module path $module must be under $prefix, because the TypeScript compiler's packages are internal to that path" >&2
86
+ exit 1
87
+ ;;
88
+ esac
89
+ imports+=" _ \"$module\""$'\n'
90
+ requires+=" $module v0.0.0"$'\n'
91
+ replaces+="replace $module => \"$folder\""$'\n'
92
+ done
93
+
94
+ cat >"$work/main.go" <<MAIN
95
+ // Written by scripts/build-with-plugins.sh.
96
+ package main
97
+
98
+ import (
99
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/cli"
100
+
101
+ $imports)
102
+
103
+ func main() { cli.Main() }
104
+ MAIN
105
+
106
+ # The go line is the compiler's, so the build uses the language version it was written for.
107
+ goline="$(awk '$1 == "go" { print; exit }' "$repo/go.mod")"
108
+ cat >"$work/go.mod" <<MOD
109
+ module ${prefix}rbxtsgo-with-plugins
110
+
111
+ $goline
112
+
113
+ require (
114
+ ${prefix%/} v0.0.0
115
+ ${prefix}rbxtsgo v0.0.0
116
+ $requires)
117
+
118
+ replace ${prefix%/} => "$typescript"
119
+
120
+ replace ${prefix}rbxtsgo => "$repo"
121
+
122
+ $replaces
123
+ MOD
124
+ # The checksums of what the compiler depends on are known already. go mod tidy adds what the plugins bring.
125
+ cp "$repo/go.sum" "$work/go.sum"
126
+
127
+ cd "$work"
128
+ go mod tidy
129
+ go build -trimpath -ldflags="-s -w" -o "$output" .
130
+ echo "built $output with ${#plugins[@]} plugin(s)" >&2
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env bash
2
+ # Purpose: reproduce third_party/ from the pins below, then apply patches/typescript/.
3
+ # Plain clones only, never forks. Push URLs are disabled. Safe to rerun: it resets each
4
+ # clone to its pin, which discards local changes in third_party/.
5
+ # Run: bash scripts/setup-third-party.sh [target-dir] (default: third_party)
6
+ # Studio: not needed.
7
+ # Date: 2026-11-05, foundation work for the port.
8
+ set -euo pipefail
9
+
10
+ # Pins. Changing a pin means re-running the differential tests (scripts/scoreboard.sh).
11
+ TYPESCRIPT_TAG=v7.1-beta
12
+ TYPESCRIPT_COMMIT=3e9236361fa97a9e6c685f4833ac457ae2d8c50a
13
+ ROBLOX_TS_COMMIT=d1d5486094ac1d1821b7eb03ce0de0890d30b82e # npm roblox-ts@3.0.0 gitHead, tag v3.0.0
14
+ ROJO_RESOLVER_COMMIT=1b3b479bc074007abbf1cf81c3082cf20cf2aad3 # npm @roblox-ts/rojo-resolver@1.1.0 gitHead, tag v1.1.0
15
+ PATH_TRANSLATOR_COMMIT=2e6f341b51f5ecc5b4f152903e7b5cfb60c4ad7e # npm @roblox-ts/path-translator@1.1.0 gitHead, tag v1.1.0
16
+ LUAU_AST_COMMIT=ef18d8bccbe5a31435ab56683a81817a7f22ac51 # npm @roblox-ts/luau-ast@2.0.0 gitHead
17
+
18
+ repo_root="$(cd "$(dirname "$0")/.." && pwd)"
19
+ target="${1:-$repo_root/third_party}"
20
+ mkdir -p "$target"
21
+ target="$(cd "$target" && pwd)"
22
+
23
+ # Git options for every clone. Line endings must match upstream exactly on Windows too.
24
+ g() { git -c core.autocrlf=false -c advice.detachedHead=false "$@"; }
25
+
26
+ # pin <dir> <url> <commit>: shallow clone of one commit, with the push URL disabled.
27
+ pin() {
28
+ local dir="$target/$1" url="$2" commit="$3"
29
+ if [ ! -d "$dir/.git" ]; then
30
+ mkdir -p "$dir"
31
+ g -C "$dir" init -q
32
+ g -C "$dir" remote add origin "$url"
33
+ fi
34
+ g -C "$dir" config core.autocrlf false
35
+ g -C "$dir" remote set-url --push origin DISABLED
36
+ if ! g -C "$dir" cat-file -e "$commit^{commit}" 2>/dev/null; then
37
+ g -C "$dir" fetch -q --depth 1 origin "$commit"
38
+ fi
39
+ g -C "$dir" checkout -q -f --detach "$commit"
40
+ echo "$1: $(g -C "$dir" rev-parse HEAD)"
41
+ }
42
+
43
+ # TypeScript has about 136k tracked files, and a full checkout fails on Windows. Keep it sparse.
44
+ ts="$target/typescript"
45
+ if [ ! -d "$ts/.git" ]; then
46
+ g clone -q --no-checkout --depth 1 --branch "$TYPESCRIPT_TAG" --filter=blob:none --sparse \
47
+ https://github.com/microsoft/TypeScript.git "$ts"
48
+ fi
49
+ g -C "$ts" config core.autocrlf false
50
+ g -C "$ts" remote set-url --push origin DISABLED
51
+ g -C "$ts" sparse-checkout set --cone tsc/cmd tsc/internal tsc/_scripts
52
+ if ! g -C "$ts" cat-file -e "$TYPESCRIPT_COMMIT^{commit}" 2>/dev/null; then
53
+ g -C "$ts" fetch -q --depth 1 --filter=blob:none origin "refs/tags/$TYPESCRIPT_TAG:refs/tags/$TYPESCRIPT_TAG"
54
+ fi
55
+ g -C "$ts" checkout -q -f --detach "$TYPESCRIPT_COMMIT"
56
+ rm -f "$ts/tsc/internal/checker/rbxtsgo_exports.go"
57
+ for patch in "$repo_root"/patches/typescript/*.patch; do
58
+ g -C "$ts" apply "$patch"
59
+ echo "typescript: applied $(basename "$patch")"
60
+ done
61
+ echo "typescript: $(g -C "$ts" rev-parse HEAD)"
62
+ if [ "$(g -C "$ts" rev-parse HEAD)" != "$TYPESCRIPT_COMMIT" ]; then
63
+ echo "typescript tag $TYPESCRIPT_TAG moved, expected $TYPESCRIPT_COMMIT" >&2
64
+ exit 1
65
+ fi
66
+
67
+ # The other clones are only read by the tests. A build of the compiler needs TypeScript alone.
68
+ if [ "${RBXTSGO_ONLY_TYPESCRIPT:-}" = "1" ]; then
69
+ exit 0
70
+ fi
71
+
72
+ pin roblox-ts https://github.com/roblox-ts/roblox-ts.git "$ROBLOX_TS_COMMIT"
73
+ pin rojo-resolver https://github.com/roblox-ts/rojo-resolver.git "$ROJO_RESOLVER_COMMIT"
74
+ pin path-translator https://github.com/roblox-ts/path-translator.git "$PATH_TRANSLATOR_COMMIT"
75
+ pin luau-ast https://github.com/roblox-ts/luau-ast.git "$LUAU_AST_COMMIT"
@@ -0,0 +1,21 @@
1
+ package transformer
2
+
3
+ // Port of src/TSTransformer/util/addIndexDiagnostics.ts.
4
+
5
+ import (
6
+ "github.com/microsoft/TypeScript/tsc/internal/ast"
7
+ "github.com/microsoft/TypeScript/tsc/internal/checker"
8
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/project/shared"
9
+ )
10
+
11
+ func addIndexDiagnostics(state *TransformState, node *ast.Node, expType *checker.Type) {
12
+ symbol := getFirstDefinedSymbol(state, expType)
13
+ if (symbol != nil && getPropertyCallMacro(state, symbol) != nil) ||
14
+ (!isValidMethodIndexWithoutCall(state, SkipUpwards(node)) && isMethod(state, node)) {
15
+ state.Diagnostic.AddDiagnostic(shared.Errors.NoIndexWithoutCall.At(shared.AtNode(node)))
16
+ }
17
+
18
+ if ast.IsPrototypeAccess(node) {
19
+ state.Diagnostic.AddDiagnostic(shared.Errors.NoPrototype.At(shared.AtNode(node)))
20
+ }
21
+ }
@@ -0,0 +1,15 @@
1
+ package transformer
2
+
3
+ // Port of src/TSTransformer/util/addOneIfArrayType.ts.
4
+
5
+ import (
6
+ "github.com/microsoft/TypeScript/tsc/internal/checker"
7
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/luau"
8
+ )
9
+
10
+ func addOneIfArrayType(state *TransformState, t *checker.Type, expression luau.Expression) luau.Expression {
11
+ if isDefinitelyType(t, isArrayType(state), isUndefinedType) {
12
+ return offset(expression, 1)
13
+ }
14
+ return expression
15
+ }
@@ -0,0 +1,25 @@
1
+ package transformer
2
+
3
+ // Port of src/TSTransformer/util/arrayBindingPatternContainsHoists.ts.
4
+
5
+ import "github.com/microsoft/TypeScript/tsc/internal/ast"
6
+
7
+ func arrayBindingPatternContainsHoists(state *TransformState, arrayBindingPattern *ast.Node) bool {
8
+ for _, element := range arrayBindingPattern.AsBindingPattern().Elements.Nodes {
9
+ // If it's not a ts.BindingElement, it must be a ts.OmittedExpression. In that case, doesn't create a variable.
10
+ // For non-identifiers, element.name must be a nested array/object binding pattern.
11
+ // For those cases, the hoisting logic is handled elsewhere and the variable here will be a tempId.
12
+ // In TS 7 an omitted element is a ts.BindingElement with a nil name.
13
+ if ast.IsBindingElement(element) && element.Name() != nil && ast.IsIdentifier(element.Name()) {
14
+ symbol := state.Checker.GetSymbolAtLocation(element.Name())
15
+ if symbol != nil {
16
+ // isHoisted is marked inside checkVariableHoist
17
+ checkVariableHoist(state, element.Name(), symbol)
18
+ if state.IsHoisted[symbol] {
19
+ return true
20
+ }
21
+ }
22
+ }
23
+ }
24
+ return false
25
+ }
@@ -0,0 +1,24 @@
1
+ package transformer
2
+
3
+ // Port of src/TSTransformer/util/assertNever.ts.
4
+
5
+ import (
6
+ "fmt"
7
+
8
+ "github.com/microsoft/TypeScript/tsc/internal/ast"
9
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/luau"
10
+ )
11
+
12
+ // assertNever panics where upstream calls LogService.fatal. The `npm ls typescript` hint is left out: Go has no
13
+ // TypeScript package to mismatch. The result type only lets callers write `return assertNever(x, "name")` in a
14
+ // function that returns an expression. It never returns.
15
+ func assertNever(value any, message string) luau.Expression {
16
+ var description string
17
+ if node, isTsNode := value.(*ast.Node); isTsNode && node != nil {
18
+ description = "a TS node of kind " + getKindName(node.Kind)
19
+ } else {
20
+ description = fmt.Sprintf("%v", value)
21
+ }
22
+ panic("Exhaustive assertion failed! " + message + ", value was " + description +
23
+ "\nThis is usually caused by a TypeScript version mismatch.")
24
+ }
@@ -0,0 +1,64 @@
1
+ package transformer
2
+
3
+ // Port of src/TSTransformer/util/assignment.ts.
4
+
5
+ import (
6
+ "github.com/microsoft/TypeScript/tsc/internal/ast"
7
+ "github.com/microsoft/TypeScript/tsc/internal/checker"
8
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/luau"
9
+ )
10
+
11
+ var compoundOperatorMap = map[ast.Kind]luau.AssignmentOperator{
12
+ // compound assignment
13
+ ast.KindMinusEqualsToken: luau.AssignSub,
14
+ ast.KindAsteriskEqualsToken: luau.AssignMul,
15
+ ast.KindSlashEqualsToken: luau.AssignDiv,
16
+ ast.KindAsteriskAsteriskEqualsToken: luau.AssignPow,
17
+ ast.KindPercentEqualsToken: luau.AssignMod,
18
+
19
+ // unary
20
+ ast.KindPlusPlusToken: luau.AssignAdd,
21
+ ast.KindMinusMinusToken: luau.AssignSub,
22
+
23
+ // normal assignment
24
+ ast.KindEqualsToken: luau.AssignEqual,
25
+ }
26
+
27
+ // getSimpleAssignmentOperator returns "" where JS returns undefined.
28
+ func getSimpleAssignmentOperator(leftType *checker.Type, operatorKind ast.Kind, rightType *checker.Type) luau.AssignmentOperator {
29
+ // plus
30
+ if operatorKind == ast.KindPlusEqualsToken {
31
+ if isDefinitelyType(leftType, isStringType) || isDefinitelyType(rightType, isStringType) {
32
+ return luau.AssignConcat
33
+ }
34
+ return luau.AssignAdd
35
+ }
36
+
37
+ return compoundOperatorMap[operatorKind]
38
+ }
39
+
40
+ func createAssignmentExpression(state *TransformState, readable luau.WritableExpression, operator luau.AssignmentOperator, value luau.Expression) luau.WritableExpression {
41
+ state.Prereq(luau.Create(&luau.Assignment{
42
+ Left: readable,
43
+ Operator: operator,
44
+ Right: value,
45
+ }))
46
+ return readable
47
+ }
48
+
49
+ func createCompoundAssignmentStatement(state *TransformState, node *ast.Node, writable luau.WritableExpression, writableType *checker.Type, readable luau.WritableExpression, operator ast.Kind, value luau.Expression, valueType *checker.Type) *luau.Assignment {
50
+ return luau.Create(&luau.Assignment{
51
+ Left: writable,
52
+ Operator: luau.AssignEqual,
53
+ Right: createBinaryFromOperator(state, node, readable, writableType, operator, value, valueType),
54
+ })
55
+ }
56
+
57
+ func createCompoundAssignmentExpression(state *TransformState, node *ast.Node, writable luau.WritableExpression, writableType *checker.Type, readable luau.WritableExpression, operator ast.Kind, value luau.Expression, valueType *checker.Type) luau.WritableExpression {
58
+ return createAssignmentExpression(
59
+ state,
60
+ writable,
61
+ luau.AssignEqual,
62
+ createBinaryFromOperator(state, node, readable, writableType, operator, value, valueType),
63
+ )
64
+ }
@@ -0,0 +1,70 @@
1
+ package transformer
2
+
3
+ // Port of src/TSTransformer/macros/callMacros.ts.
4
+
5
+ import (
6
+ "github.com/microsoft/TypeScript/tsc/internal/ast"
7
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/luau"
8
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/project/shared"
9
+ )
10
+
11
+ var primitiveLuauTypes = map[string]bool{
12
+ "nil": true,
13
+ "boolean": true,
14
+ "string": true,
15
+ "number": true,
16
+ "table": true,
17
+ "userdata": true,
18
+ "function": true,
19
+ "thread": true,
20
+ "vector": true,
21
+ "buffer": true,
22
+ }
23
+
24
+ // callMacros is CALL_MACROS.
25
+ func callMacros() map[string]callMacro {
26
+ return map[string]callMacro{
27
+ "assert": func(state *TransformState, node *ast.Node, expression luau.Expression, args []luau.Expression) luau.Expression {
28
+ args[0] = createTruthinessChecks(state, args[0], node.AsCallExpression().Arguments.Nodes[0])
29
+ return luau.NewCall(luau.Globals.Assert, args...)
30
+ },
31
+
32
+ "typeOf": func(state *TransformState, node *ast.Node, expression luau.Expression, args []luau.Expression) luau.Expression {
33
+ return luau.NewCall(luau.Globals.Typeof, args...)
34
+ },
35
+
36
+ "typeIs": func(state *TransformState, node *ast.Node, expression luau.Expression, args []luau.Expression) luau.Expression {
37
+ value, typeStr := args[0], args[1]
38
+ typeFunc := luau.Globals.Typeof
39
+ if luau.IsStringLiteral(typeStr) && primitiveLuauTypes[typeStr.(*luau.StringLiteral).Value] {
40
+ typeFunc = luau.Globals.Type
41
+ }
42
+ return luau.NewBinary(luau.NewCall(typeFunc, value), luau.BinaryEqual, typeStr)
43
+ },
44
+
45
+ "classIs": func(state *TransformState, node *ast.Node, expression luau.Expression, args []luau.Expression) luau.Expression {
46
+ value, typeStr := args[0], args[1]
47
+ return luau.NewBinary(luau.NewProperty(convertToIndexableExpression(value), "ClassName"), luau.BinaryEqual, typeStr)
48
+ },
49
+
50
+ "identity": func(state *TransformState, node *ast.Node, expression luau.Expression, args []luau.Expression) luau.Expression {
51
+ return args[0]
52
+ },
53
+
54
+ "$range": func(state *TransformState, node *ast.Node, expression luau.Expression, args []luau.Expression) luau.Expression {
55
+ state.Diagnostic.AddDiagnostic(shared.Errors.NoRangeMacroOutsideForOf.At(shared.AtNode(node.Expression())))
56
+ return luau.NewNone()
57
+ },
58
+
59
+ "$tuple": func(state *TransformState, node *ast.Node, expression luau.Expression, args []luau.Expression) luau.Expression {
60
+ state.Diagnostic.AddDiagnostic(shared.Errors.NoTupleMacroOutsideReturn.At(shared.AtNode(node)))
61
+ return luau.NewNone()
62
+ },
63
+
64
+ "$getModuleTree": func(state *TransformState, node *ast.Node, expression luau.Expression, args []luau.Expression) luau.Expression {
65
+ parts := getImportParts(state, ast.GetSourceFileOfNode(node), node.AsCallExpression().Arguments.Nodes[0])
66
+ // converts the flat array into { root, { "rest", "of", "path" } }
67
+ return luau.NewArray(parts[0], luau.NewArray(parts[1:]...))
68
+ },
69
+ }
70
+ }