ttsc 0.16.10 → 0.16.11
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 +89 -50
- package/package.json +8 -8
package/driver/emit_plugin.go
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
package driver
|
|
2
2
|
|
|
3
3
|
import (
|
|
4
|
+
"context"
|
|
4
5
|
"errors"
|
|
5
6
|
"strings"
|
|
7
|
+
"sync"
|
|
6
8
|
|
|
7
9
|
shimast "github.com/microsoft/typescript-go/shim/ast"
|
|
8
10
|
shimcompiler "github.com/microsoft/typescript-go/shim/compiler"
|
|
@@ -126,16 +128,20 @@ func restoreOriginalDeclarationSymbols(ec *shimprinter.EmitContext, node *shimas
|
|
|
126
128
|
})
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
// EmitWithPluginTransformers emits every source file by assembling tsgo's
|
|
130
|
-
// pipeline from shim parts and running the plugin transformers
|
|
131
|
-
// in the same EmitContext as the builtin chain (type-erase,
|
|
132
|
-
// module-transform, ...). No text-splice and no hand-rolled
|
|
133
|
-
// tsgo's module-transform aliases the plugins' injected
|
|
131
|
+
// EmitWithPluginTransformers emits every source file by assembling tsgo's
|
|
132
|
+
// JavaScript emit pipeline from shim parts and running the plugin transformers
|
|
133
|
+
// FIRST (in order) in the same EmitContext as the builtin chain (type-erase,
|
|
134
|
+
// import-elision, module-transform, ...). No text-splice and no hand-rolled
|
|
135
|
+
// import aliasing: tsgo's module-transform aliases the plugins' injected
|
|
136
|
+
// imports itself.
|
|
134
137
|
//
|
|
135
|
-
// Because
|
|
136
|
-
// source-map step via PrintFileWithSourceMap: a `sourceMap` /
|
|
137
|
-
// build emits a `.js.map` (and `//# sourceMappingURL=`
|
|
138
|
-
// plain build, even when a transform expanded one source
|
|
138
|
+
// Because the JavaScript side bypasses tsgo's own emitter, it reproduces the
|
|
139
|
+
// emitter's source-map step via PrintFileWithSourceMap: a `sourceMap` /
|
|
140
|
+
// `inlineSourceMap` build emits a `.js.map` (and `//# sourceMappingURL=`
|
|
141
|
+
// trailer) just like a plain build, even when a transform expanded one source
|
|
142
|
+
// line into many. All non-JavaScript outputs stay delegated to tsgo's normal
|
|
143
|
+
// dts-only emitter so declaration files, declaration maps, and any future
|
|
144
|
+
// declaration-lane outputs are not silently lost by the hand-assembled JS path.
|
|
139
145
|
func (p *Program) EmitWithPluginTransformers(transforms []PluginTransform, writeFile shimcompiler.WriteFile) ([]Diagnostic, error) {
|
|
140
146
|
if p == nil || p.TSProgram == nil {
|
|
141
147
|
return nil, errors.New("driver: nil program")
|
|
@@ -144,54 +150,87 @@ func (p *Program) EmitWithPluginTransformers(transforms []PluginTransform, write
|
|
|
144
150
|
options := p.TSProgram.Options()
|
|
145
151
|
for _, sf := range shimcompiler.GetSourceFilesToEmit(host, nil, false) {
|
|
146
152
|
paths := shimcompiler.GetOutputPathsFor(sf, options, host, false)
|
|
147
|
-
if p.outputEscapesOutDir(paths.JsFilePath()) {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
out = next
|
|
153
|
+
if paths.JsFilePath() != "" && !p.outputEscapesOutDir(paths.JsFilePath()) {
|
|
154
|
+
ec := shimprinter.NewEmitContext()
|
|
155
|
+
out := sf
|
|
156
|
+
for _, transform := range transforms {
|
|
157
|
+
if transform == nil {
|
|
158
|
+
continue
|
|
159
|
+
}
|
|
160
|
+
if next := transform(ec, out); next != nil {
|
|
161
|
+
out = next
|
|
162
|
+
}
|
|
158
163
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
out = tr.TransformSourceFile(out)
|
|
164
|
-
}
|
|
165
|
-
// Print through the source-map-aware helper so a `sourceMap` /
|
|
166
|
-
// `inlineSourceMap` build still gets its `.js.map` and sourceMappingURL
|
|
167
|
-
// trailer: the hand-assembled emit pipeline does not run tsgo's emitter, so
|
|
168
|
-
// the source-map step printSourceFile would otherwise perform has to happen
|
|
169
|
-
// here. With maps off this is the same bare-printer output as before.
|
|
170
|
-
printed := shimcompiler.PrintFileWithSourceMap(ec, out.AsNode(), out, options, host, paths.JsFilePath(), paths.SourceMapFilePath())
|
|
171
|
-
// A source-level preamble (e.g. @ttsc/banner linked into a typia host) shifts
|
|
172
|
-
// the map's source coordinates; correct them here too, so the
|
|
173
|
-
// preamble-plus-transform combination is not left uncorrected the way it
|
|
174
|
-
// would be if only the utility host's WriteFile patched maps. Covers both the
|
|
175
|
-
// external `.js.map` and an inline base64 map embedded in the JS.
|
|
176
|
-
if p.SourcePreamble != "" {
|
|
177
|
-
dropLines := strings.Count(p.SourcePreamble, "\n")
|
|
178
|
-
if adjusted, ok := AdjustEmittedSourceMap(paths.JsFilePath(), printed.JS, dropLines); ok {
|
|
179
|
-
printed.JS = adjusted
|
|
164
|
+
shimast.SetParentInChildrenUnset(out.AsNode())
|
|
165
|
+
restoreOriginalDeclarationSymbols(ec, out.AsNode())
|
|
166
|
+
for _, tr := range shimcompiler.GetScriptTransformers(ec, host, out) {
|
|
167
|
+
out = tr.TransformSourceFile(out)
|
|
180
168
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
169
|
+
// Print through the source-map-aware helper so a `sourceMap` /
|
|
170
|
+
// `inlineSourceMap` build still gets its `.js.map` and sourceMappingURL
|
|
171
|
+
// trailer: the hand-assembled emit pipeline does not run tsgo's emitter,
|
|
172
|
+
// so the source-map step printSourceFile would otherwise perform has to
|
|
173
|
+
// happen here. With maps off this is the same bare-printer output as
|
|
174
|
+
// before.
|
|
175
|
+
printed := shimcompiler.PrintFileWithSourceMap(ec, out.AsNode(), out, options, host, paths.JsFilePath(), paths.SourceMapFilePath())
|
|
176
|
+
// A source-level preamble (e.g. @ttsc/banner linked into a typia host)
|
|
177
|
+
// shifts the map's source coordinates; correct them here too, so the
|
|
178
|
+
// preamble-plus-transform combination is not left uncorrected the way it
|
|
179
|
+
// would be if only the utility host's WriteFile patched maps. Covers both
|
|
180
|
+
// the external `.js.map` and an inline base64 map embedded in the JS.
|
|
181
|
+
if p.SourcePreamble != "" {
|
|
182
|
+
dropLines := strings.Count(p.SourcePreamble, "\n")
|
|
183
|
+
if adjusted, ok := AdjustEmittedSourceMap(paths.JsFilePath(), printed.JS, dropLines); ok {
|
|
184
|
+
printed.JS = adjusted
|
|
185
|
+
}
|
|
186
|
+
if printed.MapPath != "" {
|
|
187
|
+
if adjusted, ok := AdjustEmittedSourceMap(printed.MapPath, printed.MapText, dropLines); ok {
|
|
188
|
+
printed.MapText = adjusted
|
|
189
|
+
}
|
|
184
190
|
}
|
|
185
191
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if printed.MapPath != "" {
|
|
191
|
-
if err := writeFile(printed.MapPath, printed.MapText, nil); err != nil {
|
|
192
|
+
if err := p.writePluginEmitOutput(paths.JsFilePath(), printed.JS, writeFile); err != nil {
|
|
193
|
+
return nil, err
|
|
194
|
+
}
|
|
195
|
+
if err := p.writePluginEmitOutput(printed.MapPath, printed.MapText, writeFile); err != nil {
|
|
192
196
|
return nil, err
|
|
193
197
|
}
|
|
194
198
|
}
|
|
195
199
|
}
|
|
200
|
+
if !options.GetEmitDeclarations() {
|
|
201
|
+
return nil, nil
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var wfMu sync.Mutex
|
|
205
|
+
result := p.TSProgram.Emit(context.Background(), shimcompiler.EmitOptions{
|
|
206
|
+
EmitOnly: shimcompiler.EmitOnlyDts,
|
|
207
|
+
WriteFile: func(fileName string, text string, data *shimcompiler.WriteFileData) error {
|
|
208
|
+
wfMu.Lock()
|
|
209
|
+
defer wfMu.Unlock()
|
|
210
|
+
if p.outputEscapesOutDir(fileName) {
|
|
211
|
+
if data != nil {
|
|
212
|
+
data.SkippedDtsWrite = true
|
|
213
|
+
}
|
|
214
|
+
return nil
|
|
215
|
+
}
|
|
216
|
+
if writeFile != nil {
|
|
217
|
+
return writeFile(fileName, text, data)
|
|
218
|
+
}
|
|
219
|
+
return DefaultWriteFile(fileName, text)
|
|
220
|
+
},
|
|
221
|
+
})
|
|
222
|
+
if result != nil && len(result.Diagnostics) != 0 {
|
|
223
|
+
return convertDiagnostics(result.Diagnostics), nil
|
|
224
|
+
}
|
|
196
225
|
return nil, nil
|
|
197
226
|
}
|
|
227
|
+
|
|
228
|
+
func (p *Program) writePluginEmitOutput(fileName, text string, writeFile shimcompiler.WriteFile) error {
|
|
229
|
+
if fileName == "" || p.outputEscapesOutDir(fileName) {
|
|
230
|
+
return nil
|
|
231
|
+
}
|
|
232
|
+
if writeFile != nil {
|
|
233
|
+
return writeFile(fileName, text, nil)
|
|
234
|
+
}
|
|
235
|
+
return DefaultWriteFile(fileName, text)
|
|
236
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ttsc",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.11",
|
|
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.1-rc"
|
|
33
33
|
},
|
|
34
34
|
"optionalDependencies": {
|
|
35
|
-
"@ttsc/linux-x64": "0.16.
|
|
36
|
-
"@ttsc/linux-arm": "0.16.
|
|
37
|
-
"@ttsc/
|
|
38
|
-
"@ttsc/
|
|
39
|
-
"@ttsc/
|
|
40
|
-
"@ttsc/win32-
|
|
41
|
-
"@ttsc/
|
|
35
|
+
"@ttsc/linux-x64": "0.16.11",
|
|
36
|
+
"@ttsc/linux-arm": "0.16.11",
|
|
37
|
+
"@ttsc/darwin-x64": "0.16.11",
|
|
38
|
+
"@ttsc/win32-x64": "0.16.11",
|
|
39
|
+
"@ttsc/linux-arm64": "0.16.11",
|
|
40
|
+
"@ttsc/win32-arm64": "0.16.11",
|
|
41
|
+
"@ttsc/darwin-arm64": "0.16.11"
|
|
42
42
|
},
|
|
43
43
|
"sideEffects": false,
|
|
44
44
|
"files": [
|