@kernlang/core 3.1.1 → 3.1.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.
- package/README.md +3 -0
- package/dist/codegen-core.d.ts +10 -2
- package/dist/codegen-core.js +128 -227
- package/dist/codegen-core.js.map +1 -1
- package/dist/concepts.d.ts +12 -2
- package/dist/concepts.js.map +1 -1
- package/dist/config.js +2 -2
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/parser.d.ts +13 -0
- package/dist/parser.js +152 -41
- package/dist/parser.js.map +1 -1
- package/dist/spec.d.ts +3 -3
- package/dist/spec.js +5 -3
- package/dist/spec.js.map +1 -1
- package/dist/template-engine.js +9 -5
- package/dist/template-engine.js.map +1 -1
- package/dist/types.d.ts +22 -0
- package/dist/utils.d.ts +9 -1
- package/dist/utils.js +63 -1
- package/dist/utils.js.map +1 -1
- package/package.json +10 -1
package/dist/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { IRNode } from './types.js';
|
|
1
|
+
import type { IRNode, DiagnosticOutcome, TranspileDiagnostic } from './types.js';
|
|
2
2
|
export declare function countTokens(text: string): number;
|
|
3
3
|
export declare function serializeIR(node: IRNode, indent?: string): string;
|
|
4
4
|
export declare function camelKey(text: string): string;
|
|
@@ -10,3 +10,11 @@ export declare function escapeJsxAttr(s: string): string;
|
|
|
10
10
|
export declare function escapeJsString(s: string): string;
|
|
11
11
|
/** @deprecated Use escapeJsxText, escapeJsxAttr, or escapeJsString */
|
|
12
12
|
export declare function escapeJsx(s: string): string;
|
|
13
|
+
export type AccountedEntry = {
|
|
14
|
+
outcome: DiagnosticOutcome;
|
|
15
|
+
reason?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Mark a node (and optionally all its descendants) as accounted for in the tracking map. */
|
|
18
|
+
export declare function accountNode(map: Map<IRNode, AccountedEntry>, node: IRNode, outcome: DiagnosticOutcome, reason?: string, recursive?: boolean): void;
|
|
19
|
+
/** Build diagnostics by diffing all IR nodes against the accounted map. Root-cause-only reporting. */
|
|
20
|
+
export declare function buildDiagnostics(root: IRNode, accounted: Map<IRNode, AccountedEntry>, target: string): TranspileDiagnostic[];
|
package/dist/utils.js
CHANGED
|
@@ -7,7 +7,9 @@ export function serializeIR(node, indent = '') {
|
|
|
7
7
|
for (const [k, v] of Object.entries(props)) {
|
|
8
8
|
if (k === 'styles' || k === 'pseudoStyles' || k === 'themeRefs')
|
|
9
9
|
continue;
|
|
10
|
-
|
|
10
|
+
const sv = String(v);
|
|
11
|
+
const needsQuote = typeof v === 'string' && (sv.includes(' ') || sv.includes('"'));
|
|
12
|
+
line += ` ${k}=${needsQuote ? `"${sv.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"` : sv}`;
|
|
11
13
|
}
|
|
12
14
|
if (props.styles) {
|
|
13
15
|
const pairs = Object.entries(props.styles)
|
|
@@ -44,6 +46,7 @@ export function escapeJsxAttr(s) {
|
|
|
44
46
|
return s
|
|
45
47
|
.replace(/&/g, '&')
|
|
46
48
|
.replace(/"/g, '"')
|
|
49
|
+
.replace(/'/g, ''')
|
|
47
50
|
.replace(/</g, '<')
|
|
48
51
|
.replace(/>/g, '>');
|
|
49
52
|
}
|
|
@@ -52,6 +55,9 @@ export function escapeJsString(s) {
|
|
|
52
55
|
return s
|
|
53
56
|
.replace(/\\/g, '\\\\')
|
|
54
57
|
.replace(/'/g, "\\'")
|
|
58
|
+
.replace(/"/g, '\\"')
|
|
59
|
+
.replace(/`/g, '\\`')
|
|
60
|
+
.replace(/\$/g, '\\$')
|
|
55
61
|
.replace(/\n/g, '\\n')
|
|
56
62
|
.replace(/\r/g, '\\r');
|
|
57
63
|
}
|
|
@@ -59,4 +65,60 @@ export function escapeJsString(s) {
|
|
|
59
65
|
export function escapeJsx(s) {
|
|
60
66
|
return escapeJsxText(s);
|
|
61
67
|
}
|
|
68
|
+
/** Mark a node (and optionally all its descendants) as accounted for in the tracking map. */
|
|
69
|
+
export function accountNode(map, node, outcome, reason, recursive = false) {
|
|
70
|
+
map.set(node, { outcome, reason });
|
|
71
|
+
if (recursive && node.children) {
|
|
72
|
+
for (const child of node.children) {
|
|
73
|
+
accountNode(map, child, outcome, reason, true);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Build diagnostics by diffing all IR nodes against the accounted map. Root-cause-only reporting. */
|
|
78
|
+
export function buildDiagnostics(root, accounted, target) {
|
|
79
|
+
const diagnostics = [];
|
|
80
|
+
function countUnaccountedDescendants(node) {
|
|
81
|
+
let count = 0;
|
|
82
|
+
for (const child of node.children || []) {
|
|
83
|
+
if (!accounted.has(child)) {
|
|
84
|
+
count += 1 + countUnaccountedDescendants(child);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return count;
|
|
88
|
+
}
|
|
89
|
+
function walk(node, parentUnsupported) {
|
|
90
|
+
const entry = accounted.get(node);
|
|
91
|
+
if (entry) {
|
|
92
|
+
if (entry.outcome !== 'expressed') {
|
|
93
|
+
diagnostics.push({
|
|
94
|
+
nodeType: node.type,
|
|
95
|
+
outcome: entry.outcome,
|
|
96
|
+
target,
|
|
97
|
+
loc: node.loc ? { line: node.loc.line, col: node.loc.col } : undefined,
|
|
98
|
+
reason: entry.reason,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
for (const child of node.children || [])
|
|
102
|
+
walk(child, false);
|
|
103
|
+
}
|
|
104
|
+
else if (parentUnsupported) {
|
|
105
|
+
for (const child of node.children || [])
|
|
106
|
+
walk(child, true);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
const lost = countUnaccountedDescendants(node);
|
|
110
|
+
diagnostics.push({
|
|
111
|
+
nodeType: node.type,
|
|
112
|
+
outcome: 'unsupported',
|
|
113
|
+
target,
|
|
114
|
+
loc: node.loc ? { line: node.loc.line, col: node.loc.col } : undefined,
|
|
115
|
+
childrenLost: lost || undefined,
|
|
116
|
+
});
|
|
117
|
+
for (const child of node.children || [])
|
|
118
|
+
walk(child, true);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
walk(root, false);
|
|
122
|
+
return diagnostics;
|
|
123
|
+
}
|
|
62
124
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,MAAM,GAAG,EAAE;IACnD,IAAI,IAAI,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;IAC/B,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,cAAc,IAAI,CAAC,KAAK,WAAW;YAAE,SAAS;QAC1E,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,MAAM,GAAG,EAAE;IACnD,IAAI,IAAI,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC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AAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;IAED,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAClB,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kernlang/core",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "Kern core — parser, types, spec, config, style engines, codegen",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -14,6 +14,15 @@
|
|
|
14
14
|
"files": [
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
|
+
"keywords": [
|
|
18
|
+
"kern",
|
|
19
|
+
"llm",
|
|
20
|
+
"parser",
|
|
21
|
+
"transpiler",
|
|
22
|
+
"ir",
|
|
23
|
+
"codegen",
|
|
24
|
+
"ai"
|
|
25
|
+
],
|
|
17
26
|
"license": "AGPL-3.0",
|
|
18
27
|
"repository": {
|
|
19
28
|
"type": "git",
|