@dcloudio/uni-app-uts 3.0.0-alpha-3071320230417001
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 +2 -0
- package/dist/index.js +18 -0
- package/dist/plugins/index.d.ts +2 -0
- package/dist/plugins/index.js +121 -0
- package/dist/plugins/mainUTS.d.ts +4 -0
- package/dist/plugins/mainUTS.js +25 -0
- package/dist/plugins/manifestJson.d.ts +2 -0
- package/dist/plugins/manifestJson.js +57 -0
- package/dist/plugins/pagesJson.d.ts +2 -0
- package/dist/plugins/pagesJson.js +65 -0
- package/dist/plugins/pre.d.ts +7 -0
- package/dist/plugins/pre.js +52 -0
- package/dist/plugins/utils.d.ts +4 -0
- package/dist/plugins/utils.js +29 -0
- package/dist/plugins/uvue/code/script.d.ts +4 -0
- package/dist/plugins/uvue/code/script.js +28 -0
- package/dist/plugins/uvue/code/style.d.ts +4 -0
- package/dist/plugins/uvue/code/style.js +7 -0
- package/dist/plugins/uvue/code/template/compiler/codegen.d.ts +20 -0
- package/dist/plugins/uvue/code/template/compiler/codegen.js +419 -0
- package/dist/plugins/uvue/code/template/compiler/errors.d.ts +70 -0
- package/dist/plugins/uvue/code/template/compiler/errors.js +82 -0
- package/dist/plugins/uvue/code/template/compiler/index.d.ts +8 -0
- package/dist/plugins/uvue/code/template/compiler/index.js +43 -0
- package/dist/plugins/uvue/code/template/compiler/options.d.ts +60 -0
- package/dist/plugins/uvue/code/template/compiler/options.js +2 -0
- package/dist/plugins/uvue/code/template/compiler/transform.d.ts +52 -0
- package/dist/plugins/uvue/code/template/compiler/transform.js +267 -0
- package/dist/plugins/uvue/code/template/index.d.ts +3 -0
- package/dist/plugins/uvue/code/template/index.js +12 -0
- package/dist/plugins/uvue/code/template/utils.d.ts +2 -0
- package/dist/plugins/uvue/code/template/utils.js +7 -0
- package/dist/plugins/uvue/descriptorCache.d.ts +22 -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 +2 -0
- package/dist/plugins/uvue/index.js +78 -0
- package/package.json +36 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SourceMapGenerator } from 'source-map';
|
|
2
|
+
import { JSChildNode, RootNode, SSRCodegenNode, TemplateChildNode } from '@vue/compiler-core';
|
|
3
|
+
import { CodegenOptions, CodegenResult } from './options';
|
|
4
|
+
type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode;
|
|
5
|
+
export interface CodegenContext extends Required<CodegenOptions> {
|
|
6
|
+
source: string;
|
|
7
|
+
code: string;
|
|
8
|
+
line: number;
|
|
9
|
+
column: number;
|
|
10
|
+
offset: number;
|
|
11
|
+
indentLevel: number;
|
|
12
|
+
map?: SourceMapGenerator;
|
|
13
|
+
helper(key: symbol): string;
|
|
14
|
+
push(code: string, node?: CodegenNode): void;
|
|
15
|
+
indent(): void;
|
|
16
|
+
deindent(withoutNewLine?: boolean): void;
|
|
17
|
+
newline(): void;
|
|
18
|
+
}
|
|
19
|
+
export declare function generate(ast: RootNode, options: CodegenOptions): CodegenResult;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,419 @@
|
|
|
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
|
+
function createCodegenContext(ast, { targetLanguage, mode = 'default', prefixIdentifiers = false, sourceMap = false, filename = '', }) {
|
|
9
|
+
const context = {
|
|
10
|
+
targetLanguage,
|
|
11
|
+
mode,
|
|
12
|
+
prefixIdentifiers,
|
|
13
|
+
sourceMap,
|
|
14
|
+
filename,
|
|
15
|
+
source: ast.loc.source,
|
|
16
|
+
code: ``,
|
|
17
|
+
column: 1,
|
|
18
|
+
line: 1,
|
|
19
|
+
offset: 0,
|
|
20
|
+
indentLevel: 0,
|
|
21
|
+
map: undefined,
|
|
22
|
+
helper(key) {
|
|
23
|
+
return `${compiler_core_1.helperNameMap[key]}`;
|
|
24
|
+
},
|
|
25
|
+
push(code, node) {
|
|
26
|
+
context.code += code;
|
|
27
|
+
if (context.map) {
|
|
28
|
+
if (node) {
|
|
29
|
+
let name;
|
|
30
|
+
if (node.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ && !node.isStatic) {
|
|
31
|
+
const content = node.content.replace(/^_ctx\./, '');
|
|
32
|
+
if (content !== node.content && (0, compiler_core_1.isSimpleIdentifier)(content)) {
|
|
33
|
+
name = content;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
addMapping(node.loc.start, name);
|
|
37
|
+
}
|
|
38
|
+
(0, compiler_core_1.advancePositionWithMutation)(context, code);
|
|
39
|
+
if (node && node.loc !== compiler_core_1.locStub) {
|
|
40
|
+
addMapping(node.loc.end);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
indent() {
|
|
45
|
+
newline(++context.indentLevel);
|
|
46
|
+
},
|
|
47
|
+
deindent(withoutNewLine = false) {
|
|
48
|
+
if (withoutNewLine) {
|
|
49
|
+
--context.indentLevel;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
newline(--context.indentLevel);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
newline() {
|
|
56
|
+
newline(context.indentLevel);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
function newline(n) {
|
|
60
|
+
context.push('\n' + ` `.repeat(n));
|
|
61
|
+
}
|
|
62
|
+
function addMapping(loc, name) {
|
|
63
|
+
context.map.addMapping({
|
|
64
|
+
name,
|
|
65
|
+
source: context.filename,
|
|
66
|
+
original: {
|
|
67
|
+
line: loc.line,
|
|
68
|
+
column: loc.column - 1, // source-map column is 0 based
|
|
69
|
+
},
|
|
70
|
+
generated: {
|
|
71
|
+
line: context.line,
|
|
72
|
+
column: context.column - 1,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (sourceMap) {
|
|
77
|
+
// lazy require source-map implementation, only in non-browser builds
|
|
78
|
+
context.map = new source_map_1.SourceMapGenerator();
|
|
79
|
+
context.map.setSourceContent(filename, context.source);
|
|
80
|
+
}
|
|
81
|
+
return context;
|
|
82
|
+
}
|
|
83
|
+
function generate(ast, options) {
|
|
84
|
+
const context = createCodegenContext(ast, options);
|
|
85
|
+
const { mode, deindent, indent, push } = context;
|
|
86
|
+
if (mode === 'function') {
|
|
87
|
+
push((0, utils_1.genRenderFunctionDecl)(options) + ` {`);
|
|
88
|
+
indent();
|
|
89
|
+
push(`return `);
|
|
90
|
+
}
|
|
91
|
+
if (ast.codegenNode) {
|
|
92
|
+
genNode(ast.codegenNode, context);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
push(`null`);
|
|
96
|
+
}
|
|
97
|
+
if (mode === 'function') {
|
|
98
|
+
deindent();
|
|
99
|
+
push(`}`);
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
code: context.code,
|
|
103
|
+
// SourceMapGenerator does have toJSON() method but it's not in the types
|
|
104
|
+
map: context.map ? context.map.toJSON() : undefined,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
exports.generate = generate;
|
|
108
|
+
function isText(n) {
|
|
109
|
+
return ((0, shared_1.isString)(n) ||
|
|
110
|
+
n.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
111
|
+
n.type === 2 /* NodeTypes.TEXT */ ||
|
|
112
|
+
n.type === 5 /* NodeTypes.INTERPOLATION */ ||
|
|
113
|
+
n.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */);
|
|
114
|
+
}
|
|
115
|
+
function genNodeListAsArray(nodes, context) {
|
|
116
|
+
const multilines = nodes.length > 3 || nodes.some((n) => (0, shared_1.isArray)(n) || !isText(n));
|
|
117
|
+
context.push(`[`);
|
|
118
|
+
multilines && context.indent();
|
|
119
|
+
genNodeList(nodes, context, multilines);
|
|
120
|
+
multilines && context.deindent();
|
|
121
|
+
context.push(`]`);
|
|
122
|
+
}
|
|
123
|
+
function genNodeList(nodes, context, multilines = false, comma = true) {
|
|
124
|
+
const { push, newline } = context;
|
|
125
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
126
|
+
const node = nodes[i];
|
|
127
|
+
if ((0, shared_1.isString)(node)) {
|
|
128
|
+
push(node);
|
|
129
|
+
}
|
|
130
|
+
else if ((0, shared_1.isArray)(node)) {
|
|
131
|
+
genNodeListAsArray(node, context);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
genNode(node, context);
|
|
135
|
+
}
|
|
136
|
+
if (i < nodes.length - 1) {
|
|
137
|
+
if (multilines) {
|
|
138
|
+
comma && push(',');
|
|
139
|
+
newline();
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
comma && push(', ');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function genNode(node, context) {
|
|
148
|
+
if ((0, shared_1.isString)(node)) {
|
|
149
|
+
context.push(node);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if ((0, shared_1.isSymbol)(node)) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
switch (node.type) {
|
|
156
|
+
case 1 /* NodeTypes.ELEMENT */:
|
|
157
|
+
case 9 /* NodeTypes.IF */:
|
|
158
|
+
case 11 /* NodeTypes.FOR */:
|
|
159
|
+
genNode(node.codegenNode, context);
|
|
160
|
+
break;
|
|
161
|
+
case 2 /* NodeTypes.TEXT */:
|
|
162
|
+
genText(node, context);
|
|
163
|
+
break;
|
|
164
|
+
case 4 /* NodeTypes.SIMPLE_EXPRESSION */:
|
|
165
|
+
genExpression(node, context);
|
|
166
|
+
break;
|
|
167
|
+
case 5 /* NodeTypes.INTERPOLATION */:
|
|
168
|
+
genInterpolation(node, context);
|
|
169
|
+
break;
|
|
170
|
+
case 12 /* NodeTypes.TEXT_CALL */:
|
|
171
|
+
genNode(node.codegenNode, context);
|
|
172
|
+
break;
|
|
173
|
+
case 8 /* NodeTypes.COMPOUND_EXPRESSION */:
|
|
174
|
+
genCompoundExpression(node, context);
|
|
175
|
+
break;
|
|
176
|
+
case 3 /* NodeTypes.COMMENT */:
|
|
177
|
+
genComment(node, context);
|
|
178
|
+
break;
|
|
179
|
+
case 13 /* NodeTypes.VNODE_CALL */:
|
|
180
|
+
genVNodeCall(node, context);
|
|
181
|
+
break;
|
|
182
|
+
case 14 /* NodeTypes.JS_CALL_EXPRESSION */:
|
|
183
|
+
genCallExpression(node, context);
|
|
184
|
+
break;
|
|
185
|
+
case 15 /* NodeTypes.JS_OBJECT_EXPRESSION */:
|
|
186
|
+
genObjectExpression(node, context);
|
|
187
|
+
break;
|
|
188
|
+
case 17 /* NodeTypes.JS_ARRAY_EXPRESSION */:
|
|
189
|
+
genArrayExpression(node, context);
|
|
190
|
+
break;
|
|
191
|
+
case 18 /* NodeTypes.JS_FUNCTION_EXPRESSION */:
|
|
192
|
+
genFunctionExpression(node, context);
|
|
193
|
+
break;
|
|
194
|
+
case 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */:
|
|
195
|
+
genConditionalExpression(node, context);
|
|
196
|
+
break;
|
|
197
|
+
case 20 /* NodeTypes.JS_CACHE_EXPRESSION */:
|
|
198
|
+
genCacheExpression(node, context);
|
|
199
|
+
break;
|
|
200
|
+
/* istanbul ignore next */
|
|
201
|
+
case 10 /* NodeTypes.IF_BRANCH */:
|
|
202
|
+
// noop
|
|
203
|
+
break;
|
|
204
|
+
default:
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function genText(node, context) {
|
|
208
|
+
context.push(JSON.stringify(node.content), node);
|
|
209
|
+
}
|
|
210
|
+
function genExpression(node, context) {
|
|
211
|
+
const { content, isStatic } = node;
|
|
212
|
+
context.push(isStatic ? JSON.stringify(content) : content, node);
|
|
213
|
+
}
|
|
214
|
+
function genInterpolation(node, context) {
|
|
215
|
+
const { push, helper } = context;
|
|
216
|
+
push(`${helper(compiler_core_1.TO_DISPLAY_STRING)}(`);
|
|
217
|
+
genNode(node.content, context);
|
|
218
|
+
push(`)`);
|
|
219
|
+
}
|
|
220
|
+
function genCompoundExpression(node, context) {
|
|
221
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
222
|
+
const child = node.children[i];
|
|
223
|
+
if ((0, shared_1.isString)(child)) {
|
|
224
|
+
context.push(child);
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
genNode(child, context);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function genExpressionAsPropertyKey(node, context) {
|
|
232
|
+
const { push } = context;
|
|
233
|
+
if (node.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
234
|
+
push(`[`);
|
|
235
|
+
genCompoundExpression(node, context);
|
|
236
|
+
push(`]`);
|
|
237
|
+
}
|
|
238
|
+
else if (node.isStatic) {
|
|
239
|
+
// only quote keys if necessary
|
|
240
|
+
const text = JSON.stringify(node.content);
|
|
241
|
+
push(text, node);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
push(`[${node.content}]`, node);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function genComment(node, context) {
|
|
248
|
+
const { push, helper } = context;
|
|
249
|
+
push(`${helper(compiler_core_1.CREATE_COMMENT)}(${JSON.stringify(node.content)})`, node);
|
|
250
|
+
}
|
|
251
|
+
function genVNodeCall(node, context) {
|
|
252
|
+
const { push, helper } = context;
|
|
253
|
+
const { tag, props, children, patchFlag, dynamicProps, directives,
|
|
254
|
+
// isBlock,
|
|
255
|
+
disableTracking, isComponent, } = node;
|
|
256
|
+
if (directives) {
|
|
257
|
+
push(helper(compiler_core_1.WITH_DIRECTIVES) + `(`);
|
|
258
|
+
}
|
|
259
|
+
const isBlock = false;
|
|
260
|
+
if (isBlock) {
|
|
261
|
+
push(`(${helper(compiler_core_1.OPEN_BLOCK)}(${disableTracking ? `true` : ``}), `);
|
|
262
|
+
}
|
|
263
|
+
const callHelper = isBlock
|
|
264
|
+
? (0, compiler_core_1.getVNodeBlockHelper)(false, isComponent)
|
|
265
|
+
: (0, compiler_core_1.getVNodeHelper)(false, isComponent);
|
|
266
|
+
push(helper(callHelper) + `(`, node);
|
|
267
|
+
genNodeList(genNullableArgs([tag, props, children, patchFlag, dynamicProps]), context);
|
|
268
|
+
push(`)`);
|
|
269
|
+
if (isBlock) {
|
|
270
|
+
push(`)`);
|
|
271
|
+
}
|
|
272
|
+
if (directives) {
|
|
273
|
+
push(`, `);
|
|
274
|
+
genNode(directives, context);
|
|
275
|
+
push(`)`);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function genNullableArgs(args) {
|
|
279
|
+
let i = args.length;
|
|
280
|
+
while (i--) {
|
|
281
|
+
if (args[i] != null)
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
return args.slice(0, i + 1).map((arg) => arg || `null`);
|
|
285
|
+
}
|
|
286
|
+
// JavaScript
|
|
287
|
+
function genCallExpression(node, context) {
|
|
288
|
+
const { push, helper } = context;
|
|
289
|
+
const callee = (0, shared_1.isString)(node.callee) ? node.callee : helper(node.callee);
|
|
290
|
+
push(callee + `(`, node);
|
|
291
|
+
genNodeList(node.arguments, context);
|
|
292
|
+
push(`)`);
|
|
293
|
+
}
|
|
294
|
+
function genObjectExpression(node, context) {
|
|
295
|
+
const { push, indent, deindent, newline } = context;
|
|
296
|
+
const { properties } = node;
|
|
297
|
+
if (!properties.length) {
|
|
298
|
+
push(`new Map<string,any>()`, node);
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const multilines = properties.length > 1 ||
|
|
302
|
+
properties.some((p) => p.value.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */);
|
|
303
|
+
push(`new Map<string,any>([`);
|
|
304
|
+
multilines && indent();
|
|
305
|
+
for (let i = 0; i < properties.length; i++) {
|
|
306
|
+
const { key, value } = properties[i];
|
|
307
|
+
push(`[`);
|
|
308
|
+
// key
|
|
309
|
+
genExpressionAsPropertyKey(key, context);
|
|
310
|
+
push(`, `);
|
|
311
|
+
// value
|
|
312
|
+
genNode(value, context);
|
|
313
|
+
push(`]`);
|
|
314
|
+
if (i < properties.length - 1) {
|
|
315
|
+
// will only reach this if it's multilines
|
|
316
|
+
push(`,`);
|
|
317
|
+
newline();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
multilines && deindent();
|
|
321
|
+
push(`])`);
|
|
322
|
+
}
|
|
323
|
+
function genArrayExpression(node, context) {
|
|
324
|
+
genNodeListAsArray(node.elements, context);
|
|
325
|
+
}
|
|
326
|
+
function genFunctionExpression(node, context) {
|
|
327
|
+
const { push, indent, deindent } = context;
|
|
328
|
+
const { params, returns, body, newline, isSlot } = node;
|
|
329
|
+
if (isSlot) {
|
|
330
|
+
// wrap slot functions with owner context
|
|
331
|
+
push(`_${compiler_core_1.helperNameMap[compiler_core_1.WITH_CTX]}(`);
|
|
332
|
+
}
|
|
333
|
+
push(`(`, node);
|
|
334
|
+
if ((0, shared_1.isArray)(params)) {
|
|
335
|
+
genNodeList(params, context);
|
|
336
|
+
}
|
|
337
|
+
else if (params) {
|
|
338
|
+
genNode(params, context);
|
|
339
|
+
}
|
|
340
|
+
push(`) => `);
|
|
341
|
+
if (newline || body) {
|
|
342
|
+
push(`{`);
|
|
343
|
+
indent();
|
|
344
|
+
}
|
|
345
|
+
if (returns) {
|
|
346
|
+
if (newline) {
|
|
347
|
+
push(`return `);
|
|
348
|
+
}
|
|
349
|
+
if ((0, shared_1.isArray)(returns)) {
|
|
350
|
+
genNodeListAsArray(returns, context);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
genNode(returns, context);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else if (body) {
|
|
357
|
+
genNode(body, context);
|
|
358
|
+
}
|
|
359
|
+
if (newline || body) {
|
|
360
|
+
deindent();
|
|
361
|
+
push(`}`);
|
|
362
|
+
}
|
|
363
|
+
if (isSlot) {
|
|
364
|
+
push(`)`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
function genConditionalExpression(node, context) {
|
|
368
|
+
const { test, consequent, alternate, newline: needNewline } = node;
|
|
369
|
+
const { push, indent, deindent, newline } = context;
|
|
370
|
+
if (test.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */) {
|
|
371
|
+
const needsParens = !(0, compiler_core_1.isSimpleIdentifier)(test.content);
|
|
372
|
+
needsParens && push(`(`);
|
|
373
|
+
genExpression(test, context);
|
|
374
|
+
needsParens && push(`)`);
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
push(`(`);
|
|
378
|
+
genNode(test, context);
|
|
379
|
+
push(`)`);
|
|
380
|
+
}
|
|
381
|
+
needNewline && indent();
|
|
382
|
+
context.indentLevel++;
|
|
383
|
+
needNewline || push(` `);
|
|
384
|
+
push(`? `);
|
|
385
|
+
genNode(consequent, context);
|
|
386
|
+
context.indentLevel--;
|
|
387
|
+
needNewline && newline();
|
|
388
|
+
needNewline || push(` `);
|
|
389
|
+
push(`: `);
|
|
390
|
+
const isNested = alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */;
|
|
391
|
+
if (!isNested) {
|
|
392
|
+
context.indentLevel++;
|
|
393
|
+
}
|
|
394
|
+
genNode(alternate, context);
|
|
395
|
+
if (!isNested) {
|
|
396
|
+
context.indentLevel--;
|
|
397
|
+
}
|
|
398
|
+
needNewline && deindent(true /* without newline */);
|
|
399
|
+
}
|
|
400
|
+
function genCacheExpression(node, context) {
|
|
401
|
+
const { push, helper, indent, deindent, newline } = context;
|
|
402
|
+
push(`_cache[${node.index}] || (`);
|
|
403
|
+
if (node.isVNode) {
|
|
404
|
+
indent();
|
|
405
|
+
push(`${helper(compiler_core_1.SET_BLOCK_TRACKING)}(-1),`);
|
|
406
|
+
newline();
|
|
407
|
+
}
|
|
408
|
+
push(`_cache[${node.index}] = `);
|
|
409
|
+
genNode(node.value, context);
|
|
410
|
+
if (node.isVNode) {
|
|
411
|
+
push(`,`);
|
|
412
|
+
newline();
|
|
413
|
+
push(`${helper(compiler_core_1.SET_BLOCK_TRACKING)}(1),`);
|
|
414
|
+
newline();
|
|
415
|
+
push(`_cache[${node.index}]`);
|
|
416
|
+
deindent();
|
|
417
|
+
}
|
|
418
|
+
push(`)`);
|
|
419
|
+
}
|
|
@@ -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 {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.errorMessages = exports.createCompilerError = exports.defaultOnWarn = exports.defaultOnError = void 0;
|
|
4
|
+
function defaultOnError(error) {
|
|
5
|
+
throw error;
|
|
6
|
+
}
|
|
7
|
+
exports.defaultOnError = defaultOnError;
|
|
8
|
+
function defaultOnWarn(msg) {
|
|
9
|
+
console.warn(`[Vue warn] ${msg.message}`);
|
|
10
|
+
}
|
|
11
|
+
exports.defaultOnWarn = defaultOnWarn;
|
|
12
|
+
function createCompilerError(code, loc, messages, additionalMessage) {
|
|
13
|
+
const msg = (messages || exports.errorMessages)[code] + (additionalMessage || ``);
|
|
14
|
+
const error = new SyntaxError(String(msg));
|
|
15
|
+
error.code = code;
|
|
16
|
+
error.loc = loc;
|
|
17
|
+
return error;
|
|
18
|
+
}
|
|
19
|
+
exports.createCompilerError = createCompilerError;
|
|
20
|
+
exports.errorMessages = {
|
|
21
|
+
// parse errors
|
|
22
|
+
[0 /* ErrorCodes.ABRUPT_CLOSING_OF_EMPTY_COMMENT */]: 'Illegal comment.',
|
|
23
|
+
[1 /* ErrorCodes.CDATA_IN_HTML_CONTENT */]: 'CDATA section is allowed only in XML context.',
|
|
24
|
+
[2 /* ErrorCodes.DUPLICATE_ATTRIBUTE */]: 'Duplicate attribute.',
|
|
25
|
+
[3 /* ErrorCodes.END_TAG_WITH_ATTRIBUTES */]: 'End tag cannot have attributes.',
|
|
26
|
+
[4 /* ErrorCodes.END_TAG_WITH_TRAILING_SOLIDUS */]: "Illegal '/' in tags.",
|
|
27
|
+
[5 /* ErrorCodes.EOF_BEFORE_TAG_NAME */]: 'Unexpected EOF in tag.',
|
|
28
|
+
[6 /* ErrorCodes.EOF_IN_CDATA */]: 'Unexpected EOF in CDATA section.',
|
|
29
|
+
[7 /* ErrorCodes.EOF_IN_COMMENT */]: 'Unexpected EOF in comment.',
|
|
30
|
+
[8 /* ErrorCodes.EOF_IN_SCRIPT_HTML_COMMENT_LIKE_TEXT */]: 'Unexpected EOF in script.',
|
|
31
|
+
[9 /* ErrorCodes.EOF_IN_TAG */]: 'Unexpected EOF in tag.',
|
|
32
|
+
[10 /* ErrorCodes.INCORRECTLY_CLOSED_COMMENT */]: 'Incorrectly closed comment.',
|
|
33
|
+
[11 /* ErrorCodes.INCORRECTLY_OPENED_COMMENT */]: 'Incorrectly opened comment.',
|
|
34
|
+
[12 /* ErrorCodes.INVALID_FIRST_CHARACTER_OF_TAG_NAME */]: "Illegal tag name. Use '<' to print '<'.",
|
|
35
|
+
[13 /* ErrorCodes.MISSING_ATTRIBUTE_VALUE */]: 'Attribute value was expected.',
|
|
36
|
+
[14 /* ErrorCodes.MISSING_END_TAG_NAME */]: 'End tag name was expected.',
|
|
37
|
+
[15 /* ErrorCodes.MISSING_WHITESPACE_BETWEEN_ATTRIBUTES */]: 'Whitespace was expected.',
|
|
38
|
+
[16 /* ErrorCodes.NESTED_COMMENT */]: "Unexpected '<!--' in comment.",
|
|
39
|
+
[17 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAME */]: 'Attribute name cannot contain U+0022 ("), U+0027 (\'), and U+003C (<).',
|
|
40
|
+
[18 /* ErrorCodes.UNEXPECTED_CHARACTER_IN_UNQUOTED_ATTRIBUTE_VALUE */]: 'Unquoted attribute value cannot contain U+0022 ("), U+0027 (\'), U+003C (<), U+003D (=), and U+0060 (`).',
|
|
41
|
+
[19 /* ErrorCodes.UNEXPECTED_EQUALS_SIGN_BEFORE_ATTRIBUTE_NAME */]: "Attribute name cannot start with '='.",
|
|
42
|
+
[21 /* ErrorCodes.UNEXPECTED_QUESTION_MARK_INSTEAD_OF_TAG_NAME */]: "'<?' is allowed only in XML context.",
|
|
43
|
+
[20 /* ErrorCodes.UNEXPECTED_NULL_CHARACTER */]: `Unexpected null character.`,
|
|
44
|
+
[22 /* ErrorCodes.UNEXPECTED_SOLIDUS_IN_TAG */]: "Illegal '/' in tags.",
|
|
45
|
+
// Vue-specific parse errors
|
|
46
|
+
[23 /* ErrorCodes.X_INVALID_END_TAG */]: 'Invalid end tag.',
|
|
47
|
+
[24 /* ErrorCodes.X_MISSING_END_TAG */]: 'Element is missing end tag.',
|
|
48
|
+
[25 /* ErrorCodes.X_MISSING_INTERPOLATION_END */]: 'Interpolation end sign was not found.',
|
|
49
|
+
[27 /* ErrorCodes.X_MISSING_DYNAMIC_DIRECTIVE_ARGUMENT_END */]: 'End bracket for dynamic directive argument was not found. ' +
|
|
50
|
+
'Note that dynamic directive argument cannot contain spaces.',
|
|
51
|
+
[26 /* ErrorCodes.X_MISSING_DIRECTIVE_NAME */]: 'Legal directive name was expected.',
|
|
52
|
+
// transform errors
|
|
53
|
+
[28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */]: `v-if/v-else-if is missing expression.`,
|
|
54
|
+
[29 /* ErrorCodes.X_V_IF_SAME_KEY */]: `v-if/else branches must use unique keys.`,
|
|
55
|
+
[30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */]: `v-else/v-else-if has no adjacent v-if or v-else-if.`,
|
|
56
|
+
[31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */]: `v-for is missing expression.`,
|
|
57
|
+
[32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */]: `v-for has invalid expression.`,
|
|
58
|
+
[33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */]: `<template v-for> key should be placed on the <template> tag.`,
|
|
59
|
+
[34 /* ErrorCodes.X_V_BIND_NO_EXPRESSION */]: `v-bind is missing expression.`,
|
|
60
|
+
[35 /* ErrorCodes.X_V_ON_NO_EXPRESSION */]: `v-on is missing expression.`,
|
|
61
|
+
[36 /* ErrorCodes.X_V_SLOT_UNEXPECTED_DIRECTIVE_ON_SLOT_OUTLET */]: `Unexpected custom directive on <slot> outlet.`,
|
|
62
|
+
[37 /* ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE */]: `Mixed v-slot usage on both the component and nested <template>. ` +
|
|
63
|
+
`When there are multiple named slots, all slots should use <template> ` +
|
|
64
|
+
`syntax to avoid scope ambiguity.`,
|
|
65
|
+
[38 /* ErrorCodes.X_V_SLOT_DUPLICATE_SLOT_NAMES */]: `Duplicate slot names found. `,
|
|
66
|
+
[39 /* ErrorCodes.X_V_SLOT_EXTRANEOUS_DEFAULT_SLOT_CHILDREN */]: `Extraneous children found when component already has explicitly named ` +
|
|
67
|
+
`default slot. These children will be ignored.`,
|
|
68
|
+
[40 /* ErrorCodes.X_V_SLOT_MISPLACED */]: `v-slot can only be used on components or <template> tags.`,
|
|
69
|
+
[41 /* ErrorCodes.X_V_MODEL_NO_EXPRESSION */]: `v-model is missing expression.`,
|
|
70
|
+
[42 /* ErrorCodes.X_V_MODEL_MALFORMED_EXPRESSION */]: `v-model value must be a valid JavaScript member expression.`,
|
|
71
|
+
[43 /* ErrorCodes.X_V_MODEL_ON_SCOPE_VARIABLE */]: `v-model cannot be used on v-for or v-slot scope variables because they are not writable.`,
|
|
72
|
+
[44 /* ErrorCodes.X_V_MODEL_ON_PROPS */]: `v-model cannot be used on a prop, because local prop bindings are not writable.\nUse a v-bind binding combined with a v-on listener that emits update:x event instead.`,
|
|
73
|
+
[45 /* ErrorCodes.X_INVALID_EXPRESSION */]: `Error parsing JavaScript expression: `,
|
|
74
|
+
[46 /* ErrorCodes.X_KEEP_ALIVE_INVALID_CHILDREN */]: `<KeepAlive> expects exactly one child component.`,
|
|
75
|
+
// generic errors
|
|
76
|
+
[47 /* ErrorCodes.X_PREFIX_ID_NOT_SUPPORTED */]: `"prefixIdentifiers" option is not supported in this build of compiler.`,
|
|
77
|
+
[48 /* ErrorCodes.X_MODULE_MODE_NOT_SUPPORTED */]: `ES module mode is not supported in this build of compiler.`,
|
|
78
|
+
[49 /* ErrorCodes.X_CACHE_HANDLER_NOT_SUPPORTED */]: `"cacheHandlers" option is only supported when the "prefixIdentifiers" option is enabled.`,
|
|
79
|
+
[50 /* ErrorCodes.X_SCOPE_ID_NOT_SUPPORTED */]: `"scopeId" option is only supported in module mode.`,
|
|
80
|
+
// just to fulfill types
|
|
81
|
+
[51 /* ErrorCodes.__EXTEND_POINT__ */]: ``,
|
|
82
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CodegenResult, CompilerOptions } from './options';
|
|
2
|
+
import { DirectiveTransform, NodeTransform } from './transform';
|
|
3
|
+
export type TransformPreset = [
|
|
4
|
+
NodeTransform[],
|
|
5
|
+
Record<string, DirectiveTransform>
|
|
6
|
+
];
|
|
7
|
+
export declare function getBaseTransformPreset(prefixIdentifiers?: boolean): TransformPreset;
|
|
8
|
+
export declare function compile(template: string, options: CompilerOptions): CodegenResult;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compile = exports.getBaseTransformPreset = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
6
|
+
const codegen_1 = require("./codegen");
|
|
7
|
+
const transform_1 = require("./transform");
|
|
8
|
+
function getBaseTransformPreset(prefixIdentifiers) {
|
|
9
|
+
return [
|
|
10
|
+
[
|
|
11
|
+
// order is important
|
|
12
|
+
compiler_core_1.trackVForSlotScopes,
|
|
13
|
+
compiler_core_1.transformExpression,
|
|
14
|
+
compiler_core_1.transformElement,
|
|
15
|
+
compiler_core_1.trackSlotScopes,
|
|
16
|
+
],
|
|
17
|
+
{
|
|
18
|
+
on: compiler_core_1.transformOn,
|
|
19
|
+
bind: compiler_core_1.transformBind,
|
|
20
|
+
model: compiler_core_1.transformModel,
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
}
|
|
24
|
+
exports.getBaseTransformPreset = getBaseTransformPreset;
|
|
25
|
+
function compile(template, options) {
|
|
26
|
+
const ast = (0, compiler_core_1.baseParse)(template, {
|
|
27
|
+
isCustomElement(tag) {
|
|
28
|
+
return true;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const [nodeTransforms, directiveTransforms] = getBaseTransformPreset(options.prefixIdentifiers);
|
|
32
|
+
(0, transform_1.transform)(ast, (0, shared_1.extend)({}, options, {
|
|
33
|
+
prefixIdentifiers: options.prefixIdentifiers,
|
|
34
|
+
nodeTransforms: [
|
|
35
|
+
...nodeTransforms,
|
|
36
|
+
...(options.nodeTransforms || []), // user transforms
|
|
37
|
+
],
|
|
38
|
+
directiveTransforms: (0, shared_1.extend)({}, directiveTransforms, options.directiveTransforms || {} // user transforms
|
|
39
|
+
),
|
|
40
|
+
}));
|
|
41
|
+
return (0, codegen_1.generate)(ast, options);
|
|
42
|
+
}
|
|
43
|
+
exports.compile = compile;
|