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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +239 -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 +262 -0
  49. package/plugins/session.go +223 -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 +99 -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,187 @@
1
+ #!/usr/bin/env bash
2
+ # The launcher of the npm package @data-vegle/rbxts-go, installed as `rbxts-go` and `rbxtsc`.
3
+ #
4
+ # rbxtsc [flags] compile the project in the current folder (flags as roblox-ts: -w, -p, --rojo, ...)
5
+ # rbxts-go compiler [--force] build the compiler with the plugins of this project, if it is not up to date
6
+ # rbxts-go setup prepare node_modules for TypeScript 7 (the editor and `rbxts-go typecheck`)
7
+ # rbxts-go typecheck [flags] type-check with stock TypeScript 7, emitting nothing (flags as tsc: -p, ...)
8
+ # rbxts-go together <command> [flags]
9
+ # compile with the flags and run <command> next to it; both stop together.
10
+ # For a watcher that works on the output: rbxts-go together "darklua process -w a b" -w
11
+ #
12
+ # The compiler is rbxts-go and the native plugins compiled together, so it is built on this machine the first time
13
+ # and whenever a plugin or rbxts-go changes. That needs Go and git. It lands in node_modules/.cache/rbxts-go.
14
+ #
15
+ # A plugin is found by a file named `rbxts-go-plugin` at the root of an installed package (node_modules/<name> or
16
+ # node_modules/@scope/<name>) or of the project itself. The file holds one line: the folder of the Go module,
17
+ # relative to the package, such as `transformer`.
18
+ #
19
+ # Environment: RBXTS_GO_CACHE is where the patched TypeScript sources are kept (default ~/.cache/rbxts-go).
20
+ set -euo pipefail
21
+
22
+ # The package folder: this file is <package>/npm/rbxts-go.sh, and npm runs it through a link in node_modules/.bin.
23
+ self="${BASH_SOURCE[0]}"
24
+ while [ -L "$self" ]; do
25
+ dir="$(cd "$(dirname "$self")" && pwd)"
26
+ self="$(readlink "$self")"
27
+ case "$self" in
28
+ /*) ;;
29
+ *) self="$dir/$self" ;;
30
+ esac
31
+ done
32
+ package="$(cd "$(dirname "$self")/.." && pwd)"
33
+ project="$PWD"
34
+ cache_dir="$project/node_modules/.cache/rbxts-go"
35
+ compiler="$cache_dir/rbxtsc"
36
+ if [ "${OS:-}" = "Windows_NT" ]; then
37
+ compiler="$compiler.exe"
38
+ fi
39
+
40
+ version() {
41
+ sed -n "s/^[[:space:]]*\"version\":[[:space:]]*\"\([^\"]*\)\".*/\1/p" "$package/package.json" | head -n 1
42
+ }
43
+
44
+ # setup: TypeScript 7 only accepts `for ... of` when the global Iterable interface has three type parameters, as in
45
+ # its own lib. @rbxts/compiler-types 3.0 declares `Iterable<T>`, so every loop over a Map, a Set or pairs() would be
46
+ # error TS2802 in the editor. This adds the two missing parameters, with defaults, so nothing else changes. The
47
+ # compiler itself does not need it. It does nothing once the file is patched.
48
+ setup() {
49
+ local file
50
+ for file in "$project/node_modules/@rbxts/compiler-types/types/Iterable.d.ts" \
51
+ "$package/node_modules/@rbxts/compiler-types/types/Iterable.d.ts"; do
52
+ if [ -f "$file" ] && grep -q "^interface Iterable<T> {" "$file"; then
53
+ sed -e "s/^interface Iterable<T> {/interface Iterable<T, TReturn = any, TNext = any> {/" \
54
+ -e "s/^interface AsyncIterable<T> {/interface AsyncIterable<T, TReturn = any, TNext = any> {/" \
55
+ "$file" >"$file.patched"
56
+ mv "$file.patched" "$file"
57
+ fi
58
+ done
59
+ }
60
+
61
+ # plugin_folders prints the Go module folder of every plugin, one per line: installed packages in name order, then
62
+ # the project itself.
63
+ plugin_folders() {
64
+ local marker folder
65
+ for marker in "$project"/node_modules/*/rbxts-go-plugin "$project"/node_modules/@*/*/rbxts-go-plugin \
66
+ "$project/rbxts-go-plugin"; do
67
+ [ -f "$marker" ] || continue
68
+ folder="$(dirname "$marker")/$(head -n 1 "$marker" | tr -d "\r")"
69
+ if [ ! -f "$folder/go.mod" ]; then
70
+ echo "rbxts-go: $marker names $folder, which has no go.mod" >&2
71
+ exit 1
72
+ fi
73
+ (cd "$folder" && pwd -P)
74
+ done
75
+ }
76
+
77
+ # stamp describes what the compiler is built from: the version of rbxts-go and the Go files of every plugin.
78
+ stamp() {
79
+ echo "rbxts-go $(version)"
80
+ local folder
81
+ while IFS= read -r folder; do
82
+ [ -n "$folder" ] || continue
83
+ echo "$folder $(find "$folder" -name "*.go" -not -name "*_test.go" -type f | LC_ALL=C sort | xargs cksum | cksum)"
84
+ done <<<"$1"
85
+ }
86
+
87
+ build_compiler() {
88
+ local force="${1:-}" folders wanted
89
+ folders="$(plugin_folders)"
90
+ wanted="$(stamp "$folders")"
91
+ if [ -z "$force" ] && [ -x "$compiler" ] && [ -f "$cache_dir/stamp" ] && [ "$(cat "$cache_dir/stamp")" = "$wanted" ]; then
92
+ return 0
93
+ fi
94
+
95
+ for tool in go git; do
96
+ if ! command -v "$tool" >/dev/null 2>&1; then
97
+ echo "rbxts-go: building the compiler needs $tool, which was not found" >&2
98
+ exit 1
99
+ fi
100
+ done
101
+
102
+ # The patched TypeScript sources: once per user and version, outside node_modules.
103
+ local sources="${RBXTS_GO_CACHE:-$HOME/.cache/rbxts-go}/$(version)/third_party"
104
+ if [ ! -f "$sources/ready" ]; then
105
+ echo "rbxts-go: fetching the TypeScript 7 sources into $sources (once)" >&2
106
+ RBXTSGO_ONLY_TYPESCRIPT=1 bash "$package/scripts/setup-third-party.sh" "$sources" >&2
107
+ : >"$sources/ready"
108
+ fi
109
+
110
+ echo "rbxts-go: building the compiler" >&2
111
+ mkdir -p "$cache_dir"
112
+ local args=()
113
+ while IFS= read -r folder; do
114
+ [ -n "$folder" ] && args+=("$folder")
115
+ done <<<"$folders"
116
+ RBXTSGO_TYPESCRIPT_DIR="$sources/typescript/tsc" \
117
+ bash "$package/scripts/build-with-plugins.sh" -o "$compiler" ${args[@]+"${args[@]}"}
118
+ echo "$wanted" >"$cache_dir/stamp"
119
+ }
120
+
121
+ compile() {
122
+ build_compiler
123
+ setup
124
+ # rbxts-go takes its flags before the `build` command.
125
+ "$compiler" "$@" build
126
+ }
127
+
128
+ case "${1:-}" in
129
+ setup)
130
+ setup
131
+ ;;
132
+ compiler)
133
+ shift
134
+ if [ "${1:-}" = "--force" ]; then
135
+ build_compiler force
136
+ else
137
+ build_compiler
138
+ fi
139
+ ;;
140
+ typecheck)
141
+ shift
142
+ setup
143
+ tsc="$project/node_modules/typescript/bin/tsc"
144
+ [ -f "$tsc" ] || tsc="$package/node_modules/typescript/bin/tsc"
145
+ exec node "$tsc" --noEmit --incremental false --skipLibCheck "$@"
146
+ ;;
147
+ together)
148
+ shift
149
+ if [ $# -lt 1 ]; then
150
+ echo "usage: rbxts-go together <command> [compiler flags]" >&2
151
+ exit 2
152
+ fi
153
+ other="$1"
154
+ shift
155
+ build_compiler
156
+ setup
157
+ pids=()
158
+ stop() {
159
+ trap - EXIT
160
+ for pid in "${pids[@]}"; do
161
+ kill "$pid" 2>/dev/null || true
162
+ done
163
+ }
164
+ trap stop EXIT
165
+ trap "stop; exit 130" INT TERM
166
+ "$compiler" "$@" build &
167
+ pids+=($!)
168
+ bash -c "$other" &
169
+ pids+=($!)
170
+ # Poll instead of `wait -n`, which the bash 3.2 shipped with macOS does not have.
171
+ while true; do
172
+ for pid in "${pids[@]}"; do
173
+ if ! kill -0 "$pid" 2>/dev/null; then
174
+ wait "$pid" && status=0 || status=$?
175
+ exit "$status"
176
+ fi
177
+ done
178
+ sleep 1
179
+ done
180
+ ;;
181
+ -h | --help | help)
182
+ sed -n "2,20p" "$self" | sed "s/^# \{0,1\}//"
183
+ ;;
184
+ *)
185
+ compile "$@"
186
+ ;;
187
+ esac
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
- "name": "@data-vegle/rbxts-go",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@data-vegle/rbxts-go",
3
+ "version": "1.0.0",
4
+ "description": "The roblox-ts compiler in Go, on TypeScript 7, with native plugins. One dev dependency brings the compiler launcher, the roblox-ts types and TypeScript 7.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Vegle-Data-Apps/rbxts-go.git"
9
+ },
10
+ "bin": {
11
+ "rbxts-go": "npm/rbxts-go.sh",
12
+ "rbxtsc": "npm/rbxts-go.sh"
13
+ },
14
+ "types": "npm/index.d.ts",
15
+ "files": [
16
+ "npm",
17
+ "scripts/build-with-plugins.sh",
18
+ "scripts/setup-third-party.sh",
19
+ "patches",
20
+ "docs/plugin-api.md",
21
+ "go.mod",
22
+ "go.sum",
23
+ "cli",
24
+ "compile",
25
+ "internal",
26
+ "luau",
27
+ "pluginapi",
28
+ "plugins",
29
+ "project",
30
+ "transformer",
31
+ "tsbridge",
32
+ "watch",
33
+ "!**/*_test.go",
34
+ "!**/testdata",
35
+ "THIRD_PARTY_NOTICES.md",
36
+ "README.rbxtsgo.md"
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "dependencies": {
42
+ "@rbxts/compiler-types": "3.0.0-types.0",
43
+ "@rbxts/types": "^1.0.915",
44
+ "typescript": "7.1.0-beta"
45
+ }
46
+ }
@@ -0,0 +1,40 @@
1
+ diff --git a/tsc/internal/checker/rbxtsgo_exports.go b/tsc/internal/checker/rbxtsgo_exports.go
2
+ new file mode 100644
3
+ --- /dev/null
4
+ +++ b/tsc/internal/checker/rbxtsgo_exports.go
5
+ @@ -0,0 +1,35 @@
6
+ +package checker
7
+ +
8
+ +import "github.com/microsoft/TypeScript/tsc/internal/ast"
9
+ +
10
+ +// Exports added by rbxtsgo. New file only, so upstream merges cannot conflict with it.
11
+ +
12
+ +// GetTrueType returns the regular true type, like ts.TypeChecker.getTrueType() with no argument.
13
+ +// It is a struct field, so go:linkname cannot reach it.
14
+ +func (c *Checker) GetTrueType() *Type { return c.regularTrueType }
15
+ +
16
+ +// GetFalseType returns the regular false type, like ts.TypeChecker.getFalseType() with no argument.
17
+ +func (c *Checker) GetFalseType() *Type { return c.regularFalseType }
18
+ +
19
+ +func (c *Checker) GetTypeOfAssignmentPattern(expr *ast.Node) *Type {
20
+ + return c.getTypeOfAssignmentPattern(expr)
21
+ +}
22
+ +
23
+ +func (c *Checker) CreateArrayType(elementType *Type) *Type { return c.createArrayType(elementType) }
24
+ +
25
+ +func (c *Checker) GetStringLiteralType(value string) *Type { return c.getStringLiteralType(value) }
26
+ +
27
+ +// IsMutexHeld reports whether c.mu, the mutex that EmitResolver methods take, is held right now.
28
+ +// The bridge uses it to fail loudly instead of deadlocking. It is advisory: another goroutine can
29
+ +// take the mutex right after this returns, so it only proves anything when one goroutine owns c.
30
+ +func (c *Checker) IsMutexHeld() bool {
31
+ + if c.mu.TryLock() {
32
+ + c.mu.Unlock()
33
+ + return false
34
+ + }
35
+ + return true
36
+ +}
37
+ +
38
+ +// Checker returns the checker a type belongs to. JS type objects carry theirs, and roblox-ts calls methods such as
39
+ +// type.getConstraint() on them.
40
+ +func (t *Type) Checker() *Checker { return t.checker }
@@ -0,0 +1,15 @@
1
+ diff --git a/tsc/internal/checker/checker.go b/tsc/internal/checker/checker.go
2
+ index b639d48..03355ba 100644
3
+ --- a/tsc/internal/checker/checker.go
4
+ +++ b/tsc/internal/checker/checker.go
5
+ @@ -6090,7 +6090,9 @@ func (c *Checker) getIteratedTypeOrElementType(use IterationUse, inputType *Type
6
+ }
7
+ return nil
8
+ }
9
+ - iterableExists := c.getGlobalIterableType() != c.emptyGenericType
10
+ + // rbxtsgo: compiler-types declares Iterable<T> with one type parameter, so the arity 3 lookup fails.
11
+ + // TS 5.9 decided this from the target, not the arity. Without this, for-of over Map, Set and Iterable is an error.
12
+ + iterableExists := c.getGlobalIterableType() != c.emptyGenericType || c.getGlobalSymbol("Iterable", ast.SymbolFlagsType, nil) != nil
13
+ possibleOutOfBounds := c.compilerOptions.NoUncheckedIndexedAccess == core.TSTrue && use&IterationUsePossiblyOutOfBounds != 0
14
+ if iterableExists || allowAsyncIterables {
15
+ iterationTypes := c.getIterationTypesOfIterable(inputType, use, core.IfElse(iterableExists, errorNode, nil))
@@ -0,0 +1,15 @@
1
+ diff --git a/tsc/internal/ast/utilities.go b/tsc/internal/ast/utilities.go
2
+ index ff11fd6..f895095 100644
3
+ --- a/tsc/internal/ast/utilities.go
4
+ +++ b/tsc/internal/ast/utilities.go
5
+ @@ -4327,7 +4327,9 @@ func HasContextSensitiveParameters(node *Node) bool {
6
+ // an implicit 'this' parameter which is subject to contextual typing.
7
+ parameter := core.FirstOrNil(node.Parameters())
8
+ if parameter == nil || !IsThisParameter(parameter) {
9
+ - return node.Flags&NodeFlagsContainsThis != 0
10
+ + // rbxtsgo: TS 5.5.3 returns true here. The narrower check came later, and changes whether a function
11
+ + // expression that doesn't use `this` takes the contextual `this` parameter, which decides `self` in output.
12
+ + return true
13
+ }
14
+ }
15
+ }
@@ -0,0 +1,26 @@
1
+ diff --git a/tsc/internal/printer/printer.go b/tsc/internal/printer/printer.go
2
+ index a27452d..8ebcb16 100644
3
+ --- a/tsc/internal/printer/printer.go
4
+ +++ b/tsc/internal/printer/printer.go
5
+ @@ -50,6 +50,11 @@ type PrinterOptions struct {
6
+ // StripInternal bool
7
+ PreserveSourceNewlines bool
8
+ TerminateUnterminatedLiterals bool // !!!
9
+ + // rbxtsgo: a parse tree already spells every parenthesis it needs, as a ParenthesizedExpression. TS 5.5.3's printer
10
+ + // adds none to it, while this one compares precedences and writes (a!).b and (new A)?.c for a!.b and new A?.c. The
11
+ + // reprint for transformer plugins must match TS 5.5.3's text, so with this set, only synthesized expressions get
12
+ + // parentheses here. The caller adds any that a synthesized parent needs around a parse tree child.
13
+ + KeepParseTreeParentheses bool
14
+ }
15
+
16
+ type PrintHandlers struct {
17
+ @@ -3220,7 +3225,8 @@ func (p *Printer) emitExpressionNoASI(node *ast.Expression, precedence ast.Opera
18
+ }
19
+
20
+ func (p *Printer) emitExpression(node *ast.Expression, precedence ast.OperatorPrecedence) {
21
+ - parens := ast.GetExpressionPrecedence(ast.SkipPartiallyEmittedExpressions(node)) < precedence
22
+ + parens := ast.GetExpressionPrecedence(ast.SkipPartiallyEmittedExpressions(node)) < precedence &&
23
+ + !(p.Options.KeepParseTreeParentheses && !ast.NodeIsSynthesized(node))
24
+ if parens {
25
+ p.writePunctuation("(")
26
+ }
@@ -0,0 +1,31 @@
1
+ package pluginapi
2
+
3
+ import (
4
+ "slices"
5
+
6
+ "github.com/microsoft/TypeScript/tsc/internal/ast"
7
+ "github.com/microsoft/TypeScript/tsc/internal/diagnostics"
8
+ "github.com/microsoft/TypeScript/tsc/internal/printer"
9
+ )
10
+
11
+ // This file is the host's side: what package plugins needs to run the registered plugins. A plugin calls none of it.
12
+
13
+ // Lookup returns the registered plugin that replaces a value of "transform".
14
+ func Lookup(transform string) (Plugin, bool) {
15
+ registryMu.RLock()
16
+ defer registryMu.RUnlock()
17
+ for _, plugin := range registry {
18
+ if slices.Contains(plugin.Transforms, transform) {
19
+ return plugin, true
20
+ }
21
+ }
22
+ return Plugin{}, false
23
+ }
24
+
25
+ // NewFileContext makes the context of one file. report receives what plugins pass to AddDiagnostic.
26
+ func NewFileContext(host *Host, emit *printer.EmitContext, report func(category diagnostics.Category, node *ast.Node, message string)) *FileContext {
27
+ return &FileContext{Host: host, Checker: host.Checker, EmitContext: emit, Factory: emit.Factory, report: report}
28
+ }
29
+
30
+ // ExitRequest is what FileContext.Exit panics with. The host recovers it and ends the build.
31
+ type ExitRequest struct{ Lines []string }
@@ -0,0 +1,153 @@
1
+ // Package pluginapi is what a native plugin is written against: a transformer in Go that stands in for a JavaScript
2
+ // transformer named in compilerOptions.plugins. docs/plugin-api.md is the contract, and explains each type here.
3
+ //
4
+ // A plugin is its own Go module. It registers itself from an init function, and a compiler that has it is built by
5
+ // compiling the two together: see scripts/build-with-plugins.sh.
6
+ package pluginapi
7
+
8
+ import (
9
+ "fmt"
10
+ "slices"
11
+ "sync"
12
+
13
+ "github.com/microsoft/TypeScript/tsc/internal/ast"
14
+ "github.com/microsoft/TypeScript/tsc/internal/checker"
15
+ "github.com/microsoft/TypeScript/tsc/internal/compiler"
16
+ "github.com/microsoft/TypeScript/tsc/internal/core"
17
+ "github.com/microsoft/TypeScript/tsc/internal/diagnostics"
18
+ "github.com/microsoft/TypeScript/tsc/internal/printer"
19
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/project/pathtranslator"
20
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/project/rojoresolver"
21
+ "github.com/microsoft/TypeScript/tsc/rbxtsgo/project/shared"
22
+ )
23
+
24
+ // Plugin describes a native plugin. Register it from an init function.
25
+ type Plugin struct {
26
+ // Name is for messages, such as "godawork".
27
+ Name string
28
+ // Transforms are the values of "transform" in compilerOptions.plugins that this plugin replaces, such as
29
+ // "rbxts-transformer-flamework". An entry matches when its "transform" is equal to one of them.
30
+ Transforms []string
31
+ // New is called once per program, before any file is transformed. config is the plugin's entry in
32
+ // compilerOptions.plugins, decoded from JSON (so numbers are float64, objects are map[string]any), including
33
+ // "transform". An error stops the build and is printed as it is.
34
+ New func(host *Host, config map[string]any) (Transformer, error)
35
+ }
36
+
37
+ // setgetTransform is plugins.SetgetPlugin, which is built in and so can't be registered.
38
+ const setgetTransform = "rbxts-transformer-setget"
39
+
40
+ var (
41
+ registryMu sync.RWMutex
42
+ registry []Plugin
43
+ )
44
+
45
+ // Register adds a plugin to this compiler. It panics on a plugin that could never run: one with no name, no New or no
46
+ // Transforms, or one that claims a "transform" that another plugin or the built-in setget already has.
47
+ func Register(plugin Plugin) {
48
+ if plugin.Name == "" {
49
+ panic("pluginapi: Register needs a plugin with a Name")
50
+ }
51
+ if plugin.New == nil {
52
+ panic(fmt.Sprintf("pluginapi: the plugin %q has no New", plugin.Name))
53
+ }
54
+ if len(plugin.Transforms) == 0 {
55
+ panic(fmt.Sprintf("pluginapi: the plugin %q has no Transforms, so no entry of compilerOptions.plugins can match it", plugin.Name))
56
+ }
57
+ registryMu.Lock()
58
+ defer registryMu.Unlock()
59
+ for _, transform := range plugin.Transforms {
60
+ if transform == "" {
61
+ panic(fmt.Sprintf("pluginapi: the plugin %q has an empty name in Transforms", plugin.Name))
62
+ }
63
+ if transform == setgetTransform {
64
+ panic(fmt.Sprintf("pluginapi: the plugin %q claims %q, which is built in", plugin.Name, transform))
65
+ }
66
+ for _, other := range registry {
67
+ if slices.Contains(other.Transforms, transform) {
68
+ panic(fmt.Sprintf("pluginapi: the plugins %q and %q both claim %q", other.Name, plugin.Name, transform))
69
+ }
70
+ }
71
+ }
72
+ plugin.Transforms = slices.Clone(plugin.Transforms)
73
+ registry = append(registry, plugin)
74
+ }
75
+
76
+ // Host is what a plugin may read about the build. It is valid for one program.
77
+ type Host struct {
78
+ // Program is the program made from the sources as written, before any plugin ran.
79
+ Program *compiler.Program
80
+ // Options are the normalized compiler options of that program.
81
+ Options *core.CompilerOptions
82
+ // Data is the project data: paths of the project, tsconfig, node_modules, Rojo project, and the project options.
83
+ Data *shared.ProjectData
84
+ // PathTranslator maps source paths to output paths.
85
+ PathTranslator *pathtranslator.Translator
86
+ // RojoResolver is the resolver of the project's Rojo file, as the compiler uses it. Nil when the project has
87
+ // none (a package).
88
+ RojoResolver *rojoresolver.Resolver
89
+ // Files are the files that will be compiled, in program order. They are the files TransformFile is called for.
90
+ Files []*ast.SourceFile
91
+ // Checker is the one checker that every plugin call of this program uses. See "Threads and checkers".
92
+ Checker *checker.Checker
93
+ // Watch is true in watch mode, where the same Transformer value serves several programs: see "Watch mode".
94
+ Watch bool
95
+ }
96
+
97
+ // Warn prints a warning the way the compiler prints its own.
98
+ func (h *Host) Warn(message string) {
99
+ shared.LogService.Warn(message)
100
+ }
101
+
102
+ // Transformer is one plugin's work for one program.
103
+ type Transformer interface {
104
+ // TransformFile returns the tree to compile in place of a file. file is the file as written. node is the file
105
+ // as the plugins before this one left it, which is file itself for the first plugin; it is always a SourceFile
106
+ // node. Return node unchanged when there is nothing to do. The result must be a SourceFile node made with
107
+ // ctx.Factory (or node itself).
108
+ TransformFile(ctx *FileContext, file *ast.SourceFile, node *ast.Node) *ast.Node
109
+ // Finish is called once after every file was transformed without an error, before the compile starts. It is
110
+ // where a plugin writes its own files (a build cache, an id table). An error stops the build.
111
+ Finish() error
112
+ }
113
+
114
+ // Updater is implemented by transformers that can carry their state to the next program of a watch session.
115
+ type Updater interface {
116
+ // Update prepares the transformer for the next program. changed are the files of the new program whose text
117
+ // differs from the previous program's, or that are new. TransformFile is then called for every file that needs
118
+ // compiling in this cycle, which includes the changed files.
119
+ Update(host *Host, changed []*ast.SourceFile) error
120
+ }
121
+
122
+ // FileContext is what a plugin needs while it transforms one file.
123
+ type FileContext struct {
124
+ // Host is the host of the program.
125
+ Host *Host
126
+ // Checker is Host.Checker.
127
+ Checker *checker.Checker
128
+ // EmitContext is the emit context of this file's reprint, shared by every plugin that transforms the file.
129
+ // Nodes must be created through it, so that the printer and later plugins can find what a node was made from.
130
+ EmitContext *printer.EmitContext
131
+ // Factory is EmitContext.Factory: update and create nodes with it.
132
+ Factory *printer.NodeFactory
133
+
134
+ report func(category diagnostics.Category, node *ast.Node, message string)
135
+ }
136
+
137
+ // Original returns the node of the file as written that a node was made from, or the node itself if it is one.
138
+ // It is ts.getOriginalNode: after an earlier plugin rewrote a call, a later plugin finds the call it wants by its
139
+ // original.
140
+ func (c *FileContext) Original(node *ast.Node) *ast.Node {
141
+ return c.EmitContext.MostOriginal(node)
142
+ }
143
+
144
+ // AddDiagnostic reports an error or a warning at a node of the file as written. An error stops the build after
145
+ // every plugin has seen every file, and is printed like a compiler diagnostic. The source text shown is the user's.
146
+ func (c *FileContext) AddDiagnostic(category diagnostics.Category, node *ast.Node, message string) {
147
+ c.report(category, node, message)
148
+ }
149
+
150
+ // Exit stops the build at once, printing the lines, as a JS transformer that calls process.exit does.
151
+ func (c *FileContext) Exit(lines ...string) {
152
+ panic(&ExitRequest{Lines: lines})
153
+ }
@@ -0,0 +1,18 @@
1
+ setget.go in this folder is a port of rbxts-transformer-setget@2.0.0.
2
+ Its package.json says MIT, and the LICENSE file in the same tarball is this ISC text, which is kept here as it was.
3
+
4
+ ISC License
5
+
6
+ Copyright (c) 2020, wAD4444
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted, provided that the above
10
+ copyright notice and this permission notice appear in all copies.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.