ttsc 0.7.1 → 0.7.3
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/README.md +5 -6
- package/cmd/platform/main.go +86 -76
- package/cmd/ttsc/api_compile.go +122 -105
- package/cmd/ttsc/api_transform.go +57 -49
- package/cmd/ttsc/build.go +116 -103
- package/cmd/ttsc/main.go +117 -117
- package/cmd/ttsc/main_test.go +191 -191
- package/driver/host.go +9 -9
- package/driver/program.go +285 -285
- package/driver/rewrite.go +225 -219
- package/lib/compiler/internal/compileProjectInMemory.js +3 -3
- package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
- package/lib/compiler/internal/resolveEmittedJavaScript.js +2 -1
- package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
- package/lib/compiler/internal/resolveTsgo.js.map +1 -1
- package/lib/compiler/internal/runBuild.js.map +1 -1
- package/lib/launcher/internal/getCompilerVersionText.js +1 -2
- package/lib/launcher/internal/getCompilerVersionText.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.js +92 -9
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/runTtsc.js +30 -4
- package/lib/launcher/internal/runTtsc.js.map +1 -1
- package/lib/launcher/internal/runTtsx.js +7 -2
- package/lib/launcher/internal/runTtsx.js.map +1 -1
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
- package/package.json +9 -9
- package/shim/ast/lint.go +171 -171
- package/shim/ast/shim.go +83 -83
- package/shim/bundled/shim.go +5 -1
- package/shim/checker/shim.go +79 -79
- package/shim/compiler/shim.go +16 -1
- package/shim/core/shim.go +10 -10
- package/shim/diagnosticwriter/lint.go +79 -79
- package/shim/diagnosticwriter/shim.go +19 -19
- package/shim/parser/shim.go +7 -1
- package/shim/scanner/shim.go +39 -1
- package/shim/tsoptions/shim.go +51 -1
- package/shim/tspath/shim.go +72 -1
- package/shim/vfs/cachedvfs/shim.go +1 -1
- package/shim/vfs/osvfs/shim.go +1 -1
- package/shim/vfs/shim.go +4 -1
- package/src/compiler/internal/compileProjectInMemory.ts +6 -3
- package/src/compiler/internal/resolveEmittedJavaScript.ts +2 -1
- package/src/compiler/internal/resolveTsgo.ts +0 -1
- package/src/compiler/internal/runBuild.ts +4 -1
- package/src/launcher/internal/getCompilerVersionText.ts +1 -2
- package/src/launcher/internal/prepareExecution.ts +115 -9
- package/src/launcher/internal/runTtsc.ts +35 -4
- package/src/launcher/internal/runTtsx.ts +16 -5
- package/src/plugin/internal/buildSourcePlugin.ts +7 -2
- package/test/platform.test.ts +1 -3
- package/test/tsgo.test.ts +6 -1
- package/tools/gen_shims/main.go +409 -409
package/cmd/ttsc/main_test.go
CHANGED
|
@@ -1,92 +1,92 @@
|
|
|
1
1
|
package main
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
"bytes"
|
|
5
|
+
"os"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"strings"
|
|
8
|
+
"testing"
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
// withCapture replaces stdout/stderr with buffers for the duration of fn.
|
|
12
12
|
// Keeps each test hermetic.
|
|
13
13
|
func withCapture(fn func()) (out, errOut string) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
var outBuf, errBuf bytes.Buffer
|
|
15
|
+
prevOut, prevErr := stdout, stderr
|
|
16
|
+
stdout = &outBuf
|
|
17
|
+
stderr = &errBuf
|
|
18
|
+
defer func() {
|
|
19
|
+
stdout = prevOut
|
|
20
|
+
stderr = prevErr
|
|
21
|
+
}()
|
|
22
|
+
fn()
|
|
23
|
+
return outBuf.String(), errBuf.String()
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
func TestRunNoArgsAttemptsProjectBuild(t *testing.T) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
out, errOut := withCapture(func() {
|
|
28
|
+
if code := run(nil); code == 0 {
|
|
29
|
+
t.Errorf("expected no-args run without a local tsconfig to fail")
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
if strings.Contains(out, "Usage:") {
|
|
33
|
+
t.Errorf("no-args ttsc must build the project, not print help; got %q", out)
|
|
34
|
+
}
|
|
35
|
+
if !strings.Contains(errOut, "tsconfig") {
|
|
36
|
+
t.Errorf("expected no-args build to look for tsconfig, got stderr %q", errOut)
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
func TestRunHelpVariants(t *testing.T) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
41
|
+
for _, flag := range []string{"-h", "--help", "help"} {
|
|
42
|
+
t.Run(flag, func(t *testing.T) {
|
|
43
|
+
out, _ := withCapture(func() {
|
|
44
|
+
if code := run([]string{flag}); code != 0 {
|
|
45
|
+
t.Errorf("expected exit 0, got %d", code)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
if !strings.Contains(out, "demo") {
|
|
49
|
+
t.Errorf("help text should list demo subcommand, got %q", out)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
func TestRunVersion(t *testing.T) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
56
|
+
for _, flag := range []string{"-v", "--version", "version"} {
|
|
57
|
+
t.Run(flag, func(t *testing.T) {
|
|
58
|
+
out, _ := withCapture(func() {
|
|
59
|
+
if code := run([]string{flag}); code != 0 {
|
|
60
|
+
t.Errorf("expected exit 0, got %d", code)
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
if !strings.Contains(out, "ttsc ") {
|
|
64
|
+
t.Errorf("expected version banner, got %q", out)
|
|
65
|
+
}
|
|
66
|
+
// Include useful debug bits
|
|
67
|
+
for _, tag := range []string{"commit", "go"} {
|
|
68
|
+
if !strings.Contains(out, tag) {
|
|
69
|
+
t.Errorf("expected %q substring in version output, got %q", tag, out)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
func TestRunUnknownCommandExits2(t *testing.T) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
77
|
+
_, errOut := withCapture(func() {
|
|
78
|
+
if code := run([]string{"fly-to-mars"}); code != 2 {
|
|
79
|
+
t.Errorf("expected exit 2, got %d", code)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
if !strings.Contains(errOut, "unknown command") {
|
|
83
|
+
t.Errorf("expected error text, got %q", errOut)
|
|
84
|
+
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
func TestRunBuildBlocksSemanticDiagnosticsBeforeEmit(t *testing.T) {
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
root := t.TempDir()
|
|
89
|
+
writeProjectFile(t, root, "tsconfig.json", `{
|
|
90
90
|
"compilerOptions": {
|
|
91
91
|
"module": "commonjs",
|
|
92
92
|
"target": "es2020",
|
|
@@ -95,32 +95,32 @@ func TestRunBuildBlocksSemanticDiagnosticsBeforeEmit(t *testing.T) {
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
`)
|
|
98
|
-
|
|
98
|
+
writeProjectFile(t, root, "index.ts", `const value: string = 123;
|
|
99
99
|
console.log(value);
|
|
100
100
|
`)
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
102
|
+
_, errOut := withCapture(func() {
|
|
103
|
+
if code := runBuild([]string{"--cwd", root, "--emit"}); code != 2 {
|
|
104
|
+
t.Errorf("expected exit 2, got %d", code)
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
if !strings.Contains(errOut, "Type 'number' is not assignable to type 'string'") {
|
|
108
|
+
t.Errorf("expected semantic diagnostic, got %q", errOut)
|
|
109
|
+
}
|
|
110
|
+
if !strings.Contains(errOut, "\x1b[91merror\x1b[0m") || !strings.Contains(errOut, "TS2322") {
|
|
111
|
+
t.Errorf("expected colored TypeScript-style diagnostic header, got %q", errOut)
|
|
112
|
+
}
|
|
113
|
+
if !strings.Contains(errOut, "\x1b[7m1\x1b[0m") || !strings.Contains(errOut, "~~~~~") {
|
|
114
|
+
t.Errorf("expected source context with highlighted span, got %q", errOut)
|
|
115
|
+
}
|
|
116
|
+
if _, err := os.Stat(filepath.Join(root, "bin", "index.js")); !os.IsNotExist(err) {
|
|
117
|
+
t.Errorf("expected no emitted JS, stat err=%v", err)
|
|
118
|
+
}
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
func TestRunBuildAllowsUnusedTypeParametersOnOverloadSignatures(t *testing.T) {
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
root := t.TempDir()
|
|
123
|
+
writeProjectFile(t, root, "tsconfig.json", `{
|
|
124
124
|
"compilerOptions": {
|
|
125
125
|
"module": "commonjs",
|
|
126
126
|
"target": "es2020",
|
|
@@ -131,28 +131,28 @@ func TestRunBuildAllowsUnusedTypeParametersOnOverloadSignatures(t *testing.T) {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
`)
|
|
134
|
-
|
|
134
|
+
writeProjectFile(t, root, "index.ts", `export function marker<T>(input: unknown): string;
|
|
135
135
|
export function marker(input: unknown): string {
|
|
136
136
|
return String(input);
|
|
137
137
|
}
|
|
138
138
|
`)
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
140
|
+
_, errOut := withCapture(func() {
|
|
141
|
+
if code := runBuild([]string{"--cwd", root, "--emit", "--quiet"}); code != 0 {
|
|
142
|
+
t.Errorf("expected exit 0, got %d", code)
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
if strings.Contains(errOut, "declared but never used") || strings.Contains(errOut, "All type parameters are unused") {
|
|
146
|
+
t.Errorf("overload signature type parameters must not fail noUnused checks, got %q", errOut)
|
|
147
|
+
}
|
|
148
|
+
if _, err := os.Stat(filepath.Join(root, "bin", "index.js")); err != nil {
|
|
149
|
+
t.Errorf("expected emitted JS, stat err=%v", err)
|
|
150
|
+
}
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
func TestRunBuildBlocksUnusedParametersBeforeEmit(t *testing.T) {
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
root := t.TempDir()
|
|
155
|
+
writeProjectFile(t, root, "tsconfig.json", `{
|
|
156
156
|
"compilerOptions": {
|
|
157
157
|
"module": "commonjs",
|
|
158
158
|
"target": "es2020",
|
|
@@ -162,28 +162,28 @@ func TestRunBuildBlocksUnusedParametersBeforeEmit(t *testing.T) {
|
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
164
|
`)
|
|
165
|
-
|
|
165
|
+
writeProjectFile(t, root, "index.ts", `export function run(unused: string): number {
|
|
166
166
|
return 1;
|
|
167
167
|
}
|
|
168
168
|
`)
|
|
169
169
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
170
|
+
_, errOut := withCapture(func() {
|
|
171
|
+
if code := runBuild([]string{"--cwd", root, "--emit"}); code != 2 {
|
|
172
|
+
t.Errorf("expected exit 2, got %d", code)
|
|
173
|
+
}
|
|
174
|
+
})
|
|
175
|
+
if !strings.Contains(errOut, "'unused' is declared but its value is never read") &&
|
|
176
|
+
!strings.Contains(errOut, "'unused' is declared but never used") {
|
|
177
|
+
t.Errorf("expected unused parameter diagnostic, got %q", errOut)
|
|
178
|
+
}
|
|
179
|
+
if _, err := os.Stat(filepath.Join(root, "bin", "index.js")); !os.IsNotExist(err) {
|
|
180
|
+
t.Errorf("expected no emitted JS, stat err=%v", err)
|
|
181
|
+
}
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
func TestRunBuildBlocksSyntacticDiagnosticsBeforeEmit(t *testing.T) {
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
root := t.TempDir()
|
|
186
|
+
writeProjectFile(t, root, "tsconfig.json", `{
|
|
187
187
|
"compilerOptions": {
|
|
188
188
|
"module": "commonjs",
|
|
189
189
|
"target": "es2020",
|
|
@@ -191,98 +191,98 @@ func TestRunBuildBlocksSyntacticDiagnosticsBeforeEmit(t *testing.T) {
|
|
|
191
191
|
}
|
|
192
192
|
}
|
|
193
193
|
`)
|
|
194
|
-
|
|
194
|
+
writeProjectFile(t, root, "index.ts", `console.log("before");
|
|
195
195
|
const = ;
|
|
196
196
|
`)
|
|
197
197
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
198
|
+
_, errOut := withCapture(func() {
|
|
199
|
+
if code := runBuild([]string{"--cwd", root, "--emit"}); code != 2 {
|
|
200
|
+
t.Errorf("expected exit 2, got %d", code)
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
if !strings.Contains(errOut, "Variable declaration expected") {
|
|
204
|
+
t.Errorf("expected syntactic diagnostic, got %q", errOut)
|
|
205
|
+
}
|
|
206
|
+
if _, err := os.Stat(filepath.Join(root, "bin", "index.js")); !os.IsNotExist(err) {
|
|
207
|
+
t.Errorf("expected no emitted JS, stat err=%v", err)
|
|
208
|
+
}
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
func writeProjectFile(t *testing.T, root string, name string, contents string) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
212
|
+
t.Helper()
|
|
213
|
+
file := filepath.Join(root, name)
|
|
214
|
+
if err := os.MkdirAll(filepath.Dir(file), 0o755); err != nil {
|
|
215
|
+
t.Fatal(err)
|
|
216
|
+
}
|
|
217
|
+
if err := os.WriteFile(file, []byte(contents), 0o644); err != nil {
|
|
218
|
+
t.Fatal(err)
|
|
219
|
+
}
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
func TestRunDemoString(t *testing.T) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
223
|
+
out, _ := withCapture(func() {
|
|
224
|
+
if code := run([]string{"demo", "--type=string"}); code != 0 {
|
|
225
|
+
t.Errorf("expected exit 0, got %d", code)
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
want := `(input) => "string" === typeof input`
|
|
229
|
+
if !strings.Contains(out, want) {
|
|
230
|
+
t.Errorf("expected demo output to contain %q, got:\n%s", want, out)
|
|
231
|
+
}
|
|
232
|
+
if !strings.Contains(out, "demo<string>") {
|
|
233
|
+
t.Errorf("expected comment prefix in demo output, got:\n%s", out)
|
|
234
|
+
}
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
func TestRunDemoEveryAtomic(t *testing.T) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
238
|
+
cases := map[string]string{
|
|
239
|
+
"boolean": `"boolean" === typeof input`,
|
|
240
|
+
"number": `"number" === typeof input`,
|
|
241
|
+
"bigint": `"bigint" === typeof input`,
|
|
242
|
+
"any": `(input) => true`,
|
|
243
|
+
}
|
|
244
|
+
for typ, expected := range cases {
|
|
245
|
+
t.Run(typ, func(t *testing.T) {
|
|
246
|
+
out, _ := withCapture(func() {
|
|
247
|
+
if code := run([]string{"demo", "--type=" + typ}); code != 0 {
|
|
248
|
+
t.Errorf("expected exit 0 for %s, got %d", typ, code)
|
|
249
|
+
}
|
|
250
|
+
})
|
|
251
|
+
if !strings.Contains(out, expected) {
|
|
252
|
+
t.Errorf("for --type=%s, want %q in output:\n%s", typ, expected, out)
|
|
253
|
+
}
|
|
254
|
+
})
|
|
255
|
+
}
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
func TestRunDemoUnknownTypeExits2(t *testing.T) {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
259
|
+
_, errOut := withCapture(func() {
|
|
260
|
+
if code := run([]string{"demo", "--type=object"}); code != 2 {
|
|
261
|
+
t.Errorf("expected exit 2 for unknown type, got %d", code)
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
if !strings.Contains(errOut, "unknown --type") {
|
|
265
|
+
t.Errorf("expected diagnostic text, got %q", errOut)
|
|
266
|
+
}
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
func TestDemoArrowEveryAtomic(t *testing.T) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
270
|
+
cases := map[string]string{
|
|
271
|
+
"string": `"string" === typeof input`,
|
|
272
|
+
"number": `"number" === typeof input`,
|
|
273
|
+
"boolean": `"boolean" === typeof input`,
|
|
274
|
+
"bigint": `"bigint" === typeof input`,
|
|
275
|
+
"any": `(input) => true`,
|
|
276
|
+
}
|
|
277
|
+
for name, want := range cases {
|
|
278
|
+
t.Run(name, func(t *testing.T) {
|
|
279
|
+
arrow, err := demoArrow(name)
|
|
280
|
+
if err != nil {
|
|
281
|
+
t.Fatalf("unexpected err: %v", err)
|
|
282
|
+
}
|
|
283
|
+
if !strings.Contains(arrow, want) {
|
|
284
|
+
t.Errorf("for %s want %q, got %q", name, want, arrow)
|
|
285
|
+
}
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
288
|
}
|
package/driver/host.go
CHANGED
|
@@ -5,27 +5,27 @@
|
|
|
5
5
|
//
|
|
6
6
|
// Structural note: this file is deliberately adapted from tsgonest's
|
|
7
7
|
// `internal/compiler/host.go` (MIT, github.com/tsgonest/tsgonest).
|
|
8
|
-
// The helper surface is the same
|
|
9
|
-
//
|
|
8
|
+
// The helper surface is the same because both hosts need the same bundled-lib
|
|
9
|
+
// filesystem and CompilerHost construction.
|
|
10
10
|
package driver
|
|
11
11
|
|
|
12
12
|
import (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
"github.com/microsoft/typescript-go/shim/bundled"
|
|
14
|
+
shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
|
|
15
|
+
"github.com/microsoft/typescript-go/shim/vfs"
|
|
16
|
+
"github.com/microsoft/typescript-go/shim/vfs/cachedvfs"
|
|
17
|
+
"github.com/microsoft/typescript-go/shim/vfs/osvfs"
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
// DefaultFS returns an OS-backed filesystem wrapped with tsgo's bundled libs so
|
|
21
21
|
// built-in definitions (lib.es*.d.ts, dom, etc.) resolve without a network
|
|
22
22
|
// fetch. Mirrors tsgonest/tsgolint behavior.
|
|
23
23
|
func DefaultFS() vfs.FS {
|
|
24
|
-
|
|
24
|
+
return bundled.WrapFS(cachedvfs.From(osvfs.FS()))
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// DefaultHost returns a CompilerHost anchored at cwd that can find tsgo's
|
|
28
28
|
// bundled library files via `bundled.LibPath()`.
|
|
29
29
|
func DefaultHost(cwd string, fs vfs.FS) shimcompiler.CompilerHost {
|
|
30
|
-
|
|
30
|
+
return shimcompiler.NewCompilerHost(cwd, fs, bundled.LibPath(), nil, nil)
|
|
31
31
|
}
|