@data-vegle/rbxts-go 1.0.0 → 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.
- package/docs/plugin-api.md +7 -3
- package/package.json +1 -1
- package/plugins/apply.go +1 -1
- package/plugins/native.go +10 -1
- package/plugins/session.go +15 -2
- package/tsbridge/reprint.go +22 -1
package/docs/plugin-api.md
CHANGED
|
@@ -190,9 +190,13 @@ type Updater interface {
|
|
|
190
190
|
|
|
191
191
|
What the host does today, which is more than the above asks of a plugin and can become less:
|
|
192
192
|
|
|
193
|
-
-
|
|
194
|
-
|
|
195
|
-
|
|
193
|
+
- A cycle calls `TransformFile` only for the files the change can reach: the changed files and every file that
|
|
194
|
+
imports one of them, directly or through other files. The other files keep the text they were printed with last
|
|
195
|
+
time. A plugin that needs something from every file, such as a table of all the call sites of the program, must read
|
|
196
|
+
it from `Host.Program` (in `New`, `Update` or its first `TransformFile`), not gather it from the `TransformFile`
|
|
197
|
+
calls. `Finish` is called every cycle. Every file goes through again when files are added or removed, when a
|
|
198
|
+
declaration file or a script that can change the global scope changed, when a file resolves its imports
|
|
199
|
+
differently, and whenever setget is on.
|
|
196
200
|
- `changed` is worked out against the last program the transformer was given, whether that cycle ended well or not.
|
|
197
201
|
It holds any file of the program, declaration files and JSON files too, so it is not a subset of `Host.Files`.
|
|
198
202
|
- `New` is called again, still with `Host.Watch` true, when the old transformers cannot be trusted or do not fit:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-vegle/rbxts-go",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
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
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
package/plugins/apply.go
CHANGED
|
@@ -66,7 +66,7 @@ func ApplyWithStats(ctx context.Context, p *tsbridge.Project, decision Decision,
|
|
|
66
66
|
}
|
|
67
67
|
if decision.Action == ActionPlugins {
|
|
68
68
|
run := &nativeRun{}
|
|
69
|
-
result, err := run.transform(ctx, p, decision, files, build, false, func() *accessorNames { return collectAccessorNames(p) })
|
|
69
|
+
result, err := run.transform(ctx, p, decision, files, build, false, nil, func() *accessorNames { return collectAccessorNames(p) })
|
|
70
70
|
if err != nil {
|
|
71
71
|
return nil, stats, err
|
|
72
72
|
}
|
package/plugins/native.go
CHANGED
|
@@ -89,9 +89,11 @@ func changedFiles(previous map[tspath.PathKey]*ast.SourceFile, program []*ast.So
|
|
|
89
89
|
// transform runs the plugin pass over one program: New or Update, then every file through setget (if it is on) and
|
|
90
90
|
// the plugins in order, then the printing, then Finish. It all happens on the calling goroutine with one checker,
|
|
91
91
|
// apart from the printing, which calls no plugin. names gives setget's accessor names, and is only called for setget.
|
|
92
|
+
// reused holds, by path, the outcome of the files that are not transformed again: they keep that outcome. It is nil when
|
|
93
|
+
// every file goes through.
|
|
92
94
|
//
|
|
93
95
|
// An error of AddDiagnostic comes back as a *shared.DiagnosticError.
|
|
94
|
-
func (r *nativeRun) transform(ctx context.Context, p *tsbridge.Project, decision Decision, files []*ast.SourceFile, build *Build, watch bool, names func() *accessorNames) (result *nativeResult, err error) {
|
|
96
|
+
func (r *nativeRun) transform(ctx context.Context, p *tsbridge.Project, decision Decision, files []*ast.SourceFile, build *Build, watch bool, reused map[tspath.PathKey]*fileOutcome, names func() *accessorNames) (result *nativeResult, err error) {
|
|
95
97
|
// After a panic, an Exit or an error, nothing says what state a transformer is in. The next program starts with New.
|
|
96
98
|
kept := false
|
|
97
99
|
defer func() {
|
|
@@ -168,6 +170,9 @@ func (r *nativeRun) transform(ctx context.Context, p *tsbridge.Project, decision
|
|
|
168
170
|
emits := make([]*printer.EmitContext, len(files))
|
|
169
171
|
var reported []*shared.Diagnostic
|
|
170
172
|
for i, file := range files {
|
|
173
|
+
if reused[file.PathKey()] != nil {
|
|
174
|
+
continue
|
|
175
|
+
}
|
|
171
176
|
emit := printer.NewEmitContext()
|
|
172
177
|
node := file.AsNode()
|
|
173
178
|
doing := "while transforming " + file.FileName().AsString()
|
|
@@ -217,6 +222,10 @@ func (r *nativeRun) transform(ctx context.Context, p *tsbridge.Project, decision
|
|
|
217
222
|
outcomes[i].panicText = fmt.Sprint(r)
|
|
218
223
|
}
|
|
219
224
|
}()
|
|
225
|
+
if old := reused[file.PathKey()]; old != nil {
|
|
226
|
+
outcomes[i] = *old
|
|
227
|
+
return
|
|
228
|
+
}
|
|
220
229
|
printFile(file, transformed[i], emits[i], &outcomes[i])
|
|
221
230
|
})
|
|
222
231
|
for i := range outcomes {
|
package/plugins/session.go
CHANGED
|
@@ -129,8 +129,21 @@ func (s *Session) applyNative(ctx context.Context, p *tsbridge.Project, decision
|
|
|
129
129
|
s.native = &nativeRun{}
|
|
130
130
|
change = &tsbridge.Change{Full: true, Reason: "first run of the plugins"}
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
|
|
132
|
+
// As in JS watch mode, the plugins only get the files a change can reach: the changed files and everything that
|
|
133
|
+
// imports them, directly or not. The others keep the text they were printed with last time. Plugins gather what
|
|
134
|
+
// they need from other files by reading the program, not from the calls to TransformFile. Setget's accessor names
|
|
135
|
+
// can change what any file prints, so with setget every file goes through again.
|
|
136
|
+
var kept map[tspath.PathKey]*fileOutcome
|
|
137
|
+
if !change.Full && !decision.Setget && s.outcomes != nil {
|
|
138
|
+
kept = make(map[tspath.PathKey]*fileOutcome, len(files))
|
|
139
|
+
for _, file := range files {
|
|
140
|
+
if outcome := s.outcomes[file.PathKey()]; outcome != nil && !change.Reaches(file) {
|
|
141
|
+
kept[file.PathKey()] = outcome
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
s.LastRedone = len(files) - len(kept)
|
|
146
|
+
result, err := s.native.transform(ctx, p, decision, files, build, true, kept, func() *accessorNames { return s.collectNames(p) })
|
|
134
147
|
if err != nil {
|
|
135
148
|
return nil, err
|
|
136
149
|
}
|
package/tsbridge/reprint.go
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
package tsbridge
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"os"
|
|
5
|
+
|
|
4
6
|
"github.com/microsoft/TypeScript/tsc/internal/ast"
|
|
5
7
|
"github.com/microsoft/TypeScript/tsc/internal/bundled"
|
|
6
8
|
"github.com/microsoft/TypeScript/tsc/internal/compiler"
|
|
@@ -54,8 +56,24 @@ func (p *Project) UpdatePrinted(source *Project, changed map[tspath.PathKey]stri
|
|
|
54
56
|
CompilerHost: compiler.NewCachedFSCompilerHost(bundled.WrapFS(osvfs.FS()), bundled.LibPath(), &tsc.ExtendedConfigCache{}, nil, nil),
|
|
55
57
|
printed: changed,
|
|
56
58
|
}
|
|
59
|
+
// The printed program can hold files the source program lacks: the ones only printed text imports, such as a
|
|
60
|
+
// module that a plugin's generated code brings in. They stay as they are while the file on disk has the text they
|
|
61
|
+
// were parsed from. Parsing one again would give a new object for the same declaration file, which reads as a
|
|
62
|
+
// change to the global scope and makes every file dirty.
|
|
63
|
+
extras := map[tspath.PathKey]*ast.SourceFile{}
|
|
64
|
+
extrasChanged := false
|
|
65
|
+
for path, old := range previous {
|
|
66
|
+
if _, ok := sourceFiles[path]; ok {
|
|
67
|
+
continue
|
|
68
|
+
}
|
|
69
|
+
if text, err := os.ReadFile(old.FileName().AsString()); err == nil && string(text) == old.Text() {
|
|
70
|
+
extras[path] = old
|
|
71
|
+
} else {
|
|
72
|
+
extrasChanged = true
|
|
73
|
+
}
|
|
74
|
+
}
|
|
57
75
|
// Reuse needs the same files, with only printed ones different.
|
|
58
|
-
reusable := !full && len(sourceFiles) == len(previous)
|
|
76
|
+
reusable := !full && !extrasChanged && len(sourceFiles)+len(extras) == len(previous)
|
|
59
77
|
if reusable {
|
|
60
78
|
for path, file := range sourceFiles {
|
|
61
79
|
old, ok := previous[path]
|
|
@@ -93,6 +111,9 @@ func (p *Project) UpdatePrinted(source *Project, changed map[tspath.PathKey]stri
|
|
|
93
111
|
merged[path] = file
|
|
94
112
|
}
|
|
95
113
|
}
|
|
114
|
+
for path, old := range extras {
|
|
115
|
+
merged[path] = old
|
|
116
|
+
}
|
|
96
117
|
host.previous = merged
|
|
97
118
|
program := compiler.NewProgram(compiler.ProgramOptions{Config: source.config, Host: host})
|
|
98
119
|
return &Project{config: source.config, program: program, notes: source.notes}
|