@jigs.design/compiler 0.3.5 → 0.3.6

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/dist/compile.d.ts CHANGED
@@ -182,6 +182,28 @@ export interface CompileResult {
182
182
  */
183
183
  tags: ReadonlySet<string>;
184
184
  }
185
+ /** The language's own tags: no component or define may take these names. */
186
+ export declare const RESERVED_TAGS: ReadonlySet<string>;
187
+ /** What `extendLibrary` built, and what it found in each jig. */
188
+ export interface ExtendedLibrary {
189
+ /**
190
+ * Each jig's diagnostics, by name, numbered by its own source. A name
191
+ * here but not in `library` was dropped.
192
+ */
193
+ diagnostics: ReadonlyMap<string, ReadonlyArray<Diagnostic$1>>;
194
+ /** `base`, then each jig that entered, in order. */
195
+ library: Library;
196
+ }
197
+ /**
198
+ * `base` extended by `jigs`, in order, leniently: a jig may use `base`
199
+ * and the jigs before it. Never throws. A jig enters when its source has
200
+ * exactly one `<define>`, of its name, whose name is not already in the
201
+ * library, and none of its findings leave code that cannot run (an
202
+ * `undefined_reference`, an `invalid_statement`, an `unclosed` tag). A
203
+ * jig with other findings, such as an unknown component or prop, enters
204
+ * with what still compiles, and its diagnostics say what was removed.
205
+ */
206
+ export declare function extendLibrary(base: Library, jigs: ReadonlyArray<Jig>, catalog: CompileCatalog): ExtendedLibrary;
185
207
  /**
186
208
  * Compiles `jigs` against `catalog`, in order: a jig may use the ones
187
209
  * before it. Throws when a jig has any diagnostic. Cached per catalog and
package/dist/compile.js CHANGED
@@ -7,6 +7,7 @@ import { parseJigs } from "./parse.js";
7
7
  import { isValidValue } from "./spec.js";
8
8
  import { blockHoists } from "./block-hoist.js";
9
9
  //#region src/compile.ts
10
+ /** The language's own tags: no component or define may take these names. */
10
11
  const RESERVED_TAGS = /* @__PURE__ */ new Set([
11
12
  "define",
12
13
  "each",
@@ -896,6 +897,61 @@ function buildLibrary(list, components) {
896
897
  }
897
898
  return built;
898
899
  }
900
+ /** Findings that leave a define whose code cannot run: it is dropped. */
901
+ const UNRUNNABLE = /* @__PURE__ */ new Set([
902
+ "invalid_statement",
903
+ "unclosed",
904
+ "undefined_reference"
905
+ ]);
906
+ /**
907
+ * `base` extended by `jigs`, in order, leniently: a jig may use `base`
908
+ * and the jigs before it. Never throws. A jig enters when its source has
909
+ * exactly one `<define>`, of its name, whose name is not already in the
910
+ * library, and none of its findings leave code that cannot run (an
911
+ * `undefined_reference`, an `invalid_statement`, an `unclosed` tag). A
912
+ * jig with other findings, such as an unknown component or prop, enters
913
+ * with what still compiles, and its diagnostics say what was removed.
914
+ */
915
+ function extendLibrary(base, jigs, catalog) {
916
+ const built = new Map(base);
917
+ const diagnostics = /* @__PURE__ */ new Map();
918
+ const seen = /* @__PURE__ */ new Set();
919
+ const refuse = (jig, found, message) => {
920
+ diagnostics.set(jig.name, [...found, {
921
+ code: "invalid_define",
922
+ message,
923
+ severity: "error",
924
+ span: { line: 1 }
925
+ }]);
926
+ };
927
+ for (const jig of jigs) {
928
+ if (seen.has(jig.name)) continue;
929
+ seen.add(jig.name);
930
+ if (built.has(jig.name)) {
931
+ refuse(jig, [], `<${jig.name}> is already in the library; this one was dropped`);
932
+ continue;
933
+ }
934
+ const result = compileDocument(jig.source, built, catalog);
935
+ const found = result.findings.map((finding) => toDiagnostic(jig.source, finding));
936
+ const def = result.defines[0];
937
+ if (result.defines.length !== 1 || def?.name !== jig.name) {
938
+ refuse(jig, found, `The source must be one <define name="${jig.name}">; it was dropped`);
939
+ continue;
940
+ }
941
+ diagnostics.set(jig.name, found);
942
+ if (result.findings.some((finding) => finding.severity === "error" && UNRUNNABLE.has(finding.code))) continue;
943
+ built.set(def.name, {
944
+ ...def,
945
+ origin: "library",
946
+ procedures: result.procedures,
947
+ tags: result.tags
948
+ });
949
+ }
950
+ return {
951
+ diagnostics,
952
+ library: built
953
+ };
954
+ }
899
955
  /**
900
956
  * Compiles `jigs` against `catalog`, in order: a jig may use the ones
901
957
  * before it. Throws when a jig has any diagnostic. Cached per catalog and
@@ -983,4 +1039,4 @@ function compileJigs(source, options) {
983
1039
  } : finding));
984
1040
  }
985
1041
  //#endregion
986
- export { compileJigs, compileLibrary };
1042
+ export { RESERVED_TAGS, compileJigs, compileLibrary, extendLibrary };
package/dist/index.d.ts CHANGED
@@ -2,11 +2,11 @@ import { columnAt, lineAt, rangeIn, spanIn } from "./offsets.js";
2
2
  import { JigsNode, Statement } from "./ast.js";
3
3
  import { CompileCatalog, ComponentSpec, PropSpec } from "./spec.js";
4
4
  import { ProgramOutput } from "./codegen.js";
5
- import { CompileOptions, CompileResult, CompiledDefine, Diagnostic, Jig, Library, Program, RenderNode, compileJigs, compileLibrary } from "./compile.js";
5
+ import { CompileOptions, CompileResult, CompiledDefine, Diagnostic, ExtendedLibrary, Jig, Library, Program, RESERVED_TAGS, RenderNode, compileJigs, compileLibrary, extendLibrary } from "./compile.js";
6
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 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 };
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 ExtendedLibrary, type Hoisted, type Jig, type JigsNode, type Library, type ProcedureUse, type Program, type ProgramOutput, type PropSpec, RESERVED_TAGS, type RenderNode, SEARCH_MARKER, type Statement, applyEdits, columnAt, compileJigs, compileLibrary, editBreakage, extendLibrary, hoistDeclarations, isEditReply, jigSignature, lineAt, nearest, parseEdits, parseJigs, rangeIn, spanIn };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { nearest } from "./suggest.js";
3
3
  import { ELEMENT } from "./check-code.js";
4
4
  import { parseJigs } from "./parse.js";
5
5
  import { hoistDeclarations } from "./hoist.js";
6
- import { compileJigs, compileLibrary } from "./compile.js";
6
+ import { RESERVED_TAGS, compileJigs, compileLibrary, extendLibrary } from "./compile.js";
7
7
  import { jigSignature } from "./signature.js";
8
8
  import { SEARCH_MARKER, applyEdits, editBreakage, isEditReply, parseEdits } from "./patch.js";
9
- export { ELEMENT, SEARCH_MARKER, applyEdits, columnAt, compileJigs, compileLibrary, editBreakage, hoistDeclarations, isEditReply, jigSignature, lineAt, nearest, parseEdits, parseJigs, rangeIn, spanIn };
9
+ export { ELEMENT, RESERVED_TAGS, SEARCH_MARKER, applyEdits, columnAt, compileJigs, compileLibrary, editBreakage, extendLibrary, 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.5",
3
+ "version": "0.3.6",
4
4
  "description": "The Jigs compiler: parser, checker against a catalog, code generator, jig libraries, and the edit helpers. It evolves in place, behind the server API.",
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.5"
29
+ "@jigs.design/protocol": "0.3.6"
30
30
  }
31
31
  }