@sprlab/wccompiler 0.4.1 → 0.4.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 +9 -0
- package/lib/compiler.js +4 -4
- package/lib/tree-walker.js +3 -3
- package/package.json +3 -3
- package/types/wcc.d.ts +1 -1
package/README.md
CHANGED
|
@@ -391,6 +391,15 @@ defineExpose({ doubled, handleUpdate, watchLog })
|
|
|
391
391
|
|
|
392
392
|
`defineExpose()` exposes methods and properties for external access via ref.
|
|
393
393
|
|
|
394
|
+
The language server automatically generates a typed interface (PascalCase of the tag name) that can be imported by consumers:
|
|
395
|
+
|
|
396
|
+
```ts
|
|
397
|
+
// In the parent component:
|
|
398
|
+
import type { WccTypescript } from './wcc-typescript.wcc'
|
|
399
|
+
const child = templateRef<WccTypescript>('myRef')
|
|
400
|
+
child.value!.handleUpdate() // ✅ typed
|
|
401
|
+
```
|
|
402
|
+
|
|
394
403
|
## CLI
|
|
395
404
|
|
|
396
405
|
```bash
|
package/lib/compiler.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Takes a .wcc file path and produces a self-contained JavaScript web component string.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { parseHTML } from 'linkedom';
|
|
10
10
|
import { readFileSync, existsSync } from 'node:fs';
|
|
11
11
|
import { dirname, extname, basename, resolve } from 'node:path';
|
|
12
12
|
import { walkTree, processIfChains, processForBlocks, recomputeAnchorPath, detectRefs } from './tree-walker.js';
|
|
@@ -223,9 +223,9 @@ async function compileSFC(filePath, config) {
|
|
|
223
223
|
exposeNames,
|
|
224
224
|
};
|
|
225
225
|
|
|
226
|
-
// 16. Process template through
|
|
227
|
-
const
|
|
228
|
-
const rootEl =
|
|
226
|
+
// 16. Process template through linkedom → tree-walker → codegen
|
|
227
|
+
const { document } = parseHTML(`<div id="__root">${template}</div>`);
|
|
228
|
+
const rootEl = document.getElementById('__root');
|
|
229
229
|
|
|
230
230
|
const signalNames = new Set(signals.map(s => s.name));
|
|
231
231
|
const computedNames = new Set(computeds.map(c => c.name));
|
package/lib/tree-walker.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* extracts branch templates, and replaces chains with comment anchors.
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { parseHTML } from 'linkedom';
|
|
16
16
|
import { BOOLEAN_ATTRIBUTES } from './types.js';
|
|
17
17
|
|
|
18
18
|
/** @import { Binding, EventBinding, IfBlock, IfBranch, ShowBinding, AttrBinding, ForBlock, ModelBinding, SlotBinding, SlotProp, RefBinding, ChildComponentBinding, ChildPropBinding } from './types.js' */
|
|
@@ -358,8 +358,8 @@ function isChainPredecessor(el) {
|
|
|
358
358
|
* @returns {{ bindings: Binding[], events: EventBinding[], showBindings: ShowBinding[], attrBindings: AttrBinding[], modelBindings: ModelBinding[], slots: SlotBinding[], processedHtml: string }}
|
|
359
359
|
*/
|
|
360
360
|
export function walkBranch(html, signalNames, computedNames, propNames) {
|
|
361
|
-
const
|
|
362
|
-
const branchRoot =
|
|
361
|
+
const { document } = parseHTML(`<div id="__branchRoot">${html}</div>`);
|
|
362
|
+
const branchRoot = document.getElementById('__branchRoot');
|
|
363
363
|
|
|
364
364
|
// Use walkTree on the branch root to discover bindings/events
|
|
365
365
|
const result = walkTree(branchRoot, signalNames, computedNames, propNames);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sprlab/wccompiler",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Zero-runtime compiler that transforms .wcc single-file components into native web components with signals-based reactivity",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"esbuild": "^0.27.0",
|
|
35
|
-
"
|
|
35
|
+
"linkedom": "^0.18.12"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@types/jsdom": "^28.0.1",
|
|
39
38
|
"fast-check": "^4.1.1",
|
|
39
|
+
"jsdom": "^29.1.1",
|
|
40
40
|
"typescript": "^6.0.3",
|
|
41
41
|
"vitest": "^3.2.1"
|
|
42
42
|
},
|
package/types/wcc.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare module 'wcc' {
|
|
|
19
19
|
export function defineEmits<T>(): T;
|
|
20
20
|
export function defineEmits(names: string[]): (name: string, detail?: any) => void;
|
|
21
21
|
|
|
22
|
-
export function templateRef<T = HTMLElement>(name: string): { value:
|
|
22
|
+
export function templateRef<T = HTMLElement>(name: string): { value: T | null };
|
|
23
23
|
|
|
24
24
|
export function onMount(fn: () => void | Promise<void>): void;
|
|
25
25
|
export function onDestroy(fn: () => void | Promise<void>): void;
|