@ttsc/wasm 0.30.4 → 0.31.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/README.md +3 -3
- package/build/build-wasm.cjs +5 -4
- package/build/go-build-cache.cjs +347 -0
- package/build/pack-prepare.cjs +3 -2
- package/cmd/ttsc-wasm/main.go +22 -10
- package/cmd/ttsc-wasm/main_wasm.go +2 -2
- package/dist/.ttsc-wasm-build.json +138 -58
- package/dist/go.mod +7 -5
- package/dist/ttsc.wasm +2 -2
- package/go.mod +7 -5
- package/go.sum +10 -10
- package/host/api.go +34 -41
- package/host/doc.go +7 -6
- package/host/expose.go +42 -0
- package/host/fountain.go +192 -22
- package/host/host.go +10 -25
- package/host/host_native.go +3 -5
- package/host/invoke.go +133 -0
- package/host/plugin.go +37 -72
- package/host/result.go +108 -0
- package/lib/src/BootTtscWorkerTerminationError.d.ts +20 -0
- package/lib/src/BootTtscWorkerTerminationError.js +20 -0
- package/lib/src/BootTtscWorkerTerminationError.js.map +1 -1
- package/lib/src/MemFSError.d.ts +21 -2
- package/lib/src/MemFSError.js +25 -2
- package/lib/src/MemFSError.js.map +1 -1
- package/lib/src/bootTtsc.d.ts +49 -2
- package/lib/src/bootTtsc.js +89 -23
- package/lib/src/bootTtsc.js.map +1 -1
- package/lib/src/createMemFS.d.ts +45 -0
- package/lib/src/createMemFS.js +269 -66
- package/lib/src/createMemFS.js.map +1 -1
- package/lib/src/parseResult.d.ts +19 -0
- package/lib/src/parseResult.js +19 -0
- package/lib/src/parseResult.js.map +1 -1
- package/lib/src/structures/IBootResult.d.ts +20 -2
- package/lib/src/structures/IBootTtscOptions.d.ts +28 -6
- package/lib/src/structures/IFileStats.d.ts +51 -0
- package/lib/src/structures/IMemFSHost.d.ts +89 -0
- package/lib/src/structures/ITtscApi.d.ts +154 -9
- package/lib/src/structures/ITtscBuildOpts.d.ts +18 -1
- package/lib/src/structures/ITtscCompileResult.d.ts +20 -2
- package/lib/src/structures/ITtscDiagnostic.d.ts +25 -1
- package/lib/src/structures/ITtscFileQuery.d.ts +19 -1
- package/lib/src/structures/ITtscFountainDiagnosticsResult.d.ts +20 -1
- package/lib/src/structures/ITtscNodeAtPositionResult.d.ts +18 -1
- package/lib/src/structures/ITtscNodeInfo.d.ts +23 -2
- package/lib/src/structures/ITtscPluginOpts.d.ts +24 -3
- package/lib/src/structures/ITtscPositionQuery.d.ts +21 -4
- package/lib/src/structures/ITtscReleaseSnapshotResult.d.ts +22 -2
- package/lib/src/structures/ITtscResult.d.ts +31 -5
- package/lib/src/structures/ITtscSnapshotHandle.d.ts +19 -1
- package/lib/src/structures/ITtscSnapshotResult.d.ts +22 -1
- package/lib/src/structures/ITtscSnapshotsResult.d.ts +19 -1
- package/lib/src/structures/ITtscSourceFileTextResult.d.ts +19 -1
- package/lib/src/structures/ITtscSourceFilesResult.d.ts +23 -2
- package/lib/src/structures/ITtscSymbolAtPositionResult.d.ts +18 -1
- package/lib/src/structures/ITtscSymbolDeclaration.d.ts +25 -2
- package/lib/src/structures/ITtscSymbolInfo.d.ts +19 -1
- package/lib/src/structures/ITtscTransformResult.d.ts +21 -3
- package/lib/src/structures/ITtscTypeAtPositionResult.d.ts +18 -1
- package/lib/src/structures/ITtscTypeInfo.d.ts +19 -1
- package/lib/src/structures/ITtscVersion.d.ts +28 -1
- package/lib/src/structures/IWasmExecFS.d.ts +310 -0
- package/package.json +4 -2
- package/shim-vendor/shim/ast/enums_gen.go +4 -2
- package/shim-vendor/shim/ast/go.mod +5 -5
- package/shim-vendor/shim/ast/go.sum +10 -10
- package/shim-vendor/shim/ast/lint.go +1088 -20
- package/shim-vendor/shim/ast/parent.go +38 -22
- package/shim-vendor/shim/ast/safe_text.go +48 -26
- package/shim-vendor/shim/ast/shim.go +1307 -20
- package/shim-vendor/shim/ast/test/next_jsdoc_comment_location_reaches_variable_statement_test.go +51 -0
- package/shim-vendor/shim/ast/test/node_text_joins_multi_hop_qualified_name_test.go +24 -9
- package/shim-vendor/shim/ast/test/node_text_joins_one_hop_qualified_name_test.go +9 -5
- package/shim-vendor/shim/ast/test/node_text_returns_empty_for_nil_test.go +13 -5
- package/shim-vendor/shim/ast/test/node_text_returns_identifier_text_test.go +12 -5
- package/shim-vendor/shim/ast/test/node_text_skips_empty_qualified_left_test.go +35 -5
- package/shim-vendor/shim/astnav/go.mod +5 -5
- package/shim-vendor/shim/astnav/go.sum +12 -10
- package/shim-vendor/shim/astnav/shim.go +9 -0
- package/shim-vendor/shim/bundled/go.mod +7 -1
- package/shim-vendor/shim/bundled/go.sum +12 -0
- package/shim-vendor/shim/checker/enums_gen.go +4 -2
- package/shim-vendor/shim/checker/extra-shim.json +6 -0
- package/shim-vendor/shim/checker/go.mod +5 -5
- package/shim-vendor/shim/checker/go.sum +10 -10
- package/shim-vendor/shim/checker/node_builder_fields_gen.go +19 -0
- package/shim-vendor/shim/checker/shim.go +827 -114
- package/shim-vendor/shim/compiler/emit_sourcemap.go +68 -29
- package/shim-vendor/shim/compiler/emitassemble.go +36 -2
- package/shim-vendor/shim/compiler/emithook.go +13 -3
- package/shim-vendor/shim/compiler/go.mod +5 -5
- package/shim-vendor/shim/compiler/go.sum +10 -10
- package/shim-vendor/shim/compiler/incremental.go +56 -20
- package/shim-vendor/shim/compiler/resolution.go +92 -9
- package/shim-vendor/shim/core/enums_gen.go +2 -2
- package/shim-vendor/shim/core/go.mod +6 -1
- package/shim-vendor/shim/core/go.sum +10 -0
- package/shim-vendor/shim/core/modulekind.go +9 -0
- package/shim-vendor/shim/core/shim.go +157 -6
- package/shim-vendor/shim/diagnosticwriter/go.mod +10 -1
- package/shim-vendor/shim/diagnosticwriter/go.sum +20 -0
- package/shim-vendor/shim/diagnosticwriter/lint.go +188 -10
- package/shim-vendor/shim/diagnosticwriter/shim.go +14 -0
- package/shim-vendor/shim/lsp/go.mod +5 -5
- package/shim-vendor/shim/lsp/go.sum +10 -10
- package/shim-vendor/shim/lsp/shim.go +78 -2
- package/shim-vendor/shim/parser/go.mod +10 -1
- package/shim-vendor/shim/parser/go.sum +22 -0
- package/shim-vendor/shim/printer/emithost.go +46 -1
- package/shim-vendor/shim/printer/go.mod +5 -5
- package/shim-vendor/shim/printer/go.sum +10 -10
- package/shim-vendor/shim/printer/shim.go +114 -7
- package/shim-vendor/shim/printer/sourcemap.go +55 -0
- package/shim-vendor/shim/scanner/go.mod +10 -1
- package/shim-vendor/shim/scanner/go.sum +20 -0
- package/shim-vendor/shim/scanner/regexp.go +19 -4
- package/shim-vendor/shim/scanner/shim.go +3 -0
- package/shim-vendor/shim/stringutil/extra-shim.json +1 -0
- package/shim-vendor/shim/stringutil/go.mod +5 -0
- package/shim-vendor/shim/stringutil/go.sum +2 -0
- package/shim-vendor/shim/stringutil/shim.go +119 -0
- package/shim-vendor/shim/transformers/go.mod +5 -5
- package/shim-vendor/shim/transformers/go.sum +12 -10
- package/shim-vendor/shim/transformers/shim.go +12 -3
- package/shim-vendor/shim/tsoptions/command_line_raw.go +44 -0
- package/shim-vendor/shim/tsoptions/go.mod +10 -1
- package/shim-vendor/shim/tsoptions/go.sum +22 -0
- package/shim-vendor/shim/tsoptions/shim.go +1 -1
- package/shim-vendor/shim/tspath/go.mod +1 -1
- package/shim-vendor/shim/tspath/go.sum +6 -0
- package/shim-vendor/shim/vfs/cachedvfs/go.mod +3 -1
- package/shim-vendor/shim/vfs/cachedvfs/go.sum +12 -0
- package/shim-vendor/shim/vfs/decode.go +26 -0
- package/shim-vendor/shim/vfs/decode_test.go +42 -0
- package/shim-vendor/shim/vfs/go.mod +7 -1
- package/shim-vendor/shim/vfs/go.sum +12 -0
- package/shim-vendor/shim/vfs/osvfs/go.mod +7 -1
- package/shim-vendor/shim/vfs/osvfs/go.sum +12 -0
- package/src/BootTtscWorkerTerminationError.ts +22 -0
- package/src/MemFSError.ts +29 -2
- package/src/bootTtsc.ts +104 -28
- package/src/createMemFS.ts +291 -64
- package/src/parseResult.ts +19 -0
- package/src/structures/IBootResult.ts +21 -2
- package/src/structures/IBootTtscOptions.ts +32 -6
- package/src/structures/IFileStats.ts +65 -0
- package/src/structures/IMemFSHost.ts +97 -0
- package/src/structures/ITtscApi.ts +154 -9
- package/src/structures/ITtscBuildOpts.ts +19 -1
- package/src/structures/ITtscCompileResult.ts +21 -2
- package/src/structures/ITtscDiagnostic.ts +32 -1
- package/src/structures/ITtscFileQuery.ts +19 -1
- package/src/structures/ITtscFountainDiagnosticsResult.ts +20 -1
- package/src/structures/ITtscNodeAtPositionResult.ts +18 -1
- package/src/structures/ITtscNodeInfo.ts +27 -2
- package/src/structures/ITtscPluginOpts.ts +28 -3
- package/src/structures/ITtscPositionQuery.ts +21 -4
- package/src/structures/ITtscReleaseSnapshotResult.ts +22 -2
- package/src/structures/ITtscResult.ts +34 -5
- package/src/structures/ITtscSnapshotHandle.ts +19 -1
- package/src/structures/ITtscSnapshotResult.ts +22 -1
- package/src/structures/ITtscSnapshotsResult.ts +19 -1
- package/src/structures/ITtscSourceFileTextResult.ts +19 -1
- package/src/structures/ITtscSourceFilesResult.ts +23 -2
- package/src/structures/ITtscSymbolAtPositionResult.ts +18 -1
- package/src/structures/ITtscSymbolDeclaration.ts +27 -2
- package/src/structures/ITtscSymbolInfo.ts +23 -1
- package/src/structures/ITtscTransformResult.ts +22 -3
- package/src/structures/ITtscTypeAtPositionResult.ts +18 -1
- package/src/structures/ITtscTypeInfo.ts +20 -1
- package/src/structures/ITtscVersion.ts +33 -1
- package/src/structures/IWasmExecFS.ts +336 -0
|
@@ -15,6 +15,20 @@ import (
|
|
|
15
15
|
|
|
16
16
|
// FormatASTDiagnosticsWithColorAndContext writes TypeScript-style pretty
|
|
17
17
|
// diagnostics using the same internal formatter as typescript-go.
|
|
18
|
+
// diagnostics must contain non-nil compiler diagnostics; output and source
|
|
19
|
+
// files retain their caller-owned lifetimes.
|
|
20
|
+
// The writer must be usable, and locations/message chains must satisfy the
|
|
21
|
+
// formatter's compiler-data premises. Upstream ignores individual write errors;
|
|
22
|
+
// this void operation neither reports successful delivery nor closes the writer.
|
|
23
|
+
//
|
|
24
|
+
// @evidence contracts/common.md#principled-implementation Upstream AST adapters implement the formatter's Diagnostic interface, and the same rendering/summary operations receive them with the caller's current directory and default locale.
|
|
25
|
+
// @evidence contracts/common.md#clear-and-simple-design One pure-AST rendering entry composes adaptation, contextual formatting and summary emission; mixed lint rendering stays in its separate adjacent entry.
|
|
26
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The supplied output writer receives real compiler messages; no global stream replacement or source-pattern diagnostic approximation is involved.
|
|
27
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies upstream formatting, non-nil input requirements and caller-owned writer/source lifetime before these tags.
|
|
28
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources Adapted diagnostic and related/message-chain arrays, snippet strings and summary grouping/sorting state are invocation-local, borrowing caller diagnostic/source graphs. Supplied writer storage and any source-position caches remain with their owners; output can remain retained by that writer after return. This adapter neither closes it nor imposes a fixed byte/population cap, and local state becoming unreachable does not promise immediate reclamation.
|
|
29
|
+
// @evidence contracts/performance.md#efficient-algorithms Adapt the input once, render diagnostics in supplied order, then build the error summary. Actual work includes nested messages/related data, path text, source-position lookup and snippet bytes, plus a second diagnostic scan and filename grouping/sort for the summary. Writer operations contribute their own cost; one formatter call does not make the whole operation a single linear pass over diagnostic count.
|
|
30
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This call-local renderer coordinates no completed/in-flight formatted-result cache. Upstream and source owners manage reusable message/localization or source-position state, while the caller owns whether emitted output can be reused for equivalent diagnostics and context.
|
|
31
|
+
// @evidence contracts/portability.md#os-neutral-implementation The path comparison options carry the supplied current directory and a fixed case-sensitive policy because the writer only renders display paths and compares no filesystem identities.
|
|
18
32
|
func FormatASTDiagnosticsWithColorAndContext(output io.Writer, diagnostics []*ast.Diagnostic, currentDirectory string) {
|
|
19
33
|
if len(diagnostics) == 0 {
|
|
20
34
|
return
|
|
@@ -2,15 +2,15 @@ module github.com/microsoft/typescript-go/shim/lsp
|
|
|
2
2
|
|
|
3
3
|
go 1.26
|
|
4
4
|
|
|
5
|
-
require github.com/microsoft/typescript-go v0.0.0-
|
|
5
|
+
require github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063
|
|
6
6
|
|
|
7
7
|
require (
|
|
8
8
|
github.com/Microsoft/go-winio v0.6.2 // indirect
|
|
9
|
-
github.com/go-json-experiment/json v0.0.0-
|
|
9
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6 // indirect
|
|
10
10
|
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
|
11
11
|
github.com/mackerelio/go-osstat v0.2.7 // indirect
|
|
12
12
|
github.com/zeebo/xxh3 v1.1.0 // indirect
|
|
13
|
-
golang.org/x/sync v0.
|
|
14
|
-
golang.org/x/sys v0.
|
|
15
|
-
golang.org/x/text v0.
|
|
13
|
+
golang.org/x/sync v0.21.0 // indirect
|
|
14
|
+
golang.org/x/sys v0.46.0 // indirect
|
|
15
|
+
golang.org/x/text v0.38.0 // indirect
|
|
16
16
|
)
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
|
|
2
2
|
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
|
|
3
|
-
github.com/go-json-experiment/json v0.0.0-
|
|
4
|
-
github.com/go-json-experiment/json v0.0.0-
|
|
3
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6 h1:nxP4pPoyqOAgX8lYDFCfl3DyKeXErCvSvhcyzwGV9CE=
|
|
4
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
|
|
5
5
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|
6
6
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
|
7
7
|
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
|
8
8
|
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
|
9
9
|
github.com/mackerelio/go-osstat v0.2.7 h1:TCavZi10wF49bT6iQZ9eT2keGZQpC69MTDfdJej5e94=
|
|
10
10
|
github.com/mackerelio/go-osstat v0.2.7/go.mod h1:dwpYh5pIPmvk+IEwBKNIWRFMB92mrC08CmXOhDC7nQk=
|
|
11
|
-
github.com/microsoft/typescript-go v0.0.0-
|
|
12
|
-
github.com/microsoft/typescript-go v0.0.0-
|
|
11
|
+
github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063 h1:UUVrjTrD+7nkVvkJTjxwA5+SaZ5n1uyAffm2zX2gn+o=
|
|
12
|
+
github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063/go.mod h1:s3yhRRZ7nzSZaiKicku520Tj9Mvewr9y2UtrvpwOmDE=
|
|
13
13
|
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
|
|
14
14
|
github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
|
|
15
15
|
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
|
16
16
|
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
|
17
17
|
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
|
18
18
|
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
|
19
|
-
golang.org/x/sync v0.
|
|
20
|
-
golang.org/x/sync v0.
|
|
21
|
-
golang.org/x/sys v0.
|
|
22
|
-
golang.org/x/sys v0.
|
|
23
|
-
golang.org/x/text v0.
|
|
24
|
-
golang.org/x/text v0.
|
|
19
|
+
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
|
20
|
+
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
|
21
|
+
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
|
22
|
+
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
|
23
|
+
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
|
|
24
|
+
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
|
|
25
25
|
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|
26
26
|
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// Minimal shim of tsgo's internal/lsp package. Hand-written instead of
|
|
4
4
|
// generated so the surface stays narrow for custom in-process host
|
|
5
|
-
// experiments. The shipped ttscserver wraps `
|
|
5
|
+
// experiments. The shipped ttscserver wraps `tsgo --lsp --stdio` as an
|
|
6
6
|
// external process and does not import this package. The marker on the
|
|
7
7
|
// first line tells gen_shims to skip this file.
|
|
8
8
|
package lsp
|
|
@@ -15,22 +15,98 @@ import (
|
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
// Server is the opaque LSP server type from tsgo.
|
|
18
|
+
//
|
|
19
|
+
// @evidence contracts/common.md#principled-implementation A Go alias preserves the upstream server identity and method set, so NewServer results can be used without an incompatible wrapper type.
|
|
20
|
+
// @evidence contracts/common.md#clear-and-simple-design The opaque alias leaves protocol state and execution with the existing server instead of duplicating its lifecycle in the shim.
|
|
21
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts This bridge names the actual upstream type without substituting a ttsc-specific server or mutating its methods.
|
|
22
|
+
// @evidence contracts/common.md#meaningful-documentation The declaration identifies opaque server provenance; package prose explains the experimental in-process scope and the shipped external-process host distinction.
|
|
23
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
24
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
25
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
26
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
18
27
|
type Server = innerlsp.Server
|
|
19
28
|
|
|
20
29
|
// ServerOptions mirrors the upstream construction parameters. Fields with
|
|
21
30
|
// internal-package types (e.g. ParseCache *project.ParseCache) can be left
|
|
22
31
|
// unset by callers when upstream accepts nil.
|
|
32
|
+
// Native paths, filesystem operations and process callbacks remain supplied
|
|
33
|
+
// by the embedding host; this alias adds no platform-specific defaults.
|
|
34
|
+
//
|
|
35
|
+
// @evidence contracts/common.md#principled-implementation The alias retains the upstream options fields and callback types exactly; no shadow struct loses filesystem, transport or construction distinctions.
|
|
36
|
+
// @evidence contracts/common.md#clear-and-simple-design Server construction accepts its native configuration directly, avoiding a second options mapper beside NewServer.
|
|
37
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Callers supply upstream configuration rather than consumer-specific defaults or fabricated project state.
|
|
38
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies construction purpose and the internal-type limitation, conditioning omission on upstream nil support rather than promising every field is optional.
|
|
39
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
40
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
41
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
42
|
+
// @evidence contracts/portability.md#os-neutral-implementation The exact upstream options preserve Cwd, filesystem and library/typings paths, npm execution and parent-process callback boundaries; the embedding host supplies their native semantics, while the alias performs no path folding, shell construction or platform substitution.
|
|
23
43
|
type ServerOptions = innerlsp.ServerOptions
|
|
24
44
|
|
|
25
|
-
// Reader
|
|
45
|
+
// Reader receives decoded lsproto.Message values from the upstream LSP transport.
|
|
46
|
+
//
|
|
47
|
+
// @evidence contracts/common.md#principled-implementation Aliasing the upstream interface preserves its Read result and error contract, including its exact message identity.
|
|
48
|
+
// @evidence contracts/common.md#clear-and-simple-design The reader interface names the inbound message boundary independently of byte-stream adaptation in ToReader.
|
|
49
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Messages remain upstream protocol values rather than a simplified ttsc-only request schema.
|
|
50
|
+
// @evidence contracts/common.md#meaningful-documentation The comment identifies decoded inbound messages; it does not conflate this message reader with io.Reader bytes.
|
|
51
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
52
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
53
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
54
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
26
55
|
type Reader = innerlsp.Reader
|
|
56
|
+
|
|
57
|
+
// Writer sends lsproto.Message values through the upstream LSP transport.
|
|
58
|
+
//
|
|
59
|
+
// @evidence contracts/common.md#principled-implementation Aliasing the upstream Write interface preserves message type identity and its returned transport error.
|
|
60
|
+
// @evidence contracts/common.md#clear-and-simple-design The outbound message interface remains distinct from the byte writer wrapped by ToWriter.
|
|
61
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The transport keeps upstream protocol messages without modifying a foreign writer or hiding failed writes.
|
|
62
|
+
// @evidence contracts/common.md#meaningful-documentation The native comment names outbound messages and distinguishes the interface from raw byte output.
|
|
63
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
64
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
65
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
66
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
27
67
|
type Writer = innerlsp.Writer
|
|
28
68
|
|
|
69
|
+
// NewServer constructs the upstream in-process server. opts must be non-nil
|
|
70
|
+
// and supply Cwd; missing Cwd panics under the upstream construction contract.
|
|
71
|
+
//
|
|
72
|
+
// @evidence contracts/common.md#principled-implementation The exact linked constructor receives aliased options and returns the upstream Server; its non-nil options and required Cwd premises remain caller obligations.
|
|
73
|
+
// @evidence contracts/common.md#clear-and-simple-design One constructor bridge leaves initialization, project state and queues with the upstream server rather than layering a separate host lifecycle.
|
|
74
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Explicit symbol linkage exposes the existing implementation; the shim does not fake server readiness or patch construction defaults.
|
|
75
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states in-process purpose, required options and the Cwd panic boundary before the linked declaration.
|
|
76
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources NewServer declares a signature only; the implementation owns acquisition and release of resources.
|
|
77
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms NewServer declares a signature only; the implementation owns the processing strategy.
|
|
78
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work NewServer declares a signature only; the implementation owns any shared work.
|
|
79
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation NewServer is a signature without a body here; path and platform behavior belongs to the implementation that supplies it.
|
|
80
|
+
//
|
|
29
81
|
//go:linkname NewServer github.com/microsoft/typescript-go/internal/lsp.NewServer
|
|
30
82
|
func NewServer(opts *ServerOptions) *Server
|
|
31
83
|
|
|
84
|
+
// ToReader adapts an io.Reader into the upstream framed-message decoder.
|
|
85
|
+
// It retains the supplied stream; the caller owns that stream's lifetime.
|
|
86
|
+
//
|
|
87
|
+
// @evidence contracts/common.md#principled-implementation The linked adapter constructs upstream lsproto framing and message decoding over the supplied byte stream, preserving the server's Reader contract.
|
|
88
|
+
// @evidence contracts/common.md#clear-and-simple-design A single adapter separates raw bytes from decoded messages without a parallel JSON-RPC parser in the shim.
|
|
89
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The actual stream is supplied explicitly; no process-global input replacement or canned decoded request is used.
|
|
90
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies framing and retained-stream ownership rather than merely repeating the conversion name.
|
|
91
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources ToReader declares a signature only; the implementation owns acquisition and release of resources.
|
|
92
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms ToReader declares a signature only; the implementation owns the processing strategy.
|
|
93
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work ToReader declares a signature only; the implementation owns any shared work.
|
|
94
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation ToReader is a signature without a body here; path and platform behavior belongs to the implementation that supplies it.
|
|
95
|
+
//
|
|
32
96
|
//go:linkname ToReader github.com/microsoft/typescript-go/internal/lsp.ToReader
|
|
33
97
|
func ToReader(r io.Reader) Reader
|
|
34
98
|
|
|
99
|
+
// ToWriter adapts an io.Writer into the upstream framed-message encoder.
|
|
100
|
+
// It retains the supplied stream; the caller owns that stream's lifetime.
|
|
101
|
+
//
|
|
102
|
+
// @evidence contracts/common.md#principled-implementation The linked adapter uses upstream JSON encoding and lsproto framing on the supplied byte writer, retaining the Writer error contract.
|
|
103
|
+
// @evidence contracts/common.md#clear-and-simple-design One adapter owns message-to-byte representation while the upstream transport owns serialization and framing details.
|
|
104
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Output uses the caller's stream rather than a replacement global stdout or a success-only transport stub.
|
|
105
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies encoding and retained-stream ownership, with a blank comment separator before the acknowledgment tags.
|
|
106
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources ToWriter declares a signature only; the implementation owns acquisition and release of resources.
|
|
107
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms ToWriter declares a signature only; the implementation owns the processing strategy.
|
|
108
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work ToWriter declares a signature only; the implementation owns any shared work.
|
|
109
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation ToWriter is a signature without a body here; path and platform behavior belongs to the implementation that supplies it.
|
|
110
|
+
//
|
|
35
111
|
//go:linkname ToWriter github.com/microsoft/typescript-go/internal/lsp.ToWriter
|
|
36
112
|
func ToWriter(w io.Writer) Writer
|
|
@@ -2,4 +2,13 @@ module github.com/microsoft/typescript-go/shim/parser
|
|
|
2
2
|
|
|
3
3
|
go 1.26
|
|
4
4
|
|
|
5
|
-
require github.com/microsoft/typescript-go v0.0.0-
|
|
5
|
+
require github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063
|
|
6
|
+
|
|
7
|
+
require (
|
|
8
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6 // indirect
|
|
9
|
+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
|
10
|
+
github.com/zeebo/xxh3 v1.1.0 // indirect
|
|
11
|
+
golang.org/x/sync v0.21.0 // indirect
|
|
12
|
+
golang.org/x/sys v0.46.0 // indirect
|
|
13
|
+
golang.org/x/text v0.38.0 // indirect
|
|
14
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6 h1:nxP4pPoyqOAgX8lYDFCfl3DyKeXErCvSvhcyzwGV9CE=
|
|
2
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
|
|
3
|
+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|
4
|
+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
|
5
|
+
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
|
6
|
+
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
|
7
|
+
github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063 h1:UUVrjTrD+7nkVvkJTjxwA5+SaZ5n1uyAffm2zX2gn+o=
|
|
8
|
+
github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063/go.mod h1:s3yhRRZ7nzSZaiKicku520Tj9Mvewr9y2UtrvpwOmDE=
|
|
9
|
+
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
|
|
10
|
+
github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
|
|
11
|
+
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
|
12
|
+
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
|
13
|
+
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
|
14
|
+
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
|
15
|
+
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
|
16
|
+
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
|
17
|
+
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
|
18
|
+
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
|
19
|
+
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
|
|
20
|
+
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
|
|
21
|
+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|
22
|
+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
|
@@ -9,16 +9,61 @@ import innerprinter "github.com/microsoft/typescript-go/internal/printer"
|
|
|
9
9
|
|
|
10
10
|
// EmitHost is the per-emit host interface tsgo's transformers query (Options,
|
|
11
11
|
// SourceFiles, GetEmitResolver, GetEmitModuleFormatOfFile, WriteFile, ...).
|
|
12
|
+
// The embedding host supplies native path/case policy and file output;
|
|
13
|
+
// upstream requires host operations to be thread-safe.
|
|
14
|
+
//
|
|
15
|
+
// @evidence contracts/common.md#principled-implementation The exact upstream interface alias preserves the option, resolver and output callbacks its transformer chain requires; driver hosts satisfy that same contract without conversion.
|
|
16
|
+
// @evidence contracts/common.md#clear-and-simple-design One interface alias exposes the owning compiler boundary instead of a second host abstraction with independently maintained methods.
|
|
17
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Implementing this interface is supported dependency injection; the alias neither patches a host instance nor changes upstream dispatch.
|
|
18
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies the per-emit role and representative queries, while the package introduction explains the driver-to-transformer use.
|
|
19
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
20
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
21
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
22
|
+
// @evidence contracts/portability.md#os-neutral-implementation The upstream interface preserves current/common directories, filename case policy, project-reference paths and WriteFile errors as explicit host boundaries; its implementation supplies native semantics without alias-owned path folding or an assumed universal filesystem policy.
|
|
12
23
|
type EmitHost = innerprinter.EmitHost
|
|
13
24
|
|
|
14
25
|
// EmitResolver resolves emit-time facts about nodes (referenced imports,
|
|
15
|
-
// declaration flags, ...)
|
|
26
|
+
// declaration flags, ...). Synchronization belongs to the supplied resolver
|
|
27
|
+
// implementation and host contract; the pinned checker-backed resolver locks
|
|
28
|
+
// its checker internally for semantic queries. The alias adds no lock.
|
|
29
|
+
//
|
|
30
|
+
// @evidence contracts/common.md#principled-implementation An exact resolver interface alias retains the compiler's emit-time semantic queries and lets the host supply facts from the same checked program.
|
|
31
|
+
// @evidence contracts/common.md#clear-and-simple-design The alias exposes the existing semantic boundary without duplicating checker state or inventing another resolver protocol.
|
|
32
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The host supplies a resolver through upstream's interface; no foreign method or checker global is replaced.
|
|
33
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies emit-time facts, distinguishes resolver/host synchronization from the alias and notes the pinned checker resolver's internal locking instead of requiring a caller-held checker mutex.
|
|
34
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
35
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
36
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
37
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
16
38
|
type EmitResolver = innerprinter.EmitResolver
|
|
17
39
|
|
|
18
40
|
// EmitTextWriter is the sink the printer emits into; String() yields the text.
|
|
41
|
+
//
|
|
42
|
+
// @evidence contracts/common.md#principled-implementation The upstream writer interface alias preserves printing operations and text extraction as one compatible sink contract.
|
|
43
|
+
// @evidence contracts/common.md#clear-and-simple-design The printer and host share the existing sink interface, avoiding a separate buffering adapter.
|
|
44
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The declaration introduces no replacement methods, fixture dispatch or compensating behavior.
|
|
45
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states the sink's output role and how callers obtain its accumulated text.
|
|
46
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
47
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
48
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
49
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
19
50
|
type EmitTextWriter = innerprinter.EmitTextWriter
|
|
20
51
|
|
|
21
52
|
// NewTextWriter creates a fresh writer for one emit (newLine e.g. "\n").
|
|
53
|
+
// indentSize controls spaces per indentation level; nonpositive values select
|
|
54
|
+
// the pinned writer's default of four spaces.
|
|
55
|
+
// The caller owns the returned mutable sink and its accumulated text;
|
|
56
|
+
// Clear resets its buffer state, while previously returned strings remain
|
|
57
|
+
// owned by their consumers.
|
|
58
|
+
//
|
|
59
|
+
// @evidence contracts/common.md#principled-implementation Delegating newline and indentation width preserves upstream position accounting and its four-space fallback for nonpositive widths.
|
|
60
|
+
// @evidence contracts/common.md#clear-and-simple-design The constructor returns one fresh upstream sink without shared buffers or additional output policy.
|
|
61
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Formatting parameters are explicit inputs; no consumer-specific formatting or foreign method replacement is introduced.
|
|
62
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states writer lifetime, newline example, indentation units and nonpositive-width default with tags separated from descriptive text.
|
|
63
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The returned sink retains its newline backing string and subsequently accumulated output; its caller controls Clear and reference release, and strings already returned can keep output bytes alive after Clear. Construction opens no handle and enforces no output-byte cap or concurrent-use guard.
|
|
64
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms The upstream constructor owns indentation fallback and fresh writer initialization; this adapter chooses no independent buffering or formatting strategy.
|
|
65
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This factory requests a fresh upstream writer; the caller decides when an existing sink can be cleared and reused, without an adapter-owned shared producer or request-validity cache.
|
|
66
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation NewTextWriter computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
22
67
|
func NewTextWriter(newLine string, indentSize int) EmitTextWriter {
|
|
23
68
|
return innerprinter.NewTextWriter(newLine, indentSize)
|
|
24
69
|
}
|
|
@@ -2,13 +2,13 @@ module github.com/microsoft/typescript-go/shim/printer
|
|
|
2
2
|
|
|
3
3
|
go 1.26
|
|
4
4
|
|
|
5
|
-
require github.com/microsoft/typescript-go v0.0.0-
|
|
5
|
+
require github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063
|
|
6
6
|
|
|
7
7
|
require (
|
|
8
|
-
github.com/go-json-experiment/json v0.0.0-
|
|
8
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6 // indirect
|
|
9
9
|
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
|
10
10
|
github.com/zeebo/xxh3 v1.1.0 // indirect
|
|
11
|
-
golang.org/x/sync v0.
|
|
12
|
-
golang.org/x/sys v0.
|
|
13
|
-
golang.org/x/text v0.
|
|
11
|
+
golang.org/x/sync v0.21.0 // indirect
|
|
12
|
+
golang.org/x/sys v0.46.0 // indirect
|
|
13
|
+
golang.org/x/text v0.38.0 // indirect
|
|
14
14
|
)
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
github.com/go-json-experiment/json v0.0.0-
|
|
2
|
-
github.com/go-json-experiment/json v0.0.0-
|
|
1
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6 h1:nxP4pPoyqOAgX8lYDFCfl3DyKeXErCvSvhcyzwGV9CE=
|
|
2
|
+
github.com/go-json-experiment/json v0.0.0-20260601182631-00ed12fed2a6/go.mod h1:tphK2c80bpPhMOI4v6bIc2xWywPfbqi1Z06+RcrMkDg=
|
|
3
3
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|
4
4
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
|
5
5
|
github.com/klauspost/cpuid/v2 v2.2.10 h1:tBs3QSyvjDyFTq3uoc/9xFpCuOsJQFNPiAhYdw2skhE=
|
|
6
6
|
github.com/klauspost/cpuid/v2 v2.2.10/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
|
7
|
-
github.com/microsoft/typescript-go v0.0.0-
|
|
8
|
-
github.com/microsoft/typescript-go v0.0.0-
|
|
7
|
+
github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063 h1:UUVrjTrD+7nkVvkJTjxwA5+SaZ5n1uyAffm2zX2gn+o=
|
|
8
|
+
github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063/go.mod h1:s3yhRRZ7nzSZaiKicku520Tj9Mvewr9y2UtrvpwOmDE=
|
|
9
9
|
github.com/peter-evans/patience v0.3.0 h1:rX0JdJeepqdQl1Sk9c9uvorjYYzL2TfgLX1adqYm9cA=
|
|
10
10
|
github.com/peter-evans/patience v0.3.0/go.mod h1:Kmxu5sY1NmBLFSStvXjX1wS9mIv7wMcP/ubucyMOAu0=
|
|
11
11
|
github.com/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
|
12
12
|
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
|
13
13
|
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
|
14
14
|
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
|
15
|
-
golang.org/x/sync v0.
|
|
16
|
-
golang.org/x/sync v0.
|
|
17
|
-
golang.org/x/sys v0.
|
|
18
|
-
golang.org/x/sys v0.
|
|
19
|
-
golang.org/x/text v0.
|
|
20
|
-
golang.org/x/text v0.
|
|
15
|
+
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
|
16
|
+
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
|
17
|
+
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
|
18
|
+
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
|
19
|
+
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
|
|
20
|
+
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
|
|
21
21
|
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|
22
22
|
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
|
@@ -5,28 +5,85 @@ package printer
|
|
|
5
5
|
|
|
6
6
|
import (
|
|
7
7
|
"github.com/microsoft/typescript-go/internal/ast"
|
|
8
|
+
"github.com/microsoft/typescript-go/internal/core"
|
|
8
9
|
innerprinter "github.com/microsoft/typescript-go/internal/printer"
|
|
9
10
|
)
|
|
10
11
|
|
|
11
|
-
// PrintHandlers
|
|
12
|
-
//
|
|
12
|
+
// PrintHandlers supplies the pinned printer's global-name collision hook and
|
|
13
|
+
// before/after notifications for nodes, node lists and tokens. The legacy
|
|
14
|
+
// node-substitution and custom emit-callback hooks are not exposed by this
|
|
15
|
+
// TypeScript-Go version.
|
|
16
|
+
//
|
|
17
|
+
// @evidence contracts/common.md#principled-implementation The alias preserves HasGlobalName and the six node/list/token notification callbacks with their upstream signatures, allowing collision queries and traversal observations through the printer's actual supported boundaries.
|
|
18
|
+
// @evidence contracts/common.md#clear-and-simple-design One upstream handler value groups collision queries and traversal notifications without a separate dispatch framework or a shim-owned substitution protocol.
|
|
19
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Supported callback injection supplies collision facts and traversal observations without replacing foreign printer methods; unavailable legacy substitution and custom emit callbacks are not simulated.
|
|
20
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose names the available callback families and distinguishes their notifications from unavailable legacy substitution and custom emission hooks.
|
|
21
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
22
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
23
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
24
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
13
25
|
type PrintHandlers = innerprinter.PrintHandlers
|
|
14
26
|
|
|
15
27
|
// Printer holds the stateful emitter produced by NewPrinter.
|
|
28
|
+
//
|
|
29
|
+
// @evidence contracts/common.md#principled-implementation Go alias identity preserves upstream printer state and methods, allowing direct emission of compiler AST nodes without a parallel representation.
|
|
30
|
+
// @evidence contracts/common.md#clear-and-simple-design The existing emitter remains the single printing owner; this alias adds no mutable wrapper state.
|
|
31
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Emission uses the actual compiler printer rather than source-spelling replacements or patched internals.
|
|
32
|
+
// @evidence contracts/common.md#meaningful-documentation The native comment identifies stateful construction provenance; NewPrinter documents shared emit-context use.
|
|
33
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
34
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
35
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
36
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
16
37
|
type Printer = innerprinter.Printer
|
|
17
38
|
|
|
18
39
|
// PrinterOptions configures newline style, source-map generation, and other
|
|
19
40
|
// emission knobs.
|
|
41
|
+
//
|
|
42
|
+
// @evidence contracts/common.md#principled-implementation Aliasing the complete pinned options struct preserves the printer's supported fields and enum identities instead of losing settings in an incomplete copied schema.
|
|
43
|
+
// @evidence contracts/common.md#clear-and-simple-design One native options value configures all printer constructors, without independent defaults or translation in the shim.
|
|
44
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Settings remain caller data; the alias adds no consumer-specific emission overrides.
|
|
45
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies newline and source-map configuration, distinct from the printer's retained state.
|
|
46
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
47
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
48
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
49
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
20
50
|
type PrinterOptions = innerprinter.PrinterOptions
|
|
21
51
|
|
|
22
|
-
// EmitContext
|
|
23
|
-
//
|
|
52
|
+
// EmitContext owns per-emit node provenance, generated names and helper state.
|
|
53
|
+
// Create it fresh via NewEmitContext and share it across one transform/emit round.
|
|
54
|
+
//
|
|
55
|
+
// @evidence contracts/common.md#principled-implementation The alias retains the compiler's original-node links, naming metadata and node factory identity, allowing transformations and printing to interpret one shared provenance graph.
|
|
56
|
+
// @evidence contracts/common.md#clear-and-simple-design One upstream context couples related emit operations; separate rounds use separate contexts rather than another metadata synchronization layer.
|
|
57
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Context state is supplied through the supported API rather than process-global caches or foreign AST metadata patches.
|
|
58
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states actual retained metadata and the one-round sharing/lifetime boundary.
|
|
59
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
60
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
61
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
62
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
24
63
|
type EmitContext = innerprinter.EmitContext
|
|
25
64
|
|
|
26
65
|
// AutoGenerateOptions configures how NodeFactory allocates generated names.
|
|
66
|
+
//
|
|
67
|
+
// @evidence contracts/common.md#principled-implementation The alias preserves upstream naming flags, prefix and suffix fields exactly, matching the emit context's generated-name policy.
|
|
68
|
+
// @evidence contracts/common.md#clear-and-simple-design One options value groups the naming decision without a parallel identifier allocator.
|
|
69
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Naming policy uses compiler flags and caller spelling rather than fixed names chosen for known consumers.
|
|
70
|
+
// @evidence contracts/common.md#meaningful-documentation The comment identifies generated-name allocation rather than treating this as general printer formatting options.
|
|
71
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
72
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
73
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
74
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
27
75
|
type AutoGenerateOptions = innerprinter.AutoGenerateOptions
|
|
28
76
|
|
|
29
77
|
// GeneratedIdentifierFlags controls generated-name scope and collision checks.
|
|
78
|
+
//
|
|
79
|
+
// @evidence contracts/common.md#principled-implementation Go alias identity keeps the upstream name-kind and policy bits compatible with AutoGenerateOptions and the adjacent forwarded constants.
|
|
80
|
+
// @evidence contracts/common.md#clear-and-simple-design One native flag representation expresses generated-name policy without a shim-owned enum translation.
|
|
81
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Flags use compiler definitions rather than guessed numeric bits or consumer-specific naming exemptions.
|
|
82
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies scope and collision policy, and adjacent constants expose the supported flag family.
|
|
83
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
84
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
85
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
86
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This type declaration describes a data shape only; it opens no file, builds no path and branches on no platform.
|
|
30
87
|
type GeneratedIdentifierFlags = innerprinter.GeneratedIdentifierFlags
|
|
31
88
|
|
|
32
89
|
const (
|
|
@@ -42,20 +99,70 @@ const (
|
|
|
42
99
|
GeneratedIdentifierFlagsAllowNameSubstitution = innerprinter.GeneratedIdentifierFlagsAllowNameSubstitution
|
|
43
100
|
)
|
|
44
101
|
|
|
45
|
-
// NewPrinter creates an emitter with the supplied options,
|
|
46
|
-
//
|
|
47
|
-
//
|
|
102
|
+
// NewPrinter creates an emitter with the supplied options, handlers and emit
|
|
103
|
+
// context. A nil context creates a fresh upstream context; operations that
|
|
104
|
+
// depend on one round's shared node provenance must pass that same context.
|
|
105
|
+
// The returned printer keeps its context and handler references; callers own
|
|
106
|
+
// their lifetimes and must respect the upstream mutable-state contract.
|
|
107
|
+
//
|
|
108
|
+
// @evidence contracts/common.md#principled-implementation Direct delegation preserves upstream printer construction over the supplied options, hook and shared context, so transformed-node provenance remains available during emission.
|
|
109
|
+
// @evidence contracts/common.md#clear-and-simple-design One constructor keeps printer state with the emitter while the caller explicitly supplies the context shared by the round.
|
|
110
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The supported constructor accepts dependencies directly without replacing printer internals or injecting a consumer-specific emitter.
|
|
111
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies supplied handlers, nil-context allocation, provenance sharing and caller-owned mutable printer state.
|
|
112
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The returned printer retains handlers and its supplied or newly created context, with name-generator closures referencing that printer; later writer and name/mapping state belong to its caller-owned lifetime. Construction opens no handle and supplies no population cap, concurrent-use guard or automatic round disposal.
|
|
113
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Initial field setup, nil-context construction and name-generator wiring are upstream printer responsibilities; this adapter chooses no independent initialization or emission strategy.
|
|
114
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work The caller controls which printers share a valid emit context, and the upstream printer owns its internal writer and metadata reuse; this constructor coordinates no request cache or shared producer.
|
|
115
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation NewPrinter computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
48
116
|
func NewPrinter(options PrinterOptions, handlers PrintHandlers, emitContext *EmitContext) *Printer {
|
|
49
117
|
return innerprinter.NewPrinter(options, handlers, emitContext)
|
|
50
118
|
}
|
|
51
119
|
|
|
52
120
|
// NewEmitContext allocates a fresh EmitContext for a new emit round.
|
|
121
|
+
// The caller owns its lifetime and the node metadata accumulated by the
|
|
122
|
+
// round; the context is not guaranteed to be thread-safe.
|
|
123
|
+
//
|
|
124
|
+
// @evidence contracts/common.md#principled-implementation The upstream constructor initializes the context's own node factory; each call obtains a separate metadata identity for a separate emit round.
|
|
125
|
+
// @evidence contracts/common.md#clear-and-simple-design One factory creates the context and its coupled factory together rather than exposing partially initialized emit state.
|
|
126
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Calls acquire real fresh upstream state rather than sharing a process-global context across unrelated emit rounds.
|
|
127
|
+
// @evidence contracts/common.md#meaningful-documentation The comment identifies fresh allocation and its per-round purpose; the context type explains sharing within that round.
|
|
128
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The returned context and its factory reference each other and belong to the caller's emit round; subsequent metadata maps and scope state can retain nodes and provenance until the owning consumers release them. Construction opens no handle and imposes no metadata population cap or automatic round reset.
|
|
129
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Upstream constructs the context and factory with their node hooks; this adapter owns no independent allocation or metadata processing strategy.
|
|
130
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Context identity and sharing within an emit round belong to the caller; this factory only requests fresh upstream state and owns no cross-request producer or validity coordinator.
|
|
131
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation NewEmitContext computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
53
132
|
func NewEmitContext() *EmitContext {
|
|
54
133
|
return innerprinter.NewEmitContext()
|
|
55
134
|
}
|
|
56
135
|
|
|
57
136
|
// EmitSourceFile renders the full source file through the printer and returns
|
|
58
137
|
// the emitted text.
|
|
138
|
+
// The supplied printer must be nonnil and used according to its upstream
|
|
139
|
+
// state and handler contract; this adapter adds no concurrent-use guard.
|
|
140
|
+
//
|
|
141
|
+
// @evidence contracts/common.md#principled-implementation Delegating to the supplied upstream printer preserves AST-aware source emission; callers provide a real source file and a printer constructed for their emit context.
|
|
142
|
+
// @evidence contracts/common.md#clear-and-simple-design A single rendering adapter returns text while printer configuration and context construction retain their separate owners.
|
|
143
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Source text is produced by compiler AST printing rather than guessed textual substitution or fixture-specific output.
|
|
144
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states full-file rendering and the returned text, distinct from the source-map companion operation.
|
|
145
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The returned string retains emitted bytes for its consumers; the borrowed printer owns its reusable writer object and emit context. On normal completion upstream clears the writer's builder, while context and any prior printer state remain caller-owned, with no adapter-owned historical cache or byte cap.
|
|
146
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms AST traversal, source trivia and handler work, and output-byte construction belong to the supplied upstream Printer.Emit path; this adapter chooses no independent emission algorithm, and delegation does not make those input-dependent costs constant.
|
|
147
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work The supplied printer owns writer reuse and emit context; this adapter coordinates no equivalent requests or completed-output cache and always asks that printer to render the supplied source.
|
|
148
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation EmitSourceFile computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
59
149
|
func EmitSourceFile(p *Printer, sourceFile *ast.SourceFile) string {
|
|
60
150
|
return p.EmitSourceFile(sourceFile)
|
|
61
151
|
}
|
|
152
|
+
|
|
153
|
+
// RangeStartPositionsAreOnSameLine compares two range starts after skipping
|
|
154
|
+
// leading trivia in sourceFile. The nonnil file and both nonnegative range
|
|
155
|
+
// starts must refer to the same source text, with positions within its bytes.
|
|
156
|
+
// Synthesized negative positions are not a supported source-line query.
|
|
157
|
+
//
|
|
158
|
+
// @evidence contracts/common.md#principled-implementation Upstream trivia skipping and source-line comparison preserve printer layout semantics for both range starts.
|
|
159
|
+
// @evidence contracts/common.md#clear-and-simple-design One predicate keeps source-position interpretation with the printer instead of a second line-index implementation.
|
|
160
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Actual source bytes and compiler ranges determine line identity without guessed UTF-16 offsets.
|
|
161
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states trivia handling, nonnil source and shared byte-coordinate premises.
|
|
162
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources When distinct trivia-adjusted positions require a line lookup, upstream can initialize the borrowed source file's locked line-start cache, retaining one entry per line for that source's lifetime. This adapter returns only a boolean and owns no historical state or handle; consumers own source and cache reference release.
|
|
163
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Upstream owns trivia scanning and source-line comparison: adjusted starts can shortcut when equal, otherwise first-use line indexing scans source bytes and line lookup uses binary search. This forwarding adapter chooses no independent scan or indexing strategy, and its constant wrapper size does not bound delegated work.
|
|
164
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work The borrowed source file owns lazy line-map initialization and reuse for its text identity; this adapter coordinates no equivalent requests or additional cache and delegates that same source to upstream.
|
|
165
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation RangeStartPositionsAreOnSameLine computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
166
|
+
func RangeStartPositionsAreOnSameLine(first core.TextRange, second core.TextRange, sourceFile *ast.SourceFile) bool {
|
|
167
|
+
return innerprinter.RangeStartPositionsAreOnSameLine(first, second, sourceFile)
|
|
168
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// gen_shims:hand-maintained
|
|
2
|
+
//
|
|
3
|
+
// Prints one source file together with a source map back to its original text,
|
|
4
|
+
// for hosts that hand transformed TypeScript to a bundler instead of emitting
|
|
5
|
+
// JavaScript.
|
|
6
|
+
package printer
|
|
7
|
+
|
|
8
|
+
import (
|
|
9
|
+
"github.com/microsoft/typescript-go/internal/ast"
|
|
10
|
+
innerprinter "github.com/microsoft/typescript-go/internal/printer"
|
|
11
|
+
"github.com/microsoft/typescript-go/internal/sourcemap"
|
|
12
|
+
"github.com/microsoft/typescript-go/internal/tspath"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
// EmitSourceFileWithSourceMap renders sourceFile the way EmitSourceFile does
|
|
16
|
+
// and also returns a version 3 source map, as JSON, from the rendered text back
|
|
17
|
+
// to the original positions its nodes still carry.
|
|
18
|
+
//
|
|
19
|
+
// It builds its own printer from options, handlers, and emitContext, because a
|
|
20
|
+
// printer remembers the last source it mapped across writes and would reuse
|
|
21
|
+
// that source's index in the next file's map. `file` is the source file's base
|
|
22
|
+
// name and `sources` are relative to its directory, the layout a bundler
|
|
23
|
+
// resolves a module's map against. options.InlineSources adds each source's
|
|
24
|
+
// original text as `sourcesContent`, which lets a consumer check the map
|
|
25
|
+
// against the text it was generated from.
|
|
26
|
+
// sourceFile must be nonnil. Mapping quality depends on transformed nodes
|
|
27
|
+
// retaining valid original positions through emitContext.
|
|
28
|
+
//
|
|
29
|
+
// @evidence contracts/common.md#principled-implementation The upstream printer writes text and mapping segments in the same traversal, using node positions and EmitContext provenance; the version-3 map names the output basename and resolves sources relative to its directory.
|
|
30
|
+
// @evidence contracts/common.md#clear-and-simple-design A fresh printer, generator and writer belong to one file, preventing printer-held source indexes from leaking into the next map.
|
|
31
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Fresh per-file mapping state corrects the actual source-index lifetime; source names and inline content come from compiler objects rather than consumer-specific substitutions.
|
|
32
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose explains map layout, fresh-printer ownership, inline sources, nonnil input and original-position requirements in separated paragraphs.
|
|
33
|
+
// @evidence contracts/performance.md#efficient-algorithms The same printer Write supplies text and mapping segments without a separate map-building AST pass in this adapter. Work includes upstream traversal, trivia and supplied handlers, source/name path processing, mapping encoding, cloned source/name/content lists and JSON serialization; space grows with output, mapping and optional inline source bytes, with temporary JSON bytes alongside the returned map string.
|
|
34
|
+
// @evidence contracts/performance.md#reuse-equivalent-work The same traversal supplies both outputs and EmitContext supplies original-node provenance; a fresh per-file printer is necessary because retained source indexes cannot be shared between independent map generators.
|
|
35
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The call owns its fresh printer, generator and writer; returned text and map strings retain output bytes for their consumers. Local mapping lists, source references and temporary JSON storage become unreachable when the call ends, while the borrowed emit context and handler state remain caller-owned. There is no adapter-owned historical cache, running task or enforced byte cap.
|
|
36
|
+
// @evidence contracts/portability.md#os-neutral-implementation The generator uses the emitted source directory as its lexical path base and a fixed case-sensitive policy for original source names, including names recovered through emit provenance. These map paths are presentation data rather than filesystem identity queries; the adapter performs no native lookup or case-sensitivity probe.
|
|
37
|
+
func EmitSourceFileWithSourceMap(
|
|
38
|
+
options PrinterOptions,
|
|
39
|
+
handlers PrintHandlers,
|
|
40
|
+
emitContext *EmitContext,
|
|
41
|
+
sourceFile *ast.SourceFile,
|
|
42
|
+
) (string, string) {
|
|
43
|
+
printer := innerprinter.NewPrinter(options, handlers, emitContext)
|
|
44
|
+
fileName := sourceFile.FileName()
|
|
45
|
+
directory := tspath.GetDirectoryPath(fileName)
|
|
46
|
+
generator := sourcemap.NewGenerator(
|
|
47
|
+
tspath.GetBaseFileName(fileName),
|
|
48
|
+
"",
|
|
49
|
+
directory,
|
|
50
|
+
tspath.ComparePathsOptions{UseCaseSensitiveFileNames: true, CurrentDirectory: directory},
|
|
51
|
+
)
|
|
52
|
+
writer := innerprinter.NewTextWriter(options.NewLine.GetNewLineCharacter(), 0)
|
|
53
|
+
printer.Write(sourceFile.AsNode(), sourceFile, writer, generator)
|
|
54
|
+
return writer.String(), generator.String()
|
|
55
|
+
}
|