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.
@@ -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 injects
306
- // prog.SourcePreamble at the top of every emitted output file that supports
307
- // it. Returns nil when no preamble is needed (empty preamble, nil program, or
308
- // RemoveComments enabled), which tells the caller to use the default writer.
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 == "" || shouldRemoveComments(prog) {
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 shouldEnsureSourcePreamble(fileName, text, prog.SourcePreamble) {
315
- text = driver.ApplySourcePreamble(text, prog.SourcePreamble)
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
  }