@skmtc/core 0.51.0 → 0.52.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.
@@ -4,8 +4,9 @@
4
4
  * The capture mechanism for gen-maps. A {@link CaptureSink} is owned by
5
5
  * {@link import('@/context/RenderContext.ts').RenderContext} for the
6
6
  * duration of the single render pass and published to snippets through the
7
- * shared {@link CaptureChannel}: every `SnippetBase` instance self-wraps
8
- * its `toString` at construction (own-property wrapper), and the wrapper
7
+ * shared {@link CaptureChannel}: in a run that has a channel, every
8
+ * `SnippetBase` instance self-wraps its `toString` at construction
9
+ * (own-property wrapper), and the wrapper
9
10
  * observes into the channel's sink while the **capture interval** is open
10
11
  * — the span while `channel.sink` is set. Each `toString` invocation is
11
12
  * observed into an **occurrence tree** — one node per call, keyed by
@@ -4,8 +4,9 @@
4
4
  * The capture mechanism for gen-maps. A {@link CaptureSink} is owned by
5
5
  * {@link import('@/context/RenderContext.ts').RenderContext} for the
6
6
  * duration of the single render pass and published to snippets through the
7
- * shared {@link CaptureChannel}: every `SnippetBase` instance self-wraps
8
- * its `toString` at construction (own-property wrapper), and the wrapper
7
+ * shared {@link CaptureChannel}: in a run that has a channel, every
8
+ * `SnippetBase` instance self-wraps its `toString` at construction
9
+ * (own-property wrapper), and the wrapper
9
10
  * observes into the channel's sink while the **capture interval** is open
10
11
  * — the span while `channel.sink` is set. Each `toString` invocation is
11
12
  * observed into an **occurrence tree** — one node per call, keyed by
