@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
|
@@ -2,4 +2,9 @@ module github.com/microsoft/typescript-go/shim/core
|
|
|
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
|
+
golang.org/x/sync v0.21.0 // indirect
|
|
10
|
+
)
|
|
@@ -0,0 +1,10 @@
|
|
|
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/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063 h1:UUVrjTrD+7nkVvkJTjxwA5+SaZ5n1uyAffm2zX2gn+o=
|
|
6
|
+
github.com/microsoft/typescript-go v0.0.0-20260610182825-7fc57c005063/go.mod h1:s3yhRRZ7nzSZaiKicku520Tj9Mvewr9y2UtrvpwOmDE=
|
|
7
|
+
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
|
8
|
+
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
|
9
|
+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|
10
|
+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
|
@@ -7,4 +7,13 @@ package core
|
|
|
7
7
|
import innercore "github.com/microsoft/typescript-go/internal/core"
|
|
8
8
|
|
|
9
9
|
// ModuleKind is tsgo's module-format enum (CommonJS, ESNext, NodeNext, ...).
|
|
10
|
+
//
|
|
11
|
+
// @evidence contracts/common.md#principled-implementation A Go alias preserves upstream module-format identity, matching CompilerOptions and emit-host decisions without translating enum values.
|
|
12
|
+
// @evidence contracts/common.md#clear-and-simple-design One compiler discriminator connects configuration and emit format, with constants maintained in the adjacent core shim.
|
|
13
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Formats remain actual compiler constants rather than hardcoded consumer-specific output choices.
|
|
14
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose gives representative formats and package context explains the emit-host consumer.
|
|
15
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
16
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
17
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
18
|
+
// @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.
|
|
10
19
|
type ModuleKind = innercore.ModuleKind
|
|
@@ -13,32 +13,119 @@ import (
|
|
|
13
13
|
|
|
14
14
|
// CompilerOptions holds the parsed tsconfig compiler options passed to the
|
|
15
15
|
// TypeScript-Go program host.
|
|
16
|
+
//
|
|
17
|
+
// @evidence contracts/common.md#principled-implementation A Go alias retains the parsed option fields and upstream tristate types exactly, preserving unset versus explicit false in compiler configuration.
|
|
18
|
+
// @evidence contracts/common.md#clear-and-simple-design Hosts pass the compiler's own options value instead of maintaining another option schema and conversion layer.
|
|
19
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Configuration remains caller/compiler data, with no consumer-specific option overrides in this alias.
|
|
20
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies parsed tsconfig provenance and the Program-host consumer, separate from these tags.
|
|
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.
|
|
16
25
|
type CompilerOptions = innercore.CompilerOptions
|
|
17
26
|
|
|
18
27
|
// JsxEmit is the parsed compilerOptions.jsx mode.
|
|
28
|
+
//
|
|
29
|
+
// @evidence contracts/common.md#principled-implementation The alias preserves the upstream JSX mode discriminator and the values forwarded by this package's JsxEmit constants.
|
|
30
|
+
// @evidence contracts/common.md#clear-and-simple-design One enum identity serves parsed options and compiler consumers without translating JSX modes.
|
|
31
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Modes use actual compiler constants rather than guessed strings or consumer-selected numeric values.
|
|
32
|
+
// @evidence contracts/common.md#meaningful-documentation The comment names the configuration field this discriminator represents.
|
|
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.
|
|
19
37
|
type JsxEmit = innercore.JsxEmit
|
|
20
38
|
|
|
21
39
|
// ModuleResolutionKind selects TypeScript-Go's module resolver.
|
|
40
|
+
// The alias also retains unknown and deprecated parsing values; retaining a
|
|
41
|
+
// discriminator does not certify that every value can run a resolver.
|
|
42
|
+
//
|
|
43
|
+
// @evidence contracts/common.md#principled-implementation Aliasing the upstream enum preserves its declared resolver-selection and parsing values exactly in CompilerOptions. Runtime admission and dispatch remain with compiler owners, including refusal of unsupported values.
|
|
44
|
+
// @evidence contracts/common.md#clear-and-simple-design Resolver selection remains one compiler discriminator instead of a parallel shim policy.
|
|
45
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Selection uses upstream constants without guessing a resolver from a consumer name or host OS.
|
|
46
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies resolver selection rather than merely repeating the type name.
|
|
47
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
48
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
49
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
50
|
+
// @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.
|
|
22
51
|
type ModuleResolutionKind = innercore.ModuleResolutionKind
|
|
23
52
|
|
|
24
|
-
// ResolutionMode
|
|
53
|
+
// ResolutionMode represents None, CommonJS or ESM lookup for one module use.
|
|
54
|
+
// Upstream aliases ModuleKind for this role; it is not a distinct Go type or a
|
|
55
|
+
// validated three-value set. Per-use lookup differs from project resolver policy.
|
|
56
|
+
//
|
|
57
|
+
// @evidence contracts/common.md#principled-implementation The alias preserves per-use CommonJS/ESM discrimination independently from the project's overall module resolution strategy.
|
|
58
|
+
// @evidence contracts/common.md#clear-and-simple-design The upstream alias exposes the per-use role independently from ModuleResolutionKind while preserving its actual ModuleKind type identity and None/CommonJS/ESM constants.
|
|
59
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Modes remain compiler facts rather than a file-extension heuristic in the shim.
|
|
60
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies per-use scope, None and CommonJS/ESM constants, the actual upstream type alias and absence of value validation.
|
|
61
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
62
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
63
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
64
|
+
// @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.
|
|
25
65
|
type ResolutionMode = innercore.ResolutionMode
|
|
26
66
|
|
|
27
67
|
// Tristate is a three-valued boolean: TSFalse, TSTrue, or TSUnknown. Used by
|
|
28
68
|
// CompilerOptions fields that can be explicitly unset.
|
|
69
|
+
//
|
|
70
|
+
// @evidence contracts/common.md#principled-implementation Go alias identity retains upstream false, true and unknown values, so a boolean conversion cannot erase the distinction used during option merging.
|
|
71
|
+
// @evidence contracts/common.md#clear-and-simple-design One three-valued representation serves compiler options instead of separate presence and boolean fields.
|
|
72
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Unknown is retained as a real compiler state rather than being silently coerced to a desired default.
|
|
73
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose names the three values and their configuration use before the acknowledgment block.
|
|
74
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
75
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
76
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
77
|
+
// @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.
|
|
29
78
|
type Tristate = innercore.Tristate
|
|
30
79
|
|
|
31
|
-
// TextPos is a
|
|
80
|
+
// TextPos is a signed 32-bit byte coordinate. Source offsets are zero-based;
|
|
81
|
+
// negative values also represent absent positions for synthesized nodes.
|
|
82
|
+
//
|
|
83
|
+
// @evidence contracts/common.md#principled-implementation The alias preserves the compiler's integer byte-coordinate representation; it does not reinterpret offsets as UTF-16 character positions.
|
|
84
|
+
// @evidence contracts/common.md#clear-and-simple-design A single compiler coordinate type connects source ranges and line starts without a unit-conversion wrapper.
|
|
85
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Byte offsets are retained without guessed JavaScript character conversion.
|
|
86
|
+
// @evidence contracts/common.md#meaningful-documentation The declaration states signed 32-bit storage, zero-based byte units and negative synthetic-position meaning.
|
|
87
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
88
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
89
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
90
|
+
// @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.
|
|
32
91
|
type TextPos = innercore.TextPos
|
|
33
92
|
|
|
34
93
|
// ECMALineStarts holds the byte offset of every source line the compiler
|
|
35
94
|
// recognizes under ECMAScript's line-terminator rules.
|
|
95
|
+
//
|
|
96
|
+
// @evidence contracts/common.md#principled-implementation The alias keeps upstream line-start storage and byte-coordinate identity, matching the ComputeECMALineStarts result consumed by compiler location logic.
|
|
97
|
+
// @evidence contracts/common.md#clear-and-simple-design Line positions use the compiler's existing representation rather than another indexed line model.
|
|
98
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Source line starts follow compiler semantics rather than a newline split that discards ECMAScript terminators.
|
|
99
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states byte offsets and the language's line-terminator model.
|
|
100
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
101
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
102
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
103
|
+
// @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.
|
|
36
104
|
type ECMALineStarts = innercore.ECMALineStarts
|
|
37
105
|
|
|
38
|
-
// TextRange is a half-open [Pos, End) byte range
|
|
106
|
+
// TextRange is a half-open [Pos, End) byte range, or an undefined range with
|
|
107
|
+
// negative endpoints for a synthesized node.
|
|
108
|
+
//
|
|
109
|
+
// @evidence contracts/common.md#principled-implementation Aliasing the upstream range preserves its two byte endpoints and methods, including the undefined range supplied for synthesized nodes.
|
|
110
|
+
// @evidence contracts/common.md#clear-and-simple-design One upstream interval representation serves constructors and AST users without a competing span type.
|
|
111
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Positions stay compiler values without fabricating a source interval for a synthetic node.
|
|
112
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states half-open endpoints and byte units; UndefinedTextRange documents synthesized-node absence.
|
|
113
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
114
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
115
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
116
|
+
// @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.
|
|
39
117
|
type TextRange = innercore.TextRange
|
|
40
118
|
|
|
41
119
|
// ScriptKind identifies the syntactic flavour of a source file.
|
|
120
|
+
//
|
|
121
|
+
// @evidence contracts/common.md#principled-implementation The upstream alias preserves source-language discrimination used by parsing, including TS, JS, JSX/TSX and JSON constants.
|
|
122
|
+
// @evidence contracts/common.md#clear-and-simple-design Parsed source flavour uses one compiler enum rather than a shim string-to-language mapper.
|
|
123
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The bridge forwards upstream kinds without special-casing a named file or package.
|
|
124
|
+
// @evidence contracts/common.md#meaningful-documentation The comment states syntactic source flavour and adjacent constant comments identify the supported family.
|
|
125
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
126
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
127
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
128
|
+
// @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.
|
|
42
129
|
type ScriptKind = innercore.ScriptKind
|
|
43
130
|
|
|
44
131
|
const (
|
|
@@ -95,12 +182,47 @@ const (
|
|
|
95
182
|
)
|
|
96
183
|
|
|
97
184
|
// Version reports the TypeScript compiler version typescript-go implements, in
|
|
98
|
-
//
|
|
99
|
-
//
|
|
185
|
+
// upstream's compiled version-string form, which can be overridden at link
|
|
186
|
+
// time. A graph snapshot publishes this semantic version; it does not identify
|
|
187
|
+
// the precise checker revision or certify executable/artifact identity.
|
|
188
|
+
//
|
|
189
|
+
// @evidence contracts/common.md#principled-implementation Direct delegation returns the version the pinned compiler implements, matching the checker that produced the consumer's semantic facts.
|
|
190
|
+
// @evidence contracts/common.md#clear-and-simple-design One accessor supplies upstream version identity without parsing manifests or inferring release metadata.
|
|
191
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The answer comes from the compiler rather than a hardcoded ttsc package version.
|
|
192
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose distinguishes compiler version from host release and explains the graph consumer's provenance need.
|
|
193
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The returned string borrows backing storage owned by upstream's process-lifetime compiled version variable. No new file handle, independent buffer or historical result registry is acquired here; callers can retain the string without making this wrapper the version-state owner.
|
|
194
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Upstream owns the direct compiled-string projection. This bridge chooses no independent version computation, parsing or metadata traversal.
|
|
195
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Static compiled version state belongs to upstream; this accessor coordinates no completed/in-flight version producer or cache invalidation policy.
|
|
196
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This accessor reads compiled version metadata without native filesystem, path-identity or process operations. It does not infer the selected executable's identity or OS capabilities.
|
|
100
197
|
func Version() string { return innercore.Version() }
|
|
101
198
|
|
|
199
|
+
// ApplyDebugStackLimit applies a positive TS_GO_DEBUG_STACK_LIMIT byte count
|
|
200
|
+
// to this process's Go runtime. Missing, invalid or nonpositive values do nothing.
|
|
201
|
+
// Parsing uses the runtime's int width. A successful call changes process-wide
|
|
202
|
+
// stack policy; this wrapper does not restore its previous setting.
|
|
203
|
+
//
|
|
204
|
+
// @evidence contracts/common.md#principled-implementation Upstream parsing and runtime.SetMaxStack preserve the documented opt-in process-wide limit and invalid-value no-op.
|
|
205
|
+
// @evidence contracts/common.md#clear-and-simple-design One explicit operation leaves environment parsing and runtime policy with the compiler owner.
|
|
206
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The explicit upstream operation changes the process-wide stack limit only when its environment input requests a positive limit; no consumer-specific policy is substituted.
|
|
207
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states byte units, process scope and the three no-op conditions.
|
|
208
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources Upstream may persist a new process-wide runtime stack limit after parsing the environment. No file handle or independent cache is acquired by this bridge, but absence of those resources is not absence of lasting policy state. The runtime and caller own that setting and any later replacement; this adapter provides no scoped restoration.
|
|
209
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Upstream owns environment lookup, integer parsing over the supplied value bytes and runtime policy mutation. This direct bridge chooses no independent lookup/parser/stack-management algorithm.
|
|
210
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Environment lookup and the explicit runtime setter are not coordinated as completed or in-flight shared work here; the runtime owns its policy state, and this bridge provides no separate producer or memoized setting.
|
|
211
|
+
// @evidence contracts/portability.md#os-neutral-implementation Supported os.Getenv and runtime/debug.SetMaxStack obtain the actual process environment and change this Go runtime's policy without OS-name branches or shell interpretation. strconv.Atoi admits only a positive value representable by the runtime's int width; the setting is process-wide rather than a per-call platform capability certificate.
|
|
212
|
+
func ApplyDebugStackLimit() { innercore.ApplyDebugStackLimit() }
|
|
213
|
+
|
|
102
214
|
// TypeScriptVersionSatisfiesRange reports whether the compiler's own version
|
|
103
215
|
// satisfies a typesVersions range under TypeScript-Go's semver grammar.
|
|
216
|
+
// Invalid range or compiler-version syntax returns false.
|
|
217
|
+
//
|
|
218
|
+
// @evidence contracts/common.md#principled-implementation Both range and compiler version use upstream semver parsing; the parsed range tests that version, and invalid parsing returns false rather than implying satisfaction.
|
|
219
|
+
// @evidence contracts/common.md#clear-and-simple-design One predicate owns range parsing and testing, leaving compiler version production with Version and grammar with upstream semver.
|
|
220
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts typesVersions matching uses real compiler version and parser semantics rather than consumer names or lexicographic version guesses.
|
|
221
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies typesVersions, the upstream grammar and invalid-syntax refusal.
|
|
222
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources Upstream parsing allocates alternative/comparator and version-component storage for this invocation, potentially retaining substrings until its local values become unreachable. Only a boolean escapes this function; global compiler-version and regex state remain upstream-owned. No independent parse-result history or native handle is retained here, and no fixed input/alternative count cap is imposed.
|
|
223
|
+
// @evidence contracts/performance.md#efficient-algorithms Parse the range once, return early when invalid, then parse the actual compiler version once and test it. Delegated regex/tokenization, component parsing and short-circuit alternative/comparator tests scale with supplied range/version text and parsed population; the wrapper's few calls do not make this fixed-cost work.
|
|
224
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This predicate coordinates no completed/in-flight range-result cache; parsing and matching remain invocation-local while upstream owns static regex and compiler-version state. Caller owners decide whether a result remains equivalent for unchanged range and actual compiler identity.
|
|
225
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Matching reads supplied range text and the compiled upstream version string; it performs no native filesystem, path-identity or process operation. Compiler-version metadata is semantic input, not an OS capability query.
|
|
104
226
|
func TypeScriptVersionSatisfiesRange(text string) bool {
|
|
105
227
|
versionRange, ok := innersemver.TryParseVersionRange(text)
|
|
106
228
|
if !ok {
|
|
@@ -112,12 +234,41 @@ func TypeScriptVersionSatisfiesRange(text string) bool {
|
|
|
112
234
|
|
|
113
235
|
// ComputeECMALineStarts applies the compiler's LF, CRLF, CR, LS, and PS line
|
|
114
236
|
// model to UTF-8 source text.
|
|
237
|
+
//
|
|
238
|
+
// @evidence contracts/common.md#principled-implementation Direct delegation applies the compiler's ECMAScript line-terminator scan and returns its byte offsets, preserving CRLF pairing and non-ASCII terminators.
|
|
239
|
+
// @evidence contracts/common.md#clear-and-simple-design One text-to-line-start adapter reuses the compiler model without a separate line scanner.
|
|
240
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The implementation does not approximate compiler lines by splitting only on LF or guessing UTF-16 offsets.
|
|
241
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose enumerates LF, CRLF, CR, LS and PS and identifies UTF-8 source units.
|
|
242
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources Upstream allocates and may grow a line-start backing array; the returned slice keeps that storage reachable under the caller's lifetime. Initial capacity counts LF bytes, so other terminators can require growth. The bridge keeps no independent history cache or handle and imposes no fixed source/line-count cap.
|
|
243
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms The pinned compiler owns the LF-capacity count and ECMAScript byte/rune scan, both over source text, plus line-array append/growth. This direct bridge selects no independent scanner or storage algorithm; fixed-step wrapper syntax does not remove those input-size costs.
|
|
244
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This bridge does not coordinate a source-version cache or completed/in-flight index producer; compiler and caller owners decide whether an already computed line index can be reused for equivalent text.
|
|
245
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation ComputeECMALineStarts computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
115
246
|
func ComputeECMALineStarts(text string) ECMALineStarts {
|
|
116
247
|
return innercore.ComputeECMALineStarts(text)
|
|
117
248
|
}
|
|
118
249
|
|
|
119
|
-
// NewTextRange constructs a
|
|
250
|
+
// NewTextRange constructs a half-open [pos, end) byte range. Endpoints must fit
|
|
251
|
+
// signed 32-bit TextPos storage; the constructor does not validate ordering or
|
|
252
|
+
// source bounds.
|
|
253
|
+
//
|
|
254
|
+
// @evidence contracts/common.md#principled-implementation The upstream constructor casts integer endpoints into signed 32-bit TextPos storage, preserving representable values; range ordering, representability and source bounds remain the caller's responsibility.
|
|
255
|
+
// @evidence contracts/common.md#clear-and-simple-design One constructor supplies the native range without a separate normalization or coordinate-conversion policy.
|
|
256
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Endpoints are not clamped to manufacture an apparently valid range for a consumer.
|
|
257
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states half-open byte endpoints, signed 32-bit representability and absence of constructor validation, separated from implementation grounds.
|
|
258
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources NewTextRange acquires no handle, buffer or cache and retains nothing after it returns.
|
|
259
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms The pinned constructor owns the two endpoint casts and range representation. This direct bridge chooses no separate normalization, traversal or validation algorithm.
|
|
260
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This scalar range adapter is not a completed/in-flight work producer or cache coordinator; caller operations own reuse of ranges associated with source versions.
|
|
261
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation NewTextRange computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
120
262
|
func NewTextRange(pos, end int) TextRange { return innercore.NewTextRange(pos, end) }
|
|
121
263
|
|
|
122
264
|
// UndefinedTextRange marks synthesized AST nodes that do not map to source.
|
|
265
|
+
//
|
|
266
|
+
// @evidence contracts/common.md#principled-implementation Delegation returns the compiler's own undefined-range sentinel, preserving its meaning for synthesized rather than source-backed nodes.
|
|
267
|
+
// @evidence contracts/common.md#clear-and-simple-design A named sentinel constructor distinguishes missing source provenance from ordinary NewTextRange intervals.
|
|
268
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Synthetic nodes receive upstream absence metadata rather than fabricated source coordinates.
|
|
269
|
+
// @evidence contracts/common.md#meaningful-documentation The native comment explains synthesized-node provenance and why an undefined interval exists.
|
|
270
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources UndefinedTextRange acquires no handle, buffer or cache and retains nothing after it returns.
|
|
271
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Upstream owns the scalar undefined-endpoint representation. This direct bridge chooses no independent range algorithm, source traversal or coordinate validation.
|
|
272
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work The sentinel adapter coordinates no completed/in-flight work producer or cache; it supplies scalar absence metadata for caller-owned AST operations.
|
|
273
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation UndefinedTextRange computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
123
274
|
func UndefinedTextRange() TextRange { return innercore.UndefinedTextRange() }
|
|
@@ -2,4 +2,13 @@ module github.com/microsoft/typescript-go/shim/diagnosticwriter
|
|
|
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,20 @@
|
|
|
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/zeebo/assert v1.3.0 h1:g7C04CbJuIDKNPFHmsk4hwZDO5O+kntRxzaUoNXj+IQ=
|
|
10
|
+
github.com/zeebo/assert v1.3.0/go.mod h1:Pq9JiuJQpG8JLJdtkwrJESF0Foym2/D9XMU5ciN/wJ0=
|
|
11
|
+
github.com/zeebo/xxh3 v1.1.0 h1:s7DLGDK45Dyfg7++yxI0khrfwq9661w9EN78eP/UZVs=
|
|
12
|
+
github.com/zeebo/xxh3 v1.1.0/go.mod h1:IisAie1LELR4xhVinxWS5+zf1lA4p0MW4T+w+W07F5s=
|
|
13
|
+
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
|
14
|
+
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
|
15
|
+
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
|
16
|
+
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
|
17
|
+
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
|
|
18
|
+
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
|
|
19
|
+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|
20
|
+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
|
@@ -25,7 +25,17 @@ import (
|
|
|
25
25
|
)
|
|
26
26
|
|
|
27
27
|
// LintCategory selects warning vs error rendering. Warnings render yellow,
|
|
28
|
-
// errors render red
|
|
28
|
+
// errors render red; the exit-code decision lives in the caller.
|
|
29
|
+
// Any value other than LintCategoryError maps to warning.
|
|
30
|
+
//
|
|
31
|
+
// @evidence contracts/common.md#principled-implementation Separate category constants preserve error versus warning; Category and IsError share the exact error discriminator, so display and error counting agree even for other integer values.
|
|
32
|
+
// @evidence contracts/common.md#clear-and-simple-design One category value drives both rendering and caller error classification without coupling the diagnostic to a process exit.
|
|
33
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Category constants express the renderer contract, not severity guesses based on message text or a rule's consumer.
|
|
34
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies display categories, caller-owned exit decisions and the non-error fallback.
|
|
35
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
36
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
37
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
38
|
+
// @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.
|
|
29
39
|
type LintCategory int
|
|
30
40
|
|
|
31
41
|
const (
|
|
@@ -38,6 +48,15 @@ const (
|
|
|
38
48
|
// caller's contract says they point inside the current file. Reversed and
|
|
39
49
|
// zero-width ranges select one byte when one exists at pos; EOF and empty-file
|
|
40
50
|
// ranges remain zero-width instead of manufacturing a byte past the source.
|
|
51
|
+
//
|
|
52
|
+
// @evidence contracts/common.md#principled-implementation Clamping both byte endpoints into [0, source length] and extending a nonpositive span only before EOF establishes 0 <= pos <= end <= length; nil source yields an empty project-wide span.
|
|
53
|
+
// @evidence contracts/common.md#clear-and-simple-design One boundary normalizer owns producer-range sanitation for every NewLintDiagnostic instead of requiring each renderer method to repair offsets.
|
|
54
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Clamping addresses untrusted producer coordinates against the actual source length; it does not substitute canned diagnostic ranges or hide an out-of-file byte.
|
|
55
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states half-open units, why sanitation belongs at the producer boundary, and the reversed/EOF/empty-file effects.
|
|
56
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources NormalizeLintRange acquires no handle, buffer or cache and retains nothing after it returns.
|
|
57
|
+
// @evidence contracts/performance.md#efficient-algorithms Reading the existing source text length and clamping two scalar endpoints takes constant work and space independent of source bytes; selecting one byte before EOF avoids scanning text or allocating a replacement span.
|
|
58
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This scalar sanitizer owns no cross-request producer, cache or in-flight coordinator; construction stores its result so renderer accessors do not repeat sanitation for the same diagnostic.
|
|
59
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation NormalizeLintRange computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
41
60
|
func NormalizeLintRange(file *ast.SourceFile, pos, end int) (int, int) {
|
|
42
61
|
if file == nil {
|
|
43
62
|
return 0, 0
|
|
@@ -63,9 +82,22 @@ func NormalizeLintRange(file *ast.SourceFile, pos, end int) (int, int) {
|
|
|
63
82
|
}
|
|
64
83
|
|
|
65
84
|
// LintDiagnostic is a public, plugin-emittable diagnostic shaped like the
|
|
66
|
-
// `internal/diagnosticwriter.Diagnostic` interface. The
|
|
67
|
-
//
|
|
68
|
-
//
|
|
85
|
+
// `internal/diagnosticwriter.Diagnostic` interface. The upstream interface lives
|
|
86
|
+
// in an internal package that outside plugin modules cannot import directly.
|
|
87
|
+
// This public implementation lets their findings share the compiler renderer.
|
|
88
|
+
//
|
|
89
|
+
// The source file is retained, not copied; its text must remain the version the
|
|
90
|
+
// diagnostic range describes. Stored-field accessors require a nonnil
|
|
91
|
+
// receiver; File, Message and the empty-metadata accessors are nil-safe.
|
|
92
|
+
//
|
|
93
|
+
// @evidence contracts/common.md#principled-implementation Private source, normalized byte endpoints, severity and message implement the upstream Diagnostic methods without losing project-wide nil source or already-localized lint prose.
|
|
94
|
+
// @evidence contracts/common.md#clear-and-simple-design One immutable-by-public-API value implements the renderer boundary, with construction owning range validation and accessors supplying stored facts.
|
|
95
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Lint findings enter the same formatter through an explicit interface implementation rather than modifying upstream diagnostics or injecting global output.
|
|
96
|
+
// @evidence contracts/common.md#meaningful-documentation Separate native paragraphs explain the internal-package import boundary, retained source version and nil-receiver limits; public accessors document units and optional metadata.
|
|
97
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources A type declaration acquires and holds no runtime resource.
|
|
98
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms A type declaration chooses no processing strategy.
|
|
99
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work A type declaration computes nothing, so there is no work to share.
|
|
100
|
+
// @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.
|
|
69
101
|
type LintDiagnostic struct {
|
|
70
102
|
file *ast.SourceFile
|
|
71
103
|
pos int
|
|
@@ -76,8 +108,20 @@ type LintDiagnostic struct {
|
|
|
76
108
|
}
|
|
77
109
|
|
|
78
110
|
// NewLintDiagnostic builds a lint diagnostic anchored at [pos, end) in the
|
|
79
|
-
// supplied source file. `code` shows up in the rendered banner
|
|
111
|
+
// supplied source file. `code` shows up in the rendered banner; the
|
|
80
112
|
// convention is to give each rule its own stable integer.
|
|
113
|
+
// A nil file creates a project-wide message with an empty range.
|
|
114
|
+
// The returned value borrows the source file and message backing storage;
|
|
115
|
+
// it does not validate code uniqueness, category membership or localization.
|
|
116
|
+
//
|
|
117
|
+
// @evidence contracts/common.md#principled-implementation Construction normalizes the caller's byte span before storing the supplied source identity, code, category and message; nil source retains project-wide absence, while code stability and final prose remain producer responsibilities.
|
|
118
|
+
// @evidence contracts/common.md#clear-and-simple-design One constructor establishes the range invariant for the private fields; renderer accessors need no repeated sanitation.
|
|
119
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The value contains actual producer findings; stable codes identify rules rather than synthesizing expected compiler messages.
|
|
120
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states half-open anchoring, code identity convention and nil-file meaning, with range normalization explained on its owner.
|
|
121
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources Each returned record retains the borrowed source graph and message backing storage until its consumers release their references; construction copies scalar coordinates and metadata, not source or message bytes, and opens no handle.
|
|
122
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms Range sanitation belongs to NormalizeLintRange; this constructor only transfers its normalized scalar result and supplied fields into the returned record, without an independent traversal or lookup strategy.
|
|
123
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This constructor does not own a cache, keyed producer or request coordinator; the caller decides whether existing diagnostic records can be reused for its source version and finding.
|
|
124
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation NewLintDiagnostic computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
81
125
|
func NewLintDiagnostic(file *ast.SourceFile, pos, end int, code int32, category LintCategory, message string) *LintDiagnostic {
|
|
82
126
|
pos, end = NormalizeLintRange(file, pos, end)
|
|
83
127
|
return &LintDiagnostic{
|
|
@@ -90,6 +134,17 @@ func NewLintDiagnostic(file *ast.SourceFile, pos, end int, code int32, category
|
|
|
90
134
|
}
|
|
91
135
|
}
|
|
92
136
|
|
|
137
|
+
// File supplies the retained source, or nil for a project-wide/nil diagnostic.
|
|
138
|
+
// Returning an untyped nil avoids a non-nil interface containing a nil pointer.
|
|
139
|
+
//
|
|
140
|
+
// @evidence contracts/common.md#principled-implementation The explicit nil branch preserves absent source at the interface boundary; present files retain their original compiler identity and text.
|
|
141
|
+
// @evidence contracts/common.md#clear-and-simple-design One accessor owns pointer-to-interface absence conversion without a wrapper file representation.
|
|
142
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Missing source remains absent rather than a fabricated file used to satisfy the renderer.
|
|
143
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose explains retained provenance, project-wide absence and the Go typed-nil interface consequence.
|
|
144
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources A nonnil returned interface borrows the stored SourceFile and can keep its source/AST/semantic graph reachable under the caller's lifetime. Nil cases carry no source. The diagnostic and compiler owners retain their existing graph ownership; this accessor allocates no independent source copy or history registry and does not release that graph on return.
|
|
145
|
+
// @evidence contracts/performance.md#efficient-algorithms Two nil checks select true interface absence or the existing source pointer; no source-content scan, wrapper file allocation or coordinate conversion is needed.
|
|
146
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Existing source identity belongs to the diagnostic/compiler owners; this accessor coordinates no completed/in-flight source producer or source-version cache.
|
|
147
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation File computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
93
148
|
func (d *LintDiagnostic) File() inner.FileLike {
|
|
94
149
|
if d == nil || d.file == nil {
|
|
95
150
|
return nil
|
|
@@ -97,11 +152,66 @@ func (d *LintDiagnostic) File() inner.FileLike {
|
|
|
97
152
|
return d.file
|
|
98
153
|
}
|
|
99
154
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
155
|
+
// Pos returns the normalized inclusive UTF-8 byte offset.
|
|
156
|
+
//
|
|
157
|
+
// @evidence contracts/common.md#principled-implementation Reading the constructor-normalized start preserves the source interval used by the renderer; the receiver must be non-nil.
|
|
158
|
+
// @evidence contracts/common.md#clear-and-simple-design The accessor supplies one stored endpoint without reinterpreting coordinates.
|
|
159
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The offset remains producer/source data rather than a guessed JavaScript character position.
|
|
160
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose identifies normalized origin and byte units; the type states the non-nil receiver premise.
|
|
161
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Pos acquires no handle, buffer or cache and retains nothing after it returns.
|
|
162
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms This accessor projects the constructor-normalized scalar start; it chooses no independent range-validation, source traversal or coordinate-conversion algorithm.
|
|
163
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Stored endpoint state belongs to the diagnostic owner; this accessor coordinates no completed/in-flight producer or source-version cache.
|
|
164
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Pos computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
165
|
+
func (d *LintDiagnostic) Pos() int { return d.pos }
|
|
166
|
+
|
|
167
|
+
// End returns the normalized exclusive UTF-8 byte offset.
|
|
168
|
+
//
|
|
169
|
+
// @evidence contracts/common.md#principled-implementation Reading the constructor-normalized end retains the half-open interval and its source-length bound; the receiver must be non-nil.
|
|
170
|
+
// @evidence contracts/common.md#clear-and-simple-design One endpoint accessor keeps interval facts distinct from derived length.
|
|
171
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The end is not extended past EOF to invent a visible diagnostic byte.
|
|
172
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states normalized exclusive endpoint and byte units, with receiver requirements on the type.
|
|
173
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources End acquires no handle, buffer or cache and retains nothing after it returns.
|
|
174
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms This accessor projects the endpoint already normalized by construction; it chooses no independent range-validation, coordinate-conversion or traversal algorithm.
|
|
175
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Stored endpoint state belongs to the diagnostic owner; this accessor coordinates no completed/in-flight producer or cache invalidation.
|
|
176
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation End computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
177
|
+
func (d *LintDiagnostic) End() int { return d.end }
|
|
178
|
+
|
|
179
|
+
// Len returns the normalized span length in UTF-8 bytes, including zero at EOF.
|
|
180
|
+
//
|
|
181
|
+
// @evidence contracts/common.md#principled-implementation End minus start is a nonnegative byte length because construction establishes ordered endpoints within the source; the receiver must be non-nil.
|
|
182
|
+
// @evidence contracts/common.md#clear-and-simple-design Deriving length from the two stored endpoints avoids another mutable field that could diverge from them.
|
|
183
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Zero-width spans remain real absence of covered bytes rather than a fabricated length beyond the source.
|
|
184
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states byte length and the EOF zero-width case before acknowledgment tags.
|
|
185
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Len acquires no handle, buffer or cache and retains nothing after it returns.
|
|
186
|
+
// @evidence contracts/performance.md#efficient-algorithms Subtract the two constructor-normalized scalar endpoints directly; no source scan, repeated sanitation or byte-to-character conversion is required for the stored span length.
|
|
187
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Stored range state belongs to the diagnostic owner; this scalar derived-value query coordinates no completed/in-flight producer or source-version cache.
|
|
188
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Len computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
189
|
+
func (d *LintDiagnostic) Len() int { return d.end - d.pos }
|
|
190
|
+
|
|
191
|
+
// Code returns the producer-supplied diagnostic identifier unchanged.
|
|
192
|
+
// The receiver must be nonnil; uniqueness and stability are producer policy.
|
|
193
|
+
//
|
|
194
|
+
// @evidence contracts/common.md#principled-implementation The stored int32 code passes through unchanged, retaining the rule identity used by formatter banners and consumers.
|
|
195
|
+
// @evidence contracts/common.md#clear-and-simple-design One accessor exposes producer identity independently from severity and message presentation.
|
|
196
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Codes are supplied by the producer rather than inferred from expected message text.
|
|
197
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose names stable producer identity; construction explains the per-rule convention.
|
|
198
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Code acquires no handle, buffer or cache and retains nothing after it returns.
|
|
199
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms This accessor projects a stored scalar chosen by the producer; it chooses no independent code lookup, validation, conversion or traversal algorithm.
|
|
200
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Stored diagnostic identity belongs to the producer; this accessor coordinates no completed/in-flight computation or cache invalidation policy.
|
|
201
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Code computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
103
202
|
func (d *LintDiagnostic) Code() int32 { return d.code }
|
|
104
203
|
|
|
204
|
+
// Category translates the exact error discriminator; every other value is warning.
|
|
205
|
+
// The receiver must be nonnil; stored category values are not validated here.
|
|
206
|
+
//
|
|
207
|
+
// @evidence contracts/common.md#principled-implementation The same LintCategoryError comparison used by IsError maps stored categories to upstream error/warning values, keeping rendering and failure counting consistent.
|
|
208
|
+
// @evidence contracts/common.md#clear-and-simple-design One translation boundary adapts the public lint category to the internal formatter enum.
|
|
209
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Explicit category data determines severity without message heuristics or consumer-specific reclassification.
|
|
210
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states the exact discriminator and fallback, rather than implying arbitrary integers form validated enum values.
|
|
211
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources Category acquires no handle, buffer or cache and retains nothing after it returns.
|
|
212
|
+
// @evidence contracts/performance.md#efficient-algorithms One exact scalar comparison selects the upstream error category, with warning as the fallback; no message/path scan, lookup table or allocation is needed for translation.
|
|
213
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This stored-category projection coordinates no completed/in-flight producer or cache; the diagnostic owner controls the category value and its lifetime.
|
|
214
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Category computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
105
215
|
func (d *LintDiagnostic) Category() diagnostics.Category {
|
|
106
216
|
if d.category == LintCategoryError {
|
|
107
217
|
return diagnostics.CategoryError
|
|
@@ -109,11 +219,55 @@ func (d *LintDiagnostic) Category() diagnostics.Category {
|
|
|
109
219
|
return diagnostics.CategoryWarning
|
|
110
220
|
}
|
|
111
221
|
|
|
112
|
-
|
|
113
|
-
|
|
222
|
+
// Localize returns the producer's already-localized message; locale is unused.
|
|
223
|
+
// The receiver must be nonnil. The producer supplies final prose; this method
|
|
224
|
+
// does not verify its language or perform translation.
|
|
225
|
+
//
|
|
226
|
+
// @evidence contracts/common.md#principled-implementation Returning stored prose preserves the producer's chosen message without applying another locale transformation to an already-localized value.
|
|
227
|
+
// @evidence contracts/common.md#clear-and-simple-design One formatter adapter supplies stored prose while message creation stays with the rule.
|
|
228
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts The message is not replaced by a canned compiler diagnostic or inferred translation.
|
|
229
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose explicitly states already-localized input and ignored locale semantics.
|
|
230
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The returned string borrows the stored message backing bytes, which a caller can keep reachable after the diagnostic's own lifetime. No independent message copy, native handle or historical localization registry is acquired by this accessor; the producer and caller own those bytes and retention.
|
|
231
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms This accessor projects stored text without scanning, translating or validating it; the producer owns message construction and localization algorithms.
|
|
232
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Already-produced message state belongs to the diagnostic owner; this accessor coordinates no completed/in-flight translation producer or locale-keyed cache.
|
|
233
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Localize computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
234
|
+
func (d *LintDiagnostic) Localize(_ locale.Locale) string { return d.message }
|
|
235
|
+
|
|
236
|
+
// MessageChain returns nil because this diagnostic contains one flat message.
|
|
237
|
+
//
|
|
238
|
+
// @evidence contracts/common.md#principled-implementation Nil represents the absent chain in the upstream interface; the value stores a flat message rather than structured children.
|
|
239
|
+
// @evidence contracts/common.md#clear-and-simple-design The adapter states its flat-message capability without an unused child-diagnostic hierarchy.
|
|
240
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Missing structured metadata remains absent rather than manufactured chain nodes.
|
|
241
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose explains the absence and its representation premise.
|
|
242
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources MessageChain acquires no handle, buffer or cache and retains nothing after it returns.
|
|
243
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms This capability projection supplies absent structured metadata and chooses no child-graph construction, traversal or formatting algorithm.
|
|
244
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work No message-chain computation or completed/in-flight producer is coordinated here; structured metadata is absent in this diagnostic representation.
|
|
245
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation MessageChain computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
246
|
+
func (d *LintDiagnostic) MessageChain() []inner.Diagnostic { return nil }
|
|
247
|
+
|
|
248
|
+
// RelatedInformation returns nil; this value carries no auxiliary diagnostics.
|
|
249
|
+
//
|
|
250
|
+
// @evidence contracts/common.md#principled-implementation Nil preserves the absence of related diagnostics under the upstream formatter interface.
|
|
251
|
+
// @evidence contracts/common.md#clear-and-simple-design A focused flat diagnostic does not acquire an unused related-information store.
|
|
252
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Auxiliary source sites are not fabricated from message spelling.
|
|
253
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose states the unsupported auxiliary metadata capability directly.
|
|
254
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources RelatedInformation acquires no handle, buffer or cache and retains nothing after it returns.
|
|
255
|
+
// @evidenceExclude contracts/performance.md#efficient-algorithms This capability projection supplies absent auxiliary metadata and chooses no related-site construction, source lookup or diagnostic-graph traversal algorithm.
|
|
256
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work No auxiliary-diagnostic computation or completed/in-flight producer is coordinated here; related information is absent in this flat representation.
|
|
257
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation RelatedInformation computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
114
258
|
func (d *LintDiagnostic) RelatedInformation() []inner.Diagnostic { return nil }
|
|
115
259
|
|
|
116
260
|
// Message returns the already-localized lint message.
|
|
261
|
+
// It returns an empty string for a nil receiver.
|
|
262
|
+
//
|
|
263
|
+
// @evidence contracts/common.md#principled-implementation The accessor preserves producer prose on present diagnostics and supplies the documented empty absence value for a nil receiver.
|
|
264
|
+
// @evidence contracts/common.md#clear-and-simple-design The public string accessor is separate from the locale-shaped formatter method, while both use the same stored message.
|
|
265
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Nil does not cause a fabricated finding or a guessed diagnostic message.
|
|
266
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose names already-localized content and the nil-receiver result.
|
|
267
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources A present receiver returns borrowed message backing bytes that callers may retain after return; the nil branch returns the empty string. The accessor creates no independent text copy, native handle or historical message registry, and producer/caller owners determine the stored text's lifetime.
|
|
268
|
+
// @evidence contracts/performance.md#efficient-algorithms One receiver nil check chooses empty absence or a stored string projection; no message scan, formatting, localization or copy is required here.
|
|
269
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Stored producer text belongs to the diagnostic owner; this accessor coordinates no completed/in-flight message computation or localization cache.
|
|
270
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation Message computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
117
271
|
func (d *LintDiagnostic) Message() string {
|
|
118
272
|
if d == nil {
|
|
119
273
|
return ""
|
|
@@ -123,12 +277,36 @@ func (d *LintDiagnostic) Message() string {
|
|
|
123
277
|
|
|
124
278
|
// IsError reports whether the diagnostic should fail the build. Lint plugins
|
|
125
279
|
// use this to compute their exit code separately from the renderer.
|
|
280
|
+
// The receiver must be nonnil; only the exact error discriminator is true.
|
|
281
|
+
//
|
|
282
|
+
// @evidence contracts/common.md#principled-implementation The exact error-category comparison matches Category's upstream mapping, so callers count the same diagnostics that render as errors.
|
|
283
|
+
// @evidence contracts/common.md#clear-and-simple-design A boolean category query leaves process exit-code policy with the caller instead of embedding it in a rendered diagnostic.
|
|
284
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Stored category data determines failure classification without matching consumer or message names.
|
|
285
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose explains caller-owned exit decisions and the separation from rendering.
|
|
286
|
+
// @evidenceExclude contracts/performance.md#bound-retention-and-release-resources IsError acquires no handle, buffer or cache and retains nothing after it returns.
|
|
287
|
+
// @evidence contracts/performance.md#efficient-algorithms One exact stored-category comparison supplies the scalar classification without scanning message/path text or allocating state; caller build policy is not recomputed here.
|
|
288
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work Diagnostic category state belongs to its producer; this predicate coordinates no completed/in-flight work or cross-version result cache.
|
|
289
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation IsError computes from its arguments only; it opens no file, builds no path and calls no platform or process API.
|
|
126
290
|
func (d *LintDiagnostic) IsError() bool { return d.category == LintCategoryError }
|
|
127
291
|
|
|
128
292
|
// FormatMixedDiagnostics renders raw tsgo diagnostics and lint diagnostics
|
|
129
293
|
// together with TypeScript-style colors and source context, followed by the
|
|
130
294
|
// `Found N errors` summary. Returns the count of error-level diagnostics so
|
|
131
295
|
// callers can decide on an exit code.
|
|
296
|
+
// Nil entries from either producer are ignored. Source files must remain the
|
|
297
|
+
// versions described by their diagnostic byte ranges throughout rendering.
|
|
298
|
+
// The writer and nonnil diagnostic graphs must satisfy upstream formatting
|
|
299
|
+
// premises. Individual write errors are not returned; the count classifies
|
|
300
|
+
// findings and is not a successful-output-delivery receipt.
|
|
301
|
+
//
|
|
302
|
+
// @evidence contracts/common.md#principled-implementation Upstream AST adapters and the lint interface implementation share one renderer; exact category comparisons count errors, and deterministic source/range/code/message ordering preserves both producers' complete findings.
|
|
303
|
+
// @evidence contracts/common.md#clear-and-simple-design One mixed rendering entry owns filtering, ordering and summary composition, with a private comparator centralizing tie-breaking and upstream owning snippet formatting.
|
|
304
|
+
// @evidence contracts/common.md#prohibited-implementation-shortcuts Real findings flow through a caller-supplied writer rather than a swapped global stream; nil filtering does not drop present findings or manufacture successful diagnostics.
|
|
305
|
+
// @evidence contracts/common.md#meaningful-documentation Native prose explains mixed source context, returned error count, nil-entry handling and retained source-version requirements before these tags.
|
|
306
|
+
// @evidence contracts/performance.md#bound-retention-and-release-resources The combined array, AST adapters, comparator-created message/related arrays and formatter/summary state are invocation-local and borrow diagnostic/source graphs. Writer buffers and source-owner caches can survive under their owners after return; this renderer does not close the writer, keep a historical batch registry or impose fixed byte/population limits. Unreferenced local state is eligible for collection rather than explicitly reclaimed at the last write.
|
|
307
|
+
// @evidence contracts/performance.md#efficient-algorithms Collect and count nonnil diagnostics, then sort by source/range/code/category and localized/nested content before rendering and summary construction. Sorting adds comparison-dependent work over path/message bytes and recursive diagnostic graphs; upstream snippets, location conversion, summary grouping/sort and writer operations add further work. A single formatting call does not remove those scans or make the total linear in diagnostic count.
|
|
308
|
+
// @evidenceExclude contracts/performance.md#reuse-equivalent-work This renderer coordinates no completed/in-flight formatted-batch cache. The combined array is rebuilt per invocation; upstream/source owners manage reusable localization or position state, while output reuse for an equivalent diagnostic/context snapshot belongs to callers.
|
|
309
|
+
// @evidenceExclude contracts/portability.md#os-neutral-implementation This renderer sorts diagnostic data and delegates display-path formatting using supplied cwd; it does not establish native file identity or select an executable/filesystem capability. The supplied writer's native destination and lifetime belong to its caller, and display spelling is not certified as a case-policy answer.
|
|
132
310
|
func FormatMixedDiagnostics(
|
|
133
311
|
output io.Writer,
|
|
134
312
|
astDiags []*ast.Diagnostic,
|