@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 +1 -1
- package/lib/compiler.js +14 -1
- package/lib/parser.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
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.
|
|
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
|
|
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) {
|