@am_shork/attest 0.5.0 → 0.6.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.
@@ -322,4 +322,40 @@ function numericValue(node) {
322
322
  throw new NotStatic(node, 'a number this reader cannot spell out');
323
323
  return value;
324
324
  }
325
+ export function registryInsertionPoint(file, source) {
326
+ const sf = ts.createSourceFile(file, source, ts.ScriptTarget.Latest, /* setParentNodes */ true);
327
+ const exported = defaultExportExpression(sf);
328
+ if (!exported)
329
+ return undefined;
330
+ const arg = authoringCall(exported, sf, 'defineRequirements');
331
+ if (!arg || !ts.isObjectLiteralExpression(arg))
332
+ return undefined;
333
+ const last = arg.properties[arg.properties.length - 1];
334
+ if (!last) {
335
+ // An empty registry: open the body rather than continue it. The trailing
336
+ // newline is written by the caller, so `{` does not end up sharing a line
337
+ // with the entry and the closing `}`.
338
+ return { offset: arg.getStart(sf) + 1, indent: indentOf(sf, source, arg) + ' ', leadingComma: false };
339
+ }
340
+ // Deliberately the *end of the last property*, not the end of the literal:
341
+ // inserting here sits before any trailing comma the file already has, so one
342
+ // leading comma is correct whether or not that comma is present, and the
343
+ // file's own trailing-comma style is left exactly as it was.
344
+ return { offset: last.getEnd(), indent: indentOf(sf, source, last), leadingComma: true };
345
+ }
346
+ /**
347
+ * The whitespace a node's line opens with.
348
+ *
349
+ * Read out of the source rather than computed from the column, so a file
350
+ * indented with tabs is continued with tabs. Anything else on the line (a
351
+ * property sharing a line with another) falls back to two spaces, which is the
352
+ * only case where this guesses.
353
+ */
354
+ function indentOf(sf, source, node) {
355
+ const start = node.getStart(sf);
356
+ const { line } = sf.getLineAndCharacterOfPosition(start);
357
+ const lineStart = sf.getPositionOfLineAndCharacter(line, 0);
358
+ const prefix = source.slice(lineStart, start);
359
+ return /^[\t ]*$/.test(prefix) ? prefix : ' ';
360
+ }
325
361
  //# sourceMappingURL=static-registry.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@am_shork/attest",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "TDD-native spec framework: tests are the source of truth for verification, ID-bound requirements the source of truth for intent.",
5
5
  "type": "module",
6
6
  "engines": {