nexa-compiler 0.6.4 → 0.7.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/dist/codegen/template.js
CHANGED
|
@@ -81,8 +81,11 @@ function genSlot(node) {
|
|
|
81
81
|
const propsCall = node.slotProps ? `{ ${node.slotProps} }` : '';
|
|
82
82
|
const args = node.slotProps ? `(${propsCall})` : '()';
|
|
83
83
|
const slotAccess = /^[\w$]+$/.test(node.name) ? `ctx.$slots.${node.name}` : `ctx.$slots[${node.name}]`;
|
|
84
|
+
const childrenCode = node.children && node.children.length > 0
|
|
85
|
+
? `[${node.children.map(c => genNode(c)).join(', ')}]`
|
|
86
|
+
: 'null';
|
|
84
87
|
if (node.name === 'default') {
|
|
85
|
-
return `ctx.$slots.default ? ctx.$slots.default${args} :
|
|
88
|
+
return `ctx.$slots.default ? ctx.$slots.default${args} : ${childrenCode}`;
|
|
86
89
|
}
|
|
87
|
-
return `${slotAccess} ? ${slotAccess}${args} :
|
|
90
|
+
return `${slotAccess} ? ${slotAccess}${args} : ${childrenCode}`;
|
|
88
91
|
}
|
package/dist/parse/template.d.ts
CHANGED
package/dist/parse/template.js
CHANGED
|
@@ -42,14 +42,18 @@ export function parseTemplate(template) {
|
|
|
42
42
|
type: 'slot',
|
|
43
43
|
name: attrs.find(a => a.name === 'name')?.value || 'default',
|
|
44
44
|
attrs,
|
|
45
|
+
children: []
|
|
45
46
|
};
|
|
46
47
|
stack[stack.length - 1].push(slotNode);
|
|
48
|
+
if (!isSelfClosing) {
|
|
49
|
+
stack.push(slotNode.children);
|
|
50
|
+
}
|
|
47
51
|
}
|
|
48
52
|
else {
|
|
49
53
|
stack[stack.length - 1].push(node);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
if (!isSelfClosing) {
|
|
55
|
+
stack.push(node.children);
|
|
56
|
+
}
|
|
53
57
|
}
|
|
54
58
|
lastIndex = tagRegex.lastIndex;
|
|
55
59
|
}
|
|
@@ -36,7 +36,7 @@ function transformNode(node, scopeId) {
|
|
|
36
36
|
const slotProps = dynamicAttrs.length > 0
|
|
37
37
|
? dynamicAttrs.map(a => `${a.name}: ${a.value}`).join(', ')
|
|
38
38
|
: undefined;
|
|
39
|
-
return { type: 'slot', name: node.name, slotProps };
|
|
39
|
+
return { type: 'slot', name: node.name, slotProps, children: node.children?.map(c => transformNode(c)) };
|
|
40
40
|
}
|
|
41
41
|
case 'if': {
|
|
42
42
|
const then = transformChildren(node.then, scopeId);
|
|
@@ -143,14 +143,26 @@ function genProps(attrs, tag) {
|
|
|
143
143
|
let handler = typeof attr.value === 'string' && /^\w+$/.test(attr.value)
|
|
144
144
|
? attr.value
|
|
145
145
|
: `($event) => { ${attr.value} }`;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
146
|
+
const keyMap = {
|
|
147
|
+
enter: 'Enter', esc: 'Escape', tab: 'Tab',
|
|
148
|
+
space: ' ', up: 'ArrowUp', down: 'ArrowDown',
|
|
149
|
+
left: 'ArrowLeft', right: 'ArrowRight',
|
|
150
|
+
delete: 'Delete', backspace: 'Backspace',
|
|
151
|
+
};
|
|
152
|
+
const isKeyEvent = realName.startsWith('onKey');
|
|
153
|
+
for (const mod of modifiers) {
|
|
154
|
+
if (keyMap[mod] && isKeyEvent) {
|
|
155
|
+
handler = `($event) => { if ($event.key === '${keyMap[mod]}') { (${handler})($event) } }`;
|
|
156
|
+
}
|
|
157
|
+
else if (mod === 'self') {
|
|
158
|
+
handler = `($event) => { if ($event.target === $event.currentTarget) { (${handler})($event) } }`;
|
|
159
|
+
}
|
|
160
|
+
else if (mod === 'prevent') {
|
|
161
|
+
handler = `($event) => { $event.preventDefault(); (${handler})($event) }`;
|
|
162
|
+
}
|
|
163
|
+
else if (mod === 'stop') {
|
|
164
|
+
handler = `($event) => { $event.stopPropagation(); (${handler})($event) }`;
|
|
165
|
+
}
|
|
154
166
|
}
|
|
155
167
|
parts.push(`${realName}: ${handler}`);
|
|
156
168
|
}
|