ttsc 0.12.2 → 0.12.4
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/cmd/platform/main.go +9 -0
- package/cmd/ttsc/api_compile.go +109 -101
- package/cmd/ttsc/api_compile_branches_test.go +55 -57
- package/cmd/ttsc/api_transform.go +54 -49
- package/cmd/ttsc/api_transform_branches_test.go +30 -32
- package/cmd/ttsc/build.go +111 -108
- package/cmd/ttsc/build_branches_test.go +95 -97
- package/cmd/ttsc/helpers_test.go +39 -28
- package/cmd/ttsc/main.go +111 -104
- package/cmd/ttsc/main_alias_branches_test.go +21 -23
- package/cmd/ttscserver/main.go +96 -90
- package/cmd/ttscserver/run_lsp_prefers_tsgo_flag_test.go +22 -22
- package/cmd/ttscserver/run_lsp_reports_server_error_test.go +22 -22
- package/cmd/ttscserver/run_lsp_uses_tsgo_environment_test.go +23 -23
- package/cmd/utility-host/main.go +30 -23
- package/driver/lsp.go +53 -7
- package/driver/plugins.go +88 -72
- package/driver/program.go +362 -339
- package/driver/rewrite.go +442 -380
- package/internal/lspserver/lsp_envelope.go +64 -64
- package/internal/lspserver/lsp_frame.go +60 -60
- package/internal/lspserver/lsp_plugin.go +57 -57
- package/internal/lspserver/lsp_proxy.go +265 -251
- package/internal/lspserver/lsp_server.go +155 -144
- package/lib/TtscCompiler.d.ts +7 -0
- package/lib/TtscCompiler.js +7 -0
- package/lib/TtscCompiler.js.map +1 -1
- package/lib/compiler/internal/buildNativeCompiler.d.ts +11 -1
- package/lib/compiler/internal/buildNativeCompiler.js +23 -3
- package/lib/compiler/internal/buildNativeCompiler.js.map +1 -1
- package/lib/compiler/internal/compileProjectInMemory.d.ts +9 -0
- package/lib/compiler/internal/compileProjectInMemory.js +36 -21
- package/lib/compiler/internal/compileProjectInMemory.js.map +1 -1
- package/lib/compiler/internal/paths.d.ts +27 -0
- package/lib/compiler/internal/paths.js +70 -0
- package/lib/compiler/internal/paths.js.map +1 -0
- package/lib/compiler/internal/project/readProjectConfig.d.ts +9 -1
- package/lib/compiler/internal/project/readProjectConfig.js +80 -1
- package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
- package/lib/compiler/internal/project/resolveProjectConfig.d.ts +13 -1
- package/lib/compiler/internal/project/resolveProjectConfig.js +24 -1
- package/lib/compiler/internal/project/resolveProjectConfig.js.map +1 -1
- package/lib/compiler/internal/resolveBinary.d.ts +9 -1
- package/lib/compiler/internal/resolveBinary.js +17 -1
- package/lib/compiler/internal/resolveBinary.js.map +1 -1
- package/lib/compiler/internal/resolveEmittedJavaScript.d.ts +16 -1
- package/lib/compiler/internal/resolveEmittedJavaScript.js +42 -10
- package/lib/compiler/internal/resolveEmittedJavaScript.js.map +1 -1
- package/lib/compiler/internal/resolveTsgo.d.ts +21 -1
- package/lib/compiler/internal/resolveTsgo.js +23 -1
- package/lib/compiler/internal/resolveTsgo.js.map +1 -1
- package/lib/compiler/internal/runBuild.d.ts +19 -0
- package/lib/compiler/internal/runBuild.js +112 -46
- package/lib/compiler/internal/runBuild.js.map +1 -1
- package/lib/compiler/internal/runSingleFileEmit.d.ts +10 -1
- package/lib/compiler/internal/runSingleFileEmit.js +14 -1
- package/lib/compiler/internal/runSingleFileEmit.js.map +1 -1
- package/lib/compiler/internal/sharedHostHelpers.d.ts +5 -0
- package/lib/compiler/internal/sharedHostHelpers.js +6 -2
- package/lib/compiler/internal/sharedHostHelpers.js.map +1 -1
- package/lib/compiler/internal/spawnNative.d.ts +21 -0
- package/lib/compiler/internal/spawnNative.js +59 -0
- package/lib/compiler/internal/spawnNative.js.map +1 -0
- package/lib/compiler/internal/transformProjectInMemory.d.ts +15 -1
- package/lib/compiler/internal/transformProjectInMemory.js +57 -61
- package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
- package/lib/launcher/internal/getCompilerVersionText.js +7 -0
- package/lib/launcher/internal/getCompilerVersionText.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.js +32 -0
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/resolveCacheDir.d.ts +9 -0
- package/lib/launcher/internal/resolveCacheDir.js +22 -0
- package/lib/launcher/internal/resolveCacheDir.js.map +1 -0
- package/lib/launcher/internal/resolveTtscserverBinary.js +2 -0
- package/lib/launcher/internal/resolveTtscserverBinary.js.map +1 -1
- package/lib/launcher/internal/runTtsc.d.ts +10 -0
- package/lib/launcher/internal/runTtsc.js +101 -16
- package/lib/launcher/internal/runTtsc.js.map +1 -1
- package/lib/launcher/internal/runTtscserver.js +10 -35
- package/lib/launcher/internal/runTtscserver.js.map +1 -1
- package/lib/launcher/internal/runTtsx.d.ts +8 -0
- package/lib/launcher/internal/runTtsx.js +33 -7
- package/lib/launcher/internal/runTtsx.js.map +1 -1
- package/lib/plugin/internal/buildSourcePlugin.d.ts +38 -0
- package/lib/plugin/internal/buildSourcePlugin.js +40 -17
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
- package/lib/plugin/internal/loadProjectPlugins.d.ts +26 -0
- package/lib/plugin/internal/loadProjectPlugins.js +32 -18
- package/lib/plugin/internal/loadProjectPlugins.js.map +1 -1
- package/lib/structures/ITtscCompilerTransformation.d.ts +15 -2
- package/lib/structures/internal/TtscSingleFileEmitOptions.d.ts +0 -2
- package/package.json +9 -9
- package/shim/ast/go.mod +9 -0
- package/shim/ast/go.sum +20 -0
- package/shim/ast/safe_text.go +86 -0
- package/shim/ast/shim.go +24 -0
- package/shim/ast/test/node_text_joins_multi_hop_qualified_name_test.go +32 -0
- package/shim/ast/test/node_text_joins_one_hop_qualified_name_test.go +31 -0
- package/shim/ast/test/node_text_returns_empty_for_nil_test.go +23 -0
- package/shim/ast/test/node_text_returns_identifier_text_test.go +27 -0
- package/shim/ast/test/node_text_skips_empty_qualified_left_test.go +30 -0
- package/shim/checker/shim.go +35 -0
- package/shim/core/shim.go +17 -0
- package/shim/diagnosticwriter/shim.go +4 -0
- package/shim/lsp/shim.go +3 -3
- package/shim/printer/shim.go +20 -0
- package/src/TtscCompiler.ts +7 -0
- package/src/compiler/internal/buildNativeCompiler.ts +23 -3
- package/src/compiler/internal/compileProjectInMemory.ts +34 -25
- package/src/compiler/internal/paths.ts +68 -0
- package/src/compiler/internal/project/readProjectConfig.ts +86 -1
- package/src/compiler/internal/project/resolveProjectConfig.ts +24 -1
- package/src/compiler/internal/resolveBinary.ts +17 -1
- package/src/compiler/internal/resolveEmittedJavaScript.ts +43 -12
- package/src/compiler/internal/resolveTsgo.ts +29 -1
- package/src/compiler/internal/runBuild.ts +110 -55
- package/src/compiler/internal/runSingleFileEmit.ts +14 -1
- package/src/compiler/internal/sharedHostHelpers.ts +7 -7
- package/src/compiler/internal/spawnNative.ts +64 -0
- package/src/compiler/internal/transformProjectInMemory.ts +47 -67
- package/src/launcher/internal/getCompilerVersionText.ts +7 -0
- package/src/launcher/internal/prepareExecution.ts +32 -0
- package/src/launcher/internal/resolveCacheDir.ts +19 -0
- package/src/launcher/internal/resolveTtscserverBinary.ts +2 -0
- package/src/launcher/internal/runTtsc.ts +120 -20
- package/src/launcher/internal/runTtscserver.ts +9 -1
- package/src/launcher/internal/runTtsx.ts +33 -8
- package/src/plugin/internal/buildSourcePlugin.ts +40 -14
- package/src/plugin/internal/loadProjectPlugins.ts +42 -18
- package/src/structures/ITtscCompilerTransformation.ts +15 -2
- package/src/structures/ITtscPlugin.ts +0 -1
- package/src/structures/internal/TtscSingleFileEmitOptions.ts +0 -2
- package/tools/gen_shims/main.go +43 -8
- package/utility/host.go +294 -245
package/tools/gen_shims/main.go
CHANGED
|
@@ -56,13 +56,28 @@ var packagesToShim = []string{
|
|
|
56
56
|
"vfs/osvfs",
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
// ExtraShim is the schema for the per-shim-directory `extra-shim.json` file.
|
|
60
|
+
// It lets maintainers extend the generated output beyond what gen_shims can
|
|
61
|
+
// derive automatically from the public API surface.
|
|
59
62
|
type ExtraShim struct {
|
|
60
|
-
ExtraFunctions
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
// ExtraFunctions lists unexported function names that should be shimmed via
|
|
64
|
+
// go:linkname in addition to the exported ones gen_shims discovers itself.
|
|
65
|
+
ExtraFunctions []string
|
|
66
|
+
// ExtraMethods maps type name → method names for unexported or
|
|
67
|
+
// otherwise-unlinkable methods that should be forwarded.
|
|
68
|
+
ExtraMethods map[string][]string
|
|
69
|
+
// ExtraFields maps type name → field names whose values should be exposed
|
|
70
|
+
// through unsafe pointer casts (used when go:linkname cannot reach them).
|
|
71
|
+
ExtraFields map[string][]string
|
|
72
|
+
// IgnoreFunctions lists exported function names that gen_shims should skip
|
|
73
|
+
// entirely, typically because the caller supplies a hand-written alternative.
|
|
63
74
|
IgnoreFunctions []string
|
|
64
75
|
}
|
|
65
76
|
|
|
77
|
+
// signatureHasUnexportedType reports whether any parameter of the function
|
|
78
|
+
// signature refers to an unexported named type (optionally through a pointer).
|
|
79
|
+
// Such functions cannot be linked safely because the shim package cannot
|
|
80
|
+
// reference the unexported type by name.
|
|
66
81
|
func signatureHasUnexportedType(t types.Signature) bool {
|
|
67
82
|
if params := t.Params(); params != nil {
|
|
68
83
|
for v := range params.Variables() {
|
|
@@ -128,6 +143,9 @@ func main() {
|
|
|
128
143
|
extraShim.IgnoreFunctions = []string{}
|
|
129
144
|
}
|
|
130
145
|
|
|
146
|
+
// importedPackages tracks every package import the generated file needs.
|
|
147
|
+
// true = referenced by name (needs a named import).
|
|
148
|
+
// false = only needed for its side-effects (blank import "_").
|
|
131
149
|
importedPackages := map[string]bool{}
|
|
132
150
|
importPackage := func(path string, directly bool) {
|
|
133
151
|
if directly {
|
|
@@ -137,12 +155,21 @@ func main() {
|
|
|
137
155
|
}
|
|
138
156
|
}
|
|
139
157
|
|
|
158
|
+
// qualifierOnlyPackageName records a direct import for every package the
|
|
159
|
+
// type-string references and returns just the package short name, producing
|
|
160
|
+
// output like `ast.Node` instead of a full path.
|
|
140
161
|
var qualifierOnlyPackageName types.Qualifier = func(p *types.Package) string {
|
|
141
162
|
importPackage(p.Path(), true)
|
|
142
163
|
return p.Name()
|
|
143
164
|
}
|
|
165
|
+
// qualifierEmptyPackageName omits the package qualifier entirely; used when
|
|
166
|
+
// writing the receiver type inside a go:linkname directive where the package
|
|
167
|
+
// prefix must not appear.
|
|
144
168
|
var qualifierEmptyPackageName types.Qualifier = func(p *types.Package) string { return "" }
|
|
145
169
|
|
|
170
|
+
// emitGoLinknameDirective appends a `//go:linkname localName pkg.Func`
|
|
171
|
+
// pragma line to shimBuilder, registering unsafe and the source package as
|
|
172
|
+
// blank imports so the linker can resolve the symbol.
|
|
146
173
|
emitGoLinknameDirective := func(localName string, fn *types.Func) {
|
|
147
174
|
importPackage("unsafe", false)
|
|
148
175
|
importPackage(pkg.Types.Path(), false)
|
|
@@ -161,6 +188,9 @@ func main() {
|
|
|
161
188
|
shimBuilder.WriteByte('\n')
|
|
162
189
|
}
|
|
163
190
|
|
|
191
|
+
// emitLinkedFunction emits a go:linkname directive and a matching func
|
|
192
|
+
// declaration for fn. Generic functions (TypeParams != nil) and functions
|
|
193
|
+
// with unexported parameter types are skipped (returns false).
|
|
164
194
|
emitLinkedFunction := func(fn *types.Func) bool {
|
|
165
195
|
if fn.Signature().TypeParams() != nil {
|
|
166
196
|
return false
|
|
@@ -221,10 +251,9 @@ func main() {
|
|
|
221
251
|
shimBuilder.WriteString("\n")
|
|
222
252
|
}
|
|
223
253
|
|
|
224
|
-
switch object.(type) {
|
|
254
|
+
switch typedObj := object.(type) {
|
|
225
255
|
case *types.TypeName:
|
|
226
|
-
|
|
227
|
-
t := typeName.Type()
|
|
256
|
+
t := typedObj.Type()
|
|
228
257
|
named, isNamed := t.(*types.Named)
|
|
229
258
|
if isNamed {
|
|
230
259
|
_, nameWithTypeParams, _ := strings.Cut(types.TypeString(named, qualifierOnlyPackageName), ".")
|
|
@@ -297,6 +326,10 @@ func main() {
|
|
|
297
326
|
matchedExtraFields[name] = true
|
|
298
327
|
mirrorStructName := "extra_" + name
|
|
299
328
|
|
|
329
|
+
// emitExtraStruct emits a mirror struct (`extra_<Name>`) whose field
|
|
330
|
+
// layout matches the unexported original so that unsafe.Pointer casts
|
|
331
|
+
// in the generated accessor functions are safe. Unexported pointer
|
|
332
|
+
// fields whose element type is also unexported are recursively mirrored.
|
|
300
333
|
var emitExtraStruct func(name string, s *types.Struct)
|
|
301
334
|
emitExtraStruct = func(name string, s *types.Struct) {
|
|
302
335
|
shimBuilder.WriteString("type extra_")
|
|
@@ -384,12 +417,14 @@ func main() {
|
|
|
384
417
|
printReexport("var")
|
|
385
418
|
case *types.Func:
|
|
386
419
|
if !slices.Contains(extraShim.IgnoreFunctions, name) {
|
|
387
|
-
|
|
388
|
-
emitLinkedFunction(funcType)
|
|
420
|
+
emitLinkedFunction(typedObj)
|
|
389
421
|
}
|
|
390
422
|
}
|
|
391
423
|
}
|
|
392
424
|
|
|
425
|
+
// Verify that every extra function/method requested in extra-shim.json was
|
|
426
|
+
// actually found in the package. A missing symbol means the json file is
|
|
427
|
+
// stale relative to the upstream typescript-go API.
|
|
393
428
|
exit := false
|
|
394
429
|
for fnName, found := range matchedExtraFunctions {
|
|
395
430
|
if found {
|