ttsc 0.18.1 → 0.18.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/driver/emit_plugin.go +27 -12
- package/driver/program.go +25 -12
- package/package.json +8 -8
package/driver/emit_plugin.go
CHANGED
|
@@ -80,19 +80,12 @@ func (p *Program) EmitWithPluginTransformer(transform PluginTransform, writeFile
|
|
|
80
80
|
return p.EmitWithPluginTransformers([]PluginTransform{transform}, writeFile)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
// EmitLinkedTransforms emits using the
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
83
|
+
// EmitLinkedTransforms emits using only the linked plugins' hooks, with no
|
|
84
|
+
// host-owned transformer. It is the no-transform convenience form of
|
|
85
|
+
// EmitWithPluginTransformers, which honors linked plugins on every emit it
|
|
86
|
+
// runs.
|
|
87
87
|
func (p *Program) EmitLinkedTransforms(writeFile shimcompiler.WriteFile) ([]Diagnostic, error) {
|
|
88
|
-
|
|
89
|
-
return nil, errors.New("driver: nil program")
|
|
90
|
-
}
|
|
91
|
-
transforms, err := p.plugins.emitTransforms()
|
|
92
|
-
if err != nil {
|
|
93
|
-
return nil, err
|
|
94
|
-
}
|
|
95
|
-
return p.EmitWithPluginTransformers(transforms, writeFile)
|
|
88
|
+
return p.EmitWithPluginTransformers(nil, writeFile)
|
|
96
89
|
}
|
|
97
90
|
|
|
98
91
|
// restoreOriginalDeclarationSymbols copies the binder symbol from each original
|
|
@@ -135,6 +128,11 @@ func restoreOriginalDeclarationSymbols(ec *shimprinter.EmitContext, node *shimas
|
|
|
135
128
|
// import aliasing: tsgo's module-transform aliases the plugins' injected
|
|
136
129
|
// imports itself.
|
|
137
130
|
//
|
|
131
|
+
// Linked plugins are honored on every call: registered ProgramPlugins apply
|
|
132
|
+
// to the program before emit (once per Program), and registered
|
|
133
|
+
// EmitTransformPlugins are chained after the caller's transforms in
|
|
134
|
+
// registration order.
|
|
135
|
+
//
|
|
138
136
|
// Because the JavaScript side bypasses tsgo's own emitter, it reproduces the
|
|
139
137
|
// emitter's source-map step via PrintFileWithSourceMap: a `sourceMap` /
|
|
140
138
|
// `inlineSourceMap` build emits a `.js.map` (and `//# sourceMappingURL=`
|
|
@@ -146,6 +144,23 @@ func (p *Program) EmitWithPluginTransformers(transforms []PluginTransform, write
|
|
|
146
144
|
if p == nil || p.TSProgram == nil {
|
|
147
145
|
return nil, errors.New("driver: nil program")
|
|
148
146
|
}
|
|
147
|
+
// Linked plugins ride inside whichever host binary owns the emit pass, and
|
|
148
|
+
// the host does not know which linked packages ttsc compiled into it. Honor
|
|
149
|
+
// them at the funnel every host emits through: linked ProgramPlugins mutate
|
|
150
|
+
// the program before the per-file loop below, and linked EmitTransformPlugins
|
|
151
|
+
// join the per-file chain after the host's own transforms. A host that only
|
|
152
|
+
// passes its own transform would otherwise link, register, and silently never
|
|
153
|
+
// run the linked hooks.
|
|
154
|
+
if err := p.ApplyLinkedPlugins(); err != nil {
|
|
155
|
+
return nil, err
|
|
156
|
+
}
|
|
157
|
+
linked, err := p.plugins.emitTransforms()
|
|
158
|
+
if err != nil {
|
|
159
|
+
return nil, err
|
|
160
|
+
}
|
|
161
|
+
if len(linked) != 0 {
|
|
162
|
+
transforms = append(append([]PluginTransform{}, transforms...), linked...)
|
|
163
|
+
}
|
|
149
164
|
host := &pluginEmitHost{program: p.TSProgram, emitResolver: p.Checker.GetEmitResolver()}
|
|
150
165
|
options := p.TSProgram.Options()
|
|
151
166
|
for _, sf := range shimcompiler.GetSourceFilesToEmit(host, nil, false) {
|
package/driver/program.go
CHANGED
|
@@ -94,11 +94,15 @@ func NewLintDiagnostic(
|
|
|
94
94
|
return d
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
// SourceFile returns the program source file matching filename.
|
|
97
|
+
// SourceFile returns the program source file matching filename. Like
|
|
98
|
+
// SourceFiles, it applies linked ProgramPlugins first so a single-file
|
|
99
|
+
// consumer (e.g. a host's --file transform lane) sees the same mutated tree
|
|
100
|
+
// as a whole-project walk.
|
|
98
101
|
func (p *Program) SourceFile(filename string) *ast.SourceFile {
|
|
99
102
|
if p == nil || p.TSProgram == nil {
|
|
100
103
|
return nil
|
|
101
104
|
}
|
|
105
|
+
_ = p.ApplyLinkedPlugins()
|
|
102
106
|
normalized := filepath.ToSlash(filename)
|
|
103
107
|
for _, file := range p.TSProgram.SourceFiles() {
|
|
104
108
|
if filepath.ToSlash(file.FileName()) == normalized {
|
|
@@ -185,15 +189,16 @@ func CountErrors(diagnostics []Diagnostic) int {
|
|
|
185
189
|
|
|
186
190
|
// Program is the shim-agnostic facade the rest of the engine sees.
|
|
187
191
|
type Program struct {
|
|
188
|
-
TSProgram
|
|
189
|
-
ParsedConfig
|
|
190
|
-
Checker
|
|
191
|
-
checkerRelease
|
|
192
|
-
Host
|
|
193
|
-
FS
|
|
194
|
-
SourcePreamble
|
|
195
|
-
plugins
|
|
196
|
-
pluginsApplied
|
|
192
|
+
TSProgram *shimcompiler.Program
|
|
193
|
+
ParsedConfig *tsoptions.ParsedCommandLine
|
|
194
|
+
Checker *shimchecker.Checker
|
|
195
|
+
checkerRelease func()
|
|
196
|
+
Host shimcompiler.CompilerHost
|
|
197
|
+
FS vfs.FS
|
|
198
|
+
SourcePreamble string
|
|
199
|
+
plugins linkedPluginState
|
|
200
|
+
pluginsApplied bool
|
|
201
|
+
pluginsApplyErr error
|
|
197
202
|
}
|
|
198
203
|
|
|
199
204
|
// LoadProgramOptions controls tsconfig overrides applied before tsgo creates
|
|
@@ -521,12 +526,20 @@ func (p *Program) sourceFilesRaw() []*ast.SourceFile {
|
|
|
521
526
|
}
|
|
522
527
|
|
|
523
528
|
// ApplyLinkedPlugins runs registered linked ProgramPlugin hooks exactly once.
|
|
529
|
+
// A hook failure is latched and returned on every subsequent call: SourceFiles
|
|
530
|
+
// swallows the error by contract, so without the latch a lookup that happened
|
|
531
|
+
// to run first would consume the only report and let a later emit proceed over
|
|
532
|
+
// the half-applied program as if nothing failed.
|
|
524
533
|
func (p *Program) ApplyLinkedPlugins() error {
|
|
525
|
-
if p == nil
|
|
534
|
+
if p == nil {
|
|
526
535
|
return nil
|
|
527
536
|
}
|
|
537
|
+
if p.pluginsApplied {
|
|
538
|
+
return p.pluginsApplyErr
|
|
539
|
+
}
|
|
528
540
|
p.pluginsApplied = true
|
|
529
|
-
|
|
541
|
+
p.pluginsApplyErr = p.plugins.apply(p)
|
|
542
|
+
return p.pluginsApplyErr
|
|
530
543
|
}
|
|
531
544
|
|
|
532
545
|
// Diagnostics returns project diagnostics that must block compilation or
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ttsc",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.3",
|
|
4
4
|
"description": "General-purpose TypeScript-Go compiler, runtime, plugin host, and LSP host.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -32,13 +32,13 @@
|
|
|
32
32
|
"typescript": "^7.0.2"
|
|
33
33
|
},
|
|
34
34
|
"optionalDependencies": {
|
|
35
|
-
"@ttsc/linux-x64": "0.18.
|
|
36
|
-
"@ttsc/linux-
|
|
37
|
-
"@ttsc/
|
|
38
|
-
"@ttsc/
|
|
39
|
-
"@ttsc/
|
|
40
|
-
"@ttsc/
|
|
41
|
-
"@ttsc/
|
|
35
|
+
"@ttsc/linux-x64": "0.18.3",
|
|
36
|
+
"@ttsc/linux-arm": "0.18.3",
|
|
37
|
+
"@ttsc/linux-arm64": "0.18.3",
|
|
38
|
+
"@ttsc/darwin-arm64": "0.18.3",
|
|
39
|
+
"@ttsc/win32-x64": "0.18.3",
|
|
40
|
+
"@ttsc/win32-arm64": "0.18.3",
|
|
41
|
+
"@ttsc/darwin-x64": "0.18.3"
|
|
42
42
|
},
|
|
43
43
|
"sideEffects": false,
|
|
44
44
|
"files": [
|