ttsc 0.15.1 → 0.15.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 +34 -5
- package/driver/sourcemap_preamble.go +375 -0
- package/lib/TtscCompiler.js +4 -1
- package/lib/TtscCompiler.js.map +1 -1
- package/lib/compiler/internal/project/readProjectConfig.js +4 -1
- package/lib/compiler/internal/project/readProjectConfig.js.map +1 -1
- package/lib/compiler/internal/transformProjectInMemory.d.ts +1 -0
- package/lib/compiler/internal/transformProjectInMemory.js +36 -0
- package/lib/compiler/internal/transformProjectInMemory.js.map +1 -1
- package/lib/launcher/internal/prepareExecution.js +14 -0
- package/lib/launcher/internal/prepareExecution.js.map +1 -1
- package/lib/launcher/internal/runtimeHooks.js +369 -24
- package/lib/launcher/internal/runtimeHooks.js.map +1 -1
- package/lib/plugin/internal/buildSourcePlugin.js +7 -7
- package/lib/plugin/internal/buildSourcePlugin.js.map +1 -1
- package/lib/structures/ITtscCompilerTransformation.d.ts +18 -0
- package/package.json +9 -9
- package/shim/compiler/emit_sourcemap.go +176 -0
- package/src/TtscCompiler.ts +5 -1
- package/src/compiler/internal/project/readProjectConfig.ts +5 -1
- package/src/compiler/internal/transformProjectInMemory.ts +46 -0
- package/src/launcher/internal/prepareExecution.ts +16 -0
- package/src/launcher/internal/runtimeHooks.ts +475 -33
- package/src/plugin/internal/buildSourcePlugin.ts +11 -8
- package/src/structures/ITtscCompilerTransformation.ts +20 -0
- package/utility/host.go +30 -7
|
@@ -31,6 +31,19 @@ export namespace ITtscCompilerTransformation {
|
|
|
31
31
|
* Program.
|
|
32
32
|
*/
|
|
33
33
|
typescript: Record<string, string>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Source files the transform consulted per transformed file, keyed the same
|
|
37
|
+
* way as {@link typescript}. Each entry lists the project-relative or
|
|
38
|
+
* absolute paths whose content influenced that output beyond the file
|
|
39
|
+
* itself — e.g. the declaration files a type-driven code generator read.
|
|
40
|
+
*
|
|
41
|
+
* Optional: only present when the transform native source reported a
|
|
42
|
+
* `dependencies` object in its stdout envelope. Bundler adapters use it to
|
|
43
|
+
* register watch files so type-only imports participate in HMR
|
|
44
|
+
* invalidation. ttsc passes the paths through verbatim.
|
|
45
|
+
*/
|
|
46
|
+
dependencies?: Record<string, string[]>;
|
|
34
47
|
}
|
|
35
48
|
|
|
36
49
|
/** Source-to-source transformation result that completed with diagnostics. */
|
|
@@ -49,6 +62,13 @@ export namespace ITtscCompilerTransformation {
|
|
|
49
62
|
|
|
50
63
|
/** Diagnostics reported during transformation. */
|
|
51
64
|
diagnostics: ITtscCompilerDiagnostic[];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Source files the transform consulted per transformed file. Same shape and
|
|
68
|
+
* semantics as {@link ISuccess.dependencies}; may be partial when the
|
|
69
|
+
* transform did not complete its pass.
|
|
70
|
+
*/
|
|
71
|
+
dependencies?: Record<string, string[]>;
|
|
52
72
|
}
|
|
53
73
|
|
|
54
74
|
/** Unexpected host-level error during transformation. */
|
package/utility/host.go
CHANGED
|
@@ -302,17 +302,40 @@ func setLinkedPluginManifest(input string) func() {
|
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
// makeSourcePreambleWriteFile returns a WriteFile callback that
|
|
306
|
-
//
|
|
307
|
-
//
|
|
308
|
-
//
|
|
305
|
+
// makeSourcePreambleWriteFile returns a WriteFile callback that keeps a source
|
|
306
|
+
// preamble (e.g. @ttsc/banner's copyright block) consistent in the output.
|
|
307
|
+
//
|
|
308
|
+
// The preamble is injected at the SOURCE level (sourcePreambleFS prepends it
|
|
309
|
+
// before TypeScript-Go parses), which has two output consequences this callback
|
|
310
|
+
// reconciles:
|
|
311
|
+
//
|
|
312
|
+
// - The preamble shifts every recorded source coordinate down by its line
|
|
313
|
+
// count, so emitted source maps (external `.js.map` / `.d.ts.map`, or inline
|
|
314
|
+
// base64 maps embedded in the JS/d.ts) point past the real source.
|
|
315
|
+
// AdjustEmittedSourceMap undoes that shift on every emitted file. It must run
|
|
316
|
+
// even when RemoveComments strips the banner text from the JS/d.ts, because
|
|
317
|
+
// the source is preamble-injected regardless of RemoveComments.
|
|
318
|
+
// - The banner text itself is ensured in the `.js` / `.d.ts` output, only when
|
|
319
|
+
// comments are kept; RemoveComments deliberately drops it. (For a banner
|
|
320
|
+
// build the banner is already source-injected, so this is a no-op safety net;
|
|
321
|
+
// it never runs on an inline map's JS that the line above already corrected,
|
|
322
|
+
// because the banner is present there.)
|
|
323
|
+
//
|
|
324
|
+
// Returns nil only when there is no preamble at all (nil program or empty
|
|
325
|
+
// preamble), telling the caller to use the default writer.
|
|
309
326
|
func makeSourcePreambleWriteFile(prog *driver.Program) shimcompiler.WriteFile {
|
|
310
|
-
if prog == nil || prog.SourcePreamble == ""
|
|
327
|
+
if prog == nil || prog.SourcePreamble == "" {
|
|
311
328
|
return nil
|
|
312
329
|
}
|
|
330
|
+
preamble := prog.SourcePreamble
|
|
331
|
+
dropLines := strings.Count(preamble, "\n")
|
|
332
|
+
injectBanner := !shouldRemoveComments(prog)
|
|
313
333
|
return func(fileName, text string, _ *shimcompiler.WriteFileData) error {
|
|
314
|
-
if
|
|
315
|
-
text =
|
|
334
|
+
if adjusted, ok := driver.AdjustEmittedSourceMap(fileName, text, dropLines); ok {
|
|
335
|
+
text = adjusted
|
|
336
|
+
}
|
|
337
|
+
if injectBanner && shouldEnsureSourcePreamble(fileName, text, preamble) {
|
|
338
|
+
text = driver.ApplySourcePreamble(text, preamble)
|
|
316
339
|
}
|
|
317
340
|
return driver.DefaultWriteFile(fileName, text)
|
|
318
341
|
}
|