@jigs.design/compiler 0.3.5 → 0.3.7
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 +22 -0
- package/dist/compile.js +57 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/signature.d.ts +14 -2
- package/dist/signature.js +12 -5
- package/package.json +2 -2
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
|
-
import { jigSignature } from "./signature.js";
|
|
10
|
+
import { SignatureOptions, 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 SignatureOptions, 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/dist/signature.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { Jig } from "./compile.js";
|
|
2
2
|
//#region src/signature.d.ts
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export interface SignatureOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Print a default that is an expression, such as an array of sample
|
|
6
|
+
* rows, as `prop={…}` rather than as written, so the signature stays one
|
|
7
|
+
* line and bounded by its prop names and scalar defaults. Default false.
|
|
8
|
+
*/
|
|
9
|
+
elideExpressions?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* `<statCard label value delta={0} note="">…</statCard>` when the define
|
|
13
|
+
* has a slot. A string default prints as JSON, so it is one line; an
|
|
14
|
+
* expression default prints as written unless `elideExpressions`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function jigSignature(jig: Jig, options?: SignatureOptions): string;
|
|
5
17
|
//#endregion
|
package/dist/signature.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { parseJigs } from "./parse.js";
|
|
2
2
|
//#region src/signature.ts
|
|
3
|
-
|
|
3
|
+
/** What stands in for an expression default when the signature elides them. */
|
|
4
|
+
const ELIDED = "{…}";
|
|
5
|
+
function formatAttr(prop, elideExpressions) {
|
|
4
6
|
if (prop.shorthand === true) return prop.name;
|
|
5
7
|
if (prop.value.kind === "literal") return typeof prop.value.value === "string" ? `${prop.name}=${JSON.stringify(prop.value.value)}` : `${prop.name}={${JSON.stringify(prop.value.value)}}`;
|
|
6
|
-
return `${prop.name}={${prop.value.code}}`;
|
|
8
|
+
return elideExpressions ? `${prop.name}=${ELIDED}` : `${prop.name}={${prop.value.code}}`;
|
|
7
9
|
}
|
|
8
10
|
/** A `<slot/>` anywhere in the define's body, ignoring nested defines. */
|
|
9
11
|
function hasSlot(nodes) {
|
|
@@ -13,11 +15,16 @@ function hasSlot(nodes) {
|
|
|
13
15
|
}
|
|
14
16
|
return false;
|
|
15
17
|
}
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* `<statCard label value delta={0} note="">…</statCard>` when the define
|
|
20
|
+
* has a slot. A string default prints as JSON, so it is one line; an
|
|
21
|
+
* expression default prints as written unless `elideExpressions`.
|
|
22
|
+
*/
|
|
23
|
+
function jigSignature(jig, options) {
|
|
24
|
+
const elide = options?.elideExpressions === true;
|
|
18
25
|
const define = parseJigs(jig.source).children.find((node) => node.type === "element" && node.name === "define");
|
|
19
26
|
if (define === void 0) return `<${jig.name}>`;
|
|
20
|
-
const attrs = define.props.filter((prop) => prop.name !== "name").map((prop) => formatAttr(prop));
|
|
27
|
+
const attrs = define.props.filter((prop) => prop.name !== "name").map((prop) => formatAttr(prop, elide));
|
|
21
28
|
const open = attrs.length === 0 ? `<${jig.name}>` : `<${jig.name} ${attrs.join(" ")}>`;
|
|
22
29
|
return hasSlot(define.children) ? `${open}…</${jig.name}>` : open;
|
|
23
30
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jigs.design/compiler",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
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.
|
|
29
|
+
"@jigs.design/protocol": "0.3.7"
|
|
30
30
|
}
|
|
31
31
|
}
|