@sprlab/wccompiler 0.0.1 → 0.0.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 CHANGED
@@ -5,7 +5,7 @@ Zero-runtime compiler that transforms `.html` files with Vue-like syntax into 10
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install -D wccompiler
8
+ npm install -D @sprlab/wccompiler
9
9
  ```
10
10
 
11
11
  ## Usage
package/lib/compiler.js CHANGED
@@ -28,10 +28,23 @@ export function compile(filePath, config) {
28
28
  // 2. Parse the HTML into the IR
29
29
  const parseResult = parse(html, fileName);
30
30
 
31
- // 3. Create a jsdom DOM from the template and walk it
31
+ // 3. Validate: no text nodes with bindings at template root level
32
32
  const dom = new JSDOM(`<div id="__root">${parseResult.template}</div>`);
33
33
  const rootEl = dom.window.document.getElementById('__root');
34
34
 
35
+ for (const child of rootEl.childNodes) {
36
+ if (child.nodeType === 3 && /\{\{\w+\}\}/.test(child.textContent)) {
37
+ const match = child.textContent.match(/\{\{(\w+)\}\}/);
38
+ const error = new Error(
39
+ `Error en '${fileName}': el binding {{${match[1]}}} está como texto suelto en el root del template. Debe estar dentro de un elemento (ej: <span>{{${match[1]}}}</span>)`
40
+ );
41
+ error.code = 'ROOT_TEXT_BINDING';
42
+ throw error;
43
+ }
44
+ }
45
+
46
+ // 4. Walk the template DOM
47
+
35
48
  const propsSet = new Set(parseResult.props);
36
49
  const computedNames = new Set(parseResult.computeds.map(c => c.name));
37
50
  const rootVarNames = new Set(parseResult.reactiveVars.map(v => v.name));
package/lib/parser.js CHANGED
@@ -105,8 +105,8 @@ function extractRootVars(script) {
105
105
  // Only extract at root level (depth === 0)
106
106
  if (depth !== 0) continue;
107
107
 
108
- // Skip computed and watch assignments
109
- if (/computed\s*\(/.test(line) || /watch\s*\(/.test(line)) continue;
108
+ // Skip computed, watch, and defineProps assignments
109
+ if (/computed\s*\(/.test(line) || /watch\s*\(/.test(line) || /defineProps\s*\(/.test(line)) continue;
110
110
 
111
111
  const m = line.match(/^\s*(?:const|let|var)\s+(\w+)\s*=\s*(.+?);?\s*$/);
112
112
  if (m) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sprlab/wccompiler",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Zero-runtime compiler that transforms .html files with Vue-like syntax into 100% native web components",
5
5
  "type": "module",
6
6
  "bin": {