@jigs.design/compiler 0.3.6 → 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/index.d.ts +2 -2
- package/dist/signature.d.ts +14 -2
- package/dist/signature.js +12 -5
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,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 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 };
|
|
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/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
|
}
|