@weave-framework/check 0.2.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aidas Josas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,28 @@
1
+ /**
2
+ * `weave check` core — type-check virtual modules and translate `tsc`
3
+ * diagnostics back to the original `.weave`/`.html`/`.ts` source.
4
+ *
5
+ * All virtual files share one {@link ts.Program} (fast, and lets cross-component
6
+ * imports resolve). A thin compiler-host shim serves each virtual module's text
7
+ * from memory while delegating every other read (node_modules, libs) to disk —
8
+ * so `@weave-framework/runtime` and friends resolve through their normal package exports.
9
+ */
10
+ import type { Virtual } from './emit.js';
11
+ export interface Diagnostic {
12
+ file: string;
13
+ /** 1-based */
14
+ line: number;
15
+ /** 1-based */
16
+ col: number;
17
+ code: number;
18
+ message: string;
19
+ category: 'error' | 'warning' | 'suggestion' | 'message';
20
+ }
21
+ /** Type-check the given virtual modules; returns diagnostics mapped to original source. */
22
+ export declare function runCheck(virtuals: Virtual[]): Diagnostic[];
23
+ /** Translate a character offset into a 1-based line:col within `text`. */
24
+ export declare function offsetToLineCol(text: string, offset: number): {
25
+ line: number;
26
+ col: number;
27
+ };
28
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,IAAI,EAAE,MAAM,CAAC;IACb,cAAc;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAAC;CAC1D;AAgBD,2FAA2F;AAC3F,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,UAAU,EAAE,CA8B1D;AAiDD,0EAA0E;AAC1E,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAa3F"}
package/dist/check.js ADDED
@@ -0,0 +1,103 @@
1
+ /**
2
+ * `weave check` core — type-check virtual modules and translate `tsc`
3
+ * diagnostics back to the original `.weave`/`.html`/`.ts` source.
4
+ *
5
+ * All virtual files share one {@link ts.Program} (fast, and lets cross-component
6
+ * imports resolve). A thin compiler-host shim serves each virtual module's text
7
+ * from memory while delegating every other read (node_modules, libs) to disk —
8
+ * so `@weave-framework/runtime` and friends resolve through their normal package exports.
9
+ */
10
+ import ts from 'typescript';
11
+ const OPTIONS = {
12
+ target: ts.ScriptTarget.ES2022,
13
+ module: ts.ModuleKind.ESNext,
14
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
15
+ lib: ['lib.es2022.d.ts', 'lib.dom.d.ts', 'lib.dom.iterable.d.ts'],
16
+ types: [],
17
+ strict: true,
18
+ noEmit: true,
19
+ skipLibCheck: true,
20
+ allowJs: false,
21
+ };
22
+ const norm = (p) => p.replace(/\\/g, '/').toLowerCase();
23
+ /** Type-check the given virtual modules; returns diagnostics mapped to original source. */
24
+ export function runCheck(virtuals) {
25
+ const byPath = new Map(virtuals.map((v) => [norm(v.path), v]));
26
+ const host = ts.createCompilerHost(OPTIONS, true);
27
+ const getSourceFile = host.getSourceFile.bind(host);
28
+ const readFile = host.readFile.bind(host);
29
+ const fileExists = host.fileExists.bind(host);
30
+ host.getSourceFile = (fileName, languageVersion, onError, shouldCreate) => {
31
+ const v = byPath.get(norm(fileName));
32
+ if (v)
33
+ return ts.createSourceFile(fileName, v.text, languageVersion, true);
34
+ return getSourceFile(fileName, languageVersion, onError, shouldCreate);
35
+ };
36
+ host.readFile = (fileName) => byPath.get(norm(fileName))?.text ?? readFile(fileName);
37
+ host.fileExists = (fileName) => byPath.has(norm(fileName)) || fileExists(fileName);
38
+ const program = ts.createProgram(virtuals.map((v) => v.path), OPTIONS, host);
39
+ const raw = [];
40
+ for (const v of virtuals) {
41
+ const sf = program.getSourceFile(v.path);
42
+ if (!sf)
43
+ continue;
44
+ raw.push(...program.getSyntacticDiagnostics(sf), ...program.getSemanticDiagnostics(sf));
45
+ }
46
+ return raw.map((d) => mapDiagnostic(d, byPath));
47
+ }
48
+ function mapDiagnostic(d, byPath) {
49
+ const message = ts.flattenDiagnosticMessageText(d.messageText, '\n');
50
+ const category = categoryName(d.category);
51
+ if (!d.file || d.start === undefined) {
52
+ return { file: '(global)', line: 0, col: 0, code: d.code, message, category };
53
+ }
54
+ const { line, character } = d.file.getLineAndCharacterOfPosition(d.start); // 0-based
55
+ const v = byPath.get(norm(d.file.fileName));
56
+ if (!v) {
57
+ // An error surfaced in a real dependency — report it as-is.
58
+ return { file: d.file.fileName, line: line + 1, col: character + 1, code: d.code, message, category };
59
+ }
60
+ const vLine = line + 1; // 1-based virtual line
61
+ const offset = v.templateMap.get(vLine);
62
+ if (offset !== undefined) {
63
+ const { line: l, col } = offsetToLineCol(v.templateText, offset);
64
+ return { file: v.templateFile, line: l, col, code: d.code, message, category };
65
+ }
66
+ if (vLine <= v.scriptLineCount) {
67
+ return {
68
+ file: v.scriptFile,
69
+ line: v.scriptLine + (vLine - 1) + 1,
70
+ col: character + 1,
71
+ code: d.code,
72
+ message,
73
+ category,
74
+ };
75
+ }
76
+ // A generated scaffold line — should not carry user errors; surface it plainly.
77
+ return { file: v.templateFile, line: 1, col: 1, code: d.code, message: `[generated] ${message}`, category };
78
+ }
79
+ function categoryName(c) {
80
+ switch (c) {
81
+ case ts.DiagnosticCategory.Error: return 'error';
82
+ case ts.DiagnosticCategory.Warning: return 'warning';
83
+ case ts.DiagnosticCategory.Suggestion: return 'suggestion';
84
+ default: return 'message';
85
+ }
86
+ }
87
+ /** Translate a character offset into a 1-based line:col within `text`. */
88
+ export function offsetToLineCol(text, offset) {
89
+ let line = 1;
90
+ let col = 1;
91
+ const end = Math.min(offset, text.length);
92
+ for (let i = 0; i < end; i++) {
93
+ if (text[i] === '\n') {
94
+ line++;
95
+ col = 1;
96
+ }
97
+ else {
98
+ col++;
99
+ }
100
+ }
101
+ return { line, col };
102
+ }
103
+ //# sourceMappingURL=check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.js","sourceRoot":"","sources":["../src/check.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAc5B,MAAM,OAAO,GAAuB;IAClC,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM;IAC9B,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC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,CAAC;QACrC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACrB,IAAI,EAAE,CAAC;YACP,GAAG,GAAG,CAAC,CAAC;QACV,CAAC;aAAM,CAAC;YACN,GAAG,EAAE,CAAC;QACR,CAAC;IACH,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AACvB,CAAC"}
package/dist/emit.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Virtual `.ts` generation — the heart of M8, shared by `weave check` and the
3
+ * M9 language server.
4
+ *
5
+ * For each component we synthesize a never-bundled TypeScript module: the user's
6
+ * verbatim `setup` script, followed by a `__weave__()` harness that places every
7
+ * template expression in a type-checked position against `ReturnType<typeof
8
+ * setup>` (exposed as `__ctx`). Template locals (`@for` item + `$index`…, `@let`,
9
+ * `@if … as x`) become real lexical bindings, so TypeScript scopes and narrows
10
+ * them exactly as the runtime does.
11
+ *
12
+ * Two source maps come out of the same emit:
13
+ * - `templateMap` (line → source offset) — what `weave check` uses to translate a
14
+ * `tsc` diagnostic line back to a `.weave`/`.html` line:col.
15
+ * - `mappings` (char-precise verbatim runs) — what the Volar language server uses
16
+ * to drive hover / go-to-definition / rename and to surface diagnostics at the
17
+ * exact template span. Built from `rewrite`'s segment maps.
18
+ */
19
+ /**
20
+ * A verbatim run linking the generated module to its source, char-precise. The
21
+ * `source` tag selects which file `sourceOffset` indexes into (a SFC keeps both
22
+ * in the same file; the separate form splits script ↔ template across two).
23
+ */
24
+ export interface WeaveMapping {
25
+ /** offset into the generated `text` */
26
+ generatedOffset: number;
27
+ /** offset into the mapped source file (see `source`) */
28
+ sourceOffset: number;
29
+ /** run length (same on both sides) */
30
+ length: number;
31
+ /** `script` → `scriptFile`/`scriptText`; `template` → `templateFile`/`templateText` */
32
+ source: 'script' | 'template';
33
+ }
34
+ /** A generated virtual module plus everything needed to map its diagnostics back. */
35
+ export interface Virtual {
36
+ /** Virtual module path (drives module resolution); never written to disk. */
37
+ path: string;
38
+ /** The generated TypeScript source. */
39
+ text: string;
40
+ /** File reported for template-region errors. */
41
+ templateFile: string;
42
+ /** Offset-faithful template text (template `sourceOffset`s index into this). */
43
+ templateText: string;
44
+ /** virtual line (1-based) → source offset into `templateText`. */
45
+ templateMap: Map<number, number>;
46
+ /** File reported for script-region (user TS) errors. */
47
+ scriptFile: string;
48
+ /** Script source text (script `sourceOffset`s index into this). */
49
+ scriptText: string;
50
+ /** 0-based line in `scriptFile` where the embedded script begins. */
51
+ scriptLine: number;
52
+ /** Number of leading virtual lines occupied by the embedded script. */
53
+ scriptLineCount: number;
54
+ /** Char-precise generated↔source runs for editor tooling. */
55
+ mappings: WeaveMapping[];
56
+ }
57
+ /** Build a virtual module for a `.weave` SFC. */
58
+ export declare function buildVirtualSfc(filePath: string, source: string): Virtual;
59
+ /** Build a virtual module for the separate-file form (`name.ts` + `name.html`). */
60
+ export declare function buildVirtualSeparate(tsPath: string, tsSource: string, htmlPath: string, htmlSource: string): Virtual;
61
+ //# sourceMappingURL=emit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.d.ts","sourceRoot":"","sources":["../src/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAyBH;;;;GAIG;AACH,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,eAAe,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,YAAY,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,uFAAuF;IACvF,MAAM,EAAE,QAAQ,GAAG,UAAU,CAAC;CAC/B;AAED,qFAAqF;AACrF,MAAM,WAAW,OAAO;IACtB,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,gDAAgD;IAChD,YAAY,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,YAAY,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,wDAAwD;IACxD,UAAU,EAAE,MAAM,CAAC;IACnB,mEAAmE;IACnE,UAAU,EAAE,MAAM,CAAC;IACnB,qEAAqE;IACrE,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,eAAe,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B;AA0BD,iDAAiD;AACjD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAkBzE;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,OAAO,CAmBT"}
package/dist/emit.js ADDED
@@ -0,0 +1,380 @@
1
+ /**
2
+ * Virtual `.ts` generation — the heart of M8, shared by `weave check` and the
3
+ * M9 language server.
4
+ *
5
+ * For each component we synthesize a never-bundled TypeScript module: the user's
6
+ * verbatim `setup` script, followed by a `__weave__()` harness that places every
7
+ * template expression in a type-checked position against `ReturnType<typeof
8
+ * setup>` (exposed as `__ctx`). Template locals (`@for` item + `$index`…, `@let`,
9
+ * `@if … as x`) become real lexical bindings, so TypeScript scopes and narrows
10
+ * them exactly as the runtime does.
11
+ *
12
+ * Two source maps come out of the same emit:
13
+ * - `templateMap` (line → source offset) — what `weave check` uses to translate a
14
+ * `tsc` diagnostic line back to a `.weave`/`.html` line:col.
15
+ * - `mappings` (char-precise verbatim runs) — what the Volar language server uses
16
+ * to drive hover / go-to-definition / rename and to surface diagnostics at the
17
+ * exact template span. Built from `rewrite`'s segment maps.
18
+ */
19
+ import { parseTemplate, parseSfcLoc, inferCtxNames, rewrite, } from '@weave-framework/compiler';
20
+ const FOR_VARS = ['$index', '$count', '$first', '$last', '$even', '$odd'];
21
+ const HAS_SETUP = /export\s+(?:async\s+)?function\s+setup\b|export\s+(?:const|let|var)\s+setup\b/;
22
+ /** A capitalized tag (`<TaskCard>`) is a child component, not a DOM element. */
23
+ const isComponentTag = (tag) => /^[A-Z]/.test(tag);
24
+ /** Object-literal key: bare when a valid identifier, else quoted. */
25
+ const propKey = (name) => /^[A-Za-z_$][\w$]*$/.test(name) ? name : JSON.stringify(name);
26
+ /** Build a virtual module for a `.weave` SFC. */
27
+ export function buildVirtualSfc(filePath, source) {
28
+ const loc = parseSfcLoc(source);
29
+ const nodes = parseTemplate(loc.template);
30
+ const body = emit(nodes, new Set(inferCtxNames(nodes)));
31
+ const hasSetup = HAS_SETUP.test(loc.script ?? '');
32
+ const asm = assemble(loc.script, hasSetup, body, loc.scriptOffset);
33
+ return {
34
+ path: filePath + '.ts',
35
+ text: asm.text,
36
+ templateFile: filePath,
37
+ templateText: loc.template,
38
+ templateMap: asm.templateMap,
39
+ scriptFile: filePath,
40
+ scriptText: source,
41
+ scriptLine: loc.scriptLine,
42
+ scriptLineCount: asm.scriptLineCount,
43
+ mappings: asm.mappings,
44
+ };
45
+ }
46
+ /** Build a virtual module for the separate-file form (`name.ts` + `name.html`). */
47
+ export function buildVirtualSeparate(tsPath, tsSource, htmlPath, htmlSource) {
48
+ const nodes = parseTemplate(htmlSource);
49
+ const body = emit(nodes, new Set(inferCtxNames(nodes)));
50
+ const asm = assemble(tsSource, HAS_SETUP.test(tsSource), body, 0);
51
+ return {
52
+ // Live at the real `.ts` path (shadowing disk) so a parent's `import Foo from
53
+ // './foo'` resolves to this virtual — which carries the synthesized typed
54
+ // default export — instead of the on-disk source (which has only `setup`).
55
+ path: tsPath,
56
+ text: asm.text,
57
+ templateFile: htmlPath,
58
+ templateText: htmlSource,
59
+ templateMap: asm.templateMap,
60
+ scriptFile: tsPath,
61
+ scriptText: tsSource,
62
+ scriptLine: 0,
63
+ scriptLineCount: asm.scriptLineCount,
64
+ mappings: asm.mappings,
65
+ };
66
+ }
67
+ /* ──────────── harness body emitter ──────────── */
68
+ function emit(nodes, ctx) {
69
+ const lines = [];
70
+ let awaitN = 0; // unique source-binding names for `@await` type-queries
71
+ let propsN = 0; // unique names for child-component prop-check objects
72
+ // A plain scaffolding line (no source mapping), optionally pinned to a source
73
+ // offset for the legacy line→offset `templateMap`.
74
+ const push = (text, offset) => {
75
+ lines.push({ text, offset });
76
+ };
77
+ // ctx names → `__ctx.name`; template locals → the bare lexical name.
78
+ const scopeOf = (locals) => {
79
+ const s = new Map();
80
+ for (const n of ctx)
81
+ s.set(n, { kind: 'ctx' });
82
+ for (const n of locals)
83
+ s.set(n, { kind: 'local' });
84
+ return s;
85
+ };
86
+ // A chainable line builder: `lit()` appends scaffolding text, `expr()` appends a
87
+ // rewritten template expression and records its char-precise src↔gen segments
88
+ // (offset by where the expression landed in the line). `push()` flushes the line.
89
+ const mk = () => {
90
+ let text = '';
91
+ const segs = [];
92
+ const api = {
93
+ lit(s) {
94
+ text += s;
95
+ return api;
96
+ },
97
+ expr(srcOffset, exprStr, locals) {
98
+ const r = rewrite(exprStr, scopeOf(locals), '__ctx');
99
+ // Length-preserving flatten keeps the statement single-line (so the legacy
100
+ // line map stays valid) without shifting any segment offset.
101
+ const code = r.code.replace(/[\r\n]/g, ' ');
102
+ const base = text.length;
103
+ if (srcOffset !== undefined) {
104
+ for (const s of r.segments)
105
+ segs.push({ col: base + s.gen, src: srcOffset + s.src, len: s.len });
106
+ }
107
+ text += code;
108
+ return api;
109
+ },
110
+ push(offset) {
111
+ lines.push({ text, offset, segs });
112
+ },
113
+ };
114
+ return api;
115
+ };
116
+ // A non-static attribute on a DOM element (or a directive on a component):
117
+ // place its expression in a type-checked position. `use:`/`transition:` verify
118
+ // the referenced fn is callable with the runtime's (Element, arg) pair.
119
+ const emitAttr = (attr, locals) => {
120
+ if (attr.type === 'static')
121
+ return;
122
+ if (attr.type === 'use' || attr.type === 'transition') {
123
+ const at = attr.nameOffset ?? attr.offset;
124
+ const b = mk().lit(' (').expr(at, attr.name, locals);
125
+ if (attr.expr !== undefined)
126
+ b.lit(')(null as any, ').expr(attr.offset, attr.expr, locals).lit(');');
127
+ else
128
+ b.lit(')(null as any);');
129
+ b.push(at);
130
+ return;
131
+ }
132
+ mk().lit(' void (').expr(attr.offset, attr.expr, locals).lit(');').push(attr.offset);
133
+ };
134
+ // A child component `<Tag prop={expr} …>`: assemble its data props into one typed
135
+ // object literal checked against the child's prop contract (the first parameter of
136
+ // its `setup`, exposed via the generated default export). Required/excess/mismatched
137
+ // props all surface, each pinned to its own attribute. Events stay outside the
138
+ // contract (the runtime wires them) but their handler bodies are still checked.
139
+ const emitComponent = (node, locals) => {
140
+ const dataProps = [];
141
+ for (const attr of node.attrs) {
142
+ if (attr.type === 'static') {
143
+ if (attr.name === 'slot')
144
+ continue; // slot marker, stripped by codegen
145
+ dataProps.push({ key: attr.name, staticVal: JSON.stringify(attr.value) });
146
+ }
147
+ else if (attr.type === 'attr') {
148
+ dataProps.push({ key: attr.name, expr: attr.expr, srcOffset: attr.offset });
149
+ }
150
+ else {
151
+ emitAttr(attr, locals); // events / stray directives — checked, not part of props
152
+ }
153
+ }
154
+ const id = `__props${propsN++}`;
155
+ const anchor = dataProps.find((p) => p.srcOffset !== undefined)?.srcOffset;
156
+ // The tag name is emitted as a *mapped* expression (not scaffolding), so the
157
+ // `<Component>` tag itself supports go-to-definition into the `.ts` import and an
158
+ // unknown tag surfaces "Cannot find name 'X'" pinned to the tag span.
159
+ mk()
160
+ .lit(` const ${id}: NonNullable<Parameters<typeof `)
161
+ .expr(node.tagOffset, node.tag, locals)
162
+ .lit(`>[0]> = {`)
163
+ .push(anchor ?? node.tagOffset);
164
+ for (const p of dataProps) {
165
+ if (p.expr !== undefined) {
166
+ mk().lit(` ${propKey(p.key)}: (`).expr(p.srcOffset, p.expr, locals).lit('),').push(p.srcOffset);
167
+ }
168
+ else {
169
+ push(` ${propKey(p.key)}: (${p.staticVal}),`);
170
+ }
171
+ }
172
+ push(` };`);
173
+ push(` void ${id};`);
174
+ };
175
+ const walk = (list, locals) => {
176
+ let scope = locals; // `@let` extends scope for following siblings
177
+ // Hoist sibling snippets to typed arrows first (params: any), so a `@render`
178
+ // call type-checks the snippet name/arity regardless of declaration order.
179
+ const snippets = list.filter((n) => n.type === 'snippet');
180
+ if (snippets.length) {
181
+ scope = new Set(scope);
182
+ for (const s of snippets)
183
+ scope.add(s.name);
184
+ for (const s of snippets) {
185
+ const params = s.params.map((p) => `${p}: any`).join(', ');
186
+ push(` const ${s.name} = (${params}): void => {`);
187
+ const inner = new Set(scope);
188
+ for (const p of s.params)
189
+ inner.add(p);
190
+ walk(s.children, inner);
191
+ push(` };`);
192
+ }
193
+ }
194
+ for (const node of list) {
195
+ switch (node.type) {
196
+ case 'snippet':
197
+ break; // already emitted above
198
+ case 'render':
199
+ mk().lit(' void (').expr(node.exprOffset, node.expr, scope).lit(');').push(node.exprOffset);
200
+ break;
201
+ case 'key':
202
+ mk().lit(' void (').expr(node.exprOffset, node.expr, scope).lit(');').push(node.exprOffset);
203
+ walk(node.children, scope);
204
+ break;
205
+ case 'text':
206
+ break;
207
+ case 'interp':
208
+ mk().lit(' void (').expr(node.offset, node.expr, scope).lit(');').push(node.offset);
209
+ break;
210
+ case 'let': {
211
+ mk().lit(` const ${node.name} = (`).expr(node.exprOffset, node.expr, scope).lit(');').push(node.exprOffset);
212
+ scope = new Set(scope).add(node.name);
213
+ break;
214
+ }
215
+ case 'element':
216
+ if (isComponentTag(node.tag)) {
217
+ emitComponent(node, scope);
218
+ walk(node.children, scope); // slot content is authored in the parent scope
219
+ break;
220
+ }
221
+ for (const attr of node.attrs)
222
+ emitAttr(attr, scope);
223
+ walk(node.children, scope);
224
+ break;
225
+ case 'if':
226
+ for (const br of node.branches) {
227
+ if (br.cond !== undefined) {
228
+ mk().lit(' if (').expr(br.condOffset, br.cond, scope).lit(') {').push(br.condOffset);
229
+ }
230
+ else {
231
+ push(` {`);
232
+ }
233
+ let inner = scope;
234
+ if (br.alias && br.cond !== undefined) {
235
+ mk().lit(` const ${br.alias} = (`).expr(br.condOffset, br.cond, scope).lit(');').push(br.condOffset);
236
+ inner = new Set(scope).add(br.alias);
237
+ }
238
+ walk(br.children, inner);
239
+ push(` }`);
240
+ }
241
+ break;
242
+ case 'for': {
243
+ mk().lit(` for (const ${node.item} of (`).expr(node.listOffset, node.list, scope).lit(')) {').push(node.listOffset);
244
+ push(` const $index: number = 0, $count: number = 0, ` +
245
+ `$first: boolean = true, $last: boolean = true, ` +
246
+ `$even: boolean = true, $odd: boolean = true;`);
247
+ const inner = new Set(scope).add(node.item);
248
+ for (const v of FOR_VARS)
249
+ inner.add(v);
250
+ if (node.track)
251
+ mk().lit(' void (').expr(node.trackOffset, node.track, inner).lit(');').push(node.trackOffset);
252
+ walk(node.children, inner);
253
+ push(` }`);
254
+ if (node.empty)
255
+ walk(node.empty, scope);
256
+ break;
257
+ }
258
+ case 'switch': {
259
+ mk().lit(' switch (').expr(node.exprOffset, node.expr, scope).lit(') {').push(node.exprOffset);
260
+ for (const c of node.cases) {
261
+ if (c.test !== undefined) {
262
+ mk().lit(' case ').expr(c.testOffset, c.test, scope).lit(': {').push(c.testOffset);
263
+ }
264
+ else {
265
+ push(` default: {`);
266
+ }
267
+ walk(c.children, scope);
268
+ push(` break; }`);
269
+ }
270
+ push(` }`);
271
+ break;
272
+ }
273
+ case 'defer': {
274
+ if (node.trigger.kind === 'when') {
275
+ mk().lit(' void (').expr(node.trigger.exprOffset, node.trigger.expr, scope).lit(');').push(node.trigger.exprOffset);
276
+ }
277
+ else if (node.trigger.kind === 'timer') {
278
+ mk().lit(' void (').expr(node.trigger.msOffset, node.trigger.ms, scope).lit(');').push(node.trigger.msOffset);
279
+ }
280
+ walk(node.children, scope);
281
+ if (node.placeholder)
282
+ walk(node.placeholder, scope);
283
+ break;
284
+ }
285
+ case 'await': {
286
+ // Bind the source to a const so a `typeof` type-query has an entity name
287
+ // (`typeof (expr)` is a syntax error in a type position) — and so the source
288
+ // expression itself is type-checked. Only needed when `@then` binds an alias.
289
+ let srcVar = '';
290
+ if (node.then?.alias) {
291
+ srcVar = `__await${awaitN++}`;
292
+ mk().lit(` const ${srcVar} = (`).expr(node.exprOffset, node.expr, scope).lit(');').push(node.exprOffset);
293
+ }
294
+ else {
295
+ mk().lit(' void (').expr(node.exprOffset, node.expr, scope).lit(');').push(node.exprOffset);
296
+ }
297
+ if (node.pending)
298
+ walk(node.pending, scope);
299
+ if (node.then) {
300
+ push(` {`);
301
+ let inner = scope;
302
+ if (node.then.alias) {
303
+ // the resolved value: a resource's data type or the awaited Promise type
304
+ push(` const ${node.then.alias}: __WeaveAwaited<typeof ${srcVar}> = undefined as any;`, node.exprOffset);
305
+ inner = new Set(scope).add(node.then.alias);
306
+ }
307
+ walk(node.then.children, inner);
308
+ push(` }`);
309
+ }
310
+ if (node.catch) {
311
+ push(` {`);
312
+ let inner = scope;
313
+ if (node.catch.alias) {
314
+ push(` const ${node.catch.alias}: unknown = undefined;`);
315
+ inner = new Set(scope).add(node.catch.alias);
316
+ }
317
+ walk(node.catch.children, inner);
318
+ push(` }`);
319
+ }
320
+ break;
321
+ }
322
+ }
323
+ }
324
+ };
325
+ walk(nodes, new Set());
326
+ return lines;
327
+ }
328
+ /* ──────────── assembly + line bookkeeping ──────────── */
329
+ function assemble(script, hasSetup, body, scriptBaseOffset) {
330
+ const out = [];
331
+ const scriptLines = script ? script.split('\n') : [];
332
+ for (const l of scriptLines)
333
+ out.push(l);
334
+ out.push('');
335
+ out.push(hasSetup
336
+ ? 'type __WeaveCtx = ReturnType<typeof setup>;'
337
+ : 'type __WeaveCtx = Record<string, any>;');
338
+ out.push('declare const __ctx: __WeaveCtx;');
339
+ // `@await (src)` resolved-value type: a resource's data type, else the awaited Promise.
340
+ out.push('type __WeaveAwaited<S> = S extends { data: () => infer D } ? NonNullable<D> : Awaited<S>;');
341
+ // A child component's prop contract = the first parameter of its `setup`.
342
+ out.push('type __WeavePropsOf<F> = F extends (props: infer P, ...rest: any[]) => any ? P : Record<string, never>;');
343
+ out.push('function __weave__(): void {');
344
+ const bodyBase = out.length; // out index of body[0]
345
+ const templateMap = new Map();
346
+ body.forEach((ln, i) => {
347
+ out.push(ln.text);
348
+ if (ln.offset !== undefined)
349
+ templateMap.set(bodyBase + i + 1, ln.offset); // +1 → 1-based line
350
+ });
351
+ out.push('}');
352
+ // Synthesize the typed default export the loader emits at build time
353
+ // (`defineComponent(render, setup)`), so a PARENT importing this component
354
+ // type-checks the props it passes against this component's `setup` contract.
355
+ const propsType = hasSetup ? '__WeavePropsOf<typeof setup>' : 'Record<string, never>';
356
+ out.push(`declare const __weaveDefault: (props: ${propsType}, slots?: Record<string, () => unknown>) => unknown;`);
357
+ out.push('export default __weaveDefault;'); // also forces module scope
358
+ // Char-precise mappings. The script is embedded verbatim at the very top, so it
359
+ // maps 1:1 as a single run; template runs are placed by each line's offset.
360
+ const mappings = [];
361
+ if (script && script.length) {
362
+ mappings.push({ generatedOffset: 0, sourceOffset: scriptBaseOffset, length: script.length, source: 'script' });
363
+ }
364
+ const lineGenOffset = new Array(out.length);
365
+ let acc = 0;
366
+ for (let k = 0; k < out.length; k++) {
367
+ lineGenOffset[k] = acc;
368
+ acc += out[k].length + 1; // +1 for the joining '\n'
369
+ }
370
+ body.forEach((ln, i) => {
371
+ if (!ln.segs)
372
+ return;
373
+ const gBase = lineGenOffset[bodyBase + i];
374
+ for (const s of ln.segs) {
375
+ mappings.push({ generatedOffset: gBase + s.col, sourceOffset: s.src, length: s.len, source: 'template' });
376
+ }
377
+ });
378
+ return { text: out.join('\n'), scriptLineCount: scriptLines.length, templateMap, mappings };
379
+ }
380
+ //# sourceMappingURL=emit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emit.js","sourceRoot":"","sources":["../src/emit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,aAAa,EACb,WAAW,EACX,aAAa,EACb,OAAO,GAO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C,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACvB,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,0BAA0B;IACtD,CAAC;IACD,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE;QACrB,IAAI,CAAC,EAAE,CAAC,IAAI;YAAE,OAAO;QACrB,MAAM,KAAK,GAAW,aAAa,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC;QAClD,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;YACxB,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;QAC5G,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @weave-framework/check — template type-checking (M8).
3
+ *
4
+ * Generates a never-bundled virtual `.ts` per component (verbatim `setup` + a
5
+ * synthesized `__weave__()` placing each template expression against
6
+ * `ReturnType<typeof setup>`), type-checks them with the real TypeScript
7
+ * compiler, and maps diagnostics back to the original `.weave`/`.html` line:col.
8
+ */
9
+ export { buildVirtualSfc, buildVirtualSeparate, type Virtual, type WeaveMapping } from './emit.js';
10
+ export { runCheck, offsetToLineCol, type Diagnostic } from './check.js';
11
+ export { checkProject } from './project.js';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,KAAK,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAC;AACnG,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * @weave-framework/check — template type-checking (M8).
3
+ *
4
+ * Generates a never-bundled virtual `.ts` per component (verbatim `setup` + a
5
+ * synthesized `__weave__()` placing each template expression against
6
+ * `ReturnType<typeof setup>`), type-checks them with the real TypeScript
7
+ * compiler, and maps diagnostics back to the original `.weave`/`.html` line:col.
8
+ */
9
+ export { buildVirtualSfc, buildVirtualSeparate } from './emit.js';
10
+ export { runCheck, offsetToLineCol } from './check.js';
11
+ export { checkProject } from './project.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAmC,MAAM,WAAW,CAAC;AACnG,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAmB,MAAM,YAAY,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Discovery + one-shot project check. Walks a directory for both authoring forms —
3
+ * `.weave` SFCs and `.ts` components — builds a virtual module for each, and
4
+ * type-checks them all in a single program. A `.ts` component's template/styles are
5
+ * resolved the same way the build plugin resolves them (see `extractSources`): a
6
+ * declared inline/file `template`, else the sibling `name.html`.
7
+ */
8
+ import { type Diagnostic } from './check.js';
9
+ /** Build virtuals for every component found under `roots`, then check them together. */
10
+ export declare function checkProject(roots: string[]): Diagnostic[];
11
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAIvD,wFAAwF;AACxF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,CAI1D"}
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Discovery + one-shot project check. Walks a directory for both authoring forms —
3
+ * `.weave` SFCs and `.ts` components — builds a virtual module for each, and
4
+ * type-checks them all in a single program. A `.ts` component's template/styles are
5
+ * resolved the same way the build plugin resolves them (see `extractSources`): a
6
+ * declared inline/file `template`, else the sibling `name.html`.
7
+ */
8
+ import { readFileSync, readdirSync, existsSync, statSync } from 'node:fs';
9
+ import { join, resolve, dirname } from 'node:path';
10
+ import { extractSources, classifyTemplate, faithfulTemplate } from '@weave-framework/compiler';
11
+ import { buildVirtualSfc, buildVirtualSeparate } from './emit.js';
12
+ import { runCheck } from './check.js';
13
+ const SKIP = new Set(['node_modules', 'dist', '.git', '.weave']);
14
+ /** Build virtuals for every component found under `roots`, then check them together. */
15
+ export function checkProject(roots) {
16
+ const virtuals = [];
17
+ for (const root of roots)
18
+ collect(root, virtuals);
19
+ return virtuals.length ? runCheck(virtuals) : [];
20
+ }
21
+ function collect(path, out) {
22
+ if (!existsSync(path))
23
+ return;
24
+ const st = statSync(path);
25
+ if (st.isDirectory()) {
26
+ for (const entry of readdirSync(path)) {
27
+ if (SKIP.has(entry))
28
+ continue;
29
+ collect(join(path, entry), out);
30
+ }
31
+ return;
32
+ }
33
+ if (path.endsWith('.weave')) {
34
+ out.push(absolutize(buildVirtualSfc(path, readFileSync(path, 'utf8'))));
35
+ }
36
+ else if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {
37
+ const v = collectTs(path);
38
+ if (v)
39
+ out.push(absolutize(v));
40
+ }
41
+ }
42
+ /**
43
+ * Make a virtual's module path absolute so cross-component imports resolve to it.
44
+ * TypeScript resolves a relative import specifier to an ABSOLUTE path; the host's
45
+ * lookup table is keyed on `v.path`, so an unresolved relative key would miss and
46
+ * fall through to the on-disk source (which lacks the synthesized default export).
47
+ * Display paths (`scriptFile`/`templateFile`) stay as-passed, so diagnostics keep
48
+ * their tidy relative form.
49
+ */
50
+ function absolutize(v) {
51
+ v.path = resolve(v.path);
52
+ return v;
53
+ }
54
+ /** Resolve a `.ts` component's template into a virtual (or null if it is not a component). */
55
+ function collectTs(tsPath) {
56
+ const source = readFileSync(tsPath, 'utf8');
57
+ const decl = extractSources(source);
58
+ const siblingHtml = tsPath.replace(/\.ts$/, '.html');
59
+ if (decl.template !== undefined) {
60
+ if (classifyTemplate(decl.template) === 'inline') {
61
+ // Offset-faithful: template at its real `.ts` offsets, everything else blanked,
62
+ // so diagnostics map back to the `.ts` line:col.
63
+ const faithful = decl.templateRange
64
+ ? faithfulTemplate(source, decl.templateRange)
65
+ : decl.template;
66
+ return buildVirtualSeparate(tsPath, decl.script, tsPath, faithful);
67
+ }
68
+ const file = resolve(dirname(tsPath), decl.template);
69
+ if (!existsSync(file))
70
+ return null; // build reports the missing file; check just skips
71
+ return buildVirtualSeparate(tsPath, decl.script, file, readFileSync(file, 'utf8'));
72
+ }
73
+ if (existsSync(siblingHtml)) {
74
+ return buildVirtualSeparate(tsPath, decl.script, siblingHtml, readFileSync(siblingHtml, 'utf8'));
75
+ }
76
+ return null; // ordinary module
77
+ }
78
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,IAAI,EAAE,OAAO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QAAQ,CAAC,CAAC;QAC7D,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC,CAAC,mDAAmD;QACvF,OAAO,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACrF,CAAC;IAED,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC5B,OAAO,oBAAoB,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IACnG,CAAC;IACD,OAAO,IAAI,CAAC,CAAC,kBAAkB;AACjC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@weave-framework/check",
3
+ "version": "0.2.0",
4
+ "description": "Weave template type-checking — virtual .ts generation + tsc, mapped back to source.",
5
+ "type": "module",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.js",
8
+ "module": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./emit": {
16
+ "types": "./dist/emit.d.ts",
17
+ "import": "./dist/emit.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/weave-framework/weave.git",
29
+ "directory": "packages/check"
30
+ },
31
+ "publishConfig": {
32
+ "access": "public"
33
+ },
34
+ "dependencies": {
35
+ "@weave-framework/compiler": "0.2.0"
36
+ },
37
+ "peerDependencies": {
38
+ "typescript": "^5.7.0"
39
+ },
40
+ "license": "MIT"
41
+ }