nexa-compiler 0.1.6 → 0.2.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/macros.d.ts +5 -0
- package/dist/codegen/macros.d.ts.map +1 -0
- package/dist/codegen/macros.js +62 -0
- package/dist/codegen/macros.js.map +1 -0
- package/dist/codegen/render.d.ts +2 -0
- package/dist/codegen/render.d.ts.map +1 -1
- package/dist/codegen/render.js +18 -132
- package/dist/codegen/render.js.map +1 -1
- package/dist/codegen/template.d.ts +2 -0
- package/dist/codegen/template.d.ts.map +1 -0
- package/dist/codegen/template.js +70 -0
- package/dist/codegen/template.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function parseDefineProps(script: string): Record<string, string> | null;
|
|
2
|
+
export declare function parseDefineEmits(script: string): string[] | null;
|
|
3
|
+
export declare function stripMacroLines(script: string): string;
|
|
4
|
+
export declare function extractBindings(script: string): string[];
|
|
5
|
+
//# sourceMappingURL=macros.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macros.d.ts","sourceRoot":"","sources":["../../src/codegen/macros.ts"],"names":[],"mappings":"AAWA,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAc9E;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI,CAYhE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKtD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAaxD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const typeMap = {
|
|
2
|
+
string: 'String',
|
|
3
|
+
number: 'Number',
|
|
4
|
+
boolean: 'Boolean',
|
|
5
|
+
array: 'Array',
|
|
6
|
+
object: 'Object',
|
|
7
|
+
date: 'Date',
|
|
8
|
+
function: 'Function',
|
|
9
|
+
symbol: 'Symbol',
|
|
10
|
+
};
|
|
11
|
+
export function parseDefineProps(script) {
|
|
12
|
+
const match = script.match(/defineProps\s*<\s*\{\s*([^}]+)\s*\}\s*>\s*\(\)/);
|
|
13
|
+
if (!match)
|
|
14
|
+
return null;
|
|
15
|
+
const props = {};
|
|
16
|
+
const pairs = match[1].split(';');
|
|
17
|
+
for (const pair of pairs) {
|
|
18
|
+
const trimmed = pair.trim();
|
|
19
|
+
if (!trimmed)
|
|
20
|
+
continue;
|
|
21
|
+
const [key, type] = trimmed.split(':').map(s => s.trim());
|
|
22
|
+
if (key && type) {
|
|
23
|
+
props[key] = typeMap[type.toLowerCase()] || 'null';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return Object.keys(props).length > 0 ? props : null;
|
|
27
|
+
}
|
|
28
|
+
export function parseDefineEmits(script) {
|
|
29
|
+
const match = script.match(/defineEmits\s*<\s*\{\s*([^}]+)\s*\}\s*>\s*\(\)/);
|
|
30
|
+
if (!match)
|
|
31
|
+
return null;
|
|
32
|
+
const emits = [];
|
|
33
|
+
const pairs = match[1].split(';');
|
|
34
|
+
for (const pair of pairs) {
|
|
35
|
+
const trimmed = pair.trim();
|
|
36
|
+
if (!trimmed)
|
|
37
|
+
continue;
|
|
38
|
+
const [key] = trimmed.split(':').map(s => s.trim());
|
|
39
|
+
if (key)
|
|
40
|
+
emits.push(key);
|
|
41
|
+
}
|
|
42
|
+
return emits.length > 0 ? emits : null;
|
|
43
|
+
}
|
|
44
|
+
export function stripMacroLines(script) {
|
|
45
|
+
return script
|
|
46
|
+
.split('\n')
|
|
47
|
+
.filter(line => !line.trim().startsWith('const props = defineProps') && !line.trim().startsWith('const emit = defineEmits'))
|
|
48
|
+
.join('\n');
|
|
49
|
+
}
|
|
50
|
+
export function extractBindings(script) {
|
|
51
|
+
const bindings = [];
|
|
52
|
+
const declRegex = /(?:const|let|var)\s+(\w+)\s*=/g;
|
|
53
|
+
let match;
|
|
54
|
+
while ((match = declRegex.exec(script)) !== null) {
|
|
55
|
+
const name = match[1];
|
|
56
|
+
if (name !== 'props' && name !== 'emit') {
|
|
57
|
+
bindings.push(name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return bindings;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=macros.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"macros.js","sourceRoot":"","sources":["../../src/codegen/macros.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAA2B;IACtC,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,QAAQ;IAChB,IAAI,EAAE,MAAM;IACZ,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;CACjB,CAAA;AAED,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,gDAAgD,CAAC,CAAA;IAC5E,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,MAAM,KAAK,GAA2B,EAAE,CAAA;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACjC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAA;QAC3B,IAAI,CAAC,OAAO;YAAE,SAAQ;QACtB,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAA;QACzD,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;YAChB,KAAK,CAAC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AC,0BAA0B,CAAC,CAAC;SAC3H,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAc;IAC5C,MAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B,MAAM,SAAS,GAAG,gCAAgC,CAAA;IAClD,IAAI,KAA6B,CAAA;IAEjC,OAAO,CAAC,KAAK,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;QACjD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACrB,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;YACxC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
package/dist/codegen/render.d.ts
CHANGED
|
@@ -8,12 +8,14 @@ export declare function generateComponentCode(sfc: {
|
|
|
8
8
|
script: string | null;
|
|
9
9
|
style: string | null;
|
|
10
10
|
scoped: boolean;
|
|
11
|
+
hmrId?: string;
|
|
11
12
|
}): string;
|
|
12
13
|
export declare function generateComponentCodeWithSourceMap(sfc: {
|
|
13
14
|
template: string | null;
|
|
14
15
|
script: string | null;
|
|
15
16
|
style: string | null;
|
|
16
17
|
scoped: boolean;
|
|
18
|
+
hmrId?: string;
|
|
17
19
|
}, options?: GenerateOptions): {
|
|
18
20
|
code: string;
|
|
19
21
|
map: string | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/codegen/render.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE;IACzC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,MAAM,EAAE,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/codegen/render.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE;IACzC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,GAAG,MAAM,CA6GT;AAED,wBAAgB,kCAAkC,CAChD,GAAG,EAAE;IACH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,EACD,OAAO,GAAE,eAAoB,GAC5B;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAgBtC"}
|
package/dist/codegen/render.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { parseTemplate } from '../parse/template.js';
|
|
2
|
-
import { transformTemplate } from '../transform/template.js';
|
|
3
1
|
import { transformStyle } from '../transform/style.js';
|
|
4
2
|
import { generateSourceMap } from './sourcemap.js';
|
|
3
|
+
import { parseDefineProps, parseDefineEmits, stripMacroLines, extractBindings } from './macros.js';
|
|
4
|
+
import { generateRenderCode } from './template.js';
|
|
5
5
|
export function generateComponentCode(sfc) {
|
|
6
6
|
const lines = [];
|
|
7
7
|
const scriptContent = sfc.script || '';
|
|
@@ -15,28 +15,36 @@ export function generateComponentCode(sfc) {
|
|
|
15
15
|
setupLines.push(line);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
let needsDefaultImport = importLines.length === 0;
|
|
18
19
|
for (const imp of importLines) {
|
|
19
20
|
if (imp.includes('from \'nexa-framework\'') || imp.includes('from "nexa-framework"')) {
|
|
20
21
|
const match = imp.match(/import\s+\{([^}]+)}\s+from/);
|
|
21
22
|
if (match) {
|
|
22
23
|
const existing = match[1].split(',').map(s => s.trim());
|
|
23
|
-
const needed = ['h', 'hText', 'effect', 'defineComponent'].filter(n => !existing.includes(n));
|
|
24
|
+
const needed = ['h', 'hText', 'effect', 'defineComponent', 'registerComponent', 'reloadComponent', 'injectStyle'].filter(n => !existing.includes(n));
|
|
24
25
|
if (needed.length > 0) {
|
|
25
26
|
const merged = [...existing, ...needed].join(', ');
|
|
26
27
|
lines.push(imp.replace(/\{[^}]+\}/, `{ ${merged} }`));
|
|
28
|
+
needsDefaultImport = false;
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
31
|
lines.push(imp);
|
|
32
|
+
needsDefaultImport = false;
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
else {
|
|
33
36
|
lines.push(imp);
|
|
37
|
+
needsDefaultImport = false;
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
else {
|
|
37
41
|
lines.push(imp);
|
|
42
|
+
needsDefaultImport = false;
|
|
38
43
|
}
|
|
39
44
|
}
|
|
45
|
+
if (needsDefaultImport) {
|
|
46
|
+
lines.push('import { h, hText, effect, defineComponent, registerComponent, reloadComponent, injectStyle } from \'nexa-framework\'');
|
|
47
|
+
}
|
|
40
48
|
const { scopeId, styleCode } = transformStyle(sfc.style, sfc.scoped, sfc.template);
|
|
41
49
|
const fullScript = setupLines.join('\n');
|
|
42
50
|
const propsDef = parseDefineProps(fullScript);
|
|
@@ -44,10 +52,13 @@ export function generateComponentCode(sfc) {
|
|
|
44
52
|
const cleanSetup = stripMacroLines(fullScript);
|
|
45
53
|
const bindings = extractBindings(cleanSetup);
|
|
46
54
|
lines.push('');
|
|
47
|
-
lines.push('
|
|
55
|
+
lines.push('const _sfc_main = defineComponent({');
|
|
48
56
|
if (scopeId) {
|
|
49
57
|
lines.push(` __scopeId: '${scopeId}',`);
|
|
50
58
|
}
|
|
59
|
+
if (sfc.hmrId) {
|
|
60
|
+
lines.push(` __hmrId: '${sfc.hmrId}',`);
|
|
61
|
+
}
|
|
51
62
|
if (propsDef) {
|
|
52
63
|
lines.push(' props: {');
|
|
53
64
|
for (const [key, val] of Object.entries(propsDef)) {
|
|
@@ -79,9 +90,12 @@ export function generateComponentCode(sfc) {
|
|
|
79
90
|
lines.push(' },');
|
|
80
91
|
}
|
|
81
92
|
lines.push('})');
|
|
93
|
+
lines.push('');
|
|
94
|
+
lines.push('export default _sfc_main');
|
|
82
95
|
if (styleCode) {
|
|
83
96
|
lines.push('');
|
|
84
97
|
lines.push(`const __style = \`${styleCode}\``);
|
|
98
|
+
lines.push(`injectStyle('${scopeId || sfc.hmrId || 'style'}', __style)`);
|
|
85
99
|
}
|
|
86
100
|
return lines.join('\n');
|
|
87
101
|
}
|
|
@@ -94,132 +108,4 @@ export function generateComponentCodeWithSourceMap(sfc, options = {}) {
|
|
|
94
108
|
const map = generateSourceMap(options.filename, code, options.source, scriptLines);
|
|
95
109
|
return { code, map };
|
|
96
110
|
}
|
|
97
|
-
function generateRenderCode(template) {
|
|
98
|
-
const ast = parseTemplate(template);
|
|
99
|
-
const transformed = transformTemplate(ast);
|
|
100
|
-
const children = transformed.children;
|
|
101
|
-
if (children.length === 0) {
|
|
102
|
-
return ' return null';
|
|
103
|
-
}
|
|
104
|
-
if (children.length === 1) {
|
|
105
|
-
return ' return ' + genNode(children[0]);
|
|
106
|
-
}
|
|
107
|
-
const items = children.map(child => genNode(child)).join(',\n ');
|
|
108
|
-
return ` return h('div', null, [\n ${items}\n ])`;
|
|
109
|
-
}
|
|
110
|
-
function genNode(node) {
|
|
111
|
-
switch (node.type) {
|
|
112
|
-
case 'text':
|
|
113
|
-
return JSON.stringify(node.content);
|
|
114
|
-
case 'expression':
|
|
115
|
-
return node.content;
|
|
116
|
-
case 'element':
|
|
117
|
-
return genElement(node);
|
|
118
|
-
case 'slot':
|
|
119
|
-
return genSlot(node);
|
|
120
|
-
case 'comment':
|
|
121
|
-
return 'null';
|
|
122
|
-
default:
|
|
123
|
-
return 'null';
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
function genElement(node) {
|
|
127
|
-
const { tag, props, children } = node;
|
|
128
|
-
const childStr = genChildren(children);
|
|
129
|
-
const elementCode = buildElementCode(tag, props, childStr);
|
|
130
|
-
if (node.vFor) {
|
|
131
|
-
const { item, index, list } = node.vFor;
|
|
132
|
-
return `${list}.map((${item}, ${index}) =>\n ${elementCode}\n )`;
|
|
133
|
-
}
|
|
134
|
-
if (node.vIf) {
|
|
135
|
-
return `${node.vIf} ? ${elementCode} : null`;
|
|
136
|
-
}
|
|
137
|
-
return elementCode;
|
|
138
|
-
}
|
|
139
|
-
function buildElementCode(tag, propStr, childStr) {
|
|
140
|
-
if (propStr && childStr) {
|
|
141
|
-
return `h('${tag}', { ${propStr} }, [\n ${childStr}\n ])`;
|
|
142
|
-
}
|
|
143
|
-
if (propStr) {
|
|
144
|
-
return `h('${tag}', { ${propStr} })`;
|
|
145
|
-
}
|
|
146
|
-
if (childStr) {
|
|
147
|
-
return `h('${tag}', null, [\n ${childStr}\n ])`;
|
|
148
|
-
}
|
|
149
|
-
return `h('${tag}')`;
|
|
150
|
-
}
|
|
151
|
-
function genChildren(children) {
|
|
152
|
-
if (!children || children.length === 0)
|
|
153
|
-
return '';
|
|
154
|
-
return children.map(child => genNode(child)).join(',\n ');
|
|
155
|
-
}
|
|
156
|
-
function genSlot(node) {
|
|
157
|
-
const propsCall = node.slotProps ? `{ ${node.slotProps} }` : '';
|
|
158
|
-
const args = node.slotProps ? `(${propsCall})` : '()';
|
|
159
|
-
if (node.name === 'default') {
|
|
160
|
-
return `ctx.$slots.default ? ctx.$slots.default${args} : null`;
|
|
161
|
-
}
|
|
162
|
-
return `ctx.$slots.${node.name} ? ctx.$slots.${node.name}${args} : null`;
|
|
163
|
-
}
|
|
164
|
-
const typeMap = {
|
|
165
|
-
string: 'String',
|
|
166
|
-
number: 'Number',
|
|
167
|
-
boolean: 'Boolean',
|
|
168
|
-
array: 'Array',
|
|
169
|
-
object: 'Object',
|
|
170
|
-
date: 'Date',
|
|
171
|
-
function: 'Function',
|
|
172
|
-
symbol: 'Symbol',
|
|
173
|
-
};
|
|
174
|
-
function parseDefineProps(script) {
|
|
175
|
-
const match = script.match(/defineProps\s*<\s*\{\s*([^}]+)\s*\}\s*>\s*\(\)/);
|
|
176
|
-
if (!match)
|
|
177
|
-
return null;
|
|
178
|
-
const props = {};
|
|
179
|
-
const pairs = match[1].split(';');
|
|
180
|
-
for (const pair of pairs) {
|
|
181
|
-
const trimmed = pair.trim();
|
|
182
|
-
if (!trimmed)
|
|
183
|
-
continue;
|
|
184
|
-
const [key, type] = trimmed.split(':').map(s => s.trim());
|
|
185
|
-
if (key && type) {
|
|
186
|
-
props[key] = typeMap[type.toLowerCase()] || 'null';
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return Object.keys(props).length > 0 ? props : null;
|
|
190
|
-
}
|
|
191
|
-
function parseDefineEmits(script) {
|
|
192
|
-
const match = script.match(/defineEmits\s*<\s*\{\s*([^}]+)\s*\}\s*>\s*\(\)/);
|
|
193
|
-
if (!match)
|
|
194
|
-
return null;
|
|
195
|
-
const emits = [];
|
|
196
|
-
const pairs = match[1].split(';');
|
|
197
|
-
for (const pair of pairs) {
|
|
198
|
-
const trimmed = pair.trim();
|
|
199
|
-
if (!trimmed)
|
|
200
|
-
continue;
|
|
201
|
-
const [key] = trimmed.split(':').map(s => s.trim());
|
|
202
|
-
if (key)
|
|
203
|
-
emits.push(key);
|
|
204
|
-
}
|
|
205
|
-
return emits.length > 0 ? emits : null;
|
|
206
|
-
}
|
|
207
|
-
function stripMacroLines(script) {
|
|
208
|
-
return script
|
|
209
|
-
.split('\n')
|
|
210
|
-
.filter(line => !line.trim().startsWith('const props = defineProps') && !line.trim().startsWith('const emit = defineEmits'))
|
|
211
|
-
.join('\n');
|
|
212
|
-
}
|
|
213
|
-
function extractBindings(script) {
|
|
214
|
-
const bindings = [];
|
|
215
|
-
const declRegex = /(?:const|let|var)\s+(\w+)\s*=/g;
|
|
216
|
-
let match;
|
|
217
|
-
while ((match = declRegex.exec(script)) !== null) {
|
|
218
|
-
const name = match[1];
|
|
219
|
-
if (name !== 'props' && name !== 'emit') {
|
|
220
|
-
bindings.push(name);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return bindings;
|
|
224
|
-
}
|
|
225
111
|
//# sourceMappingURL=render.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/codegen/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/codegen/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAClG,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAQlD,MAAM,UAAU,qBAAqB,CAAC,GAMrC;IACC,MAAM,KAAK,GAAa,EAAE,CAAA;IAE1B,MAAM,aAAa,GAAG,GAAG,CAAC,MAAM,IAAI,EAAE,CAAA;I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,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAA;IACxF,MAAM,GAAG,GAAG,iBAAiB,CAC3B,OAAO,CAAC,QAAQ,EAChB,IAAI,EACJ,OAAO,CAAC,MAAM,EACd,WAAW,CACZ,CAAA;IAED,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/codegen/template.ts"],"names":[],"mappings":"AAGA,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAe3D"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { parseTemplate } from '../parse/template.js';
|
|
2
|
+
import { transformTemplate } from '../transform/template.js';
|
|
3
|
+
export function generateRenderCode(template) {
|
|
4
|
+
const ast = parseTemplate(template);
|
|
5
|
+
const transformed = transformTemplate(ast);
|
|
6
|
+
const children = transformed.children;
|
|
7
|
+
if (children.length === 0) {
|
|
8
|
+
return ' return null';
|
|
9
|
+
}
|
|
10
|
+
if (children.length === 1) {
|
|
11
|
+
return ' return ' + genNode(children[0]);
|
|
12
|
+
}
|
|
13
|
+
const items = children.map(child => genNode(child)).join(',\n ');
|
|
14
|
+
return ` return h('div', null, [\n ${items}\n ])`;
|
|
15
|
+
}
|
|
16
|
+
function genNode(node) {
|
|
17
|
+
switch (node.type) {
|
|
18
|
+
case 'text':
|
|
19
|
+
return JSON.stringify(node.content);
|
|
20
|
+
case 'expression':
|
|
21
|
+
return node.content;
|
|
22
|
+
case 'element':
|
|
23
|
+
return genElement(node);
|
|
24
|
+
case 'slot':
|
|
25
|
+
return genSlot(node);
|
|
26
|
+
case 'comment':
|
|
27
|
+
return 'null';
|
|
28
|
+
default:
|
|
29
|
+
return 'null';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function genElement(node) {
|
|
33
|
+
const { tag, props, children } = node;
|
|
34
|
+
const childStr = genChildren(children);
|
|
35
|
+
const elementCode = buildElementCode(tag, props, childStr);
|
|
36
|
+
if (node.vFor) {
|
|
37
|
+
const { item, index, list } = node.vFor;
|
|
38
|
+
return `${list}.map((${item}, ${index}) =>\n ${elementCode}\n )`;
|
|
39
|
+
}
|
|
40
|
+
if (node.vIf) {
|
|
41
|
+
return `${node.vIf} ? ${elementCode} : null`;
|
|
42
|
+
}
|
|
43
|
+
return elementCode;
|
|
44
|
+
}
|
|
45
|
+
function buildElementCode(tag, propStr, childStr) {
|
|
46
|
+
if (propStr && childStr) {
|
|
47
|
+
return `h('${tag}', { ${propStr} }, [\n ${childStr}\n ])`;
|
|
48
|
+
}
|
|
49
|
+
if (propStr) {
|
|
50
|
+
return `h('${tag}', { ${propStr} })`;
|
|
51
|
+
}
|
|
52
|
+
if (childStr) {
|
|
53
|
+
return `h('${tag}', null, [\n ${childStr}\n ])`;
|
|
54
|
+
}
|
|
55
|
+
return `h('${tag}')`;
|
|
56
|
+
}
|
|
57
|
+
function genChildren(children) {
|
|
58
|
+
if (!children || children.length === 0)
|
|
59
|
+
return '';
|
|
60
|
+
return children.map(child => genNode(child)).join(',\n ');
|
|
61
|
+
}
|
|
62
|
+
function genSlot(node) {
|
|
63
|
+
const propsCall = node.slotProps ? `{ ${node.slotProps} }` : '';
|
|
64
|
+
const args = node.slotProps ? `(${propsCall})` : '()';
|
|
65
|
+
if (node.name === 'default') {
|
|
66
|
+
return `ctx.$slots.default ? ctx.$slots.default${args} : null`;
|
|
67
|
+
}
|
|
68
|
+
return `ctx.$slots.${node.name} ? ctx.$slots.${node.name}${args} : null`;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../src/codegen/template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,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