@jigs.design/compiler 0.3.1 → 0.3.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.
@@ -44,5 +44,14 @@ export interface DataRead {
44
44
  places: Array<Place | null>;
45
45
  procedure: string;
46
46
  }
47
+ /**
48
+ * The top-level fields of each procedure's data a document reads, by
49
+ * procedure: `orders.data.total` and `data["total"]` read `total`. `"all"`
50
+ * when the data, or the handle, is used whole: aliased, spread, passed on,
51
+ * read with a computed key, or anything else that is not a chain of
52
+ * written-out fields. So a caller that trims a procedure's data to these
53
+ * fields changes nothing the document sees.
54
+ */
55
+ export type DataFields = Readonly<Record<string, ReadonlyArray<string> | "all">>;
47
56
  //#endregion
48
57
  export {};
@@ -280,6 +280,17 @@ function readBody(statements, define, outer) {
280
280
  function checkCode(tree, defines, pageStatements, findings, hoists, dropped = /* @__PURE__ */ new Set()) {
281
281
  const procedures = [];
282
282
  const reads = [];
283
+ const dataFields = /* @__PURE__ */ new Map();
284
+ /** Records that `procedure`'s data is read at `field`, or whole. */
285
+ const readField = (procedure, field) => {
286
+ const known = dataFields.get(procedure);
287
+ if (known === "all") return;
288
+ if (field === "all") {
289
+ dataFields.set(procedure, "all");
290
+ return;
291
+ }
292
+ dataFields.set(procedure, /* @__PURE__ */ new Set([...known ?? [], field]));
293
+ };
283
294
  const report = (place, code, message, fix) => {
284
295
  const finding = {
285
296
  code,
@@ -350,6 +361,15 @@ function checkCode(tree, defines, pageStatements, findings, hoists, dropped = /*
350
361
  procedure: source.procedure
351
362
  });
352
363
  }
364
+ const chainAt = new Map(facts.chains.map((entry) => [`${entry.object}@${entry.offset}`, entry]));
365
+ for (const { name, offset } of facts.references) {
366
+ const source = shadowed(name) ? void 0 : body.sources.get(name);
367
+ if (source === void 0) continue;
368
+ const path = chainAt.get(`${name}@${offset}`)?.path ?? [];
369
+ if (source.field === "data") readField(source.procedure, path[0] ?? "all");
370
+ else if (path[0] === "data") readField(source.procedure, path[1] ?? "all");
371
+ else if (path.length === 0) readField(source.procedure, "all");
372
+ }
353
373
  for (const issue of facts.issues) report(placeAt(issue.offset, issue.end), issue.code, issue.message);
354
374
  const seen = /* @__PURE__ */ new Set();
355
375
  const callsFetch = facts.calls.some((call) => call.callee === "fetch");
@@ -570,6 +590,7 @@ function checkCode(tree, defines, pageStatements, findings, hoists, dropped = /*
570
590
  checkBody(def.statements, def.body, body, props);
571
591
  }
572
592
  return {
593
+ fields: Object.fromEntries([...dataFields].map(([procedure, read]) => [procedure, read === "all" ? "all" : [...read].toSorted()])),
573
594
  procedures: procedures.toSorted((a, b) => a.line - b.line),
574
595
  reads
575
596
  };
package/dist/compile.d.ts CHANGED
@@ -2,7 +2,7 @@ import { OffsetMap } from "./offsets.js";
2
2
  import { ExprNode, PropValue, Statement, TextNode } from "./ast.js";
3
3
  import { CompileCatalog } from "./spec.js";
4
4
  import { ProgramOutput } from "./codegen.js";
5
- import { DataRead, ProcedureUse } from "./check-code.js";
5
+ import { DataFields, DataRead, ProcedureUse } from "./check-code.js";
6
6
  import { Diagnostic, Severity } from "@jigs.design/protocol";
7
7
  //#region src/compile.d.ts
8
8
  type DiagnosticCode = "coerced" | "handle_field" | "hook_placement" | "invalid_control" | "invalid_define" | "invalid_expression" | "invalid_literal" | "invalid_statement" | "missing_declarations" | "missing_prop" | "mutate_in_render" | "outer_reference" | "query_options" | "repaired" | "shadows_library" | "unclosed" | "undefined_compare" | "undefined_reference" | "unexpected_children" | "unknown_component" | "unknown_prop" | "unstable_input" | "unsupported_syntax" | "use_before_declare";
@@ -145,6 +145,11 @@ export interface CompileOptions {
145
145
  export interface CompileResult {
146
146
  defines: ReadonlyArray<CompiledDefine>;
147
147
  diagnostics: Array<Diagnostic$1>;
148
+ /**
149
+ * The top-level fields of each procedure's data the document and its
150
+ * defines read, or `"all"` where the data is used whole (`DataFields`).
151
+ */
152
+ fields: DataFields;
148
153
  /** The jigs this document was compiled against. */
149
154
  library: ReadonlyMap<string, CompiledDefine>;
150
155
  output: ProgramOutput;
package/dist/compile.js CHANGED
@@ -850,6 +850,7 @@ function compileDocument(source, library, components) {
850
850
  findings.sort((a, b) => a.line - b.line);
851
851
  return {
852
852
  defines: docDefines,
853
+ fields: uses.fields,
853
854
  findings,
854
855
  library,
855
856
  output: generated.output,
@@ -958,6 +959,7 @@ function compileJigs(source, options) {
958
959
  if (problems(fixed.findings) !== problems(result.findings) - covered) return withDiagnostics(result, source, result.findings);
959
960
  return withDiagnostics({
960
961
  ...fixed,
962
+ fields: result.fields,
961
963
  procedures: result.procedures,
962
964
  reads: result.reads
963
965
  }, source, result.findings.map((finding) => finding.fix !== void 0 && patched.applied.has(finding.fix) ? {
package/dist/index.d.ts CHANGED
@@ -3,10 +3,10 @@ import { JigsNode, Statement } from "./ast.js";
3
3
  import { CompileCatalog, ComponentSpec, PropSpec } from "./spec.js";
4
4
  import { ProgramOutput } from "./codegen.js";
5
5
  import { CompileOptions, CompileResult, CompiledDefine, Diagnostic, Jig, Library, Program, RenderNode, compileJigs, compileLibrary } from "./compile.js";
6
- import { DataRead, ELEMENT, ProcedureUse } from "./check-code.js";
6
+ import { DataFields, DataRead, ELEMENT, ProcedureUse } from "./check-code.js";
7
7
  import { Hoisted, hoistDeclarations } from "./hoist.js";
8
8
  import { parseJigs } from "./parse.js";
9
9
  import { nearest } from "./suggest.js";
10
10
  import { jigSignature } from "./signature.js";
11
11
  import { Edit, EditFailure, EditFailureReason, SEARCH_MARKER, applyEdits, editBreakage, isEditReply, parseEdits } from "./patch.js";
12
- export { type CompileCatalog, type CompileOptions, type CompileResult, type CompiledDefine, type ComponentSpec, type DataRead, type Diagnostic, ELEMENT, type Edit, type EditFailure, type EditFailureReason, type Hoisted, type Jig, type JigsNode, type Library, type ProcedureUse, type Program, type ProgramOutput, type PropSpec, type RenderNode, SEARCH_MARKER, type Statement, applyEdits, columnAt, compileJigs, compileLibrary, editBreakage, hoistDeclarations, isEditReply, jigSignature, lineAt, nearest, parseEdits, parseJigs, rangeIn, spanIn };
12
+ export { type CompileCatalog, type CompileOptions, type CompileResult, type CompiledDefine, type ComponentSpec, type DataFields, type DataRead, type Diagnostic, ELEMENT, type Edit, type EditFailure, type EditFailureReason, type Hoisted, type Jig, type JigsNode, type Library, type ProcedureUse, type Program, type ProgramOutput, type PropSpec, type RenderNode, SEARCH_MARKER, type Statement, applyEdits, columnAt, compileJigs, compileLibrary, editBreakage, hoistDeclarations, isEditReply, jigSignature, lineAt, nearest, parseEdits, parseJigs, rangeIn, spanIn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jigs.design/compiler",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Today's Jigs compiler: parser, checker against a catalog, code generator, jig libraries, and the edit helpers. The v2 rewrite replaces it.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -26,6 +26,6 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "acorn": "8.19.0",
29
- "@jigs.design/protocol": "0.3.1"
29
+ "@jigs.design/protocol": "0.3.3"
30
30
  }
31
31
  }