@dcloudio/uni-app-uts 3.0.0-3080720230630001
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/LICENSE +202 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +30 -0
- package/dist/plugins/css.d.ts +2 -0
- package/dist/plugins/css.js +94 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +203 -0
- package/dist/plugins/mainUTS.d.ts +2 -0
- package/dist/plugins/mainUTS.js +24 -0
- package/dist/plugins/manifestJson.d.ts +2 -0
- package/dist/plugins/manifestJson.js +68 -0
- package/dist/plugins/pagesJson.d.ts +2 -0
- package/dist/plugins/pagesJson.js +84 -0
- package/dist/plugins/pre.d.ts +7 -0
- package/dist/plugins/pre.js +52 -0
- package/dist/plugins/utils.d.ts +8 -0
- package/dist/plugins/utils.js +85 -0
- package/dist/plugins/uvue/code/script.d.ts +4 -0
- package/dist/plugins/uvue/code/script.js +14 -0
- package/dist/plugins/uvue/code/style.d.ts +12 -0
- package/dist/plugins/uvue/code/style.js +90 -0
- package/dist/plugins/uvue/code/template.d.ts +3 -0
- package/dist/plugins/uvue/code/template.js +16 -0
- package/dist/plugins/uvue/compiler/codegen.d.ts +22 -0
- package/dist/plugins/uvue/compiler/codegen.js +579 -0
- package/dist/plugins/uvue/compiler/errors.d.ts +70 -0
- package/dist/plugins/uvue/compiler/errors.js +82 -0
- package/dist/plugins/uvue/compiler/index.d.ts +9 -0
- package/dist/plugins/uvue/compiler/index.js +65 -0
- package/dist/plugins/uvue/compiler/options.d.ts +92 -0
- package/dist/plugins/uvue/compiler/options.js +2 -0
- package/dist/plugins/uvue/compiler/runtimeHelpers.d.ts +10 -0
- package/dist/plugins/uvue/compiler/runtimeHelpers.js +25 -0
- package/dist/plugins/uvue/compiler/transform.d.ts +53 -0
- package/dist/plugins/uvue/compiler/transform.js +294 -0
- package/dist/plugins/uvue/compiler/transforms/transformExpression.d.ts +5 -0
- package/dist/plugins/uvue/compiler/transforms/transformExpression.js +208 -0
- package/dist/plugins/uvue/compiler/transforms/transformInterpolation.d.ts +4 -0
- package/dist/plugins/uvue/compiler/transforms/transformInterpolation.js +107 -0
- package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.d.ts +10 -0
- package/dist/plugins/uvue/compiler/transforms/transformSlotOutlet.js +79 -0
- package/dist/plugins/uvue/compiler/transforms/transformText.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/transformText.js +99 -0
- package/dist/plugins/uvue/compiler/transforms/vBind.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/vBind.js +83 -0
- package/dist/plugins/uvue/compiler/transforms/vFor.d.ts +12 -0
- package/dist/plugins/uvue/compiler/transforms/vFor.js +325 -0
- package/dist/plugins/uvue/compiler/transforms/vIf.d.ts +4 -0
- package/dist/plugins/uvue/compiler/transforms/vIf.js +212 -0
- package/dist/plugins/uvue/compiler/transforms/vModel.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/vModel.js +51 -0
- package/dist/plugins/uvue/compiler/transforms/vOn.d.ts +8 -0
- package/dist/plugins/uvue/compiler/transforms/vOn.js +136 -0
- package/dist/plugins/uvue/compiler/transforms/vShow.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/vShow.js +11 -0
- package/dist/plugins/uvue/compiler/transforms/vText.d.ts +2 -0
- package/dist/plugins/uvue/compiler/transforms/vText.js +29 -0
- package/dist/plugins/uvue/compiler/utils.d.ts +5 -0
- package/dist/plugins/uvue/compiler/utils.js +37 -0
- package/dist/plugins/uvue/descriptorCache.d.ts +24 -0
- package/dist/plugins/uvue/descriptorCache.js +57 -0
- package/dist/plugins/uvue/error.d.ts +3 -0
- package/dist/plugins/uvue/error.js +22 -0
- package/dist/plugins/uvue/index.d.ts +13 -0
- package/dist/plugins/uvue/index.js +188 -0
- package/lib/automator/apis/App.uts +144 -0
- package/lib/automator/apis/Page.uts +55 -0
- package/lib/automator/apis/util.uts +63 -0
- package/lib/automator/index.uts +106 -0
- package/package.json +42 -0
|
@@ -0,0 +1,579 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generate = void 0;
|
|
4
|
+
const source_map_1 = require("source-map");
|
|
5
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
6
|
+
const shared_1 = require("@vue/shared");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const runtimeHelpers_1 = require("./runtimeHelpers");
|
|
9
|
+
const utils_2 = require("./utils");
|
|
10
|
+
function createCodegenContext(ast, { targetLanguage, mode = 'default', prefixIdentifiers = false, bindingMetadata = {}, sourceMap = false, filename = '', matchEasyCom = shared_1.NOOP, parseUTSComponent = shared_1.NOOP, }) {
|
|
11
|
+
const context = {
|
|
12
|
+
targetLanguage,
|
|
13
|
+
mode,
|
|
14
|
+
prefixIdentifiers,
|
|
15
|
+
bindingMetadata,
|
|
16
|
+
sourceMap,
|
|
17
|
+
filename,
|
|
18
|
+
source: ast.loc.source,
|
|
19
|
+
code: ``,
|
|
20
|
+
importEasyComponents: [],
|
|
21
|
+
importUTSComponents: [],
|
|
22
|
+
column: 1,
|
|
23
|
+
line: 1,
|
|
24
|
+
offset: 0,
|
|
25
|
+
indentLevel: 0,
|
|
26
|
+
map: undefined,
|
|
27
|
+
matchEasyCom,
|
|
28
|
+
parseUTSComponent,
|
|
29
|
+
helper(key) {
|
|
30
|
+
return `${compiler_core_1.helperNameMap[key]}`;
|
|
31
|
+
},
|
|
32
|
+
push(code, node) {
|
|
33
|
+
context.code += code;
|
|
34
|
+
if (context.map) {
|
|
35
|
+
if (node) {
|
|
36
|
+
let name;
|
|
37
|
+
if (node.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
38
|
+
const content = node.content.replace(/^_ctx\./, '');
|
|
39
|
+
if (content !== node.content && (0, compiler_core_1.isSimpleIdentifier)(content)) {
|
|
40
|
+
name = content;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
addMapping(node.loc.start, name);
|
|
44
|
+
}
|
|
45
|
+
(0, compiler_core_1.advancePositionWithMutation)(context, code);
|
|
46
|
+
if (node && node.loc !== compiler_core_1.locStub) {
|
|
47
|
+
addMapping(node.loc.end);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
indent() {
|
|
52
|
+
newline(++context.indentLevel);
|
|
53
|
+
},
|
|
54
|
+
deindent(withoutNewLine = false) {
|
|
55
|
+
if (withoutNewLine) {
|
|
56
|
+
--context.indentLevel;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
newline(--context.indentLevel);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
newline() {
|
|
63
|
+
newline(context.indentLevel);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
function newline(n) {
|
|
67
|
+
context.push('\n' + ` `.repeat(n));
|
|
68
|
+
}
|
|
69
|
+
function addMapping(loc, name) {
|
|
70
|
+
context.map.addMapping({
|
|
71
|
+
name,
|
|
72
|
+
source: context.filename,
|
|
73
|
+
original: {
|
|
74
|
+
line: loc.line,
|
|
75
|
+
column: loc.column - 1, // source-map column is 0 based
|
|
76
|
+
},
|
|
77
|
+
generated: {
|
|
78
|
+
line: context.line,
|
|
79
|
+
column: context.column - 1,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (sourceMap) {
|
|
84
|
+
// lazy require source-map implementation, only in non-browser builds
|
|
85
|
+
context.map = new source_map_1.SourceMapGenerator();
|
|
86
|
+
context.map.setSourceContent(filename, context.source);
|
|
87
|
+
}
|
|
88
|
+
return context;
|
|
89
|
+
}
|
|
90
|
+
function generate(ast, options) {
|
|
91
|
+
const context = createCodegenContext(ast, options);
|
|
92
|
+
const { mode, deindent, indent, push, newline } = context;
|
|
93
|
+
if (mode === 'function') {
|
|
94
|
+
genEasyComImports(ast.components, context);
|
|
95
|
+
push((0, utils_1.genRenderFunctionDecl)(options) + ` {`);
|
|
96
|
+
// generate asset resolution statements
|
|
97
|
+
if (ast.components.length) {
|
|
98
|
+
newline();
|
|
99
|
+
genAssets(ast.components, 'component', context);
|
|
100
|
+
if (ast.directives.length || ast.temps > 0) {
|
|
101
|
+
newline();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (ast.directives.length) {
|
|
105
|
+
genAssets(ast.directives, 'directive', context);
|
|
106
|
+
if (ast.temps > 0) {
|
|
107
|
+
newline();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (ast.components.length || ast.directives.length || ast.temps) {
|
|
111
|
+
newline();
|
|
112
|
+
}
|
|
113
|
+
indent();
|
|
114
|
+
push(`return `);
|
|
115
|
+
}
|
|
116
|
+
if (ast.codegenNode) {
|
|
117
|
+
genNode(ast.codegenNode, context);
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
push(`null`);
|
|
121
|
+
}
|
|
122
|
+
if (mode === 'function') {
|
|
123
|
+
deindent();
|
|
124
|
+
push(`}`);
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
code: context.code,
|
|
128
|
+
importEasyComponents: context.importEasyComponents,
|
|
129
|
+
importUTSComponents: context.importUTSComponents,
|
|
130
|
+
// SourceMapGenerator does have toJSON() method but it's not in the types
|
|
131
|
+
map: context.map ? context.map.toJSON() : undefined,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
exports.generate = generate;
|
|
135
|
+
function genEasyComImports(components, { push, newline, matchEasyCom, targetLanguage }) {
|
|
136
|
+
for (let i = 0; i < components.length; i++) {
|
|
137
|
+
let id = components[i];
|
|
138
|
+
const maybeSelfReference = id.endsWith('__self');
|
|
139
|
+
if (maybeSelfReference) {
|
|
140
|
+
id = id.slice(0, -6);
|
|
141
|
+
}
|
|
142
|
+
const source = matchEasyCom(id, true);
|
|
143
|
+
if (source) {
|
|
144
|
+
const componentId = (0, compiler_core_1.toValidAssetId)(id, 'easycom');
|
|
145
|
+
push(`import ${componentId} from '${source}'`);
|
|
146
|
+
newline();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function genAssets(assets, type, { helper, push, newline, importEasyComponents, matchEasyCom }) {
|
|
151
|
+
const resolver = helper(type === 'component' ? runtimeHelpers_1.RESOLVE_COMPONENT : runtimeHelpers_1.RESOLVE_DIRECTIVE);
|
|
152
|
+
for (let i = 0; i < assets.length; i++) {
|
|
153
|
+
let id = assets[i];
|
|
154
|
+
// potential component implicit self-reference inferred from SFC filename
|
|
155
|
+
const maybeSelfReference = id.endsWith('__self');
|
|
156
|
+
if (maybeSelfReference) {
|
|
157
|
+
id = id.slice(0, -6);
|
|
158
|
+
}
|
|
159
|
+
let assetCode = '';
|
|
160
|
+
if (type === 'component') {
|
|
161
|
+
const source = matchEasyCom(id, false);
|
|
162
|
+
if (source) {
|
|
163
|
+
const easyComponentId = (0, compiler_core_1.toValidAssetId)(id, 'easycom');
|
|
164
|
+
const componentId = (0, compiler_core_1.toValidAssetId)(id, type);
|
|
165
|
+
assetCode = `const ${componentId} = ${helper(runtimeHelpers_1.RESOLVE_EASY_COMPONENT)}(${JSON.stringify(id)},${easyComponentId}${maybeSelfReference ? `, true` : ``})`;
|
|
166
|
+
const importCode = `import ${easyComponentId} from '${source}';`;
|
|
167
|
+
if (!importEasyComponents.includes(importCode)) {
|
|
168
|
+
importEasyComponents.push(importCode);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!assetCode) {
|
|
173
|
+
assetCode = `const ${(0, compiler_core_1.toValidAssetId)(id, type)} = ${resolver}(${JSON.stringify(id)}${maybeSelfReference ? `, true` : ``})`;
|
|
174
|
+
}
|
|
175
|
+
push(assetCode);
|
|
176
|
+
if (i < assets.length - 1) {
|
|
177
|
+
newline();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
function isText(n) {
|
|
182
|
+
return ((0, shared_1.isString)(n) ||
|
|
183
|
+
n.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
184
|
+
n.type === 2 /* NodeTypes.TEXT */ ||
|
|
185
|
+
n.type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
186
|
+
n.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */);
|
|
187
|
+
}
|
|
188
|
+
function genNodeListAsArray(nodes, context) {
|
|
189
|
+
const multilines = nodes.length > 3 || nodes.some((n) => (0, shared_1.isArray)(n) || !isText(n));
|
|
190
|
+
context.push(`[`);
|
|
191
|
+
multilines && context.indent();
|
|
192
|
+
genNodeList(nodes, context, multilines);
|
|
193
|
+
multilines && context.deindent();
|
|
194
|
+
context.push(`]`);
|
|
195
|
+
}
|
|
196
|
+
function genNodeList(nodes, context, multilines = false, comma = true) {
|
|
197
|
+
const { push, newline } = context;
|
|
198
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
199
|
+
const node = nodes[i];
|
|
200
|
+
if ((0, shared_1.isString)(node)) {
|
|
201
|
+
push(node);
|
|
202
|
+
}
|
|
203
|
+
else if ((0, shared_1.isArray)(node)) {
|
|
204
|
+
genNodeListAsArray(node, context);
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
genNode(node, context);
|
|
208
|
+
}
|
|
209
|
+
if (i < nodes.length - 1) {
|
|
210
|
+
if (multilines) {
|
|
211
|
+
comma && push(',');
|
|
212
|
+
newline();
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
comma && push(', ');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
function genNode(node, context) {
|
|
221
|
+
if ((0, shared_1.isString)(node)) {
|
|
222
|
+
context.push(node);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if ((0, shared_1.isSymbol)(node)) {
|
|
226
|
+
context.push(context.helper(node));
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
switch (node.type) {
|
|
230
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
231
|
+
case 9 /* NodeTypes.IF */:
|
|
232
|
+
case 11 /* NodeTypes.FOR */:
|
|
233
|
+
genNode(node.codegenNode, context);
|
|
234
|
+
break;
|
|
235
|
+
case 2 /* NodeTypes.TEXT */:
|
|
236
|
+
genText(node, context);
|
|
237
|
+
break;
|
|
238
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
239
|
+
genExpression(node, context);
|
|
240
|
+
break;
|
|
241
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
242
|
+
genInterpolation(node, context);
|
|
243
|
+
break;
|
|
244
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
245
|
+
genNode(node.codegenNode, context);
|
|
246
|
+
break;
|
|
247
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
248
|
+
genCompoundExpression(node, context);
|
|
249
|
+
break;
|
|
250
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
251
|
+
genComment(node, context);
|
|
252
|
+
break;
|
|
253
|
+
case 13 /* NodeTypes.VNODE_CALL */:
|
|
254
|
+
genVNodeCall(node, context);
|
|
255
|
+
break;
|
|
256
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
257
|
+
genCallExpression(node, context);
|
|
258
|
+
break;
|
|
259
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
260
|
+
genObjectExpression(node, context);
|
|
261
|
+
break;
|
|
262
|
+
case 17 /* NodeTypes.JS_ARRAY_EXPRESSION */:
|
|
263
|
+
genArrayExpression(node, context);
|
|
264
|
+
break;
|
|
265
|
+
case 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */:
|
|
266
|
+
genFunctionExpression(node, context);
|
|
267
|
+
break;
|
|
268
|
+
case 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */:
|
|
269
|
+
genConditionalExpression(node, context);
|
|
270
|
+
break;
|
|
271
|
+
case 20 /* NodeTypes.JS_CACHE_EXPRESSION */:
|
|
272
|
+
genCacheExpression(node, context);
|
|
273
|
+
break;
|
|
274
|
+
/* istanbul ignore next */
|
|
275
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
276
|
+
// noop
|
|
277
|
+
break;
|
|
278
|
+
default:
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
function genText(node, context) {
|
|
282
|
+
context.push(JSON.stringify(node.content), node);
|
|
283
|
+
}
|
|
284
|
+
function genExpression(node, context) {
|
|
285
|
+
const { content, isStatic } = node;
|
|
286
|
+
context.push(isStatic ? JSON.stringify(content) : content, node);
|
|
287
|
+
}
|
|
288
|
+
function genInterpolation(node, context) {
|
|
289
|
+
const { push, helper } = context;
|
|
290
|
+
push(`${helper(compiler_core_1.TO_DISPLAY_STRING)}(`);
|
|
291
|
+
genNode(node.content, context);
|
|
292
|
+
push(`)`);
|
|
293
|
+
}
|
|
294
|
+
function genCompoundExpression(node, context) {
|
|
295
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
296
|
+
const child = node.children[i];
|
|
297
|
+
if ((0, shared_1.isString)(child)) {
|
|
298
|
+
context.push(child);
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
genNode(child, context);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
function genExpressionAsPropertyKey(node, context) {
|
|
306
|
+
const { push } = context;
|
|
307
|
+
if (node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
308
|
+
// dynamic arg genObjectExpression have added []
|
|
309
|
+
// push(`[`)
|
|
310
|
+
genCompoundExpression(node, context);
|
|
311
|
+
// push(`]`)
|
|
312
|
+
}
|
|
313
|
+
else if (node.isStatic) {
|
|
314
|
+
// only quote keys if necessary
|
|
315
|
+
const text = JSON.stringify(node.content);
|
|
316
|
+
push(text, node);
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
// dynamic arg genObjectExpression have added []
|
|
320
|
+
// push(`[${node.content}]`, node)
|
|
321
|
+
push(`${node.content}`, node);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
function genComment(node, context) {
|
|
325
|
+
const { push, helper } = context;
|
|
326
|
+
push(`${helper(compiler_core_1.CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
|
|
327
|
+
}
|
|
328
|
+
function parseTag(tag, { parseUTSComponent, targetLanguage, importUTSComponents }) {
|
|
329
|
+
if ((0, shared_1.isString)(tag)) {
|
|
330
|
+
// 原生UTS组件
|
|
331
|
+
const utsComponentOptions = parseUTSComponent(tag.slice(1, -1), targetLanguage);
|
|
332
|
+
if (utsComponentOptions) {
|
|
333
|
+
const importCode = `import '${utsComponentOptions.source}';`;
|
|
334
|
+
if (!importUTSComponents.includes(importCode)) {
|
|
335
|
+
importUTSComponents.push(importCode);
|
|
336
|
+
}
|
|
337
|
+
return (utsComponentOptions.namespace +
|
|
338
|
+
'.' +
|
|
339
|
+
utsComponentOptions.className +
|
|
340
|
+
'.name');
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return tag;
|
|
344
|
+
}
|
|
345
|
+
function genVNodeCall(node, context) {
|
|
346
|
+
const { push, helper } = context;
|
|
347
|
+
const { tag, props, children, patchFlag, dynamicProps, directives,
|
|
348
|
+
// isBlock,
|
|
349
|
+
disableTracking, isComponent, } = node;
|
|
350
|
+
if (directives) {
|
|
351
|
+
push(helper(compiler_core_1.WITH_DIRECTIVES) + `(`);
|
|
352
|
+
}
|
|
353
|
+
const isBlock = false;
|
|
354
|
+
if (isBlock) {
|
|
355
|
+
push(`(${helper(compiler_core_1.OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
|
|
356
|
+
}
|
|
357
|
+
const callHelper = isBlock
|
|
358
|
+
? (0, compiler_core_1.getVNodeBlockHelper)(false, isComponent)
|
|
359
|
+
: (0, compiler_core_1.getVNodeHelper)(false, isComponent);
|
|
360
|
+
push(helper(callHelper) + `(`, node);
|
|
361
|
+
genNodeList(genNullableArgs([
|
|
362
|
+
parseTag(tag, context),
|
|
363
|
+
props,
|
|
364
|
+
children,
|
|
365
|
+
patchFlag,
|
|
366
|
+
dynamicProps,
|
|
367
|
+
]), context);
|
|
368
|
+
push(`)`);
|
|
369
|
+
if (isBlock) {
|
|
370
|
+
push(`)`);
|
|
371
|
+
}
|
|
372
|
+
if (directives) {
|
|
373
|
+
push(`, `);
|
|
374
|
+
genNode(directives, context);
|
|
375
|
+
push(`)`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function genNullableArgs(args) {
|
|
379
|
+
let i = args.length;
|
|
380
|
+
while (i--) {
|
|
381
|
+
if (args[i] != null)
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
return args.slice(0, i + 1).map((arg) => arg || `null`);
|
|
385
|
+
}
|
|
386
|
+
// JavaScript
|
|
387
|
+
function genCallExpression(node, context) {
|
|
388
|
+
const { push, helper } = context;
|
|
389
|
+
const callee = (0, shared_1.isString)(node.callee) ? node.callee : helper(node.callee);
|
|
390
|
+
push(callee + `(`, node);
|
|
391
|
+
if (callee === helper(runtimeHelpers_1.RENDER_LIST)) {
|
|
392
|
+
genRenderList(node);
|
|
393
|
+
}
|
|
394
|
+
if (callee === helper(runtimeHelpers_1.TO_HANDLERS)) {
|
|
395
|
+
genToHandlers(node, push);
|
|
396
|
+
}
|
|
397
|
+
genNodeList(node.arguments, context);
|
|
398
|
+
push(`)`);
|
|
399
|
+
}
|
|
400
|
+
function genRenderList(node) {
|
|
401
|
+
node.arguments.forEach((argument) => {
|
|
402
|
+
if (argument.type === 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */) {
|
|
403
|
+
argument.returnType = 'VNode';
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
function genToHandlers(node, push) {
|
|
408
|
+
push(`new Map<string, any | null>([`);
|
|
409
|
+
const argument = node.arguments[0];
|
|
410
|
+
if (argument?.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
411
|
+
;
|
|
412
|
+
argument.children.forEach((child, index) => {
|
|
413
|
+
if ((0, shared_1.isString)(child)) {
|
|
414
|
+
if (index ===
|
|
415
|
+
argument.children.length - 1) {
|
|
416
|
+
;
|
|
417
|
+
argument.children[index] =
|
|
418
|
+
child.replace('}', '])');
|
|
419
|
+
}
|
|
420
|
+
else {
|
|
421
|
+
;
|
|
422
|
+
argument.children[index] = child
|
|
423
|
+
.replace('{', '["')
|
|
424
|
+
.replace(',', ',["')
|
|
425
|
+
.replace(':', '",')
|
|
426
|
+
.replaceAll(' ', '');
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
child.content = child.content += ']';
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
if (argument?.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
435
|
+
;
|
|
436
|
+
argument.content =
|
|
437
|
+
(0, utils_2.object2Map)(argument.content, false) + '])';
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
function genObjectExpression(node, context) {
|
|
441
|
+
const { push, indent, deindent, newline } = context;
|
|
442
|
+
const { properties } = node;
|
|
443
|
+
if (!properties.length) {
|
|
444
|
+
push(`new Map<string, any | null>()`, node);
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
const multilines = properties.length > 1 ||
|
|
448
|
+
properties.some((p) => p.value.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */);
|
|
449
|
+
push(`new Map<string, any | null>([`);
|
|
450
|
+
multilines && indent();
|
|
451
|
+
for (let i = 0; i < properties.length; i++) {
|
|
452
|
+
const { key, value } = properties[i];
|
|
453
|
+
push(`[`);
|
|
454
|
+
// key
|
|
455
|
+
genExpressionAsPropertyKey(key, context);
|
|
456
|
+
push(`, `);
|
|
457
|
+
// value
|
|
458
|
+
genNode(value, context);
|
|
459
|
+
push(`]`);
|
|
460
|
+
if (i < properties.length - 1) {
|
|
461
|
+
// will only reach this if it's multilines
|
|
462
|
+
push(`,`);
|
|
463
|
+
newline();
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
multilines && deindent();
|
|
467
|
+
push(`])`);
|
|
468
|
+
}
|
|
469
|
+
function genArrayExpression(node, context) {
|
|
470
|
+
genNodeListAsArray(node.elements, context);
|
|
471
|
+
}
|
|
472
|
+
function genFunctionExpression(node, context) {
|
|
473
|
+
const { push, indent, deindent } = context;
|
|
474
|
+
const { params, returns, body, newline, isSlot } = node;
|
|
475
|
+
if (isSlot) {
|
|
476
|
+
// wrap slot functions with owner context
|
|
477
|
+
// push(`_${helperNameMap[WITH_CTX]}(`)
|
|
478
|
+
push('(');
|
|
479
|
+
}
|
|
480
|
+
push(`(`, node);
|
|
481
|
+
if ((0, shared_1.isArray)(params)) {
|
|
482
|
+
genNodeList(params, context);
|
|
483
|
+
}
|
|
484
|
+
else if (params) {
|
|
485
|
+
genNode(params, context);
|
|
486
|
+
}
|
|
487
|
+
if (node.returnType) {
|
|
488
|
+
push(`):${node.returnType} => `);
|
|
489
|
+
}
|
|
490
|
+
else {
|
|
491
|
+
if (isSlot) {
|
|
492
|
+
// TODO: supplement types slots params type based on user-defined slots
|
|
493
|
+
if (params) {
|
|
494
|
+
push(`: Map<string, any | null>): any[] => `);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
push(`): any[] => `);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
push(`) => `);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if (newline || body) {
|
|
505
|
+
push(`{`);
|
|
506
|
+
indent();
|
|
507
|
+
}
|
|
508
|
+
if (returns) {
|
|
509
|
+
if (newline) {
|
|
510
|
+
push(`return `);
|
|
511
|
+
}
|
|
512
|
+
if ((0, shared_1.isArray)(returns)) {
|
|
513
|
+
genNodeListAsArray(returns, context);
|
|
514
|
+
}
|
|
515
|
+
else {
|
|
516
|
+
genNode(returns, context);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
else if (body) {
|
|
520
|
+
genNode(body, context);
|
|
521
|
+
}
|
|
522
|
+
if (newline || body) {
|
|
523
|
+
deindent();
|
|
524
|
+
push(`}`);
|
|
525
|
+
}
|
|
526
|
+
if (isSlot) {
|
|
527
|
+
push(`)`);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function genConditionalExpression(node, context) {
|
|
531
|
+
const { test, consequent, alternate, newline: needNewline } = node;
|
|
532
|
+
const { push, indent, deindent, newline } = context;
|
|
533
|
+
push(`${context.helper(runtimeHelpers_1.IS_TRUE)}(`);
|
|
534
|
+
if (test.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
535
|
+
genExpression(test, context);
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
genNode(test, context);
|
|
539
|
+
}
|
|
540
|
+
push(`)`);
|
|
541
|
+
needNewline && indent();
|
|
542
|
+
context.indentLevel++;
|
|
543
|
+
needNewline || push(` `);
|
|
544
|
+
push(`? `);
|
|
545
|
+
genNode(consequent, context);
|
|
546
|
+
context.indentLevel--;
|
|
547
|
+
needNewline && newline();
|
|
548
|
+
needNewline || push(` `);
|
|
549
|
+
push(`: `);
|
|
550
|
+
const isNested = alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */;
|
|
551
|
+
if (!isNested) {
|
|
552
|
+
context.indentLevel++;
|
|
553
|
+
}
|
|
554
|
+
genNode(alternate, context);
|
|
555
|
+
if (!isNested) {
|
|
556
|
+
context.indentLevel--;
|
|
557
|
+
}
|
|
558
|
+
needNewline && deindent(true /* without newline */);
|
|
559
|
+
}
|
|
560
|
+
function genCacheExpression(node, context) {
|
|
561
|
+
const { push, helper, indent, deindent, newline } = context;
|
|
562
|
+
push(`_cache[${node.index}] || (`);
|
|
563
|
+
if (node.isVNode) {
|
|
564
|
+
indent();
|
|
565
|
+
push(`${helper(compiler_core_1.SET_BLOCK_TRACKING)}(-1),`);
|
|
566
|
+
newline();
|
|
567
|
+
}
|
|
568
|
+
push(`_cache[${node.index}] = `);
|
|
569
|
+
genNode(node.value, context);
|
|
570
|
+
if (node.isVNode) {
|
|
571
|
+
push(`,`);
|
|
572
|
+
newline();
|
|
573
|
+
push(`${helper(compiler_core_1.SET_BLOCK_TRACKING)}(1),`);
|
|
574
|
+
newline();
|
|
575
|
+
push(`_cache[${node.index}]`);
|
|
576
|
+
deindent();
|
|
577
|
+
}
|
|
578
|
+
push(`)`);
|
|
579
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { SourceLocation } from '@vue/compiler-core';
|
|
2
|
+
export interface CompilerError extends SyntaxError {
|
|
3
|
+
code: number | string;
|
|
4
|
+
loc?: SourceLocation;
|
|
5
|
+
}
|
|
6
|
+
export interface CoreCompilerError extends CompilerError {
|
|
7
|
+
code: ErrorCodes;
|
|
8
|
+
}
|
|
9
|
+
export declare function defaultOnError(error: CompilerError): void;
|
|
10
|
+
export declare function defaultOnWarn(msg: CompilerError): void;
|
|
11
|
+
type InferCompilerError<T> = T extends ErrorCodes ? CoreCompilerError : CompilerError;
|
|
12
|
+
export declare function createCompilerError<T extends number>(code: T, loc?: SourceLocation, messages?: {
|
|
13
|
+
[code: number]: string;
|
|
14
|
+
}, additionalMessage?: string): InferCompilerError<T>;
|
|
15
|
+
export declare const enum ErrorCodes {
|
|
16
|
+
ABRUPT_CLOSING_OF_EMPTY_COMMENT = 0,
|
|
17
|
+
CDATA_IN_HTML_CONTENT = 1,
|
|
18
|
+
DUPLICATE_ATTRIBUTE = 2,
|
|
19
|
+
END_TAG_WITH_ATTRIBUTES = 3,
|
|
20
|
+
END_TAG_WITH_TRAILING_SOLIDUS = 4,
|
|
21
|
+
EOF_BEFORE_TAG_NAME = 5,
|
|
22
|
+
EOF_IN_CDATA = 6,
|
|
23
|
+
EOF_IN_COMMENT = 7,
|
|
24
|
+
EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT = 8,
|
|
25
|
+
EOF_IN_TAG = 9,
|
|
26
|
+
INCORRECTLY_CLOSED_COMMENT = 10,
|
|
27
|
+
INCORRECTLY_OPENED_COMMENT = 11,
|
|
28
|
+
INVALID_FIRST_CHARACTER_OF_TAG_NAME = 12,
|
|
29
|
+
MISSING_ATTRIBUTE_VALUE = 13,
|
|
30
|
+
MISSING_END_TAG_NAME = 14,
|
|
31
|
+
MISSING_WHITESPACE_BETWEEN_ATTRIBUTES = 15,
|
|
32
|
+
NESTED_COMMENT = 16,
|
|
33
|
+
UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME = 17,
|
|
34
|
+
UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE = 18,
|
|
35
|
+
UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME = 19,
|
|
36
|
+
UNEXPECTED_NULL_CHARACTER = 20,
|
|
37
|
+
UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME = 21,
|
|
38
|
+
UNEXPECTED_SOLIDUS_IN_TAG = 22,
|
|
39
|
+
X_INVALID_END_TAG = 23,
|
|
40
|
+
X_MISSING_END_TAG = 24,
|
|
41
|
+
X_MISSING_INTERPOLATION_END = 25,
|
|
42
|
+
X_MISSING_DIRECTIVE_NAME = 26,
|
|
43
|
+
X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END = 27,
|
|
44
|
+
X_V_IF_NO_EXPRESSION = 28,
|
|
45
|
+
X_V_IF_SAME_KEY = 29,
|
|
46
|
+
X_V_ELSE_NO_ADJACENT_IF = 30,
|
|
47
|
+
X_V_FOR_NO_EXPRESSION = 31,
|
|
48
|
+
X_V_FOR_MALFORMED_EXPRESSION = 32,
|
|
49
|
+
X_V_FOR_TEMPLATE_KEY_PLACEMENT = 33,
|
|
50
|
+
X_V_BIND_NO_EXPRESSION = 34,
|
|
51
|
+
X_V_ON_NO_EXPRESSION = 35,
|
|
52
|
+
X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET = 36,
|
|
53
|
+
X_V_SLOT_MIXED_SLOT_USAGE = 37,
|
|
54
|
+
X_V_SLOT_DUPLICATE_SLOT_NAMES = 38,
|
|
55
|
+
X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN = 39,
|
|
56
|
+
X_V_SLOT_MISPLACED = 40,
|
|
57
|
+
X_V_MODEL_NO_EXPRESSION = 41,
|
|
58
|
+
X_V_MODEL_MALFORMED_EXPRESSION = 42,
|
|
59
|
+
X_V_MODEL_ON_SCOPE_VARIABLE = 43,
|
|
60
|
+
X_V_MODEL_ON_PROPS = 44,
|
|
61
|
+
X_INVALID_EXPRESSION = 45,
|
|
62
|
+
X_KEEP_ALIVE_INVALID_CHILDREN = 46,
|
|
63
|
+
X_PREFIX_ID_NOT_SUPPORTED = 47,
|
|
64
|
+
X_MODULE_MODE_NOT_SUPPORTED = 48,
|
|
65
|
+
X_CACHE_HANDLER_NOT_SUPPORTED = 49,
|
|
66
|
+
X_SCOPE_ID_NOT_SUPPORTED = 50,
|
|
67
|
+
__EXTEND_POINT__ = 51
|
|
68
|
+
}
|
|
69
|
+
export declare const errorMessages: Record<ErrorCodes, string>;
|
|
70
|
+
export {};
|