@ttsc/wasm 0.26.1 → 0.27.0
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/dist/.ttsc-wasm-build.json +10 -6
- package/dist/ttsc.wasm +0 -0
- package/package.json +1 -1
- package/shim-vendor/shim/checker/go.mod +9 -0
- package/shim-vendor/shim/checker/go.sum +22 -0
- package/shim-vendor/shim/checker/shim.go +75 -0
- package/shim-vendor/shim/compiler/emit_sourcemap.go +56 -15
- package/shim-vendor/shim/compiler/incremental.go +45 -8
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": 1,
|
|
3
|
-
"identity": "
|
|
3
|
+
"identity": "909fe771e33d587b54640b0c1f1971dbda3250440df3de236c2824dd9986231f",
|
|
4
4
|
"artifacts": [
|
|
5
5
|
{
|
|
6
6
|
"path": "/home/runner/work/ttsc/ttsc/packages/wasm/dist/ttsc.wasm",
|
|
7
7
|
"type": "file",
|
|
8
|
-
"sha256": "
|
|
8
|
+
"sha256": "566c2e1f04b41c9c41c249b4d693efae7aa97a326c4946711a50d867069d30f7"
|
|
9
9
|
},
|
|
10
10
|
{
|
|
11
11
|
"path": "/home/runner/work/ttsc/ttsc/packages/wasm/dist/wasm_exec.js",
|
|
@@ -111,15 +111,19 @@
|
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
113
|
"path": "checker/go.mod",
|
|
114
|
-
"sha256": "
|
|
114
|
+
"sha256": "94e107d6628d4693f2da8a342e49ff326ad28d5d0c31bec30ad3a42a98aad4cf"
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
"path": "checker/go.sum",
|
|
118
|
+
"sha256": "a94c806630860a27e74df1db99b2abf86fada0e699937a813b42fe190021a16d"
|
|
115
119
|
},
|
|
116
120
|
{
|
|
117
121
|
"path": "checker/shim.go",
|
|
118
|
-
"sha256": "
|
|
122
|
+
"sha256": "432f81d0e74e879f6a67a1f96c248b82950a899db8fe16a983bd48c9fa5af488"
|
|
119
123
|
},
|
|
120
124
|
{
|
|
121
125
|
"path": "compiler/emit_sourcemap.go",
|
|
122
|
-
"sha256": "
|
|
126
|
+
"sha256": "78e2a0ad04a7d8845b95a7a248c70fc8348d1c932854ab7976aa7e4e2cc7ecdc"
|
|
123
127
|
},
|
|
124
128
|
{
|
|
125
129
|
"path": "compiler/emitassemble.go",
|
|
@@ -143,7 +147,7 @@
|
|
|
143
147
|
},
|
|
144
148
|
{
|
|
145
149
|
"path": "compiler/incremental.go",
|
|
146
|
-
"sha256": "
|
|
150
|
+
"sha256": "3c873bed3659cfe1969a97caea105d230dad510e66d8da6e4ca2c4dc6617a04c"
|
|
147
151
|
},
|
|
148
152
|
{
|
|
149
153
|
"path": "compiler/shim.go",
|
package/dist/ttsc.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -3,3 +3,12 @@ module github.com/microsoft/typescript-go/shim/checker
|
|
|
3
3
|
go 1.26
|
|
4
4
|
|
|
5
5
|
require github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157
|
|
6
|
+
|
|
7
|
+
require (
|
|
8
|
+
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 // 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.20.0 // indirect
|
|
12
|
+
golang.org/x/sys v0.43.0 // indirect
|
|
13
|
+
golang.org/x/text v0.36.0 // indirect
|
|
14
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433 h1:vymEbVwYFP/L05h5TKQxvkXoKxNvTpjxYKdF1Nlwuao=
|
|
2
|
+
github.com/go-json-experiment/json v0.0.0-20260214004413-d219187c3433/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-20260429010842-56ab4af42157 h1:llOMPhKDiQ+UEJiAaQuuWaJOTg5V7tNNTEf9JPWoYSY=
|
|
8
|
+
github.com/microsoft/typescript-go v0.0.0-20260429010842-56ab4af42157/go.mod h1:m8YA0PMC7ti0GW0RI05D6fEcjQeu98XVS+FWF+VDW2k=
|
|
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.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
|
16
|
+
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
|
17
|
+
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
|
|
18
|
+
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
|
19
|
+
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
|
|
20
|
+
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
|
|
21
|
+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
|
|
22
|
+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
|
|
@@ -22,6 +22,8 @@ type IndexInfo = innerchecker.IndexInfo
|
|
|
22
22
|
type Signature = innerchecker.Signature
|
|
23
23
|
type SignatureKind = innerchecker.SignatureKind
|
|
24
24
|
type Type = innerchecker.Type
|
|
25
|
+
type TypeMapper = innerchecker.TypeMapper
|
|
26
|
+
type TypeMapperKind = innerchecker.TypeMapperKind
|
|
25
27
|
type TypeFlags = innerchecker.TypeFlags
|
|
26
28
|
type ObjectFlags = innerchecker.ObjectFlags
|
|
27
29
|
type ElementFlags = innerchecker.ElementFlags
|
|
@@ -216,6 +218,11 @@ func Checker_isSymbolAccessibleAsValue(recv *innerchecker.Checker, symbol *inner
|
|
|
216
218
|
const (
|
|
217
219
|
SignatureKindCall = innerchecker.SignatureKindCall
|
|
218
220
|
|
|
221
|
+
TypeMapperKindUnknown = innerchecker.TypeMapperKindUnknown
|
|
222
|
+
TypeMapperKindSimple = innerchecker.TypeMapperKindSimple
|
|
223
|
+
TypeMapperKindArray = innerchecker.TypeMapperKindArray
|
|
224
|
+
TypeMapperKindMerged = innerchecker.TypeMapperKindMerged
|
|
225
|
+
|
|
219
226
|
TypeFlagsAny = innerchecker.TypeFlagsAny
|
|
220
227
|
TypeFlagsUnknown = innerchecker.TypeFlagsUnknown
|
|
221
228
|
TypeFlagsUndefined = innerchecker.TypeFlagsUndefined
|
|
@@ -597,3 +604,71 @@ func Checker_getRestTypeOfSignature(recv *innerchecker.Checker, signature *inner
|
|
|
597
604
|
}
|
|
598
605
|
return recv.GetRestTypeOfSignature(signature)
|
|
599
606
|
}
|
|
607
|
+
|
|
608
|
+
//go:linkname checkerInstantiateType github.com/microsoft/typescript-go/internal/checker.(*Checker).instantiateType
|
|
609
|
+
func checkerInstantiateType(recv *innerchecker.Checker, t *innerchecker.Type, m *innerchecker.TypeMapper) *innerchecker.Type
|
|
610
|
+
|
|
611
|
+
//go:linkname checkerNewSimpleTypeMapper github.com/microsoft/typescript-go/internal/checker.newSimpleTypeMapper
|
|
612
|
+
func checkerNewSimpleTypeMapper(source *innerchecker.Type, target *innerchecker.Type) *innerchecker.TypeMapper
|
|
613
|
+
|
|
614
|
+
//go:linkname checkerNewTypeMapper github.com/microsoft/typescript-go/internal/checker.newTypeMapper
|
|
615
|
+
func checkerNewTypeMapper(sources []*innerchecker.Type, targets []*innerchecker.Type) *innerchecker.TypeMapper
|
|
616
|
+
|
|
617
|
+
// Checker_instantiateType substitutes the type parameters of `t` with the
|
|
618
|
+
// concrete types in `mapper`, returning the instantiated type. A type-transform
|
|
619
|
+
// plugin uses it to instantiate a generic class's constructor type with the
|
|
620
|
+
// reference's type arguments, so a type parameter nested inside a container
|
|
621
|
+
// (`A[]`, `[A, B]`) is substituted for free. Returns nil if recv or t is nil.
|
|
622
|
+
func Checker_instantiateType(recv *innerchecker.Checker, t *innerchecker.Type, mapper *innerchecker.TypeMapper) *innerchecker.Type {
|
|
623
|
+
if recv == nil || t == nil {
|
|
624
|
+
return nil
|
|
625
|
+
}
|
|
626
|
+
return checkerInstantiateType(recv, t, mapper)
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// Checker_newSimpleTypeMapper builds a single-pair type mapper that substitutes
|
|
630
|
+
// `source` with `target`. It is the building block for instantiating a generic
|
|
631
|
+
// class's constructor type with its reference type arguments. Returns nil if
|
|
632
|
+
// source or target is nil.
|
|
633
|
+
func Checker_newSimpleTypeMapper(source *innerchecker.Type, target *innerchecker.Type) *innerchecker.TypeMapper {
|
|
634
|
+
if source == nil || target == nil {
|
|
635
|
+
return nil
|
|
636
|
+
}
|
|
637
|
+
return checkerNewSimpleTypeMapper(source, target)
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
// Checker_newTypeMapper builds a parallel type mapper from corresponding
|
|
641
|
+
// source and target slices. Unlike Checker_combineTypeMappers, it does not feed
|
|
642
|
+
// one substitution's target through later substitutions, so a mapping such as
|
|
643
|
+
// `[A, B] -> [B, A]` preserves both target identities. Returns nil when the
|
|
644
|
+
// slices are empty, differ in length, or contain nil types.
|
|
645
|
+
func Checker_newTypeMapper(sources []*innerchecker.Type, targets []*innerchecker.Type) *innerchecker.TypeMapper {
|
|
646
|
+
if len(sources) == 0 || len(sources) != len(targets) {
|
|
647
|
+
return nil
|
|
648
|
+
}
|
|
649
|
+
for i := range sources {
|
|
650
|
+
if sources[i] == nil || targets[i] == nil {
|
|
651
|
+
return nil
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
return checkerNewTypeMapper(sources, targets)
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
//go:linkname checkerCombineTypeMappers github.com/microsoft/typescript-go/internal/checker.(*Checker).combineTypeMappers
|
|
658
|
+
func checkerCombineTypeMappers(recv *innerchecker.Checker, m1 *innerchecker.TypeMapper, m2 *innerchecker.TypeMapper) *innerchecker.TypeMapper
|
|
659
|
+
|
|
660
|
+
// Checker_combineTypeMappers composes two mapper stages. The first mapper's
|
|
661
|
+
// substituted target is instantiated through the second mapper, so use
|
|
662
|
+
// Checker_newTypeMapper instead when source and target slices are parallel
|
|
663
|
+
// declaration-parameter mappings. Returns m2 when m1 is nil, including when
|
|
664
|
+
// recv is nil. Returns nil when m1 is non-nil and recv or m2 is nil, because
|
|
665
|
+
// both are required to build a usable composite mapper.
|
|
666
|
+
func Checker_combineTypeMappers(recv *innerchecker.Checker, m1 *innerchecker.TypeMapper, m2 *innerchecker.TypeMapper) *innerchecker.TypeMapper {
|
|
667
|
+
if m1 == nil {
|
|
668
|
+
return m2
|
|
669
|
+
}
|
|
670
|
+
if recv == nil || m2 == nil {
|
|
671
|
+
return nil
|
|
672
|
+
}
|
|
673
|
+
return checkerCombineTypeMappers(recv, m1, m2)
|
|
674
|
+
}
|
|
@@ -5,12 +5,27 @@
|
|
|
5
5
|
// tsgo's Program.Emit has no hook to inject a custom transformer, so ttsc's
|
|
6
6
|
// driver assembles the per-file emit pipeline by hand (see GetSourceFilesToEmit
|
|
7
7
|
// / GetScriptTransformers / GetOutputPathsFor). That hand-assembly must also
|
|
8
|
-
// reproduce
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
// `
|
|
12
|
-
//
|
|
13
|
-
//
|
|
8
|
+
// reproduce every step the emitter would otherwise run: building the printer's
|
|
9
|
+
// options from the compiler options, the source-map branch a bare printer.Write
|
|
10
|
+
// with a nil generator drops entirely, the `emitBOM` byte-order mark, and the
|
|
11
|
+
// `WriteFileData` the emitter hands its writeFile callback. This file ports
|
|
12
|
+
// internal/compiler/emitter.go's `emitJSFile` PrinterOptions construction and
|
|
13
|
+
// the whole of its `printSourceFile` so a build that goes through a plugin
|
|
14
|
+
// transform honors the same compiler options — and produces the same map (and
|
|
15
|
+
// `//# sourceMappingURL=` trailer, and the same first bytes) — a plain build
|
|
16
|
+
// does.
|
|
17
|
+
//
|
|
18
|
+
// Keep it in sync with that emitter source when the pin is bumped. Anything
|
|
19
|
+
// `emitJSFile` sets and this file omits takes the Go zero value, which silently
|
|
20
|
+
// turns the option off for every project that emits through a plugin transform,
|
|
21
|
+
// and anything `printSourceFile` does around the printer that this file omits
|
|
22
|
+
// is missing from the plugin lane's output even when the option set matches.
|
|
23
|
+
// `printer_options_field_set_matches_pinned_emitter_test.go` fails when the pin
|
|
24
|
+
// changes the PrinterOptions field set,
|
|
25
|
+
// `write_file_data_field_set_matches_pinned_emitter_test.go` fails when it
|
|
26
|
+
// changes the WriteFileData field set, and
|
|
27
|
+
// `emit_plugin_transform_matches_plain_emit_for_printer_options_test.go` fails
|
|
28
|
+
// when a forwarded option stops matching the plain emit.
|
|
14
29
|
package compiler
|
|
15
30
|
|
|
16
31
|
import (
|
|
@@ -25,24 +40,43 @@ import (
|
|
|
25
40
|
|
|
26
41
|
// PrintedFile is the rendered output of one source file in the plugin-transform
|
|
27
42
|
// emit path. JS is the JavaScript text, already carrying a trailing
|
|
28
|
-
// `//# sourceMappingURL=` comment when a map was produced
|
|
29
|
-
//
|
|
30
|
-
//
|
|
43
|
+
// `//# sourceMappingURL=` comment when a map was produced and a leading UTF-8
|
|
44
|
+
// byte order mark when `emitBOM` is on. MapText/MapPath are the external
|
|
45
|
+
// source-map file and its path; both are empty when no external map is written
|
|
46
|
+
// (source maps disabled, or an inline map encoded into the JS).
|
|
31
47
|
type PrintedFile struct {
|
|
32
48
|
JS string
|
|
33
49
|
MapText string
|
|
34
50
|
MapPath string
|
|
51
|
+
// SourceMapUrlPos is the offset of the `//# sourceMappingURL=` trailer in JS,
|
|
52
|
+
// or -1 when no trailer was written — the value tsgo's emitter reports as
|
|
53
|
+
// WriteFileData.SourceMapUrlPos so a caller can locate and rewrite the
|
|
54
|
+
// trailer without re-scanning the text. Like the emitter's, it is the printer
|
|
55
|
+
// writer's text position, taken BEFORE the `emitBOM` mark is prepended, so a
|
|
56
|
+
// BOM build's offset is three bytes short of the trailer's position in the
|
|
57
|
+
// written file. That is the pinned emitter's own behavior
|
|
58
|
+
// (internal/compiler/emitter.go::printSourceFile computes sourceMapUrlPos
|
|
59
|
+
// from the writer and only then calls AddUTF8ByteOrderMark), and this lane
|
|
60
|
+
// exists to match it: "correcting" the offset here would make a plugin build
|
|
61
|
+
// disagree with the plain build of the same project.
|
|
62
|
+
SourceMapUrlPos int
|
|
35
63
|
}
|
|
36
64
|
|
|
37
65
|
// PrintFileWithSourceMap renders sourceFile through a printer built from options
|
|
38
66
|
// and emitContext, optionally generating a source map, mirroring
|
|
39
|
-
// emitter.printSourceFile for the single-file
|
|
67
|
+
// emitter.emitJSFile and emitter.printSourceFile for the single-file
|
|
68
|
+
// plugin-transform path. The PrinterOptions below are emitJSFile's, field for
|
|
69
|
+
// field: `removeComments`, `newLine`, `noEmitHelpers`, `sourceMap`,
|
|
70
|
+
// `inlineSourceMap`, `inlineSources`, and `target`. When
|
|
40
71
|
// `sourceMap`/`inlineSourceMap` is enabled (and the file is not JSON) it builds a
|
|
41
72
|
// sourcemap.Generator, feeds it to the printer so positions are recorded,
|
|
42
|
-
// appends the sourceMappingURL trailer, and returns the
|
|
43
|
-
// (or encodes the map inline).
|
|
44
|
-
//
|
|
45
|
-
//
|
|
73
|
+
// appends the sourceMappingURL trailer, records its offset, and returns the
|
|
74
|
+
// external map text/path (or encodes the map inline). `emitBOM` prepends the
|
|
75
|
+
// UTF-8 byte order mark to the JavaScript afterwards, exactly where
|
|
76
|
+
// printSourceFile does it — outside PrinterOptions, which is why forwarding the
|
|
77
|
+
// whole options struct never reached it. The external map is written without a
|
|
78
|
+
// mark, matching the emitter's own `writeText(sourceMapFilePath, ..., nil)`.
|
|
79
|
+
// host supplies the same directory/casing context tsgo's emitter reads.
|
|
46
80
|
func PrintFileWithSourceMap(
|
|
47
81
|
emitContext *innerprinter.EmitContext,
|
|
48
82
|
node *innerast.Node,
|
|
@@ -53,10 +87,13 @@ func PrintFileWithSourceMap(
|
|
|
53
87
|
sourceMapFilePath string,
|
|
54
88
|
) PrintedFile {
|
|
55
89
|
printer := innerprinter.NewPrinter(innerprinter.PrinterOptions{
|
|
90
|
+
RemoveComments: options.RemoveComments.IsTrue(),
|
|
56
91
|
NewLine: options.NewLine,
|
|
92
|
+
NoEmitHelpers: options.NoEmitHelpers.IsTrue(),
|
|
57
93
|
SourceMap: options.SourceMap.IsTrue(),
|
|
58
94
|
InlineSourceMap: options.InlineSourceMap.IsTrue(),
|
|
59
95
|
InlineSources: options.InlineSources.IsTrue(),
|
|
96
|
+
Target: options.Target,
|
|
60
97
|
}, innerprinter.PrintHandlers{}, emitContext)
|
|
61
98
|
writer := innerprinter.NewTextWriter(options.NewLine.GetNewLineCharacter(), 0)
|
|
62
99
|
|
|
@@ -78,7 +115,7 @@ func PrintFileWithSourceMap(
|
|
|
78
115
|
|
|
79
116
|
printer.Write(node, sourceFile, writer, generator)
|
|
80
117
|
|
|
81
|
-
result := PrintedFile{}
|
|
118
|
+
result := PrintedFile{SourceMapUrlPos: -1}
|
|
82
119
|
if generator != nil {
|
|
83
120
|
url := sourceMappingURL(options, generator, host, jsFilePath, sourceMapFilePath, sourceFile)
|
|
84
121
|
if len(url) > 0 {
|
|
@@ -89,6 +126,7 @@ func PrintFileWithSourceMap(
|
|
|
89
126
|
writer.RawWrite("\n")
|
|
90
127
|
}
|
|
91
128
|
}
|
|
129
|
+
result.SourceMapUrlPos = writer.GetTextPos()
|
|
92
130
|
writer.WriteComment("//# sourceMappingURL=")
|
|
93
131
|
writer.WriteComment(url)
|
|
94
132
|
}
|
|
@@ -100,6 +138,9 @@ func PrintFileWithSourceMap(
|
|
|
100
138
|
writer.WriteLine()
|
|
101
139
|
}
|
|
102
140
|
result.JS = writer.String()
|
|
141
|
+
if options.EmitBOM.IsTrue() {
|
|
142
|
+
result.JS = innerstringutil.AddUTF8ByteOrderMark(result.JS)
|
|
143
|
+
}
|
|
103
144
|
return result
|
|
104
145
|
}
|
|
105
146
|
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
// gen_shims:hand-maintained
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
3
|
+
// Parts of tsgo's own incremental engine (`tsc --incremental` semantics),
|
|
4
|
+
// exposed from internal/execute/incremental for the two things a ttsc host
|
|
5
|
+
// needs from it:
|
|
6
|
+
//
|
|
7
|
+
// - the reference graph, so transform envelopes can carry the same
|
|
8
|
+
// language-semantic input bound the compiler itself uses for invalidation:
|
|
9
|
+
// per-file direct resolved references and the files that contribute to the
|
|
10
|
+
// global scope;
|
|
11
|
+
// - the build-information emit, so a host that constructs its Program
|
|
12
|
+
// in-process still writes the `.tsbuildinfo` an `incremental` or
|
|
13
|
+
// `composite` project asked for.
|
|
8
14
|
package compiler
|
|
9
15
|
|
|
10
16
|
import (
|
|
17
|
+
"context"
|
|
11
18
|
_ "unsafe"
|
|
12
19
|
|
|
13
20
|
innerast "github.com/microsoft/typescript-go/internal/ast"
|
|
@@ -15,11 +22,41 @@ import (
|
|
|
15
22
|
innercompiler "github.com/microsoft/typescript-go/internal/compiler"
|
|
16
23
|
"github.com/microsoft/typescript-go/internal/tspath"
|
|
17
24
|
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
|
|
25
|
+
// Imported for EmitFreshWithBuildInfo below, and for the linknamed symbols
|
|
26
|
+
// further down: compiling the package into every shim consumer is what makes
|
|
27
|
+
// those references resolve.
|
|
28
|
+
"github.com/microsoft/typescript-go/internal/execute/incremental"
|
|
21
29
|
)
|
|
22
30
|
|
|
31
|
+
// EmitFreshWithBuildInfo runs a full emit through tsgo's own incremental
|
|
32
|
+
// program, so an `incremental` or `composite` project gets the `.tsbuildinfo`
|
|
33
|
+
// tsgo would have written, in the exact format and location
|
|
34
|
+
// `outputpaths.GetBuildInfoFileName` resolves from the compiler options.
|
|
35
|
+
//
|
|
36
|
+
// This is the emit half of `tsc.go::performIncrementalCompilation`, which the
|
|
37
|
+
// tsgo CLI takes whenever `CompilerOptions.IsIncremental()`. A host that builds
|
|
38
|
+
// its Program in-process (ttsc's driver, and therefore every plugin sidecar
|
|
39
|
+
// emitting through it) never reaches that CLI path, so without this the build
|
|
40
|
+
// information is silently dropped even though the options parsed cleanly.
|
|
41
|
+
//
|
|
42
|
+
// "Fresh" is the load-bearing word: no previous snapshot is supplied, so
|
|
43
|
+
// `programToSnapshot` marks every file changed and this emits the whole program
|
|
44
|
+
// exactly as `Program.Emit` does, then writes the build info. A ttsc plugin's
|
|
45
|
+
// output is not a pure function of the source text a build info records — it
|
|
46
|
+
// also depends on the plugin binary, its config file, and its contributors —
|
|
47
|
+
// so reusing a previous snapshot to skip a file would serve stale transformed
|
|
48
|
+
// output. Producing the record is sound; consuming it needs plugin identity in
|
|
49
|
+
// the invalidation key first.
|
|
50
|
+
func EmitFreshWithBuildInfo(ctx context.Context, program *Program, options EmitOptions) *EmitResult {
|
|
51
|
+
incrementalProgram := incremental.NewProgram(
|
|
52
|
+
program,
|
|
53
|
+
nil,
|
|
54
|
+
incremental.CreateHost(program.Host()),
|
|
55
|
+
false,
|
|
56
|
+
)
|
|
57
|
+
return incrementalProgram.Emit(ctx, options)
|
|
58
|
+
}
|
|
59
|
+
|
|
23
60
|
//go:linkname incrementalGetReferencedFiles github.com/microsoft/typescript-go/internal/execute/incremental.getReferencedFiles
|
|
24
61
|
func incrementalGetReferencedFiles(program *innercompiler.Program, file *innerast.SourceFile) *collections.Set[tspath.Path]
|
|
25
62
|
|