@@ -96,9 +96,10 @@ export type ToArtifactsArgs = {
96
96
  /** Whether to suppress console output */
97
97
  silent: boolean;
98
98
  /**
99
- * Optional attribution (gen-maps) **emission** config. Capture is
100
- * always on; when `postPass` is set, the pipeline emits sidecars + a
101
- * generation map alongside the usual artifacts. See
99
+ * Optional attribution (gen-maps) **emission** config. Location
100
+ * capture is always on; when `postPass` is set, the run's snippets wrap
101
+ * their `toString` and the pipeline emits sidecars + a generation map
102
+ * alongside the usual artifacts. See
102
103
  * {@link AttributionState}.
103
104
  */
104
105
  attribution?: AttributionState;
@@ -314,8 +314,12 @@ export class CoreContext {
314
314
  // The shared attribution capture channel: snippets constructed
315
315
  // during generate hold the GenerateContext, whose `captureSink`
316
316
  // reads this slot; RenderContext flips it around the one capturing
317
- // render. One object per run wires the two phases together.
318
- const captureChannel = { sink: undefined };
317
+ // render. One object per run wires the two phases together. A run
318
+ // with no `attribution.postPass` has no capturing render, so it has
319
+ // no channel, and its snippets install no `toString` wrapper.
320
+ const captureChannel = attribution?.postPass
321
+ ? { sink: undefined }
322
+ : undefined;
319
323
  const { files, previews, inspection, enrichmentWarnings } = stackTrail.trace('generate', st => {
320
324
  __classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
321
325
  const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
@@ -416,13 +420,12 @@ export class CoreContext {
416
420
  __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
417
421
  const subjects = stackTrail.trace('generate', () => {
418
422
  __classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
419
- // Capability probing never renders, so the capture interval never
420
- // opens — a throwaway channel satisfies the wiring.
423
+ // Capability probing never renders, so it has no capture channel.
421
424
  const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
422
425
  toGeneratorConfigMap,
423
426
  document: parsedDocument,
424
427
  settings,
425
- captureChannel: { sink: undefined }
428
+ captureChannel: undefined
426
429
  });
427
430
  __classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
428
431
  return generatePhase.context.toSupportedSubjects();
@@ -466,13 +469,12 @@ export class CoreContext {
466
469
  __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
467
470
  const enrichmentDefaults = stackTrail.trace('generate', () => {
468
471
  __classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
469
- // Seeding never renders, so the capture interval never opens — a
470
- // throwaway channel satisfies the wiring.
472
+ // Seeding never renders, so it has no capture channel.
471
473
  const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
472
474
  toGeneratorConfigMap,
473
475
  document: parsedDocument,
474
476
  settings,
475
- captureChannel: { sink: undefined }
477
+ captureChannel: undefined
476
478
  });
477
479
  __classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
478
480
  return generatePhase.context.toEnrichmentDefaults();
@@ -47,7 +47,8 @@ type ConstructorArgs = {
47
47
  * Shared attribution capture channel — the slot `RenderContext` flips to
48
48
  * open/close the capture interval. Snippets read it through this
49
49
  * context's {@link GenerateContext.captureSink}. Optional: when omitted
50
- * (tests, capture-less runs) `captureSink` is always `undefined`.
50
+ * (tests, capture-less runs) `captureSink` is always `undefined` and
51
+ * `capturesRender` is false, so no snippet installs a `toString` wrapper.
51
52
  */
52
53
  captureChannel?: CaptureChannel;
53
54
  /**
@@ -178,6 +179,12 @@ export declare class GenerateContext implements GenerateContextType {
178
179
  * shared channel's `sink`.
179
180
  */
180
181
  get captureSink(): CaptureSink | undefined;
182
+ /**
183
+ * Whether this run has a capturing render: it was given a capture
184
+ * channel. A `SnippetBase` instance installs its `toString` wrapper only
185
+ * then.
186
+ */
187
+ get capturesRender(): boolean;
181
188
  /**
182
189
  * The trail of the subject whose variant is being generated, or
183
190
  * `undefined` outside one. Log lines and the results the logger
@@ -218,6 +218,14 @@ export class GenerateContext {
218
218
  get captureSink() {
219
219
  return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f")?.sink;
220
220
  }
221
+ /**
222
+ * Whether this run has a capturing render: it was given a capture
223
+ * channel. A `SnippetBase` instance installs its `toString` wrapper only
224
+ * then.
225
+ */
226
+ get capturesRender() {
227
+ return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f") !== undefined;
228
+ }
221
229
  /**
222
230
  * The trail of the subject whose variant is being generated, or
223
231
  * `undefined` outside one. Log lines and the results the logger
@@ -123,9 +123,8 @@ export class RenderContext {
123
123
  */
124
124
  render(stackTrail) {
125
125
  const postPassConfig = this.attribution?.postPass;
126
- // No emission configured → plain render, no capture: the capture
127
- // interval never opens, so every snippet's `toString` wrapper takes
128
- // the pass-through path.
126
+ // No emission configured → plain render, no capture: the run has no
127
+ // capture channel, so its snippets have no `toString` wrapper.
129
128
  if (!postPassConfig) {
130
129
  const result = this.collate(stackTrail);
131
130
  return {
@@ -450,11 +450,8 @@ export type GenerateContextType = {
450
450
  pendingStack: PendingDefinition[];
451
451
  document: SkmtcParsedDocument;
452
452
  /**
453
- * Attribution (gen-maps) state. When set, every `SnippetBase`
454
- * instance wraps its `toString` to record parent/child edges in a
455
- * module-level render stack, so the post-render span resolver can
456
- * attribute byte ranges to producers. When omitted, the wrap is
457
- * skipped entirely — zero cost.
453
+ * Attribution (gen-maps) state. It does not decide whether a
454
+ * `SnippetBase` wraps its `toString`: {@link capturesRender} does.
458
455
  */
459
456
  attribution?: AttributionState;
460
457
  /**
@@ -462,10 +459,18 @@ export type GenerateContextType = {
462
459
  * capture interval. Read by every `SnippetBase` instance's `toString`
463
460
  * wrapper; `RenderContext` opens/closes the interval through the shared
464
461
  * {@link import('@/anchors/CaptureSink.ts').CaptureChannel} that
465
- * `CoreContext` wires into both contexts. Bare test mocks read
466
- * `undefined` and take the pass-through path.
462
+ * `CoreContext` wires into both contexts. In a run with no capturing
463
+ * render (`capturesRender` false, as in a bare test mock) no snippet
464
+ * has a wrapper, so nothing reads it.
467
465
  */
468
466
  captureSink: CaptureSink | undefined;
467
+ /**
468
+ * Whether the run has a capturing render (attribution emission is
469
+ * configured). Read once by every `SnippetBase` instance, at
470
+ * construction: it installs its `toString` wrapper only when this is
471
+ * true.
472
+ */
473
+ capturesRender: boolean;
469
474
  toArtifacts: (stackTrail: StackTrail) => GenerateResult;
470
475
  registerJson: ({ destinationPath, json }: RegisterJsonArgs) => void;
471
476
  registerMarkdown: ({ destinationPath, markdown }: RegisterMarkdownArgs) => void;
@@ -47,8 +47,11 @@ export type SnippetBaseArgs = {
47
47
  *
48
48
  * ## Attribution (gen-maps)
49
49
  *
50
- * Every instance self-wraps its `toString` at construction (an
51
- * own-property wrapper — shared function, non-enumerable). The wrapper is
50
+ * In a run that captures a render (`context.capturesRender`: attribution
51
+ * emission is configured), every instance self-wraps its `toString` at
52
+ * construction (an own-property wrapper — shared function,
53
+ * non-enumerable). In any other run no instance has a wrapper, and
54
+ * `toString` is the subclass's own. The wrapper is
52
55
  * gated by the **capture interval**: the span while
53
56
  * {@link import('@/context/generateTypes.ts').GenerateContextType.captureSink}
54
57
  * is set, which `RenderContext` opens around the one capturing render and
@@ -1,7 +1,8 @@
1
1
  import { StackTrail } from '../context/StackTrail.js';
2
2
  /**
3
- * The own-property `toString` wrapper every {@link SnippetBase} instance
4
- * installs at construction — ONE shared function, no per-instance closure.
3
+ * The own-property `toString` wrapper a {@link SnippetBase} instance
4
+ * installs at construction, in a run that captures a render
5
+ * (`context.capturesRender`) — ONE shared function, no per-instance closure.
5
6
  *
6
7
  * Own properties shadow every prototype, so this intercepts the leaf
7
8
  * subclass's `toString` no matter where in the hierarchy it is declared —
@@ -11,9 +12,7 @@ import { StackTrail } from '../context/StackTrail.js';
11
12
  * instance's own property).
12
13
  *
13
14
  * Outside the capture interval (`context.captureSink` unset) this is a
14
- * pure pass-through — one property read and one branch. Bare test mocks
15
- * (`{} as GenerateContextType`) read `undefined` and take the pass-through
16
- * path.
15
+ * pure pass-through — one property read and one branch.
17
16
  */
18
17
  const capturingToString = function () {
19
18
  const impl = Object.getPrototypeOf(this).toString;
@@ -43,8 +42,11 @@ const capturingToString = function () {
43
42
  *
44
43
  * ## Attribution (gen-maps)
45
44
  *
46
- * Every instance self-wraps its `toString` at construction (an
47
- * own-property wrapper — shared function, non-enumerable). The wrapper is
45
+ * In a run that captures a render (`context.capturesRender`: attribution
46
+ * emission is configured), every instance self-wraps its `toString` at
47
+ * construction (an own-property wrapper — shared function,
48
+ * non-enumerable). In any other run no instance has a wrapper, and
49
+ * `toString` is the subclass's own. The wrapper is
48
50
  * gated by the **capture interval**: the span while
49
51
  * {@link import('@/context/generateTypes.ts').GenerateContextType.captureSink}
50
52
  * is set, which `RenderContext` opens around the one capturing render and
@@ -104,10 +106,14 @@ export class SnippetBase {
104
106
  // Self-wrap for attribution capture: an own-property `toString`
105
107
  // (shared function value, non-enumerable) that observes into the
106
108
  // context's capture sink while the capture interval is open and
107
- // passes through otherwise.
108
- Object.defineProperty(this, 'toString', {
109
- value: capturingToString,
110
- configurable: true
111
- });
109
+ // passes through otherwise. A run with no capturing render never
110
+ // opens the interval, so its snippets get no wrapper: one property
111
+ // definition for each snippet of the run is otherwise made for nothing.
112
+ if (context.capturesRender) {
113
+ Object.defineProperty(this, 'toString', {
114
+ value: capturingToString,
115
+ configurable: true
116
+ });
117
+ }
112
118
  }
113
119
  }
@@ -1,21 +1,22 @@
1
1
  /**
2
2
  * Attribution (gen-maps) **emission** config.
3
3
  *
4
- * Attribution *capture* is always on and needs no configuration — it is
5
- * intrinsic to the pipeline:
4
+ * Attribution *location capture* is always on and needs no configuration:
6
5
  *
7
6
  * - **Parse phase**: every parsed OAS / GQL node snapshots the visitor's
8
7
  * `StackTrail` into its `OasBase` base (`toLocation()` → JSON Pointer).
9
- * - **Generate phase**: every `SnippetBase` instance wraps its
10
- * `toString` to capture parent/child edges via a render stack, so
11
- * the post-render span resolver can attribute byte ranges to producers.
8
+ * - **Generate phase**: in a run with `postPass`, every `SnippetBase`
9
+ * instance wraps its `toString` to capture parent/child edges, so the
10
+ * post-render span resolver can attribute byte ranges to producers. A
11
+ * run with no `postPass` installs no wrapper.
12
12
  *
13
13
  * This type configures only **emission**: it is supplied at the run level
14
14
  * (`CoreContext.toArtifacts`) and consumed solely by the post-render
15
- * pass. The parse and generate contexts do not carry it, because capture
16
- * is unconditional. Without `postPass` you still get capture but no
17
- * on-disk output; setting `postPass` activates the pass and surfaces
18
- * `sidecars` / `generationMap` on the result.
15
+ * pass. The parse and generate contexts do not carry it; the generate
16
+ * context only knows whether the run has a capture channel. Without
17
+ * `postPass` you get location capture but no on-disk output; setting
18
+ * `postPass` activates the pass and surfaces `sidecars` /
19
+ * `generationMap` on the result.
19
20
  */
20
21
  import type { ParserAdapter } from '../anchors/ParserAdapter.js';
21
22
  import type { GeneratorMetaLookup } from '../anchors/postPass.js';
@@ -1,20 +1,21 @@
1
1
  /**
2
2
  * Attribution (gen-maps) **emission** config.
3
3
  *
4
- * Attribution *capture* is always on and needs no configuration — it is
5
- * intrinsic to the pipeline:
4
+ * Attribution *location capture* is always on and needs no configuration:
6
5
  *
7
6
  * - **Parse phase**: every parsed OAS / GQL node snapshots the visitor's
8
7
  * `StackTrail` into its `OasBase` base (`toLocation()` → JSON Pointer).
9
- * - **Generate phase**: every `SnippetBase` instance wraps its
10
- * `toString` to capture parent/child edges via a render stack, so
11
- * the post-render span resolver can attribute byte ranges to producers.
8
+ * - **Generate phase**: in a run with `postPass`, every `SnippetBase`
9
+ * instance wraps its `toString` to capture parent/child edges, so the
10
+ * post-render span resolver can attribute byte ranges to producers. A
11
+ * run with no `postPass` installs no wrapper.
12
12
  *
13
13
  * This type configures only **emission**: it is supplied at the run level
14
14
  * (`CoreContext.toArtifacts`) and consumed solely by the post-render
15
- * pass. The parse and generate contexts do not carry it, because capture
16
- * is unconditional. Without `postPass` you still get capture but no
17
- * on-disk output; setting `postPass` activates the pass and surfaces
18
- * `sidecars` / `generationMap` on the result.
15
+ * pass. The parse and generate contexts do not carry it; the generate
16
+ * context only knows whether the run has a capture channel. Without
17
+ * `postPass` you get location capture but no on-disk output; setting
18
+ * `postPass` activates the pass and surfaces `sidecars` /
19
+ * `generationMap` on the result.
19
20
  */
20
21
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.51.0",
3
+ "version": "0.52.0",
4
4
  "description": "Skmtc is a declarative code generation framework",
5
5
  "keywords": [
6
6
  "openapi",
@@ -4,8 +4,9 @@
4
4
  * The capture mechanism for gen-maps. A {@link CaptureSink} is owned by
5
5
  * {@link import('@/context/RenderContext.ts').RenderContext} for the
6
6
  * duration of the single render pass and published to snippets through the
7
- * shared {@link CaptureChannel}: every `SnippetBase` instance self-wraps
8
- * its `toString` at construction (own-property wrapper), and the wrapper
7
+ * shared {@link CaptureChannel}: in a run that has a channel, every
8
+ * `SnippetBase` instance self-wraps its `toString` at construction
9
+ * (own-property wrapper), and the wrapper
9
10
  * observes into the channel's sink while the **capture interval** is open
10
11
  * — the span while `channel.sink` is set. Each `toString` invocation is
11
12
  * observed into an **occurrence tree** — one node per call, keyed by
@@ -5,8 +5,9 @@
5
5
  * The capture mechanism for gen-maps. A {@link CaptureSink} is owned by
6
6
  * {@link import('@/context/RenderContext.ts').RenderContext} for the
7
7
  * duration of the single render pass and published to snippets through the
8
- * shared {@link CaptureChannel}: every `SnippetBase` instance self-wraps
9
- * its `toString` at construction (own-property wrapper), and the wrapper
8
+ * shared {@link CaptureChannel}: in a run that has a channel, every
9
+ * `SnippetBase` instance self-wraps its `toString` at construction
10
+ * (own-property wrapper), and the wrapper
10
11
  * observes into the channel's sink while the **capture interval** is open
11
12
  * — the span while `channel.sink` is set. Each `toString` invocation is
12
13
  * observed into an **occurrence tree** — one node per call, keyed by
@@ -96,9 +96,10 @@ export type ToArtifactsArgs = {
96
96
  /** Whether to suppress console output */
97
97
  silent: boolean;
98
98
  /**
99
- * Optional attribution (gen-maps) **emission** config. Capture is
100
- * always on; when `postPass` is set, the pipeline emits sidecars + a
101
- * generation map alongside the usual artifacts. See
99
+ * Optional attribution (gen-maps) **emission** config. Location
100
+ * capture is always on; when `postPass` is set, the run's snippets wrap
101
+ * their `toString` and the pipeline emits sidecars + a generation map
102
+ * alongside the usual artifacts. See
102
103
  * {@link AttributionState}.
103
104
  */
104
105
  attribution?: AttributionState;
@@ -352,8 +352,12 @@ class CoreContext {
352
352
  // The shared attribution capture channel: snippets constructed
353
353
  // during generate hold the GenerateContext, whose `captureSink`
354
354
  // reads this slot; RenderContext flips it around the one capturing
355
- // render. One object per run wires the two phases together.
356
- const captureChannel = { sink: undefined };
355
+ // render. One object per run wires the two phases together. A run
356
+ // with no `attribution.postPass` has no capturing render, so it has
357
+ // no channel, and its snippets install no `toString` wrapper.
358
+ const captureChannel = attribution?.postPass
359
+ ? { sink: undefined }
360
+ : undefined;
357
361
  const { files, previews, inspection, enrichmentWarnings } = stackTrail.trace('generate', st => {
358
362
  __classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
359
363
  const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
@@ -454,13 +458,12 @@ class CoreContext {
454
458
  __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
455
459
  const subjects = stackTrail.trace('generate', () => {
456
460
  __classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
457
- // Capability probing never renders, so the capture interval never
458
- // opens — a throwaway channel satisfies the wiring.
461
+ // Capability probing never renders, so it has no capture channel.
459
462
  const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
460
463
  toGeneratorConfigMap,
461
464
  document: parsedDocument,
462
465
  settings,
463
- captureChannel: { sink: undefined }
466
+ captureChannel: undefined
464
467
  });
465
468
  __classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
466
469
  return generatePhase.context.toSupportedSubjects();
@@ -504,13 +507,12 @@ class CoreContext {
504
507
  __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_logParseLine).call(this, parsedDocument, phase.context.issues, runStartedAt);
505
508
  const enrichmentDefaults = stackTrail.trace('generate', () => {
506
509
  __classPrivateFieldSet(this, _CoreContext_phaseName, 'generate', "f");
507
- // Seeding never renders, so the capture interval never opens — a
508
- // throwaway channel satisfies the wiring.
510
+ // Seeding never renders, so it has no capture channel.
509
511
  const generatePhase = __classPrivateFieldGet(this, _CoreContext_instances, "m", _CoreContext_setupGeneratePhase).call(this, {
510
512
  toGeneratorConfigMap,
511
513
  document: parsedDocument,
512
514
  settings,
513
- captureChannel: { sink: undefined }
515
+ captureChannel: undefined
514
516
  });
515
517
  __classPrivateFieldSet(this, _CoreContext_phase, generatePhase, "f");
516
518
  return generatePhase.context.toEnrichmentDefaults();
@@ -47,7 +47,8 @@ type ConstructorArgs = {
47
47
  * Shared attribution capture channel — the slot `RenderContext` flips to
48
48
  * open/close the capture interval. Snippets read it through this
49
49
  * context's {@link GenerateContext.captureSink}. Optional: when omitted
50
- * (tests, capture-less runs) `captureSink` is always `undefined`.
50
+ * (tests, capture-less runs) `captureSink` is always `undefined` and
51
+ * `capturesRender` is false, so no snippet installs a `toString` wrapper.
51
52
  */
52
53
  captureChannel?: CaptureChannel;
53
54
  /**
@@ -178,6 +179,12 @@ export declare class GenerateContext implements GenerateContextType {
178
179
  * shared channel's `sink`.
179
180
  */
180
181
  get captureSink(): CaptureSink | undefined;
182
+ /**
183
+ * Whether this run has a capturing render: it was given a capture
184
+ * channel. A `SnippetBase` instance installs its `toString` wrapper only
185
+ * then.
186
+ */
187
+ get capturesRender(): boolean;
181
188
  /**
182
189
  * The trail of the subject whose variant is being generated, or
183
190
  * `undefined` outside one. Log lines and the results the logger
@@ -224,6 +224,14 @@ class GenerateContext {
224
224
  get captureSink() {
225
225
  return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f")?.sink;
226
226
  }
227
+ /**
228
+ * Whether this run has a capturing render: it was given a capture
229
+ * channel. A `SnippetBase` instance installs its `toString` wrapper only
230
+ * then.
231
+ */
232
+ get capturesRender() {
233
+ return __classPrivateFieldGet(this, _GenerateContext_captureChannel, "f") !== undefined;
234
+ }
227
235
  /**
228
236
  * The trail of the subject whose variant is being generated, or
229
237
  * `undefined` outside one. Log lines and the results the logger
@@ -129,9 +129,8 @@ class RenderContext {
129
129
  */
130
130
  render(stackTrail) {
131
131
  const postPassConfig = this.attribution?.postPass;
132
- // No emission configured → plain render, no capture: the capture
133
- // interval never opens, so every snippet's `toString` wrapper takes
134
- // the pass-through path.
132
+ // No emission configured → plain render, no capture: the run has no
133
+ // capture channel, so its snippets have no `toString` wrapper.
135
134
  if (!postPassConfig) {
136
135
  const result = this.collate(stackTrail);
137
136
  return {
@@ -450,11 +450,8 @@ export type GenerateContextType = {
450
450
  pendingStack: PendingDefinition[];
451
451
  document: SkmtcParsedDocument;
452
452
  /**
453
- * Attribution (gen-maps) state. When set, every `SnippetBase`
454
- * instance wraps its `toString` to record parent/child edges in a
455
- * module-level render stack, so the post-render span resolver can
456
- * attribute byte ranges to producers. When omitted, the wrap is
457
- * skipped entirely — zero cost.
453
+ * Attribution (gen-maps) state. It does not decide whether a
454
+ * `SnippetBase` wraps its `toString`: {@link capturesRender} does.
458
455
  */
459
456
  attribution?: AttributionState;
460
457
  /**
@@ -462,10 +459,18 @@ export type GenerateContextType = {
462
459
  * capture interval. Read by every `SnippetBase` instance's `toString`
463
460
  * wrapper; `RenderContext` opens/closes the interval through the shared
464
461
  * {@link import('@/anchors/CaptureSink.ts').CaptureChannel} that
465
- * `CoreContext` wires into both contexts. Bare test mocks read
466
- * `undefined` and take the pass-through path.
462
+ * `CoreContext` wires into both contexts. In a run with no capturing
463
+ * render (`capturesRender` false, as in a bare test mock) no snippet
464
+ * has a wrapper, so nothing reads it.
467
465
  */
468
466
  captureSink: CaptureSink | undefined;
467
+ /**
468
+ * Whether the run has a capturing render (attribution emission is
469
+ * configured). Read once by every `SnippetBase` instance, at
470
+ * construction: it installs its `toString` wrapper only when this is
471
+ * true.
472
+ */
473
+ capturesRender: boolean;
469
474
  toArtifacts: (stackTrail: StackTrail) => GenerateResult;
470
475
  registerJson: ({ destinationPath, json }: RegisterJsonArgs) => void;
471
476
  registerMarkdown: ({ destinationPath, markdown }: RegisterMarkdownArgs) => void;
@@ -47,8 +47,11 @@ export type SnippetBaseArgs = {
47
47
  *
48
48
  * ## Attribution (gen-maps)
49
49
  *
50
- * Every instance self-wraps its `toString` at construction (an
51
- * own-property wrapper — shared function, non-enumerable). The wrapper is
50
+ * In a run that captures a render (`context.capturesRender`: attribution
51
+ * emission is configured), every instance self-wraps its `toString` at
52
+ * construction (an own-property wrapper — shared function,
53
+ * non-enumerable). In any other run no instance has a wrapper, and
54
+ * `toString` is the subclass's own. The wrapper is
52
55
  * gated by the **capture interval**: the span while
53
56
  * {@link import('@/context/generateTypes.ts').GenerateContextType.captureSink}
54
57
  * is set, which `RenderContext` opens around the one capturing render and
@@ -3,8 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SnippetBase = void 0;
4
4
  const StackTrail_js_1 = require("../context/StackTrail.js");
5
5
  /**
6
- * The own-property `toString` wrapper every {@link SnippetBase} instance
7
- * installs at construction — ONE shared function, no per-instance closure.
6
+ * The own-property `toString` wrapper a {@link SnippetBase} instance
7
+ * installs at construction, in a run that captures a render
8
+ * (`context.capturesRender`) — ONE shared function, no per-instance closure.
8
9
  *
9
10
  * Own properties shadow every prototype, so this intercepts the leaf
10
11
  * subclass's `toString` no matter where in the hierarchy it is declared —
@@ -14,9 +15,7 @@ const StackTrail_js_1 = require("../context/StackTrail.js");
14
15
  * instance's own property).
15
16
  *
16
17
  * Outside the capture interval (`context.captureSink` unset) this is a
17
- * pure pass-through — one property read and one branch. Bare test mocks
18
- * (`{} as GenerateContextType`) read `undefined` and take the pass-through
19
- * path.
18
+ * pure pass-through — one property read and one branch.
20
19
  */
21
20
  const capturingToString = function () {
22
21
  const impl = Object.getPrototypeOf(this).toString;
@@ -46,8 +45,11 @@ const capturingToString = function () {
46
45
  *
47
46
  * ## Attribution (gen-maps)
48
47
  *
49
- * Every instance self-wraps its `toString` at construction (an
50
- * own-property wrapper — shared function, non-enumerable). The wrapper is
48
+ * In a run that captures a render (`context.capturesRender`: attribution
49
+ * emission is configured), every instance self-wraps its `toString` at
50
+ * construction (an own-property wrapper — shared function,
51
+ * non-enumerable). In any other run no instance has a wrapper, and
52
+ * `toString` is the subclass's own. The wrapper is
51
53
  * gated by the **capture interval**: the span while
52
54
  * {@link import('@/context/generateTypes.ts').GenerateContextType.captureSink}
53
55
  * is set, which `RenderContext` opens around the one capturing render and
@@ -107,11 +109,15 @@ class SnippetBase {
107
109
  // Self-wrap for attribution capture: an own-property `toString`
108
110
  // (shared function value, non-enumerable) that observes into the
109
111
  // context's capture sink while the capture interval is open and
110
- // passes through otherwise.
111
- Object.defineProperty(this, 'toString', {
112
- value: capturingToString,
113
- configurable: true
114
- });
112
+ // passes through otherwise. A run with no capturing render never
113
+ // opens the interval, so its snippets get no wrapper: one property
114
+ // definition for each snippet of the run is otherwise made for nothing.
115
+ if (context.capturesRender) {
116
+ Object.defineProperty(this, 'toString', {
117
+ value: capturingToString,
118
+ configurable: true
119
+ });
120
+ }
115
121
  }
116
122
  }
117
123
  exports.SnippetBase = SnippetBase;
@@ -1,21 +1,22 @@
1
1
  /**
2
2
  * Attribution (gen-maps) **emission** config.
3
3
  *
4
- * Attribution *capture* is always on and needs no configuration — it is
5
- * intrinsic to the pipeline:
4
+ * Attribution *location capture* is always on and needs no configuration:
6
5
  *
7
6
  * - **Parse phase**: every parsed OAS / GQL node snapshots the visitor's
8
7
  * `StackTrail` into its `OasBase` base (`toLocation()` → JSON Pointer).
9
- * - **Generate phase**: every `SnippetBase` instance wraps its
10
- * `toString` to capture parent/child edges via a render stack, so
11
- * the post-render span resolver can attribute byte ranges to producers.
8
+ * - **Generate phase**: in a run with `postPass`, every `SnippetBase`
9
+ * instance wraps its `toString` to capture parent/child edges, so the
10
+ * post-render span resolver can attribute byte ranges to producers. A
11
+ * run with no `postPass` installs no wrapper.
12
12
  *
13
13
  * This type configures only **emission**: it is supplied at the run level
14
14
  * (`CoreContext.toArtifacts`) and consumed solely by the post-render
15
- * pass. The parse and generate contexts do not carry it, because capture
16
- * is unconditional. Without `postPass` you still get capture but no
17
- * on-disk output; setting `postPass` activates the pass and surfaces
18
- * `sidecars` / `generationMap` on the result.
15
+ * pass. The parse and generate contexts do not carry it; the generate
16
+ * context only knows whether the run has a capture channel. Without
17
+ * `postPass` you get location capture but no on-disk output; setting
18
+ * `postPass` activates the pass and surfaces `sidecars` /
19
+ * `generationMap` on the result.
19
20
  */
20
21
  import type { ParserAdapter } from '../anchors/ParserAdapter.js';
21
22
  import type { GeneratorMetaLookup } from '../anchors/postPass.js';
@@ -2,20 +2,21 @@
2
2
  /**
3
3
  * Attribution (gen-maps) **emission** config.
4
4
  *
5
- * Attribution *capture* is always on and needs no configuration — it is
6
- * intrinsic to the pipeline:
5
+ * Attribution *location capture* is always on and needs no configuration:
7
6
  *
8
7
  * - **Parse phase**: every parsed OAS / GQL node snapshots the visitor's
9
8
  * `StackTrail` into its `OasBase` base (`toLocation()` → JSON Pointer).
10
- * - **Generate phase**: every `SnippetBase` instance wraps its
11
- * `toString` to capture parent/child edges via a render stack, so
12
- * the post-render span resolver can attribute byte ranges to producers.
9
+ * - **Generate phase**: in a run with `postPass`, every `SnippetBase`
10
+ * instance wraps its `toString` to capture parent/child edges, so the
11
+ * post-render span resolver can attribute byte ranges to producers. A
12
+ * run with no `postPass` installs no wrapper.
13
13
  *
14
14
  * This type configures only **emission**: it is supplied at the run level
15
15
  * (`CoreContext.toArtifacts`) and consumed solely by the post-render
16
- * pass. The parse and generate contexts do not carry it, because capture
17
- * is unconditional. Without `postPass` you still get capture but no
18
- * on-disk output; setting `postPass` activates the pass and surfaces
19
- * `sidecars` / `generationMap` on the result.
16
+ * pass. The parse and generate contexts do not carry it; the generate
17
+ * context only knows whether the run has a capture channel. Without
18
+ * `postPass` you get location capture but no on-disk output; setting
19
+ * `postPass` activates the pass and surfaces `sidecars` /
20
+ * `generationMap` on the result.
20
21
  */
21
22
  Object.defineProperty(exports, "__esModule", { value: true });