nexa-compiler 0.7.4 → 0.7.6
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/render.js +7 -2
- package/dist/transform/template.js +26 -3
- package/package.json +1 -1
package/dist/codegen/render.js
CHANGED
|
@@ -24,10 +24,13 @@ export function generateComponentCode(sfc, filename) {
|
|
|
24
24
|
// Only add Teleport/Transition if they are used in template (keeping it simple for tests)
|
|
25
25
|
const hasTeleport = sfc.template?.includes('<Teleport');
|
|
26
26
|
const hasTransition = sfc.template?.includes('<Transition');
|
|
27
|
+
const hasVCurrency = sfc.template?.includes('v-currency');
|
|
27
28
|
if (hasTeleport && !existing.includes('Teleport'))
|
|
28
29
|
needed.push('Teleport');
|
|
29
30
|
if (hasTransition && !existing.includes('Transition'))
|
|
30
31
|
needed.push('Transition');
|
|
32
|
+
if (hasVCurrency && !existing.includes('vCurrency'))
|
|
33
|
+
needed.push('vCurrency');
|
|
31
34
|
if (needed.length > 0) {
|
|
32
35
|
const merged = [...existing, ...needed].join(', ');
|
|
33
36
|
lines.push(imp.replace(/\{[^}]+\}/s, `{ ${merged} }`));
|
|
@@ -51,6 +54,8 @@ export function generateComponentCode(sfc, filename) {
|
|
|
51
54
|
defaultImports.push('Teleport');
|
|
52
55
|
if (sfc.template?.includes('<Transition'))
|
|
53
56
|
defaultImports.push('Transition');
|
|
57
|
+
if (sfc.template?.includes('v-currency'))
|
|
58
|
+
defaultImports.push('vCurrency');
|
|
54
59
|
lines.push(`import { ${defaultImports.join(', ')} } from 'nexa-framework'`);
|
|
55
60
|
}
|
|
56
61
|
const { scopeId, styleCode } = transformStyle(sfc.style, sfc.scoped, sfc.template);
|
|
@@ -65,7 +70,7 @@ export function generateComponentCode(sfc, filename) {
|
|
|
65
70
|
const emitsDef = parseDefineEmits(fullScript);
|
|
66
71
|
const cleanSetup = stripMacroLines(fullScript);
|
|
67
72
|
const scriptBindings = extractBindings(cleanSetup);
|
|
68
|
-
const importBindings = extractImportBindings(importLines).filter(b => !['h', 'hText', 'effect', 'defineComponent', 'registerComponent', 'reloadComponent', 'injectStyle', 'signal', 'computed', 'watch', 'onMounted', 'onUnmounted', 'Teleport', 'Transition'].includes(b));
|
|
73
|
+
const importBindings = extractImportBindings(importLines).filter(b => !['h', 'hText', 'effect', 'defineComponent', 'registerComponent', 'reloadComponent', 'injectStyle', 'signal', 'computed', 'watch', 'onMounted', 'onUnmounted', 'Teleport', 'Transition', 'vCurrency'].includes(b));
|
|
69
74
|
if (propsDef) {
|
|
70
75
|
if (!propsDef._isJS) {
|
|
71
76
|
propsKeys = Object.keys(propsDef);
|
|
@@ -176,7 +181,7 @@ export function generateComponentCode(sfc, filename) {
|
|
|
176
181
|
const componentBindings = renderBindings.map(b => /^[A-Z]/.test(b) ? `${b}: _ntc_${b}` : b);
|
|
177
182
|
const allRenderBindings = [...componentBindings, ...usedBuiltIns.map(b => `${b}: _ntc_${b}`)];
|
|
178
183
|
if (allRenderBindings.length > 0) {
|
|
179
|
-
lines.push(`
|
|
184
|
+
lines.push(` let { ${allRenderBindings.join(', ')} } = ctx`);
|
|
180
185
|
}
|
|
181
186
|
lines.push(generateRenderCode(sfc.template, scopeId || undefined));
|
|
182
187
|
lines.push('}');
|
|
@@ -138,6 +138,9 @@ function genProps(attrs, tag) {
|
|
|
138
138
|
if (propName === 'vShow' && typeof attr.value === 'string') {
|
|
139
139
|
parts.push(`${propName}: ${attr.value}`);
|
|
140
140
|
}
|
|
141
|
+
else if (propName === 'vCurrency' && typeof attr.value === 'string') {
|
|
142
|
+
parts.push(`${propName}: ${attr.value}`);
|
|
143
|
+
}
|
|
141
144
|
else if (propName === 'vModel' && typeof attr.value === 'string') {
|
|
142
145
|
const isComponent = /^[A-Z]/.test(tag) || tag.includes('-');
|
|
143
146
|
if (isComponent) {
|
|
@@ -153,9 +156,29 @@ function genProps(attrs, tag) {
|
|
|
153
156
|
const parts_name = propName.split('.');
|
|
154
157
|
const realName = parts_name[0];
|
|
155
158
|
const modifiers = parts_name.slice(1);
|
|
156
|
-
let handler
|
|
157
|
-
|
|
158
|
-
|
|
159
|
+
let handler;
|
|
160
|
+
if (typeof attr.value === 'string' && /^\w+$/.test(attr.value)) {
|
|
161
|
+
handler = attr.value;
|
|
162
|
+
}
|
|
163
|
+
else if (typeof attr.value === 'string') {
|
|
164
|
+
const eqIdx = attr.value.indexOf('=');
|
|
165
|
+
if (eqIdx > 0) {
|
|
166
|
+
const lhs = attr.value.slice(0, eqIdx).trim();
|
|
167
|
+
const rhs = attr.value.slice(eqIdx + 1).trim();
|
|
168
|
+
if (/^[a-zA-Z_$]\w*$/.test(lhs)) {
|
|
169
|
+
handler = `($event) => { ${lhs}.value = ${rhs} }`;
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
handler = `($event) => { ${attr.value} }`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
handler = `($event) => { ${attr.value} }`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
handler = `($event) => { ${attr.value} }`;
|
|
181
|
+
}
|
|
159
182
|
const keyMap = {
|
|
160
183
|
enter: 'Enter', esc: 'Escape', tab: 'Tab',
|
|
161
184
|
space: ' ', up: 'ArrowUp', down: 'ArrowDown',
|