@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.
- package/LICENSE +21 -0
- package/README.md +181 -2
- package/README.rbxtsgo.md +169 -0
- package/THIRD_PARTY_NOTICES.md +745 -0
- package/cli/cli.go +454 -0
- package/compile/compile.go +388 -0
- package/compile/declarations.go +221 -0
- package/compile/incremental.go +349 -0
- package/compile/times.go +9 -0
- package/docs/plugin-api.md +239 -0
- package/go.mod +20 -0
- package/go.sum +24 -0
- package/internal/difftest/difftest.go +530 -0
- package/internal/plugintest/plugintest.go +181 -0
- package/luau/create.go +351 -0
- package/luau/doc.go +71 -0
- package/luau/globals.go +178 -0
- package/luau/jsnum.go +188 -0
- package/luau/kinds.go +128 -0
- package/luau/list.go +227 -0
- package/luau/nodes.go +479 -0
- package/luau/operators.go +46 -0
- package/luau/render.go +134 -0
- package/luau/render_expressions.go +264 -0
- package/luau/render_fields.go +81 -0
- package/luau/render_indexable.go +81 -0
- package/luau/render_state.go +134 -0
- package/luau/render_statements.go +235 -0
- package/luau/render_util.go +296 -0
- package/luau/solve_temp_ids.go +212 -0
- package/luau/typeguards.go +175 -0
- package/luau/util.go +184 -0
- package/luau/visit.go +138 -0
- package/npm/index.d.ts +3 -0
- package/npm/rbxts-go.sh +187 -0
- package/package.json +45 -5
- package/patches/typescript/0001-checker-exports.patch +40 -0
- package/patches/typescript/0002-iterable-arity.patch +15 -0
- package/patches/typescript/0003-context-sensitive-this.patch +15 -0
- package/patches/typescript/0004-printer-keep-parse-tree-parentheses.patch +26 -0
- package/pluginapi/host.go +31 -0
- package/pluginapi/pluginapi.go +153 -0
- package/plugins/LICENSE-rbxts-transformer-setget +18 -0
- package/plugins/apply.go +342 -0
- package/plugins/config.go +431 -0
- package/plugins/fallback.go +84 -0
- package/plugins/fixemit.go +60 -0
- package/plugins/native.go +262 -0
- package/plugins/session.go +223 -0
- package/plugins/setget.go +478 -0
- package/project/copy.go +333 -0
- package/project/include/Promise.lua +2068 -0
- package/project/include/RuntimeLib.lua +260 -0
- package/project/nodepath/nodepath.go +917 -0
- package/project/pathtranslator/pathtranslator.go +214 -0
- package/project/project.go +498 -0
- package/project/rojoresolver/json.go +248 -0
- package/project/rojoresolver/rojoresolver.go +559 -0
- package/project/shared/constants.go +83 -0
- package/project/shared/diagnostic.go +238 -0
- package/project/shared/diagnostics.go +388 -0
- package/project/shared/elapsed.go +14 -0
- package/project/shared/eol_other.go +6 -0
- package/project/shared/eol_windows.go +4 -0
- package/project/shared/kleur.go +40 -0
- package/project/shared/util.go +183 -0
- package/scripts/build-with-plugins.sh +130 -0
- package/scripts/setup-third-party.sh +75 -0
- package/transformer/add_index_diagnostics.go +21 -0
- package/transformer/add_one_if_array_type.go +15 -0
- package/transformer/array_binding_pattern_contains_hoists.go +25 -0
- package/transformer/assert_never.go +24 -0
- package/transformer/assignment.go +64 -0
- package/transformer/call_macros.go +70 -0
- package/transformer/check_variable_hoist.go +125 -0
- package/transformer/clean_module_name.go +28 -0
- package/transformer/constructor_macros.go +122 -0
- package/transformer/convert_to_indexable_expression.go +12 -0
- package/transformer/create_binary_from_operator.go +86 -0
- package/transformer/create_continue_statements.go +68 -0
- package/transformer/create_get_service.go +15 -0
- package/transformer/create_hoist_declaration.go +27 -0
- package/transformer/create_import_expression.go +220 -0
- package/transformer/create_string_from_literal.go +195 -0
- package/transformer/create_truthiness_checks.go +63 -0
- package/transformer/create_type_check.go +9 -0
- package/transformer/ensure_transform_order.go +53 -0
- package/transformer/expression_chain.go +27 -0
- package/transformer/expression_might_mutate.go +60 -0
- package/transformer/find_constructor.go +15 -0
- package/transformer/fixup_whitespace_and_decode_entities.go +377 -0
- package/transformer/get_accessor_for_binding_type.go +160 -0
- package/transformer/get_add_iterable_to_array_builder.go +363 -0
- package/transformer/get_assignable_value.go +15 -0
- package/transformer/get_constant_value_literal.go +20 -0
- package/transformer/get_declared_variables.go +34 -0
- package/transformer/get_extends_node.go +23 -0
- package/transformer/get_flags.go +21 -0
- package/transformer/get_kind_name.go +18 -0
- package/transformer/get_original_symbol_of_node.go +16 -0
- package/transformer/get_source_file_from_module_specifier.go +68 -0
- package/transformer/get_statements.go +12 -0
- package/transformer/has_multiple_definitions.go +18 -0
- package/transformer/hoist_functions_past_final_statement.go +43 -0
- package/transformer/identifier_macros.go +17 -0
- package/transformer/is_blocked_by_try_statement.go +19 -0
- package/transformer/is_method.go +104 -0
- package/transformer/is_symbol_mutable.go +26 -0
- package/transformer/is_symbol_of_value.go +11 -0
- package/transformer/is_used_as_statement.go +25 -0
- package/transformer/is_valid_method_index_without_call.go +36 -0
- package/transformer/macro_manager.go +92 -0
- package/transformer/object_accessor.go +32 -0
- package/transformer/offset.go +58 -0
- package/transformer/pointer.go +53 -0
- package/transformer/property_call_macros.go +1035 -0
- package/transformer/state.go +606 -0
- package/transformer/transform_array_assignment_pattern.go +65 -0
- package/transformer/transform_array_binding_pattern.go +49 -0
- package/transformer/transform_array_literal_expression.go +97 -0
- package/transformer/transform_await_expression.go +12 -0
- package/transformer/transform_binary_expression.go +221 -0
- package/transformer/transform_binding_name.go +25 -0
- package/transformer/transform_block.go +14 -0
- package/transformer/transform_boolean_literal.go +13 -0
- package/transformer/transform_break_statement.go +26 -0
- package/transformer/transform_call_expression.go +266 -0
- package/transformer/transform_class_constructor.go +125 -0
- package/transformer/transform_class_declaration.go +12 -0
- package/transformer/transform_class_expression.go +14 -0
- package/transformer/transform_class_like_declaration.go +355 -0
- package/transformer/transform_conditional_expression.go +70 -0
- package/transformer/transform_continue_statement.go +30 -0
- package/transformer/transform_decorators.go +253 -0
- package/transformer/transform_delete_expression.go +17 -0
- package/transformer/transform_do_statement.go +39 -0
- package/transformer/transform_element_access_expression.go +114 -0
- package/transformer/transform_entity_name.go +21 -0
- package/transformer/transform_enum_declaration.go +135 -0
- package/transformer/transform_export_assignment.go +57 -0
- package/transformer/transform_export_declaration.go +150 -0
- package/transformer/transform_expression.go +120 -0
- package/transformer/transform_expression_statement.go +71 -0
- package/transformer/transform_for_of_statement.go +461 -0
- package/transformer/transform_for_statement.go +599 -0
- package/transformer/transform_function_declaration.go +84 -0
- package/transformer/transform_function_expression.go +48 -0
- package/transformer/transform_identifier.go +194 -0
- package/transformer/transform_if_statement.go +44 -0
- package/transformer/transform_import_declaration.go +146 -0
- package/transformer/transform_import_equals_declaration.go +46 -0
- package/transformer/transform_import_expression.go +36 -0
- package/transformer/transform_initializer.go +22 -0
- package/transformer/transform_interpolated_string_part.go +12 -0
- package/transformer/transform_jsx.go +41 -0
- package/transformer/transform_jsx_attributes.go +110 -0
- package/transformer/transform_jsx_children.go +50 -0
- package/transformer/transform_jsx_element.go +14 -0
- package/transformer/transform_jsx_expression.go +20 -0
- package/transformer/transform_jsx_fragment.go +42 -0
- package/transformer/transform_jsx_self_closing_element.go +13 -0
- package/transformer/transform_jsx_tag_name.go +53 -0
- package/transformer/transform_logical.go +160 -0
- package/transformer/transform_logical_or_coalescing_assignment_expression.go +103 -0
- package/transformer/transform_method_declaration.go +102 -0
- package/transformer/transform_module_declaration.go +143 -0
- package/transformer/transform_new_expression.go +27 -0
- package/transformer/transform_no_substitution_template_literal.go +16 -0
- package/transformer/transform_numeric_literal.go +15 -0
- package/transformer/transform_object_assignment_pattern.go +86 -0
- package/transformer/transform_object_binding_pattern.go +49 -0
- package/transformer/transform_object_literal_expression.go +107 -0
- package/transformer/transform_omitted_expression.go +9 -0
- package/transformer/transform_optional_chain.go +312 -0
- package/transformer/transform_parameters.go +124 -0
- package/transformer/transform_parenthesized_expression.go +17 -0
- package/transformer/transform_property_access_expression.go +37 -0
- package/transformer/transform_property_declaration.go +33 -0
- package/transformer/transform_property_name.go +20 -0
- package/transformer/transform_return_statement.go +83 -0
- package/transformer/transform_source_file.go +230 -0
- package/transformer/transform_spread_element.go +35 -0
- package/transformer/transform_statement.go +84 -0
- package/transformer/transform_statement_list.go +90 -0
- package/transformer/transform_string_literal.go +22 -0
- package/transformer/transform_super_keyword.go +9 -0
- package/transformer/transform_switch_statement.go +145 -0
- package/transformer/transform_tagged_template_expression.go +34 -0
- package/transformer/transform_template_expression.go +35 -0
- package/transformer/transform_this_expression.go +33 -0
- package/transformer/transform_throw_statement.go +18 -0
- package/transformer/transform_try_statement.go +192 -0
- package/transformer/transform_type_expression.go +12 -0
- package/transformer/transform_unary_expression.go +79 -0
- package/transformer/transform_variable_statement.go +178 -0
- package/transformer/transform_void_expression.go +13 -0
- package/transformer/transform_while_statement.go +34 -0
- package/transformer/transform_writable.go +69 -0
- package/transformer/transform_yield_expression.go +56 -0
- package/transformer/type_guards.go +30 -0
- package/transformer/types.go +381 -0
- package/transformer/validate_identifier.go +17 -0
- package/transformer/validate_method_assignment.go +106 -0
- package/transformer/validate_not_any.go +37 -0
- package/transformer/wrap_expression_statement.go +20 -0
- package/transformer/wrap_return_if_lua_tuple.go +63 -0
- package/transformer/wrap_statements_as_generator.go +22 -0
- package/tsbridge/affected.go +141 -0
- package/tsbridge/config.go +71 -0
- package/tsbridge/diagnostics.go +128 -0
- package/tsbridge/doc.go +16 -0
- package/tsbridge/macros.go +207 -0
- package/tsbridge/macrospec.go +30 -0
- package/tsbridge/pool.go +142 -0
- package/tsbridge/project.go +137 -0
- package/tsbridge/reprint.go +99 -0
- package/tsbridge/update.go +128 -0
- package/watch/poll.go +126 -0
- package/watch/session.go +651 -0
- package/watch/watch.go +180 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
package shared
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
|
|
6
|
+
"github.com/microsoft/TypeScript/tsc/internal/ast"
|
|
7
|
+
"github.com/microsoft/TypeScript/tsc/internal/core"
|
|
8
|
+
"github.com/microsoft/TypeScript/tsc/internal/diagnostics"
|
|
9
|
+
"github.com/microsoft/TypeScript/tsc/internal/diagnosticwriter"
|
|
10
|
+
"github.com/microsoft/TypeScript/tsc/internal/locale"
|
|
11
|
+
"github.com/microsoft/TypeScript/tsc/internal/scanner"
|
|
12
|
+
"github.com/microsoft/TypeScript/tsc/internal/tspath"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
// Diagnostic is what DiagnosticService collects: either a roblox-ts diagnostic or a wrapped TypeScript one.
|
|
16
|
+
type Diagnostic struct {
|
|
17
|
+
category diagnostics.Category
|
|
18
|
+
// id is the factory id for a located roblox-ts diagnostic, and -1 otherwise, where JS has undefined.
|
|
19
|
+
id int
|
|
20
|
+
message string
|
|
21
|
+
file *ast.SourceFile
|
|
22
|
+
start int
|
|
23
|
+
length int
|
|
24
|
+
ts *ast.Diagnostic
|
|
25
|
+
// context is set on diagnostics from a context factory. ContextReplay uses it to rebuild the text in file order.
|
|
26
|
+
context []string
|
|
27
|
+
factory *contextFactory
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// FromTS wraps a TypeScript diagnostic.
|
|
31
|
+
func FromTS(d *ast.Diagnostic) *Diagnostic {
|
|
32
|
+
return &Diagnostic{category: d.Category(), id: -1, ts: d}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// FromTSList wraps several TypeScript diagnostics.
|
|
36
|
+
func FromTSList(list []*ast.Diagnostic) []*Diagnostic {
|
|
37
|
+
result := make([]*Diagnostic, len(list))
|
|
38
|
+
for i, d := range list {
|
|
39
|
+
result[i] = FromTS(d)
|
|
40
|
+
}
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Category is diagnostic.category.
|
|
45
|
+
func (d *Diagnostic) Category() diagnostics.Category { return d.category }
|
|
46
|
+
|
|
47
|
+
// ID is getDiagnosticId, or -1 where JS gives undefined.
|
|
48
|
+
func (d *Diagnostic) ID() int { return d.id }
|
|
49
|
+
|
|
50
|
+
// IsRobloxTS reports whether roblox-ts made this diagnostic, rather than TypeScript.
|
|
51
|
+
func (d *Diagnostic) IsRobloxTS() bool { return d.ts == nil }
|
|
52
|
+
|
|
53
|
+
// Code is the TypeScript code, or 0 for a roblox-ts diagnostic.
|
|
54
|
+
func (d *Diagnostic) Code() int32 {
|
|
55
|
+
if d.ts != nil {
|
|
56
|
+
return d.ts.Code()
|
|
57
|
+
}
|
|
58
|
+
return 0
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Message is the message text. For a TypeScript diagnostic it has only the top line of the chain.
|
|
62
|
+
func (d *Diagnostic) Message() string {
|
|
63
|
+
if d.ts != nil {
|
|
64
|
+
return d.ts.String()
|
|
65
|
+
}
|
|
66
|
+
return d.message
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// File is the source file, or nil for a text diagnostic.
|
|
70
|
+
func (d *Diagnostic) File() *ast.SourceFile {
|
|
71
|
+
if d.ts != nil {
|
|
72
|
+
return d.ts.File()
|
|
73
|
+
}
|
|
74
|
+
return d.file
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Start is the byte offset of the start. JS has a UTF-16 offset here.
|
|
78
|
+
func (d *Diagnostic) Start() int {
|
|
79
|
+
if d.ts != nil {
|
|
80
|
+
return d.ts.Pos()
|
|
81
|
+
}
|
|
82
|
+
return d.start
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Length is the length in bytes. See the note on SourceRange about its meaning for those.
|
|
86
|
+
func (d *Diagnostic) Length() int {
|
|
87
|
+
if d.ts != nil {
|
|
88
|
+
return d.ts.Len()
|
|
89
|
+
}
|
|
90
|
+
return d.length
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Relocated returns the diagnostic with its location, and its related locations, moved by relocate. relocate says false
|
|
94
|
+
// to leave one where it is. The message doesn't change.
|
|
95
|
+
func (d *Diagnostic) Relocated(relocate func(*ast.SourceFile, core.TextRange) (*ast.SourceFile, core.TextRange, bool)) *Diagnostic {
|
|
96
|
+
moved := *d
|
|
97
|
+
if d.ts != nil {
|
|
98
|
+
moved.ts = relocateTS(d.ts, relocate)
|
|
99
|
+
} else if d.file != nil {
|
|
100
|
+
if file, loc, ok := relocate(d.file, core.NewTextRange(d.start, d.start+d.length)); ok {
|
|
101
|
+
moved.file, moved.start, moved.length = file, loc.Pos(), loc.Len()
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return &moved
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
func relocateTS(d *ast.Diagnostic, relocate func(*ast.SourceFile, core.TextRange) (*ast.SourceFile, core.TextRange, bool)) *ast.Diagnostic {
|
|
108
|
+
moved := d.Clone()
|
|
109
|
+
if d.File() != nil {
|
|
110
|
+
if file, loc, ok := relocate(d.File(), d.Loc()); ok {
|
|
111
|
+
moved.SetFile(file)
|
|
112
|
+
moved.SetLocation(loc)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if related := d.RelatedInformation(); len(related) > 0 {
|
|
116
|
+
list := make([]*ast.Diagnostic, len(related))
|
|
117
|
+
for i, info := range related {
|
|
118
|
+
list[i] = relocateTS(info, relocate)
|
|
119
|
+
}
|
|
120
|
+
moved.SetRelatedInfo(list)
|
|
121
|
+
}
|
|
122
|
+
return moved
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// SourceRange is SourceFileWithTextRange.
|
|
126
|
+
//
|
|
127
|
+
// Upstream's createDiagnosticWithLocation stores range.end as the length here, not end - pos. That's kept, so the
|
|
128
|
+
// squiggle in formatted output is too long in the same way.
|
|
129
|
+
type SourceRange struct {
|
|
130
|
+
File *ast.SourceFile
|
|
131
|
+
Pos int
|
|
132
|
+
End int
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Location is ts.Node | SourceFileWithTextRange: where a located diagnostic points.
|
|
136
|
+
type Location struct {
|
|
137
|
+
node *ast.Node
|
|
138
|
+
file *ast.SourceFile
|
|
139
|
+
start int
|
|
140
|
+
len int
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// AtNode points at a node, like node.getStart() and node.getWidth().
|
|
144
|
+
func AtNode(node *ast.Node) Location {
|
|
145
|
+
file := ast.GetSourceFileOfNode(node)
|
|
146
|
+
start := scanner.GetTokenPosOfNode(node, file, false)
|
|
147
|
+
return Location{node: node, file: file, start: start, len: node.End() - start}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// AtRange points at a text range.
|
|
151
|
+
func AtRange(r SourceRange) Location {
|
|
152
|
+
return Location{file: r.File, start: r.Pos, len: r.End}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// TextDiagnostic is createTextDiagnostic.
|
|
156
|
+
func TextDiagnostic(message string, category diagnostics.Category) *Diagnostic {
|
|
157
|
+
return &Diagnostic{category: category, id: -1, message: message}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// LocatedDiagnostic is a diagnostic with its own message at a place in a file. A native plugin's diagnostics are these:
|
|
161
|
+
// JS has no one function for it, because a transformer there builds the ts.Diagnostic itself.
|
|
162
|
+
func LocatedDiagnostic(message string, category diagnostics.Category, file *ast.SourceFile, start, length int) *Diagnostic {
|
|
163
|
+
return &Diagnostic{category: category, id: -1, message: message, file: file, start: start, length: length}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// HasErrors is hasErrors.
|
|
167
|
+
func HasErrors(list []*Diagnostic) bool {
|
|
168
|
+
for _, d := range list {
|
|
169
|
+
if d.category == diagnostics.CategoryError {
|
|
170
|
+
return true
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return false
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// robloxTSPrefix gets printed as the diagnostic code, because upstream sets code to " roblox-ts" and TypeScript
|
|
177
|
+
// prints "TS" + code. The writer always appends a number, so it is written with a marker, then fixed afterwards.
|
|
178
|
+
const (
|
|
179
|
+
robloxTSSource = "TS roblox-ts"
|
|
180
|
+
robloxTSWritten = robloxTSSource + "0: "
|
|
181
|
+
robloxTSWanted = robloxTSSource + ": "
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
// writerDiagnostic adapts a roblox-ts diagnostic for diagnosticwriter.
|
|
185
|
+
type writerDiagnostic struct{ d *Diagnostic }
|
|
186
|
+
|
|
187
|
+
func (w *writerDiagnostic) File() diagnosticwriter.FileLike {
|
|
188
|
+
if w.d.file == nil {
|
|
189
|
+
return nil
|
|
190
|
+
}
|
|
191
|
+
return w.d.file
|
|
192
|
+
}
|
|
193
|
+
func (w *writerDiagnostic) Pos() int { return w.d.start }
|
|
194
|
+
func (w *writerDiagnostic) End() int { return w.d.start + w.Len() }
|
|
195
|
+
|
|
196
|
+
// Len clamps to the end of the file. Upstream stores range.end as the length, so start + length can run past the
|
|
197
|
+
// end, which TS tolerates and tsgo's writer panics on.
|
|
198
|
+
func (w *writerDiagnostic) Len() int {
|
|
199
|
+
if w.d.file != nil {
|
|
200
|
+
return min(w.d.length, len(w.d.file.Text())-w.d.start)
|
|
201
|
+
}
|
|
202
|
+
return w.d.length
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
func (w *writerDiagnostic) Code() int32 { return 0 }
|
|
206
|
+
func (w *writerDiagnostic) Category() diagnostics.Category { return w.d.category }
|
|
207
|
+
func (w *writerDiagnostic) Source() string { return robloxTSSource }
|
|
208
|
+
func (w *writerDiagnostic) Localize(locale.Locale) string { return w.d.message }
|
|
209
|
+
func (w *writerDiagnostic) MessageChain() []diagnosticwriter.Diagnostic { return nil }
|
|
210
|
+
func (w *writerDiagnostic) RelatedInformation() []diagnosticwriter.Diagnostic { return nil }
|
|
211
|
+
|
|
212
|
+
// FormatDiagnostics is formatDiagnostics: ts.formatDiagnosticsWithColorAndContext with the given cwd and newline.
|
|
213
|
+
// The TS 7 writer stands in for the TS 5.5.3 one. The tests compare the two on roblox-ts diagnostics.
|
|
214
|
+
// Messages from TypeScript itself can differ between those versions.
|
|
215
|
+
func FormatDiagnostics(list []*Diagnostic, cwd tspath.RootedDirectoryPath, caseSensitivity tspath.CaseSensitivity, newLine string) string {
|
|
216
|
+
converted := make([]diagnosticwriter.Diagnostic, len(list))
|
|
217
|
+
for i, d := range list {
|
|
218
|
+
if d.ts != nil {
|
|
219
|
+
converted[i] = diagnosticwriter.WrapASTDiagnostic(d.ts)
|
|
220
|
+
} else {
|
|
221
|
+
converted[i] = &writerDiagnostic{d: d}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
options := &diagnosticwriter.FormattingOptions{
|
|
225
|
+
CaseSensitivity: caseSensitivity,
|
|
226
|
+
CurrentDirectory: cwd,
|
|
227
|
+
NewLine: newLine,
|
|
228
|
+
}
|
|
229
|
+
var b strings.Builder
|
|
230
|
+
for _, d := range converted {
|
|
231
|
+
diagnosticwriter.FormatDiagnosticWithColorAndContext(&b, d, options)
|
|
232
|
+
// TS 5.5.3 ends every diagnostic with a newline, and the writer only does for those with a code snippet.
|
|
233
|
+
if d.File() == nil {
|
|
234
|
+
b.WriteString(newLine)
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return strings.ReplaceAll(b.String(), robloxTSWritten, robloxTSWanted)
|
|
238
|
+
}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
package shared
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"slices"
|
|
6
|
+
"strings"
|
|
7
|
+
"sync"
|
|
8
|
+
|
|
9
|
+
"github.com/microsoft/TypeScript/tsc/internal/diagnostics"
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
// DiagnosticFactory is the factory type from src/Shared/diagnostics.ts, for diagnostics with no context.
|
|
13
|
+
type DiagnosticFactory struct {
|
|
14
|
+
// ID is the factory's position in definition order, as in upstream, and is what getDiagnosticId returns.
|
|
15
|
+
ID int
|
|
16
|
+
category diagnostics.Category
|
|
17
|
+
messages []string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// At makes a diagnostic at a location. Use AtNode or AtRange for the location.
|
|
21
|
+
func (f *DiagnosticFactory) At(location Location) *Diagnostic {
|
|
22
|
+
return newLocated(f.ID, f.category, f.messages, location)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func newLocated(id int, category diagnostics.Category, messages []string, location Location) *Diagnostic {
|
|
26
|
+
return &Diagnostic{
|
|
27
|
+
category: category,
|
|
28
|
+
id: id,
|
|
29
|
+
message: strings.Join(messages, "\n"),
|
|
30
|
+
file: location.file,
|
|
31
|
+
start: location.start,
|
|
32
|
+
length: location.len,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// contextFactory is a factory with a context formatter. Upstream's result function does
|
|
37
|
+
// messages.push(...contextFormatter(...context)) on the array it closed over, so each call adds to what the next
|
|
38
|
+
// call prints. That bug is kept, because it's visible in rbxtsc's output: the second "Could not find Rojo data"
|
|
39
|
+
// in a build also repeats the first one's text. With parallel workers the order of those calls can differ from
|
|
40
|
+
// rbxtsc's file order, so that repeated text can come out in a different order.
|
|
41
|
+
type contextFactory struct {
|
|
42
|
+
ID int
|
|
43
|
+
mu sync.Mutex
|
|
44
|
+
category diagnostics.Category
|
|
45
|
+
messages []string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func (f *contextFactory) at(location Location, context ...string) *Diagnostic {
|
|
49
|
+
f.mu.Lock()
|
|
50
|
+
defer f.mu.Unlock()
|
|
51
|
+
f.messages = append(f.messages, context...)
|
|
52
|
+
d := newLocated(f.ID, f.category, f.messages, location)
|
|
53
|
+
d.context = slices.Clone(context)
|
|
54
|
+
d.factory = f
|
|
55
|
+
return d
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// ContextReplay rebuilds the accumulated text of context diagnostics in a fixed order. contextFactory.at runs in
|
|
59
|
+
// whatever order the workers reach it, and some of those diagnostics get dropped because an earlier file stopped the
|
|
60
|
+
// compile. A compile merges its diagnostics in file order and passes them through Apply, which gives each one the
|
|
61
|
+
// text rbxtsc would have printed: every context its factory received before it. Use one ContextReplay for the life
|
|
62
|
+
// of the process, because upstream's accumulation lasts that long too.
|
|
63
|
+
type ContextReplay struct {
|
|
64
|
+
added map[*contextFactory][]string
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// NewContextReplay makes an empty replay.
|
|
68
|
+
func NewContextReplay() *ContextReplay {
|
|
69
|
+
return &ContextReplay{added: map[*contextFactory][]string{}}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Apply rewrites the message of every context diagnostic in list, in list order.
|
|
73
|
+
func (r *ContextReplay) Apply(list []*Diagnostic) {
|
|
74
|
+
for _, d := range list {
|
|
75
|
+
if d.factory == nil {
|
|
76
|
+
continue
|
|
77
|
+
}
|
|
78
|
+
r.added[d.factory] = append(r.added[d.factory], d.context...)
|
|
79
|
+
d.message = strings.Join(r.added[d.factory], "\n")
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// NoRojoDataFactory is errors.noRojoData.
|
|
84
|
+
type NoRojoDataFactory struct {
|
|
85
|
+
contextFactory
|
|
86
|
+
kleur Kleur
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// At is errors.noRojoData(node, path, isPackage).
|
|
90
|
+
func (f *NoRojoDataFactory) At(location Location, path string, isPackage bool) *Diagnostic {
|
|
91
|
+
context := []string{"Could not find Rojo data. There is no $path in your Rojo config that covers " + path}
|
|
92
|
+
if isPackage {
|
|
93
|
+
context = append(context, suggestion(f.kleur, "Did you forget to add a custom npm scope to your default.project.json?"))
|
|
94
|
+
}
|
|
95
|
+
return f.at(location, context...)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// NoPackageImportWithoutScopeFactory is errors.noPackageImportWithoutScope.
|
|
99
|
+
type NoPackageImportWithoutScopeFactory struct {
|
|
100
|
+
contextFactory
|
|
101
|
+
kleur Kleur
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// At is errors.noPackageImportWithoutScope(node, path, rbxPath).
|
|
105
|
+
func (f *NoPackageImportWithoutScopeFactory) At(location Location, path string, rbxPath []string) *Diagnostic {
|
|
106
|
+
return f.at(location,
|
|
107
|
+
"Imported package Roblox path is missing an npm scope!",
|
|
108
|
+
"Package path: "+path,
|
|
109
|
+
"Roblox path: "+strings.Join(rbxPath, "."),
|
|
110
|
+
suggestion(f.kleur, "You might need to update your \"node_modules\" in default.project.json to match:\n\"node_modules\": {\n\t\"$className\": \"Folder\",\n\t\"@rbxts\": {\n\t\t\"$path\": \"node_modules/@rbxts\"\n\t}\n}"),
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
func suggestion(k Kleur, text string) string { return "Suggestion: " + k.Yellow(text) }
|
|
115
|
+
|
|
116
|
+
func issue(k Kleur, id int) string {
|
|
117
|
+
return "More information: " + k.Grey(fmt.Sprintf("https://github.com/roblox-ts/roblox-ts/issues/%d", id))
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// ErrorDefinitions is `errors` from src/Shared/diagnostics.ts. Fields are in source order.
|
|
121
|
+
type ErrorDefinitions struct {
|
|
122
|
+
// reserved identifiers
|
|
123
|
+
NoInvalidIdentifier *DiagnosticFactory
|
|
124
|
+
NoReservedIdentifier *DiagnosticFactory
|
|
125
|
+
NoReservedClassFields *DiagnosticFactory
|
|
126
|
+
NoClassMetamethods *DiagnosticFactory
|
|
127
|
+
|
|
128
|
+
// banned statements
|
|
129
|
+
NoForInStatement *DiagnosticFactory
|
|
130
|
+
NoLabeledStatement *DiagnosticFactory
|
|
131
|
+
NoDebuggerStatement *DiagnosticFactory
|
|
132
|
+
|
|
133
|
+
// banned expressions
|
|
134
|
+
NoNullLiteral *DiagnosticFactory
|
|
135
|
+
NoPrivateIdentifier *DiagnosticFactory
|
|
136
|
+
NoTypeOfExpression *DiagnosticFactory
|
|
137
|
+
NoRegex *DiagnosticFactory
|
|
138
|
+
NoBigInt *DiagnosticFactory
|
|
139
|
+
|
|
140
|
+
// banned features
|
|
141
|
+
NoAny *DiagnosticFactory
|
|
142
|
+
NoVar *DiagnosticFactory
|
|
143
|
+
NoGetterSetter *DiagnosticFactory
|
|
144
|
+
NoAutoAccessorModifiers *DiagnosticFactory
|
|
145
|
+
NoEqualsEquals *DiagnosticFactory
|
|
146
|
+
NoExclamationEquals *DiagnosticFactory
|
|
147
|
+
NoEnumMerging *DiagnosticFactory
|
|
148
|
+
NoNamespaceMerging *DiagnosticFactory
|
|
149
|
+
NoSpreadDestructuring *DiagnosticFactory
|
|
150
|
+
NoFunctionExpressionName *DiagnosticFactory
|
|
151
|
+
NoPrecedingSpreadElement *DiagnosticFactory
|
|
152
|
+
NoLuaTupleDestructureAssignmentExpression *DiagnosticFactory
|
|
153
|
+
NoExportAssignmentLet *DiagnosticFactory
|
|
154
|
+
NoGlobalThis *DiagnosticFactory
|
|
155
|
+
NoArguments *DiagnosticFactory
|
|
156
|
+
NoPrototype *DiagnosticFactory
|
|
157
|
+
NoRobloxSymbolInstanceof *DiagnosticFactory
|
|
158
|
+
NoNonNumberStringRelationOperator *DiagnosticFactory
|
|
159
|
+
NoInstanceMethodCollisions *DiagnosticFactory
|
|
160
|
+
NoStaticMethodCollisions *DiagnosticFactory
|
|
161
|
+
NoUnaryPlus *DiagnosticFactory
|
|
162
|
+
NoNonNumberUnaryMinus *DiagnosticFactory
|
|
163
|
+
NoAwaitForOf *DiagnosticFactory
|
|
164
|
+
NoAsyncGeneratorFunctions *DiagnosticFactory
|
|
165
|
+
NoNonStringModuleSpecifier *DiagnosticFactory
|
|
166
|
+
NoIterableIteration *DiagnosticFactory
|
|
167
|
+
NoUnsupportedIteration *DiagnosticFactory
|
|
168
|
+
NoMixedTypeCall *DiagnosticFactory
|
|
169
|
+
NoIndexWithoutCall *DiagnosticFactory
|
|
170
|
+
NoCommentDirectives *DiagnosticFactory
|
|
171
|
+
|
|
172
|
+
// macro methods
|
|
173
|
+
NoOptionalMacroCall *DiagnosticFactory
|
|
174
|
+
NoConstructorMacroWithoutNew *DiagnosticFactory
|
|
175
|
+
NoMacroExtends *DiagnosticFactory
|
|
176
|
+
NoMacroUnion *DiagnosticFactory
|
|
177
|
+
NoMacroObjectSpread *DiagnosticFactory
|
|
178
|
+
NoVarArgsMacroSpread *DiagnosticFactory
|
|
179
|
+
NoRangeMacroOutsideForOf *DiagnosticFactory
|
|
180
|
+
NoTupleMacroOutsideReturn *DiagnosticFactory
|
|
181
|
+
|
|
182
|
+
// import/export
|
|
183
|
+
NoModuleSpecifierFile *DiagnosticFactory
|
|
184
|
+
NoInvalidModule *DiagnosticFactory
|
|
185
|
+
NoUnscopedModule *DiagnosticFactory
|
|
186
|
+
NoNonModuleImport *DiagnosticFactory
|
|
187
|
+
NoIsolatedImport *DiagnosticFactory
|
|
188
|
+
NoServerImport *DiagnosticFactory
|
|
189
|
+
|
|
190
|
+
// jsx
|
|
191
|
+
NoPrecedingJsxSpreadElement *DiagnosticFactory
|
|
192
|
+
|
|
193
|
+
// semantic
|
|
194
|
+
ExpectedMethodGotFunction *DiagnosticFactory
|
|
195
|
+
ExpectedFunctionGotMethod *DiagnosticFactory
|
|
196
|
+
|
|
197
|
+
// files
|
|
198
|
+
NoRojoData *NoRojoDataFactory
|
|
199
|
+
NoPackageImportWithoutScope *NoPackageImportWithoutScopeFactory
|
|
200
|
+
|
|
201
|
+
kleur Kleur
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// IncorrectFileName is errors.incorrectFileName.
|
|
205
|
+
func (e *ErrorDefinitions) IncorrectFileName(originalFileName, suggestedFileName, fullPath string) *Diagnostic {
|
|
206
|
+
return TextDiagnostic(strings.Join([]string{
|
|
207
|
+
"Incorrect file name: `" + originalFileName + "`!",
|
|
208
|
+
"Full path: " + fullPath,
|
|
209
|
+
suggestion(e.kleur, "Change `"+originalFileName+"` to `"+suggestedFileName+"`."),
|
|
210
|
+
}, "\n"), diagnostics.CategoryError)
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// RojoPathInSrc is errors.rojoPathInSrc.
|
|
214
|
+
func (e *ErrorDefinitions) RojoPathInSrc(partitionPath, suggestedPath string) *Diagnostic {
|
|
215
|
+
return TextDiagnostic(strings.Join([]string{
|
|
216
|
+
"Invalid Rojo configuration. $path fields should be relative to out directory.",
|
|
217
|
+
suggestion(e.kleur, `Change the value of $path from "`+partitionPath+`" to "`+suggestedPath+`".`),
|
|
218
|
+
}, "\n"), diagnostics.CategoryError)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// WarningDefinitions is `warnings` from src/Shared/diagnostics.ts.
|
|
222
|
+
type WarningDefinitions struct {
|
|
223
|
+
RuntimeLibUsedInReplicatedFirst *DiagnosticFactory
|
|
224
|
+
|
|
225
|
+
kleur Kleur
|
|
226
|
+
mu sync.Mutex
|
|
227
|
+
nextID int
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
func (w *WarningDefinitions) newFactory(messages ...string) *DiagnosticFactory {
|
|
231
|
+
w.mu.Lock()
|
|
232
|
+
defer w.mu.Unlock()
|
|
233
|
+
f := &DiagnosticFactory{ID: w.nextID, category: diagnostics.CategoryWarning, messages: messages}
|
|
234
|
+
w.nextID++
|
|
235
|
+
return f
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// TruthyChange is warnings.truthyChange. Each call makes a new factory and so a new id, as upstream does.
|
|
239
|
+
func (w *WarningDefinitions) TruthyChange(checksStr string) *DiagnosticFactory {
|
|
240
|
+
return w.newFactory("Value will be checked against " + checksStr)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// StringOffsetChange is warnings.stringOffsetChange. Each call makes a new factory and so a new id.
|
|
244
|
+
func (w *WarningDefinitions) StringOffsetChange(text string) *DiagnosticFactory {
|
|
245
|
+
return w.newFactory("String macros no longer offset inputs: " + text)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// TransformerNotFound is warnings.transformerNotFound.
|
|
249
|
+
func (w *WarningDefinitions) TransformerNotFound(name, err string) *Diagnostic {
|
|
250
|
+
return TextDiagnostic(strings.Join([]string{
|
|
251
|
+
"Transformer `" + name + "` was not found!",
|
|
252
|
+
"More info: " + err,
|
|
253
|
+
suggestion(w.kleur, "Did you forget to install the package?"),
|
|
254
|
+
}, "\n"), diagnostics.CategoryWarning)
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// NewDefinitions builds `errors` and `warnings`. Ids count up through both, in source order.
|
|
258
|
+
// portOnlyDiagnosticID is the first id of diagnostics JS 3.0.0 doesn't have. It's far past any id it hands out.
|
|
259
|
+
const portOnlyDiagnosticID = 1 << 20
|
|
260
|
+
|
|
261
|
+
func NewDefinitions(k Kleur) (*ErrorDefinitions, *WarningDefinitions) {
|
|
262
|
+
id := 0
|
|
263
|
+
errorFactory := func(messages ...string) *DiagnosticFactory {
|
|
264
|
+
f := &DiagnosticFactory{ID: id, category: diagnostics.CategoryError, messages: messages}
|
|
265
|
+
id++
|
|
266
|
+
return f
|
|
267
|
+
}
|
|
268
|
+
s := func(text string) string { return suggestion(k, text) }
|
|
269
|
+
e := &ErrorDefinitions{kleur: k}
|
|
270
|
+
|
|
271
|
+
// reserved identifiers
|
|
272
|
+
e.NoInvalidIdentifier = errorFactory(
|
|
273
|
+
"Invalid Luau identifier!",
|
|
274
|
+
"Luau identifiers must start with a letter and only contain letters, numbers, and underscores.",
|
|
275
|
+
"Reserved Luau keywords cannot be used as identifiers.",
|
|
276
|
+
)
|
|
277
|
+
e.NoReservedIdentifier = errorFactory("Cannot use identifier reserved for compiler internal usage.")
|
|
278
|
+
e.NoReservedClassFields = errorFactory("Cannot use class field reserved for compiler internal usage.")
|
|
279
|
+
e.NoClassMetamethods = errorFactory("Metamethods cannot be used in class definitions!")
|
|
280
|
+
|
|
281
|
+
// banned statements
|
|
282
|
+
e.NoForInStatement = errorFactory("for-in loop statements are not supported!")
|
|
283
|
+
e.NoLabeledStatement = errorFactory("labels are not supported!")
|
|
284
|
+
e.NoDebuggerStatement = errorFactory("`debugger` is not supported!")
|
|
285
|
+
|
|
286
|
+
// banned expressions
|
|
287
|
+
e.NoNullLiteral = errorFactory("`null` is not supported!", s("Use `undefined` instead."))
|
|
288
|
+
e.NoPrivateIdentifier = errorFactory("Private identifiers are not supported!")
|
|
289
|
+
e.NoTypeOfExpression = errorFactory("`typeof` operator is not supported!", s("Use `typeIs(value, type)` or `typeOf(value)` instead."))
|
|
290
|
+
e.NoRegex = errorFactory("Regular expressions are not supported!")
|
|
291
|
+
e.NoBigInt = errorFactory("BigInt literals are not supported!")
|
|
292
|
+
|
|
293
|
+
// banned features
|
|
294
|
+
e.NoAny = errorFactory("Using values of type `any` is not supported!", s("Use `unknown` instead."))
|
|
295
|
+
e.NoVar = errorFactory("`var` keyword is not supported!", s("Use `let` or `const` instead."))
|
|
296
|
+
e.NoGetterSetter = errorFactory("Getters and Setters are not supported!", issue(k, 457))
|
|
297
|
+
e.NoAutoAccessorModifiers = errorFactory(
|
|
298
|
+
"Getters and Setters are not supported!",
|
|
299
|
+
"The `accessor` keyword requires generating get/set accessors",
|
|
300
|
+
issue(k, 457),
|
|
301
|
+
)
|
|
302
|
+
e.NoEqualsEquals = errorFactory("operator `==` is not supported!", s("Use `===` instead."))
|
|
303
|
+
e.NoExclamationEquals = errorFactory("operator `!=` is not supported!", s("Use `!==` instead."))
|
|
304
|
+
e.NoEnumMerging = errorFactory("Enum merging is not supported!")
|
|
305
|
+
e.NoNamespaceMerging = errorFactory("Namespace merging is not supported!")
|
|
306
|
+
e.NoSpreadDestructuring = errorFactory("Operator `...` is not supported for destructuring!")
|
|
307
|
+
e.NoFunctionExpressionName = errorFactory("Function expression names are not supported!")
|
|
308
|
+
e.NoPrecedingSpreadElement = errorFactory("Spread element must come last in a list of arguments!")
|
|
309
|
+
e.NoLuaTupleDestructureAssignmentExpression = errorFactory("Cannot destructure LuaTuple<T> expression outside of an ExpressionStatement!")
|
|
310
|
+
e.NoExportAssignmentLet = errorFactory("Cannot use `export =` on a `let` variable!", s("Use `const` instead."))
|
|
311
|
+
e.NoGlobalThis = errorFactory("`globalThis` is not supported!")
|
|
312
|
+
e.NoArguments = errorFactory("`arguments` is not supported!")
|
|
313
|
+
e.NoPrototype = errorFactory("`prototype` is not supported!")
|
|
314
|
+
e.NoRobloxSymbolInstanceof = errorFactory(
|
|
315
|
+
"The `instanceof` operator can only be used on roblox-ts classes!",
|
|
316
|
+
s("Use `typeIs(myThing, \"TypeToCheck\") instead"),
|
|
317
|
+
)
|
|
318
|
+
e.NoNonNumberStringRelationOperator = errorFactory("Relation operators can only be used on number or string types!")
|
|
319
|
+
e.NoInstanceMethodCollisions = errorFactory("Static methods cannot use the same name as instance methods!")
|
|
320
|
+
e.NoStaticMethodCollisions = errorFactory("Instance methods cannot use the same name as static methods!")
|
|
321
|
+
e.NoUnaryPlus = errorFactory("Unary `+` is not supported!", s("Use `tonumber(x)` instead."))
|
|
322
|
+
e.NoNonNumberUnaryMinus = errorFactory("Unary `-` is only supported for number types!")
|
|
323
|
+
e.NoAwaitForOf = errorFactory("`await` is not supported in for-of loops!")
|
|
324
|
+
e.NoAsyncGeneratorFunctions = errorFactory("Async generator functions are not supported!")
|
|
325
|
+
e.NoNonStringModuleSpecifier = errorFactory("Module specifiers must be a string literal.")
|
|
326
|
+
e.NoIterableIteration = errorFactory("Iterating on Iterable<T> is not supported! You must use a more specific type.")
|
|
327
|
+
e.NoMixedTypeCall = errorFactory("Attempted to call a function with mixed types! All definitions must either be a method or a callback.")
|
|
328
|
+
e.NoIndexWithoutCall = errorFactory("Cannot index a method without calling it!", s("Use the form `() => a.b()` instead of `a.b`."))
|
|
329
|
+
e.NoCommentDirectives = errorFactory(
|
|
330
|
+
"Usage of `@ts-ignore`, `@ts-expect-error`, and `@ts-nocheck` are not supported!",
|
|
331
|
+
"roblox-ts needs type and symbol info to compile correctly.",
|
|
332
|
+
s("Consider using type assertions or `declare` statements."),
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
// macro methods
|
|
336
|
+
e.NoOptionalMacroCall = errorFactory("Macro methods can not be optionally called!", s("Macros always exist. Use a normal call."))
|
|
337
|
+
e.NoConstructorMacroWithoutNew = errorFactory("Cannot index a constructor macro without using the `new` operator!")
|
|
338
|
+
e.NoMacroExtends = errorFactory("Cannot extend from a macro class!", s("Store an instance of the macro class in a property."))
|
|
339
|
+
e.NoMacroUnion = errorFactory("Macro cannot be applied to a union type!")
|
|
340
|
+
e.NoMacroObjectSpread = errorFactory("Macro classes cannot be used in an object spread!", s("Did you mean to use an array spread? `[ ...exp ]`"))
|
|
341
|
+
e.NoVarArgsMacroSpread = errorFactory("Macros which use variadic arguments do not support spread expressions!", issue(k, 1149))
|
|
342
|
+
e.NoRangeMacroOutsideForOf = errorFactory("$range() macro is only valid as an expression of a for-of loop!")
|
|
343
|
+
e.NoTupleMacroOutsideReturn = errorFactory("$tuple() macro is only valid as an expression of a return statement!")
|
|
344
|
+
|
|
345
|
+
// import/export
|
|
346
|
+
e.NoModuleSpecifierFile = errorFactory("Could not find file for import. Did you forget to `npm install`?")
|
|
347
|
+
e.NoInvalidModule = errorFactory("You can only use npm scopes that are listed in your typeRoots.")
|
|
348
|
+
e.NoUnscopedModule = errorFactory("You cannot use modules directly under node_modules.")
|
|
349
|
+
e.NoNonModuleImport = errorFactory("Cannot import a non-ModuleScript!")
|
|
350
|
+
e.NoIsolatedImport = errorFactory("Attempted to import a file inside of an isolated container from outside!")
|
|
351
|
+
e.NoServerImport = errorFactory("Cannot import a server file from a shared or client location!", s("Move the file you want to import to a shared location."))
|
|
352
|
+
|
|
353
|
+
// jsx
|
|
354
|
+
e.NoPrecedingJsxSpreadElement = errorFactory("JSX spread expression must come last in children!")
|
|
355
|
+
|
|
356
|
+
// semantic
|
|
357
|
+
e.ExpectedMethodGotFunction = errorFactory("Attempted to assign non-method where method was expected.")
|
|
358
|
+
e.ExpectedFunctionGotMethod = errorFactory("Attempted to assign method where non-method was expected.")
|
|
359
|
+
|
|
360
|
+
// files
|
|
361
|
+
e.NoRojoData = &NoRojoDataFactory{contextFactory: contextFactory{ID: id, category: diagnostics.CategoryError}, kleur: k}
|
|
362
|
+
id++
|
|
363
|
+
e.NoPackageImportWithoutScope = &NoPackageImportWithoutScopeFactory{contextFactory: contextFactory{ID: id, category: diagnostics.CategoryError}, kleur: k}
|
|
364
|
+
id++
|
|
365
|
+
|
|
366
|
+
// From upstream's master (#3052), where it comes after noIterableIteration. JS 3.0.0 crashes where this is reported, so
|
|
367
|
+
// it has no id in 3.0.0's order, and taking one here would change every id after it.
|
|
368
|
+
e.NoUnsupportedIteration = &DiagnosticFactory{
|
|
369
|
+
ID: portOnlyDiagnosticID,
|
|
370
|
+
category: diagnostics.CategoryError,
|
|
371
|
+
messages: []string{
|
|
372
|
+
"Cannot iterate over this type!",
|
|
373
|
+
"roblox-ts needs a supported, specific iterable type to generate the correct iteration code.",
|
|
374
|
+
s("Use a supported type such as Array<T>, Set<T>, or Map<K, V>."),
|
|
375
|
+
},
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
w := &WarningDefinitions{kleur: k, nextID: id}
|
|
379
|
+
w.RuntimeLibUsedInReplicatedFirst = w.newFactory("This statement would generate a call to the runtime library. The runtime library should not be used from ReplicatedFirst.")
|
|
380
|
+
return e, w
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// Errors and Warnings are the process-wide definitions, like the module-level values upstream.
|
|
384
|
+
// Color is detected once, as kleur does.
|
|
385
|
+
var Errors, Warnings = NewDefinitions(DetectKleur())
|
|
386
|
+
|
|
387
|
+
// Color is the process-wide Kleur, for messages built at call sites such as validateCompilerOptions.
|
|
388
|
+
var Color = DetectKleur()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
package shared
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"fmt"
|
|
5
|
+
"time"
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
// FormatElapsed is a build's duration for people to read: whole milliseconds under a second, then seconds.
|
|
9
|
+
func FormatElapsed(d time.Duration) string {
|
|
10
|
+
if d < time.Second {
|
|
11
|
+
return fmt.Sprintf("%d ms", d.Milliseconds())
|
|
12
|
+
}
|
|
13
|
+
return fmt.Sprintf("%.2f s", d.Seconds())
|
|
14
|
+
}
|