@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,325 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createForLoopParams = exports.parseForExpression = exports.processFor = exports.transformFor = void 0;
|
|
4
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const compiler_core_2 = require("@vue/compiler-core");
|
|
7
|
+
const runtimeHelpers_1 = require("../runtimeHelpers");
|
|
8
|
+
const transformExpression_1 = require("./transformExpression");
|
|
9
|
+
// import { validateBrowserExpression } from '../validateExpression'
|
|
10
|
+
const shared_1 = require("@vue/shared");
|
|
11
|
+
const transform_1 = require("../transform");
|
|
12
|
+
exports.transformFor = (0, transform_1.createStructuralDirectiveTransform)('for', (node, dir, context) => {
|
|
13
|
+
const { helper, removeHelper } = context;
|
|
14
|
+
return processFor(node, dir, context, (forNode) => {
|
|
15
|
+
// create the loop render function expression now, and add the
|
|
16
|
+
// iterator on exit after all children have been traversed
|
|
17
|
+
const renderExp = (0, compiler_core_1.createCallExpression)(helper(runtimeHelpers_1.RENDER_LIST), [
|
|
18
|
+
forNode.source,
|
|
19
|
+
]);
|
|
20
|
+
const isTemplate = (0, compiler_core_2.isTemplateNode)(node);
|
|
21
|
+
// const memo = findDir(node, 'memo')
|
|
22
|
+
const keyProp = (0, compiler_core_2.findProp)(node, `key`);
|
|
23
|
+
const keyExp = keyProp &&
|
|
24
|
+
(keyProp.type === 6 /* NodeTypes.ATTRIBUTE */
|
|
25
|
+
? (0, compiler_core_1.createSimpleExpression)(keyProp.value.content, true)
|
|
26
|
+
: keyProp.exp);
|
|
27
|
+
const keyProperty = keyProp ? (0, compiler_core_1.createObjectProperty)(`key`, keyExp) : null;
|
|
28
|
+
// if (!__BROWSER__ && isTemplate) {
|
|
29
|
+
if (isTemplate) {
|
|
30
|
+
// #2085 / #5288 process :key and v-memo expressions need to be
|
|
31
|
+
// processed on `<template v-for>`. In this case the node is discarded
|
|
32
|
+
// and never traversed so its binding expressions won't be processed
|
|
33
|
+
// by the normal transforms.
|
|
34
|
+
// if (memo) {
|
|
35
|
+
// memo.exp = processExpression(
|
|
36
|
+
// memo.exp! as SimpleExpressionNode,
|
|
37
|
+
// context
|
|
38
|
+
// )
|
|
39
|
+
// }
|
|
40
|
+
if (keyProperty && keyProp.type !== 6 /* NodeTypes.ATTRIBUTE */) {
|
|
41
|
+
keyProperty.value = (0, transformExpression_1.processExpression)(keyProperty.value, context);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const isStableFragment = forNode.source.type === 4 /* NodeTypes.SIMPLE_EXPRESSION */ &&
|
|
45
|
+
forNode.source.constType > 0 /* ConstantTypes.NOT_CONSTANT */;
|
|
46
|
+
const fragmentFlag = isStableFragment
|
|
47
|
+
? 64 /* PatchFlags.STABLE_FRAGMENT */
|
|
48
|
+
: keyProp
|
|
49
|
+
? 128 /* PatchFlags.KEYED_FRAGMENT */
|
|
50
|
+
: 256 /* PatchFlags.UNKEYED_FRAGMENT */;
|
|
51
|
+
forNode.codegenNode = (0, compiler_core_1.createVNodeCall)(context, helper(runtimeHelpers_1.FRAGMENT), undefined, renderExp, fragmentFlag +
|
|
52
|
+
// (__DEV__ ? ` /* ${PatchFlagNames[fragmentFlag]} */` : ``),
|
|
53
|
+
` /* ${shared_1.PatchFlagNames[fragmentFlag]} */`, undefined, undefined, true /* isBlock */, !isStableFragment /* disableTracking */, false /* isComponent */, node.loc);
|
|
54
|
+
return () => {
|
|
55
|
+
// finish the codegen now that all children have been traversed
|
|
56
|
+
let childBlock;
|
|
57
|
+
const { children } = forNode;
|
|
58
|
+
// check <template v-for> key placement
|
|
59
|
+
// if ((__DEV__ || !__BROWSER__) && isTemplate) {
|
|
60
|
+
if (isTemplate) {
|
|
61
|
+
node.children.some((c) => {
|
|
62
|
+
if (c.type === 1 /* NodeTypes.ELEMENT */) {
|
|
63
|
+
const key = (0, compiler_core_2.findProp)(c, 'key');
|
|
64
|
+
if (key) {
|
|
65
|
+
context.onError((0, errors_1.createCompilerError)(33 /* ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT */, key.loc));
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const needFragmentWrapper = children.length !== 1 || children[0].type !== 1 /* NodeTypes.ELEMENT */;
|
|
72
|
+
const slotOutlet = (0, compiler_core_2.isSlotOutlet)(node)
|
|
73
|
+
? node
|
|
74
|
+
: isTemplate &&
|
|
75
|
+
node.children.length === 1 &&
|
|
76
|
+
(0, compiler_core_2.isSlotOutlet)(node.children[0])
|
|
77
|
+
? node.children[0] // api-extractor somehow fails to infer this
|
|
78
|
+
: null;
|
|
79
|
+
if (slotOutlet) {
|
|
80
|
+
// <slot v-for="..."> or <template v-for="..."><slot/></template>
|
|
81
|
+
childBlock = slotOutlet.codegenNode;
|
|
82
|
+
if (isTemplate && keyProperty) {
|
|
83
|
+
// <template v-for="..." :key="..."><slot/></template>
|
|
84
|
+
// we need to inject the key to the renderSlot() call.
|
|
85
|
+
// the props for renderSlot is passed as the 3rd argument.
|
|
86
|
+
(0, compiler_core_2.injectProp)(childBlock, keyProperty, context);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
else if (needFragmentWrapper) {
|
|
90
|
+
// <template v-for="..."> with text or multi-elements
|
|
91
|
+
// should generate a fragment block for each loop
|
|
92
|
+
childBlock = (0, compiler_core_1.createVNodeCall)(context, helper(runtimeHelpers_1.FRAGMENT), keyProperty ? (0, compiler_core_1.createObjectExpression)([keyProperty]) : undefined, node.children, 64 /* PatchFlags.STABLE_FRAGMENT */ +
|
|
93
|
+
// (__DEV__
|
|
94
|
+
// ? ` /* ${PatchFlagNames[PatchFlags.STABLE_FRAGMENT]} */`
|
|
95
|
+
// : ``),
|
|
96
|
+
` /* ${shared_1.PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */]} */`, undefined, undefined, true, undefined, false /* isComponent */);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Normal element v-for. Directly use the child's codegenNode
|
|
100
|
+
// but mark it as a block.
|
|
101
|
+
childBlock = children[0]
|
|
102
|
+
.codegenNode;
|
|
103
|
+
if (isTemplate && keyProperty) {
|
|
104
|
+
(0, compiler_core_2.injectProp)(childBlock, keyProperty, context);
|
|
105
|
+
}
|
|
106
|
+
if (childBlock.isBlock !== !isStableFragment) {
|
|
107
|
+
if (childBlock.isBlock) {
|
|
108
|
+
// switch from block to vnode
|
|
109
|
+
removeHelper(runtimeHelpers_1.OPEN_BLOCK);
|
|
110
|
+
removeHelper((0, compiler_core_2.getVNodeBlockHelper)(false, childBlock.isComponent));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// switch from vnode to block
|
|
114
|
+
removeHelper((0, compiler_core_2.getVNodeHelper)(false, childBlock.isComponent));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
childBlock.isBlock = !isStableFragment;
|
|
118
|
+
if (childBlock.isBlock) {
|
|
119
|
+
helper(runtimeHelpers_1.OPEN_BLOCK);
|
|
120
|
+
helper((0, compiler_core_2.getVNodeBlockHelper)(false, childBlock.isComponent));
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
helper((0, compiler_core_2.getVNodeHelper)(false, childBlock.isComponent));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
// if (memo) {
|
|
127
|
+
// const loop = createFunctionExpression(
|
|
128
|
+
// createForLoopParams(forNode.parseResult, [
|
|
129
|
+
// createSimpleExpression(`_cached`)
|
|
130
|
+
// ])
|
|
131
|
+
// )
|
|
132
|
+
// loop.body = createBlockStatement([
|
|
133
|
+
// createCompoundExpression([`const _memo = (`, memo.exp!, `)`]),
|
|
134
|
+
// createCompoundExpression([
|
|
135
|
+
// `if (_cached`,
|
|
136
|
+
// ...(keyExp ? [` && _cached.key === `, keyExp] : []),
|
|
137
|
+
// ` && ${context.helperString(
|
|
138
|
+
// IS_MEMO_SAME
|
|
139
|
+
// )}(_cached, _memo)) return _cached`
|
|
140
|
+
// ]),
|
|
141
|
+
// createCompoundExpression([`const _item = `, childBlock as any]),
|
|
142
|
+
// createSimpleExpression(`_item.memo = _memo`),
|
|
143
|
+
// createSimpleExpression(`return _item`)
|
|
144
|
+
// ])
|
|
145
|
+
// renderExp.arguments.push(
|
|
146
|
+
// loop as ForIteratorExpression,
|
|
147
|
+
// createSimpleExpression(`_cache`),
|
|
148
|
+
// createSimpleExpression(String(context.cached++))
|
|
149
|
+
// )
|
|
150
|
+
// } else {
|
|
151
|
+
renderExp.arguments.push((0, compiler_core_1.createFunctionExpression)(createForLoopParams(forNode.parseResult), childBlock, true /* force newline */));
|
|
152
|
+
// }
|
|
153
|
+
};
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
// target-agnostic transform used for both Client and SSR
|
|
157
|
+
function processFor(node, dir, context, processCodegen) {
|
|
158
|
+
if (!dir.exp) {
|
|
159
|
+
context.onError((0, errors_1.createCompilerError)(31 /* ErrorCodes.X_V_FOR_NO_EXPRESSION */, dir.loc));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const parseResult = parseForExpression(
|
|
163
|
+
// can only be simple expression because vFor transform is applied
|
|
164
|
+
// before expression transform.
|
|
165
|
+
dir.exp, context);
|
|
166
|
+
if (!parseResult) {
|
|
167
|
+
context.onError((0, errors_1.createCompilerError)(32 /* ErrorCodes.X_V_FOR_MALFORMED_EXPRESSION */, dir.loc));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const { addIdentifiers, removeIdentifiers, scopes } = context;
|
|
171
|
+
const { source, value, key, index } = parseResult;
|
|
172
|
+
if (key === undefined) {
|
|
173
|
+
parseResult.key = {
|
|
174
|
+
constType: 2,
|
|
175
|
+
content: '_',
|
|
176
|
+
isStatic: false,
|
|
177
|
+
loc: value?.loc,
|
|
178
|
+
type: 4,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
if (index === undefined) {
|
|
182
|
+
parseResult.index = {
|
|
183
|
+
constType: 2,
|
|
184
|
+
content: '_',
|
|
185
|
+
isStatic: false,
|
|
186
|
+
loc: value?.loc,
|
|
187
|
+
type: 4,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const forNode = {
|
|
191
|
+
type: 11 /* NodeTypes.FOR */,
|
|
192
|
+
loc: dir.loc,
|
|
193
|
+
source,
|
|
194
|
+
valueAlias: value,
|
|
195
|
+
keyAlias: key,
|
|
196
|
+
objectIndexAlias: index,
|
|
197
|
+
parseResult,
|
|
198
|
+
children: (0, compiler_core_2.isTemplateNode)(node) ? node.children : [node],
|
|
199
|
+
};
|
|
200
|
+
context.replaceNode(forNode);
|
|
201
|
+
// bookkeeping
|
|
202
|
+
scopes.vFor++;
|
|
203
|
+
// if (!__BROWSER__ && context.prefixIdentifiers) {
|
|
204
|
+
if (context.prefixIdentifiers) {
|
|
205
|
+
// scope management
|
|
206
|
+
// inject identifiers to context
|
|
207
|
+
value && addIdentifiers(value);
|
|
208
|
+
key && addIdentifiers(key);
|
|
209
|
+
index && addIdentifiers(index);
|
|
210
|
+
}
|
|
211
|
+
const onExit = processCodegen && processCodegen(forNode);
|
|
212
|
+
return () => {
|
|
213
|
+
scopes.vFor--;
|
|
214
|
+
// if (!__BROWSER__ && context.prefixIdentifiers) {
|
|
215
|
+
if (context.prefixIdentifiers) {
|
|
216
|
+
value && removeIdentifiers(value);
|
|
217
|
+
key && removeIdentifiers(key);
|
|
218
|
+
index && removeIdentifiers(index);
|
|
219
|
+
}
|
|
220
|
+
if (onExit)
|
|
221
|
+
onExit();
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
exports.processFor = processFor;
|
|
225
|
+
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
|
|
226
|
+
// This regex doesn't cover the case if key or index aliases have destructuring,
|
|
227
|
+
// but those do not make sense in the first place, so this works in practice.
|
|
228
|
+
const forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
|
|
229
|
+
const stripParensRE = /^\(|\)$/g;
|
|
230
|
+
function parseForExpression(input, context) {
|
|
231
|
+
const loc = input.loc;
|
|
232
|
+
const exp = input.content;
|
|
233
|
+
const inMatch = exp.match(forAliasRE);
|
|
234
|
+
if (!inMatch)
|
|
235
|
+
return;
|
|
236
|
+
const [, LHS, RHS] = inMatch;
|
|
237
|
+
const result = {
|
|
238
|
+
source: createAliasExpression(loc, RHS.trim(), exp.indexOf(RHS, LHS.length)),
|
|
239
|
+
value: undefined,
|
|
240
|
+
key: undefined,
|
|
241
|
+
index: undefined,
|
|
242
|
+
};
|
|
243
|
+
// if (!__BROWSER__ && context.prefixIdentifiers) {
|
|
244
|
+
if (context.prefixIdentifiers) {
|
|
245
|
+
result.source = (0, transformExpression_1.processExpression)(result.source, context);
|
|
246
|
+
}
|
|
247
|
+
// if (__DEV__ && __BROWSER__) {
|
|
248
|
+
// validateBrowserExpression(result.source as SimpleExpressionNode, context)
|
|
249
|
+
// }
|
|
250
|
+
let valueContent = LHS.trim().replace(stripParensRE, '').trim();
|
|
251
|
+
const trimmedOffset = LHS.indexOf(valueContent);
|
|
252
|
+
const iteratorMatch = valueContent.match(forIteratorRE);
|
|
253
|
+
if (iteratorMatch) {
|
|
254
|
+
valueContent = valueContent.replace(forIteratorRE, '').trim();
|
|
255
|
+
const keyContent = iteratorMatch[1].trim();
|
|
256
|
+
let keyOffset;
|
|
257
|
+
if (keyContent) {
|
|
258
|
+
keyOffset = exp.indexOf(keyContent, trimmedOffset + valueContent.length);
|
|
259
|
+
result.key = createAliasExpression(loc, keyContent, keyOffset);
|
|
260
|
+
// if (!__BROWSER__ && context.prefixIdentifiers) {
|
|
261
|
+
if (context.prefixIdentifiers) {
|
|
262
|
+
result.key = (0, transformExpression_1.processExpression)(result.key, context, true);
|
|
263
|
+
}
|
|
264
|
+
// if (__DEV__ && __BROWSER__) {
|
|
265
|
+
// validateBrowserExpression(
|
|
266
|
+
// result.key as SimpleExpressionNode,
|
|
267
|
+
// context,
|
|
268
|
+
// true
|
|
269
|
+
// )
|
|
270
|
+
// }
|
|
271
|
+
}
|
|
272
|
+
if (iteratorMatch[2]) {
|
|
273
|
+
const indexContent = iteratorMatch[2].trim();
|
|
274
|
+
if (indexContent) {
|
|
275
|
+
result.index = createAliasExpression(loc, indexContent, exp.indexOf(indexContent, result.key
|
|
276
|
+
? keyOffset + keyContent.length
|
|
277
|
+
: trimmedOffset + valueContent.length));
|
|
278
|
+
// if (!__BROWSER__ && context.prefixIdentifiers) {
|
|
279
|
+
if (context.prefixIdentifiers) {
|
|
280
|
+
result.index = (0, transformExpression_1.processExpression)(result.index, context, true);
|
|
281
|
+
}
|
|
282
|
+
// if (__DEV__ && __BROWSER__) {
|
|
283
|
+
// validateBrowserExpression(
|
|
284
|
+
// result.index as SimpleExpressionNode,
|
|
285
|
+
// context,
|
|
286
|
+
// true
|
|
287
|
+
// )
|
|
288
|
+
// }
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (valueContent) {
|
|
293
|
+
result.value = createAliasExpression(loc, valueContent, trimmedOffset);
|
|
294
|
+
// if (!__BROWSER__ && context.prefixIdentifiers) {
|
|
295
|
+
if (context.prefixIdentifiers) {
|
|
296
|
+
result.value = (0, transformExpression_1.processExpression)(result.value, context, true);
|
|
297
|
+
}
|
|
298
|
+
// if (__DEV__ && __BROWSER__) {
|
|
299
|
+
// validateBrowserExpression(
|
|
300
|
+
// result.value as SimpleExpressionNode,
|
|
301
|
+
// context,
|
|
302
|
+
// true
|
|
303
|
+
// )
|
|
304
|
+
// }
|
|
305
|
+
}
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
exports.parseForExpression = parseForExpression;
|
|
309
|
+
function createAliasExpression(range, content, offset) {
|
|
310
|
+
return (0, compiler_core_1.createSimpleExpression)(content, false, (0, compiler_core_2.getInnerRange)(range, offset, content.length));
|
|
311
|
+
}
|
|
312
|
+
function createForLoopParams({ value, key, index }, memoArgs = []) {
|
|
313
|
+
return createParamsList([value, key, index, ...memoArgs]);
|
|
314
|
+
}
|
|
315
|
+
exports.createForLoopParams = createForLoopParams;
|
|
316
|
+
function createParamsList(args) {
|
|
317
|
+
let i = args.length;
|
|
318
|
+
while (i--) {
|
|
319
|
+
if (args[i])
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
return args
|
|
323
|
+
.slice(0, i + 1)
|
|
324
|
+
.map((arg, i) => arg || (0, compiler_core_1.createSimpleExpression)(`_`.repeat(i + 1), false));
|
|
325
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DirectiveNode, ElementNode, IfBranchNode, IfNode } from '@vue/compiler-core';
|
|
2
|
+
import { TransformContext } from '../transform';
|
|
3
|
+
export declare const transformIf: import("../transform").NodeTransform;
|
|
4
|
+
export declare function processIf(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (node: IfNode, branch: IfBranchNode, isRoot: boolean) => (() => void) | undefined): (() => void) | undefined;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.processIf = exports.transformIf = void 0;
|
|
4
|
+
const shared_1 = require("@vue/shared");
|
|
5
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
6
|
+
const transform_1 = require("../transform");
|
|
7
|
+
const errors_1 = require("../errors");
|
|
8
|
+
const transformExpression_1 = require("./transformExpression");
|
|
9
|
+
exports.transformIf = (0, transform_1.createStructuralDirectiveTransform)(/^(if|else|else-if)$/, (node, dir, context) => {
|
|
10
|
+
return processIf(node, dir, context, (ifNode, branch, isRoot) => {
|
|
11
|
+
// #1587: We need to dynamically increment the key based on the current
|
|
12
|
+
// node's sibling nodes, since chained v-if/else branches are
|
|
13
|
+
// rendered at the same depth
|
|
14
|
+
const siblings = context.parent.children;
|
|
15
|
+
let i = siblings.indexOf(ifNode);
|
|
16
|
+
let key = 0;
|
|
17
|
+
while (i-- >= 0) {
|
|
18
|
+
const sibling = siblings[i];
|
|
19
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
20
|
+
key += sibling.branches.length;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
// Exit callback. Complete the codegenNode when all children have been
|
|
24
|
+
// transformed.
|
|
25
|
+
return () => {
|
|
26
|
+
if (isRoot) {
|
|
27
|
+
ifNode.codegenNode = createCodegenNodeForBranch(branch, key, context);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// attach this branch's codegen node to the v-if root.
|
|
31
|
+
const parentCondition = getParentCondition(ifNode.codegenNode);
|
|
32
|
+
parentCondition.alternate = createCodegenNodeForBranch(branch, key + ifNode.branches.length - 1, context);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
// target-agnostic transform used for both Client and SSR
|
|
38
|
+
function processIf(node, dir, context, processCodegen) {
|
|
39
|
+
if (dir.name !== 'else' &&
|
|
40
|
+
(!dir.exp || !dir.exp.content.trim())) {
|
|
41
|
+
const loc = dir.exp ? dir.exp.loc : node.loc;
|
|
42
|
+
context.onError((0, errors_1.createCompilerError)(28 /* ErrorCodes.X_V_IF_NO_EXPRESSION */, dir.loc));
|
|
43
|
+
dir.exp = (0, compiler_core_1.createSimpleExpression)(`true`, false, loc);
|
|
44
|
+
}
|
|
45
|
+
if (context.prefixIdentifiers && dir.exp) {
|
|
46
|
+
// dir.exp can only be simple expression because vIf transform is applied
|
|
47
|
+
// before expression transform.
|
|
48
|
+
dir.exp = (0, transformExpression_1.processExpression)(dir.exp, context);
|
|
49
|
+
}
|
|
50
|
+
if (dir.name === 'if') {
|
|
51
|
+
const branch = createIfBranch(node, dir);
|
|
52
|
+
const ifNode = {
|
|
53
|
+
type: 9 /* NodeTypes.IF */,
|
|
54
|
+
loc: node.loc,
|
|
55
|
+
branches: [branch],
|
|
56
|
+
};
|
|
57
|
+
context.replaceNode(ifNode);
|
|
58
|
+
if (processCodegen) {
|
|
59
|
+
return processCodegen(ifNode, branch, true);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// locate the adjacent v-if
|
|
64
|
+
const siblings = context.parent.children;
|
|
65
|
+
let i = siblings.indexOf(node);
|
|
66
|
+
while (i-- >= -1) {
|
|
67
|
+
const sibling = siblings[i];
|
|
68
|
+
if (sibling && sibling.type === 3 /* NodeTypes.COMMENT */) {
|
|
69
|
+
context.removeNode(sibling);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (sibling &&
|
|
73
|
+
((sibling.type === 2 /* NodeTypes.TEXT */ && !sibling.content.trim().length) ||
|
|
74
|
+
// handle tag text but type = NodeTypes.ELEMENT
|
|
75
|
+
(sibling.type === 1 /* NodeTypes.ELEMENT */ &&
|
|
76
|
+
sibling.tag === 'text' &&
|
|
77
|
+
!sibling.children[0].content.trim().length))) {
|
|
78
|
+
context.removeNode(sibling);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (sibling && sibling.type === 9 /* NodeTypes.IF */) {
|
|
82
|
+
// Check if v-else was followed by v-else-if
|
|
83
|
+
if (dir.name === 'else-if' &&
|
|
84
|
+
sibling.branches[sibling.branches.length - 1].condition === undefined) {
|
|
85
|
+
context.onError((0, errors_1.createCompilerError)(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
86
|
+
}
|
|
87
|
+
// move the node to the if node's branches
|
|
88
|
+
context.removeNode();
|
|
89
|
+
const branch = createIfBranch(node, dir);
|
|
90
|
+
// check if user is forcing same key on different branches
|
|
91
|
+
const key = branch.userKey;
|
|
92
|
+
if (key) {
|
|
93
|
+
sibling.branches.forEach(({ userKey }) => {
|
|
94
|
+
if (isSameKey(userKey, key)) {
|
|
95
|
+
context.onError((0, errors_1.createCompilerError)(29 /* ErrorCodes.X_V_IF_SAME_KEY */, branch.userKey.loc));
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
sibling.branches.push(branch);
|
|
100
|
+
const onExit = processCodegen && processCodegen(sibling, branch, false);
|
|
101
|
+
// since the branch was removed, it will not be traversed.
|
|
102
|
+
// make sure to traverse here.
|
|
103
|
+
(0, transform_1.traverseNode)(branch, context);
|
|
104
|
+
// call on exit
|
|
105
|
+
if (onExit)
|
|
106
|
+
onExit();
|
|
107
|
+
// make sure to reset currentNode after traversal to indicate this
|
|
108
|
+
// node has been removed.
|
|
109
|
+
context.currentNode = null;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
context.onError((0, errors_1.createCompilerError)(30 /* ErrorCodes.X_V_ELSE_NO_ADJACENT_IF */, node.loc));
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
exports.processIf = processIf;
|
|
119
|
+
function createIfBranch(node, dir) {
|
|
120
|
+
const isTemplateIf = node.tagType === 3 /* ElementTypes.TEMPLATE */;
|
|
121
|
+
return {
|
|
122
|
+
type: 10 /* NodeTypes.IF_BRANCH */,
|
|
123
|
+
loc: node.loc,
|
|
124
|
+
condition: dir.name === 'else' ? undefined : dir.exp,
|
|
125
|
+
children: isTemplateIf && !(0, compiler_core_1.findDir)(node, 'for') ? node.children : [node],
|
|
126
|
+
userKey: (0, compiler_core_1.findProp)(node, `key`),
|
|
127
|
+
isTemplateIf,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function createCodegenNodeForBranch(branch, keyIndex, context) {
|
|
131
|
+
if (branch.condition) {
|
|
132
|
+
return (0, compiler_core_1.createConditionalExpression)(branch.condition, createChildrenCodegenNode(branch, keyIndex, context),
|
|
133
|
+
// make sure to pass in asBlock: true so that the comment node call
|
|
134
|
+
// closes the current block.
|
|
135
|
+
(0, compiler_core_1.createCallExpression)(context.helper(compiler_core_1.CREATE_COMMENT), ['"v-if"', 'true']));
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
return createChildrenCodegenNode(branch, keyIndex, context);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
142
|
+
const { helper } = context;
|
|
143
|
+
const keyProperty = (0, compiler_core_1.createObjectProperty)(`key`, (0, compiler_core_1.createSimpleExpression)(`${keyIndex}`, false, compiler_core_1.locStub, 2 /* ConstantTypes.CAN_HOIST */));
|
|
144
|
+
const { children } = branch;
|
|
145
|
+
const firstChild = children[0];
|
|
146
|
+
const needFragmentWrapper = children.length !== 1 || firstChild.type !== 1 /* NodeTypes.ELEMENT */;
|
|
147
|
+
if (needFragmentWrapper) {
|
|
148
|
+
if (children.length === 1 && firstChild.type === 11 /* NodeTypes.FOR */) {
|
|
149
|
+
// optimize away nested fragments when child is a ForNode
|
|
150
|
+
const vnodeCall = firstChild.codegenNode;
|
|
151
|
+
(0, compiler_core_1.injectProp)(vnodeCall, keyProperty, context);
|
|
152
|
+
return vnodeCall;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
let patchFlag = 64 /* PatchFlags.STABLE_FRAGMENT */;
|
|
156
|
+
let patchFlagText = shared_1.PatchFlagNames[64 /* PatchFlags.STABLE_FRAGMENT */];
|
|
157
|
+
// check if the fragment actually contains a single valid child with
|
|
158
|
+
// the rest being comments
|
|
159
|
+
return (0, compiler_core_1.createVNodeCall)(context, helper(compiler_core_1.FRAGMENT), (0, compiler_core_1.createObjectExpression)([keyProperty]), children, patchFlag + ` /* ${patchFlagText} */`, undefined, undefined, true, false, false /* isComponent */, branch.loc);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const ret = firstChild.codegenNode;
|
|
164
|
+
const vnodeCall = (0, compiler_core_1.getMemoedVNodeCall)(ret);
|
|
165
|
+
// Change createVNode to createBlock.
|
|
166
|
+
if (vnodeCall.type === 13 /* NodeTypes.VNODE_CALL */) {
|
|
167
|
+
(0, compiler_core_1.makeBlock)(vnodeCall, context);
|
|
168
|
+
}
|
|
169
|
+
// inject branch key
|
|
170
|
+
(0, compiler_core_1.injectProp)(vnodeCall, keyProperty, context);
|
|
171
|
+
return ret;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function isSameKey(a, b) {
|
|
175
|
+
if (!a || a.type !== b.type) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
if (a.type === 6 /* NodeTypes.ATTRIBUTE */) {
|
|
179
|
+
if (a.value.content !== b.value.content) {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// directive
|
|
185
|
+
const exp = a.exp;
|
|
186
|
+
const branchExp = b.exp;
|
|
187
|
+
if (exp.type !== branchExp.type) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (exp.type !== 4 /* NodeTypes.SIMPLE_EXPRESSION */ ||
|
|
191
|
+
exp.isStatic !== branchExp.isStatic ||
|
|
192
|
+
exp.content !== branchExp.content) {
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
function getParentCondition(node) {
|
|
199
|
+
while (true) {
|
|
200
|
+
if (node.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
201
|
+
if (node.alternate.type === 19 /* NodeTypes.JS_CONDITIONAL_EXPRESSION */) {
|
|
202
|
+
node = node.alternate;
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
return node;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else if (node.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */) {
|
|
209
|
+
node = node.value;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transformModel = void 0;
|
|
4
|
+
const compiler_core_1 = require("@vue/compiler-core");
|
|
5
|
+
const shared_1 = require("@vue/shared");
|
|
6
|
+
const tags = ['input', 'textarea'];
|
|
7
|
+
const transformModel = (dir, node, context) => {
|
|
8
|
+
const result = (0, compiler_core_1.transformModel)(dir, node, context);
|
|
9
|
+
// 将 input,textarea 的 onUpdate:modelValue 事件转换为 onInput
|
|
10
|
+
if (tags.includes(node.tag) && result.props.length >= 2) {
|
|
11
|
+
const key = result.props[1].key;
|
|
12
|
+
let value = result.props[1].value;
|
|
13
|
+
if (value.type === 20 /* NodeTypes.JS_CACHE_EXPRESSION */) {
|
|
14
|
+
value = value.value;
|
|
15
|
+
}
|
|
16
|
+
if ((0, compiler_core_1.isStaticExp)(key) &&
|
|
17
|
+
key.content === 'onUpdate:modelValue' &&
|
|
18
|
+
value.type === 8 /* NodeTypes.COMPOUND_EXPRESSION */) {
|
|
19
|
+
key.content = getEventName(dir);
|
|
20
|
+
// 调整函数类型及返回表达式,适配 uts
|
|
21
|
+
value.children = value.children.map((child) => {
|
|
22
|
+
if ((0, shared_1.isString)(child)) {
|
|
23
|
+
if (child === '$event => ((') {
|
|
24
|
+
return `($event: ${getEventParamsType(dir)}): any => {`;
|
|
25
|
+
}
|
|
26
|
+
else if (child === ') = $event)') {
|
|
27
|
+
return ` = ${withNumber(dir) ? '_looseToNumber(' : ''}$event.detail.value${withTrim(dir) ? '.trim()' : ''}${withNumber(dir) ? ')' : ''};\nreturn ${withNumber(dir) ? '_looseToNumber(' : ''}$event.detail.value${withTrim(dir) ? '.trim()' : ''}${withNumber(dir) ? ')' : ''};}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return child;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
exports.transformModel = transformModel;
|
|
37
|
+
function getEventName(dir) {
|
|
38
|
+
return withLazy(dir) ? 'onBlur' : 'onInput';
|
|
39
|
+
}
|
|
40
|
+
function getEventParamsType(dir) {
|
|
41
|
+
return withLazy(dir) ? 'InputBlurEvent' : 'InputEvent';
|
|
42
|
+
}
|
|
43
|
+
function withLazy(dir) {
|
|
44
|
+
return dir.modifiers.includes('lazy');
|
|
45
|
+
}
|
|
46
|
+
function withNumber(dir) {
|
|
47
|
+
return dir.modifiers.includes('number');
|
|
48
|
+
}
|
|
49
|
+
function withTrim(dir) {
|
|
50
|
+
return dir.modifiers.includes('trim');
|
|
51
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DirectiveTransform } from '../transform';
|
|
2
|
+
import { DirectiveNode, ExpressionNode, SimpleExpressionNode } from '@vue/compiler-core';
|
|
3
|
+
export declare const inlineStatementCannotUseEventMsg = "Inline statement cannot use $event, please use a function expression instead.";
|
|
4
|
+
export interface VOnDirectiveNode extends DirectiveNode {
|
|
5
|
+
arg: ExpressionNode;
|
|
6
|
+
exp: SimpleExpressionNode | undefined;
|
|
7
|
+
}
|
|
8
|
+
export declare const transformOn: DirectiveTransform;
|