@vue/compiler-vapor 3.6.0-beta.1 → 3.6.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compiler-vapor.cjs.js +116 -75
- package/dist/compiler-vapor.d.ts +8 -10
- package/dist/compiler-vapor.esm-browser.js +119 -77
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.3
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -28,7 +28,29 @@ const newBlock = (node) => ({
|
|
|
28
28
|
});
|
|
29
29
|
function wrapTemplate(node, dirs) {
|
|
30
30
|
if (node.tagType === 3) {
|
|
31
|
-
|
|
31
|
+
const otherStructuralDirs = ["if", "else-if", "else", "for"];
|
|
32
|
+
const hasOtherStructuralDir = node.props.some(
|
|
33
|
+
(prop) => prop.type === 7 && otherStructuralDirs.includes(prop.name) && !dirs.includes(prop.name)
|
|
34
|
+
);
|
|
35
|
+
if (!hasOtherStructuralDir) {
|
|
36
|
+
return node;
|
|
37
|
+
}
|
|
38
|
+
const reserved2 = [];
|
|
39
|
+
const pass2 = [];
|
|
40
|
+
node.props.forEach((prop) => {
|
|
41
|
+
if (prop.type === 7 && dirs.includes(prop.name)) {
|
|
42
|
+
reserved2.push(prop);
|
|
43
|
+
} else {
|
|
44
|
+
pass2.push(prop);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return shared.extend({}, node, {
|
|
48
|
+
type: 1,
|
|
49
|
+
tag: "template",
|
|
50
|
+
props: reserved2,
|
|
51
|
+
tagType: 3,
|
|
52
|
+
children: [shared.extend({}, node, { props: pass2 })]
|
|
53
|
+
});
|
|
32
54
|
}
|
|
33
55
|
const reserved = [];
|
|
34
56
|
const pass = [];
|
|
@@ -107,10 +129,6 @@ function getLiteralExpressionValue(exp, excludeNumber) {
|
|
|
107
129
|
}
|
|
108
130
|
return exp.isStatic ? exp.content : null;
|
|
109
131
|
}
|
|
110
|
-
function isInTransition(context) {
|
|
111
|
-
const parentNode = context.parent && context.parent.node;
|
|
112
|
-
return !!(parentNode && isTransitionNode(parentNode));
|
|
113
|
-
}
|
|
114
132
|
function isTransitionNode(node) {
|
|
115
133
|
return node.type === 1 && isTransitionTag(node.tag);
|
|
116
134
|
}
|
|
@@ -149,6 +167,8 @@ class TransformContext {
|
|
|
149
167
|
this.node = node;
|
|
150
168
|
this.selfName = null;
|
|
151
169
|
this.parent = null;
|
|
170
|
+
// cached parent that skips template tags
|
|
171
|
+
this.effectiveParent = null;
|
|
152
172
|
this.index = 0;
|
|
153
173
|
this.block = this.ir.block;
|
|
154
174
|
this.template = "";
|
|
@@ -161,6 +181,12 @@ class TransformContext {
|
|
|
161
181
|
this.component = this.ir.component;
|
|
162
182
|
this.directive = this.ir.directive;
|
|
163
183
|
this.slots = [];
|
|
184
|
+
// whether this node is the last effective child of its parent
|
|
185
|
+
// (all siblings after it are components, which don't appear in HTML template)
|
|
186
|
+
this.isLastEffectiveChild = true;
|
|
187
|
+
// whether this node is on the rightmost path of the tree
|
|
188
|
+
// (all ancestors are also last effective children)
|
|
189
|
+
this.isOnRightmostPath = true;
|
|
164
190
|
this.globalId = 0;
|
|
165
191
|
this.nextIdMap = null;
|
|
166
192
|
this.increaseId = () => {
|
|
@@ -241,15 +267,31 @@ class TransformContext {
|
|
|
241
267
|
this.block.operation.push(...node);
|
|
242
268
|
}
|
|
243
269
|
create(node, index) {
|
|
270
|
+
let effectiveParent = this;
|
|
271
|
+
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) {
|
|
272
|
+
effectiveParent = effectiveParent.parent;
|
|
273
|
+
}
|
|
274
|
+
const isLastEffectiveChild = this.isEffectivelyLastChild(index);
|
|
275
|
+
const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
|
|
244
276
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
245
277
|
node,
|
|
246
278
|
parent: this,
|
|
247
279
|
index,
|
|
248
280
|
template: "",
|
|
249
281
|
childrenTemplate: [],
|
|
250
|
-
dynamic: newDynamic()
|
|
282
|
+
dynamic: newDynamic(),
|
|
283
|
+
effectiveParent,
|
|
284
|
+
isLastEffectiveChild,
|
|
285
|
+
isOnRightmostPath
|
|
251
286
|
});
|
|
252
287
|
}
|
|
288
|
+
isEffectivelyLastChild(index) {
|
|
289
|
+
const children = this.node.children;
|
|
290
|
+
if (!children) return true;
|
|
291
|
+
return children.every(
|
|
292
|
+
(c, i) => i <= index || c.type === 1 && c.tagType === 1
|
|
293
|
+
);
|
|
294
|
+
}
|
|
253
295
|
}
|
|
254
296
|
const defaultOptions = {
|
|
255
297
|
filename: "",
|
|
@@ -537,14 +579,12 @@ const IRNodeTypes = {
|
|
|
537
579
|
"12": "SLOT_OUTLET_NODE",
|
|
538
580
|
"DIRECTIVE": 13,
|
|
539
581
|
"13": "DIRECTIVE",
|
|
540
|
-
"
|
|
541
|
-
"14": "
|
|
542
|
-
"
|
|
543
|
-
"15": "
|
|
544
|
-
"
|
|
545
|
-
"16": "
|
|
546
|
-
"GET_TEXT_CHILD": 17,
|
|
547
|
-
"17": "GET_TEXT_CHILD"
|
|
582
|
+
"IF": 14,
|
|
583
|
+
"14": "IF",
|
|
584
|
+
"FOR": 15,
|
|
585
|
+
"15": "FOR",
|
|
586
|
+
"GET_TEXT_CHILD": 16,
|
|
587
|
+
"16": "GET_TEXT_CHILD"
|
|
548
588
|
};
|
|
549
589
|
const DynamicFlag = {
|
|
550
590
|
"NONE": 0,
|
|
@@ -558,7 +598,7 @@ const DynamicFlag = {
|
|
|
558
598
|
};
|
|
559
599
|
function isBlockOperation(op) {
|
|
560
600
|
const type = op.type;
|
|
561
|
-
return type === 11 || type === 12 || type ===
|
|
601
|
+
return type === 11 || type === 12 || type === 14 || type === 15;
|
|
562
602
|
}
|
|
563
603
|
|
|
564
604
|
function genInsertNode({ parent, elements, anchor }, { helper }) {
|
|
@@ -789,6 +829,10 @@ function analyzeExpressions(expressions) {
|
|
|
789
829
|
end: id.end
|
|
790
830
|
});
|
|
791
831
|
});
|
|
832
|
+
const parentOfMemberExp = parentStack[parentStack.length - 2];
|
|
833
|
+
if (parentOfMemberExp && isCallExpression(parentOfMemberExp)) {
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
792
836
|
registerVariable(
|
|
793
837
|
memberExp,
|
|
794
838
|
exp,
|
|
@@ -1005,6 +1049,8 @@ function extractMemberExpression(exp, onIdentifier) {
|
|
|
1005
1049
|
return `${extractMemberExpression(exp.left, onIdentifier)} ${exp.operator} ${extractMemberExpression(exp.right, onIdentifier)}`;
|
|
1006
1050
|
case "CallExpression":
|
|
1007
1051
|
return `${extractMemberExpression(exp.callee, onIdentifier)}(${exp.arguments.map((arg) => extractMemberExpression(arg, onIdentifier)).join(", ")})`;
|
|
1052
|
+
case "OptionalCallExpression":
|
|
1053
|
+
return `${extractMemberExpression(exp.callee, onIdentifier)}?.(${exp.arguments.map((arg) => extractMemberExpression(arg, onIdentifier)).join(", ")})`;
|
|
1008
1054
|
case "MemberExpression":
|
|
1009
1055
|
// foo[bar.baz]
|
|
1010
1056
|
case "OptionalMemberExpression":
|
|
@@ -1017,6 +1063,9 @@ function extractMemberExpression(exp, onIdentifier) {
|
|
|
1017
1063
|
return "";
|
|
1018
1064
|
}
|
|
1019
1065
|
}
|
|
1066
|
+
const isCallExpression = (node) => {
|
|
1067
|
+
return node.type === "CallExpression" || node.type === "OptionalCallExpression";
|
|
1068
|
+
};
|
|
1020
1069
|
const isMemberExpression = (node) => {
|
|
1021
1070
|
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "TSNonNullExpression";
|
|
1022
1071
|
};
|
|
@@ -1700,21 +1749,16 @@ function genSetTemplateRef(oper, context) {
|
|
|
1700
1749
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
1701
1750
|
return [
|
|
1702
1751
|
NEWLINE,
|
|
1703
|
-
oper.effect && `r${oper.element} = `,
|
|
1704
1752
|
...genCall(
|
|
1705
1753
|
setTemplateRefIdent,
|
|
1706
1754
|
// will be generated in root scope
|
|
1707
1755
|
`n${oper.element}`,
|
|
1708
1756
|
refValue,
|
|
1709
|
-
oper.effect ? `r${oper.element}` : oper.refFor ? "void 0" : void 0,
|
|
1710
1757
|
oper.refFor && "true",
|
|
1711
1758
|
refKey
|
|
1712
1759
|
)
|
|
1713
1760
|
];
|
|
1714
1761
|
}
|
|
1715
|
-
function genDeclareOldRef(oper) {
|
|
1716
|
-
return [NEWLINE, `let r${oper.id}`];
|
|
1717
|
-
}
|
|
1718
1762
|
function genRefValue(value, context) {
|
|
1719
1763
|
if (value && context.options.inline) {
|
|
1720
1764
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -2102,15 +2146,7 @@ function genDynamicProps(props, context) {
|
|
|
2102
2146
|
}
|
|
2103
2147
|
} else {
|
|
2104
2148
|
expr = genExpression(p.value, context);
|
|
2105
|
-
if (p.handler)
|
|
2106
|
-
expr = genCall(
|
|
2107
|
-
helper("toHandlers"),
|
|
2108
|
-
expr,
|
|
2109
|
-
`false`,
|
|
2110
|
-
// preserveCaseIfNecessary: false, not needed for component
|
|
2111
|
-
`true`
|
|
2112
|
-
// wrap handler values in functions
|
|
2113
|
-
);
|
|
2149
|
+
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
2114
2150
|
}
|
|
2115
2151
|
}
|
|
2116
2152
|
frags.push(["() => (", ...expr, ")"]);
|
|
@@ -2304,10 +2340,10 @@ function hasComponentOrSlotInDynamic(dynamic) {
|
|
|
2304
2340
|
if (type === 11 || type === 12) {
|
|
2305
2341
|
return true;
|
|
2306
2342
|
}
|
|
2307
|
-
if (type ===
|
|
2343
|
+
if (type === 14) {
|
|
2308
2344
|
if (hasComponentOrSlotInIf(dynamic.operation)) return true;
|
|
2309
2345
|
}
|
|
2310
|
-
if (type ===
|
|
2346
|
+
if (type === 15) {
|
|
2311
2347
|
if (hasComponentOrSlotInBlock(dynamic.operation.render))
|
|
2312
2348
|
return true;
|
|
2313
2349
|
}
|
|
@@ -2323,10 +2359,10 @@ function hasComponentOrSlotInOperations(operations) {
|
|
|
2323
2359
|
case 11:
|
|
2324
2360
|
case 12:
|
|
2325
2361
|
return true;
|
|
2326
|
-
case
|
|
2362
|
+
case 14:
|
|
2327
2363
|
if (hasComponentOrSlotInIf(op)) return true;
|
|
2328
2364
|
break;
|
|
2329
|
-
case
|
|
2365
|
+
case 15:
|
|
2330
2366
|
if (hasComponentOrSlotInBlock(op.render)) return true;
|
|
2331
2367
|
break;
|
|
2332
2368
|
}
|
|
@@ -2406,19 +2442,17 @@ function genOperation(oper, context) {
|
|
|
2406
2442
|
return genInsertNode(oper, context);
|
|
2407
2443
|
case 10:
|
|
2408
2444
|
return genPrependNode(oper, context);
|
|
2409
|
-
case
|
|
2445
|
+
case 14:
|
|
2410
2446
|
return genIf(oper, context);
|
|
2411
|
-
case
|
|
2447
|
+
case 15:
|
|
2412
2448
|
return genFor(oper, context);
|
|
2413
2449
|
case 11:
|
|
2414
2450
|
return genCreateComponent(oper, context);
|
|
2415
|
-
case 14:
|
|
2416
|
-
return genDeclareOldRef(oper);
|
|
2417
2451
|
case 12:
|
|
2418
2452
|
return genSlotOutlet(oper, context);
|
|
2419
2453
|
case 13:
|
|
2420
2454
|
return genBuiltinDirective(oper, context);
|
|
2421
|
-
case
|
|
2455
|
+
case 16:
|
|
2422
2456
|
return genGetTextChild(oper, context);
|
|
2423
2457
|
default:
|
|
2424
2458
|
const exhaustiveCheck = oper;
|
|
@@ -2619,7 +2653,7 @@ function genBlock(oper, context, args = [], root) {
|
|
|
2619
2653
|
}
|
|
2620
2654
|
function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
2621
2655
|
const [frag, push] = buildCodeFragment();
|
|
2622
|
-
const { dynamic, effect, operation, returns
|
|
2656
|
+
const { dynamic, effect, operation, returns } = block;
|
|
2623
2657
|
const resetBlock = context.enterBlock(block);
|
|
2624
2658
|
if (root) {
|
|
2625
2659
|
for (let name of context.ir.component) {
|
|
@@ -2652,12 +2686,6 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
2652
2686
|
if (root && context.ir.hasDeferredVShow) {
|
|
2653
2687
|
push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`);
|
|
2654
2688
|
}
|
|
2655
|
-
if (dynamic.needsKey) {
|
|
2656
|
-
for (const child of dynamic.children) {
|
|
2657
|
-
const keyValue = key ? genExpression(key, context) : JSON.stringify(child.id);
|
|
2658
|
-
push(NEWLINE, `n${child.id}.$key = `, ...keyValue);
|
|
2659
|
-
}
|
|
2660
|
-
}
|
|
2661
2689
|
push(NEWLINE, `return `);
|
|
2662
2690
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
2663
2691
|
const returnsCode = returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"];
|
|
@@ -2996,7 +3024,10 @@ const transformElement = (node, context) => {
|
|
|
2996
3024
|
propsResult,
|
|
2997
3025
|
singleRoot,
|
|
2998
3026
|
context,
|
|
2999
|
-
getEffectIndex
|
|
3027
|
+
getEffectIndex,
|
|
3028
|
+
// Root-level elements generate dedicated templates
|
|
3029
|
+
// so closing tags can be omitted
|
|
3030
|
+
context.root === context.effectiveParent || canOmitEndTag(node, context)
|
|
3000
3031
|
);
|
|
3001
3032
|
}
|
|
3002
3033
|
if (parentSlots) {
|
|
@@ -3004,6 +3035,17 @@ const transformElement = (node, context) => {
|
|
|
3004
3035
|
}
|
|
3005
3036
|
};
|
|
3006
3037
|
};
|
|
3038
|
+
function canOmitEndTag(node, context) {
|
|
3039
|
+
const { block, parent } = context;
|
|
3040
|
+
if (!parent) return false;
|
|
3041
|
+
if (block !== parent.block) {
|
|
3042
|
+
return true;
|
|
3043
|
+
}
|
|
3044
|
+
if (shared.isFormattingTag(node.tag) || parent.node.type === 1 && node.tag === parent.node.tag) {
|
|
3045
|
+
return context.isOnRightmostPath;
|
|
3046
|
+
}
|
|
3047
|
+
return context.isLastEffectiveChild;
|
|
3048
|
+
}
|
|
3007
3049
|
function isSingleRoot(context) {
|
|
3008
3050
|
if (context.inVFor) {
|
|
3009
3051
|
return false;
|
|
@@ -3093,7 +3135,8 @@ function resolveSetupReference(name, context) {
|
|
|
3093
3135
|
return bindings[name] ? name : bindings[camelName] ? camelName : bindings[PascalName] ? PascalName : void 0;
|
|
3094
3136
|
}
|
|
3095
3137
|
const dynamicKeys = ["indeterminate"];
|
|
3096
|
-
|
|
3138
|
+
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
3139
|
+
function transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex, omitEndTag) {
|
|
3097
3140
|
const { tag } = node;
|
|
3098
3141
|
const { scopeId } = context.options;
|
|
3099
3142
|
let template = "";
|
|
@@ -3113,16 +3156,24 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
3113
3156
|
getEffectIndex
|
|
3114
3157
|
);
|
|
3115
3158
|
} else {
|
|
3159
|
+
let prevWasQuoted = false;
|
|
3116
3160
|
for (const prop of propsResult[1]) {
|
|
3117
3161
|
const { key, values } = prop;
|
|
3118
3162
|
if (context.imports.some(
|
|
3119
3163
|
(imported) => values[0].content.includes(imported.exp.content)
|
|
3120
3164
|
)) {
|
|
3121
|
-
template += `
|
|
3165
|
+
if (!prevWasQuoted) template += ` `;
|
|
3166
|
+
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
3167
|
+
prevWasQuoted = true;
|
|
3122
3168
|
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
3123
|
-
template += `
|
|
3124
|
-
|
|
3125
|
-
|
|
3169
|
+
if (!prevWasQuoted) template += ` `;
|
|
3170
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
3171
|
+
template += key.content;
|
|
3172
|
+
if (value) {
|
|
3173
|
+
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
3174
|
+
} else {
|
|
3175
|
+
prevWasQuoted = false;
|
|
3176
|
+
}
|
|
3126
3177
|
} else {
|
|
3127
3178
|
dynamicProps.push(key.content);
|
|
3128
3179
|
context.registerEffect(
|
|
@@ -3139,7 +3190,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
3139
3190
|
}
|
|
3140
3191
|
}
|
|
3141
3192
|
template += `>` + context.childrenTemplate.join("");
|
|
3142
|
-
if (!shared.isVoidTag(tag)) {
|
|
3193
|
+
if (!shared.isVoidTag(tag) && !omitEndTag) {
|
|
3143
3194
|
template += `</${tag}>`;
|
|
3144
3195
|
}
|
|
3145
3196
|
if (singleRoot) {
|
|
@@ -3357,7 +3408,7 @@ const transformVText = (dir, node, context) => {
|
|
|
3357
3408
|
const isComponent = node.tagType === 1;
|
|
3358
3409
|
if (!isComponent) {
|
|
3359
3410
|
context.registerOperation({
|
|
3360
|
-
type:
|
|
3411
|
+
type: 16,
|
|
3361
3412
|
parent: context.reference()
|
|
3362
3413
|
});
|
|
3363
3414
|
}
|
|
@@ -3537,10 +3588,6 @@ const transformTemplateRef = (node, context) => {
|
|
|
3537
3588
|
return () => {
|
|
3538
3589
|
const id = context.reference();
|
|
3539
3590
|
const effect = !isConstantExpression(value);
|
|
3540
|
-
effect && context.registerOperation({
|
|
3541
|
-
type: 14,
|
|
3542
|
-
id
|
|
3543
|
-
});
|
|
3544
3591
|
context.registerEffect([value], {
|
|
3545
3592
|
type: 8,
|
|
3546
3593
|
element: id,
|
|
@@ -3625,7 +3672,7 @@ function processTextContainer(children, context) {
|
|
|
3625
3672
|
} else {
|
|
3626
3673
|
context.childrenTemplate = [" "];
|
|
3627
3674
|
context.registerOperation({
|
|
3628
|
-
type:
|
|
3675
|
+
type: 16,
|
|
3629
3676
|
parent: context.reference()
|
|
3630
3677
|
});
|
|
3631
3678
|
context.registerEffect(values, {
|
|
@@ -3814,7 +3861,7 @@ function processIf(node, dir, context) {
|
|
|
3814
3861
|
return () => {
|
|
3815
3862
|
onExit();
|
|
3816
3863
|
context.dynamic.operation = {
|
|
3817
|
-
type:
|
|
3864
|
+
type: 14,
|
|
3818
3865
|
id,
|
|
3819
3866
|
condition: dir.exp,
|
|
3820
3867
|
positive: branch,
|
|
@@ -3829,7 +3876,7 @@ function processIf(node, dir, context) {
|
|
|
3829
3876
|
if (siblings) {
|
|
3830
3877
|
let i = siblings.length;
|
|
3831
3878
|
while (i--) {
|
|
3832
|
-
if (siblings[i].operation && siblings[i].operation.type ===
|
|
3879
|
+
if (siblings[i].operation && siblings[i].operation.type === 14) {
|
|
3833
3880
|
lastIfNode = siblings[i].operation;
|
|
3834
3881
|
break;
|
|
3835
3882
|
}
|
|
@@ -3838,14 +3885,14 @@ function processIf(node, dir, context) {
|
|
|
3838
3885
|
if (
|
|
3839
3886
|
// check if v-if is the sibling node
|
|
3840
3887
|
!siblingIf || // check if IfNode is the last operation and get the root IfNode
|
|
3841
|
-
!lastIfNode || lastIfNode.type !==
|
|
3888
|
+
!lastIfNode || lastIfNode.type !== 14
|
|
3842
3889
|
) {
|
|
3843
3890
|
context.options.onError(
|
|
3844
3891
|
compilerDom.createCompilerError(30, node.loc)
|
|
3845
3892
|
);
|
|
3846
3893
|
return;
|
|
3847
3894
|
}
|
|
3848
|
-
while (lastIfNode.negative && lastIfNode.negative.type ===
|
|
3895
|
+
while (lastIfNode.negative && lastIfNode.negative.type === 14) {
|
|
3849
3896
|
lastIfNode = lastIfNode.negative;
|
|
3850
3897
|
}
|
|
3851
3898
|
if (dir.name === "else-if" && lastIfNode.negative) {
|
|
@@ -3865,7 +3912,7 @@ function processIf(node, dir, context) {
|
|
|
3865
3912
|
lastIfNode.negative = branch;
|
|
3866
3913
|
} else {
|
|
3867
3914
|
lastIfNode.negative = {
|
|
3868
|
-
type:
|
|
3915
|
+
type: 14,
|
|
3869
3916
|
id: -1,
|
|
3870
3917
|
condition: dir.exp,
|
|
3871
3918
|
positive: branch,
|
|
@@ -3880,7 +3927,6 @@ function createIfBranch(node, context) {
|
|
|
3880
3927
|
const branch = newBlock(node);
|
|
3881
3928
|
const exitBlock = context.enterBlock(branch);
|
|
3882
3929
|
context.reference();
|
|
3883
|
-
branch.dynamic.needsKey = isInTransition(context);
|
|
3884
3930
|
return [branch, exitBlock];
|
|
3885
3931
|
}
|
|
3886
3932
|
|
|
@@ -3918,7 +3964,7 @@ function processFor(node, dir, context) {
|
|
|
3918
3964
|
const { parent } = context;
|
|
3919
3965
|
const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
|
|
3920
3966
|
context.dynamic.operation = {
|
|
3921
|
-
type:
|
|
3967
|
+
type: 15,
|
|
3922
3968
|
id,
|
|
3923
3969
|
source,
|
|
3924
3970
|
value,
|
|
@@ -4079,10 +4125,10 @@ function transformComponentSlot(node, dir, context) {
|
|
|
4079
4125
|
markNonTemplate(n, context);
|
|
4080
4126
|
});
|
|
4081
4127
|
}
|
|
4082
|
-
|
|
4128
|
+
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
4083
4129
|
if (isTransitionNode(node) && nonSlotTemplateChildren.length) {
|
|
4084
4130
|
const nonCommentChild = nonSlotTemplateChildren.find(
|
|
4085
|
-
(n) => n
|
|
4131
|
+
(n) => !compilerDom.isCommentOrWhitespace(n)
|
|
4086
4132
|
);
|
|
4087
4133
|
if (nonCommentChild) {
|
|
4088
4134
|
const keyProp = findProp(
|
|
@@ -4090,11 +4136,10 @@ function transformComponentSlot(node, dir, context) {
|
|
|
4090
4136
|
"key"
|
|
4091
4137
|
);
|
|
4092
4138
|
if (keyProp) {
|
|
4093
|
-
|
|
4139
|
+
block.key = keyProp.exp;
|
|
4094
4140
|
}
|
|
4095
4141
|
}
|
|
4096
4142
|
}
|
|
4097
|
-
const [block, onExit] = createSlotBlock(node, dir, context, slotKey);
|
|
4098
4143
|
const { slots } = context;
|
|
4099
4144
|
return () => {
|
|
4100
4145
|
onExit();
|
|
@@ -4228,13 +4273,9 @@ function hasStaticSlot(slots, name) {
|
|
|
4228
4273
|
if (slot.slotType === 0) return !!slot.slots[name];
|
|
4229
4274
|
});
|
|
4230
4275
|
}
|
|
4231
|
-
function createSlotBlock(slotNode, dir, context
|
|
4276
|
+
function createSlotBlock(slotNode, dir, context) {
|
|
4232
4277
|
const block = newBlock(slotNode);
|
|
4233
4278
|
block.props = dir && dir.exp;
|
|
4234
|
-
if (key) {
|
|
4235
|
-
block.key = key;
|
|
4236
|
-
block.dynamic.needsKey = true;
|
|
4237
|
-
}
|
|
4238
4279
|
const exitBlock = context.enterBlock(block);
|
|
4239
4280
|
return [block, exitBlock];
|
|
4240
4281
|
}
|
package/dist/compiler-vapor.d.ts
CHANGED
|
@@ -75,10 +75,9 @@ export declare enum IRNodeTypes {
|
|
|
75
75
|
CREATE_COMPONENT_NODE = 11,
|
|
76
76
|
SLOT_OUTLET_NODE = 12,
|
|
77
77
|
DIRECTIVE = 13,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
GET_TEXT_CHILD = 17
|
|
78
|
+
IF = 14,
|
|
79
|
+
FOR = 15,
|
|
80
|
+
GET_TEXT_CHILD = 16
|
|
82
81
|
}
|
|
83
82
|
export interface BaseIRNode {
|
|
84
83
|
type: IRNodeTypes;
|
|
@@ -230,10 +229,6 @@ export interface CreateComponentIRNode extends BaseIRNode {
|
|
|
230
229
|
append?: boolean;
|
|
231
230
|
last?: boolean;
|
|
232
231
|
}
|
|
233
|
-
export interface DeclareOldRefIRNode extends BaseIRNode {
|
|
234
|
-
type: IRNodeTypes.DECLARE_OLD_REF;
|
|
235
|
-
id: number;
|
|
236
|
-
}
|
|
237
232
|
export interface SlotOutletIRNode extends BaseIRNode {
|
|
238
233
|
type: IRNodeTypes.SLOT_OUTLET_NODE;
|
|
239
234
|
id: number;
|
|
@@ -252,7 +247,7 @@ export interface GetTextChildIRNode extends BaseIRNode {
|
|
|
252
247
|
parent: number;
|
|
253
248
|
}
|
|
254
249
|
export type IRNode = OperationNode | RootIRNode;
|
|
255
|
-
export type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | InsertNodeIRNode | PrependNodeIRNode | DirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode |
|
|
250
|
+
export type OperationNode = SetPropIRNode | SetDynamicPropsIRNode | SetTextIRNode | SetEventIRNode | SetDynamicEventsIRNode | SetHtmlIRNode | SetTemplateRefIRNode | InsertNodeIRNode | PrependNodeIRNode | DirectiveIRNode | IfIRNode | ForIRNode | CreateComponentIRNode | SlotOutletIRNode | GetTextChildIRNode;
|
|
256
251
|
export declare enum DynamicFlag {
|
|
257
252
|
NONE = 0,
|
|
258
253
|
/**
|
|
@@ -275,7 +270,6 @@ export interface IRDynamicInfo {
|
|
|
275
270
|
children: IRDynamicInfo[];
|
|
276
271
|
template?: number;
|
|
277
272
|
hasDynamicChild?: boolean;
|
|
278
|
-
needsKey?: boolean;
|
|
279
273
|
operation?: OperationNode;
|
|
280
274
|
ifBranch?: boolean;
|
|
281
275
|
}
|
|
@@ -314,6 +308,7 @@ export declare class TransformContext<T extends AllNode = AllNode> {
|
|
|
314
308
|
node: T;
|
|
315
309
|
selfName: string | null;
|
|
316
310
|
parent: TransformContext<RootNode | ElementNode> | null;
|
|
311
|
+
effectiveParent: TransformContext<RootNode | ElementNode> | null;
|
|
317
312
|
root: TransformContext<RootNode>;
|
|
318
313
|
index: number;
|
|
319
314
|
block: BlockIRNode;
|
|
@@ -328,6 +323,8 @@ export declare class TransformContext<T extends AllNode = AllNode> {
|
|
|
328
323
|
component: Set<string>;
|
|
329
324
|
directive: Set<string>;
|
|
330
325
|
slots: IRSlots[];
|
|
326
|
+
isLastEffectiveChild: boolean;
|
|
327
|
+
isOnRightmostPath: boolean;
|
|
331
328
|
private globalId;
|
|
332
329
|
private nextIdMap;
|
|
333
330
|
constructor(ir: RootIRNode, node: T, options?: TransformOptions);
|
|
@@ -340,6 +337,7 @@ export declare class TransformContext<T extends AllNode = AllNode> {
|
|
|
340
337
|
registerEffect(expressions: SimpleExpressionNode[], operation: OperationNode | OperationNode[], getIndex?: () => number): void;
|
|
341
338
|
registerOperation(...node: OperationNode[]): void;
|
|
342
339
|
create<T extends TemplateChildNode>(node: T, index: number): TransformContext<T>;
|
|
340
|
+
private isEffectivelyLastChild;
|
|
343
341
|
}
|
|
344
342
|
export declare function transform(node: RootNode, options?: TransformOptions): RootIRNode;
|
|
345
343
|
export declare function createStructuralDirectiveTransform(name: string | string[], fn: StructuralDirectiveTransform): NodeTransform;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-vapor v3.6.0-beta.
|
|
2
|
+
* @vue/compiler-vapor v3.6.0-beta.3
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -66,10 +66,12 @@ const HTML_TAGS = "html,body,base,head,link,meta,style,title,address,article,asi
|
|
|
66
66
|
const SVG_TAGS = "svg,animate,animateMotion,animateTransform,circle,clipPath,color-profile,defs,desc,discard,ellipse,feBlend,feColorMatrix,feComponentTransfer,feComposite,feConvolveMatrix,feDiffuseLighting,feDisplacementMap,feDistantLight,feDropShadow,feFlood,feFuncA,feFuncB,feFuncG,feFuncR,feGaussianBlur,feImage,feMerge,feMergeNode,feMorphology,feOffset,fePointLight,feSpecularLighting,feSpotLight,feTile,feTurbulence,filter,foreignObject,g,hatch,hatchpath,image,line,linearGradient,marker,mask,mesh,meshgradient,meshpatch,meshrow,metadata,mpath,path,pattern,polygon,polyline,radialGradient,rect,set,solidcolor,stop,switch,symbol,text,textPath,title,tspan,unknown,use,view";
|
|
67
67
|
const MATH_TAGS = "annotation,annotation-xml,maction,maligngroup,malignmark,math,menclose,merror,mfenced,mfrac,mfraction,mglyph,mi,mlabeledtr,mlongdiv,mmultiscripts,mn,mo,mover,mpadded,mphantom,mprescripts,mroot,mrow,ms,mscarries,mscarry,msgroup,msline,mspace,msqrt,msrow,mstack,mstyle,msub,msubsup,msup,mtable,mtd,mtext,mtr,munder,munderover,none,semantics";
|
|
68
68
|
const VOID_TAGS = "area,base,br,col,embed,hr,img,input,link,meta,param,source,track,wbr";
|
|
69
|
+
const FORMATTING_TAGS = "a,b,big,code,em,font,i,nobr,s,small,strike,strong,tt,u";
|
|
69
70
|
const isHTMLTag = /* @__PURE__ */ makeMap(HTML_TAGS);
|
|
70
71
|
const isSVGTag = /* @__PURE__ */ makeMap(SVG_TAGS);
|
|
71
72
|
const isMathMLTag = /* @__PURE__ */ makeMap(MATH_TAGS);
|
|
72
73
|
const isVoidTag = /* @__PURE__ */ makeMap(VOID_TAGS);
|
|
74
|
+
const isFormattingTag = /* @__PURE__ */ makeMap(FORMATTING_TAGS);
|
|
73
75
|
|
|
74
76
|
function shouldSetAsAttr(tagName, key) {
|
|
75
77
|
if (key === "spellcheck" || key === "draggable" || key === "translate" || key === "autocorrect") {
|
|
@@ -18629,8 +18631,7 @@ function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [
|
|
|
18629
18631
|
if (includeAll || isRefed && !isLocal) {
|
|
18630
18632
|
onIdentifier(node, parent, parentStack, isRefed, isLocal);
|
|
18631
18633
|
}
|
|
18632
|
-
} else if (node.type === "ObjectProperty" &&
|
|
18633
|
-
(parent == null ? void 0 : parent.type) === "ObjectPattern") {
|
|
18634
|
+
} else if (node.type === "ObjectProperty" && (parent == null ? void 0 : parent.type) === "ObjectPattern") {
|
|
18634
18635
|
node.inPattern = true;
|
|
18635
18636
|
} else if (isFunctionType(node)) {
|
|
18636
18637
|
if (node.scopeIds) {
|
|
@@ -23689,7 +23690,29 @@ const newBlock = (node) => ({
|
|
|
23689
23690
|
});
|
|
23690
23691
|
function wrapTemplate(node, dirs) {
|
|
23691
23692
|
if (node.tagType === 3) {
|
|
23692
|
-
|
|
23693
|
+
const otherStructuralDirs = ["if", "else-if", "else", "for"];
|
|
23694
|
+
const hasOtherStructuralDir = node.props.some(
|
|
23695
|
+
(prop) => prop.type === 7 && otherStructuralDirs.includes(prop.name) && !dirs.includes(prop.name)
|
|
23696
|
+
);
|
|
23697
|
+
if (!hasOtherStructuralDir) {
|
|
23698
|
+
return node;
|
|
23699
|
+
}
|
|
23700
|
+
const reserved2 = [];
|
|
23701
|
+
const pass2 = [];
|
|
23702
|
+
node.props.forEach((prop) => {
|
|
23703
|
+
if (prop.type === 7 && dirs.includes(prop.name)) {
|
|
23704
|
+
reserved2.push(prop);
|
|
23705
|
+
} else {
|
|
23706
|
+
pass2.push(prop);
|
|
23707
|
+
}
|
|
23708
|
+
});
|
|
23709
|
+
return extend({}, node, {
|
|
23710
|
+
type: 1,
|
|
23711
|
+
tag: "template",
|
|
23712
|
+
props: reserved2,
|
|
23713
|
+
tagType: 3,
|
|
23714
|
+
children: [extend({}, node, { props: pass2 })]
|
|
23715
|
+
});
|
|
23693
23716
|
}
|
|
23694
23717
|
const reserved = [];
|
|
23695
23718
|
const pass = [];
|
|
@@ -23768,10 +23791,6 @@ function getLiteralExpressionValue(exp, excludeNumber) {
|
|
|
23768
23791
|
}
|
|
23769
23792
|
return exp.isStatic ? exp.content : null;
|
|
23770
23793
|
}
|
|
23771
|
-
function isInTransition(context) {
|
|
23772
|
-
const parentNode = context.parent && context.parent.node;
|
|
23773
|
-
return !!(parentNode && isTransitionNode(parentNode));
|
|
23774
|
-
}
|
|
23775
23794
|
function isTransitionNode(node) {
|
|
23776
23795
|
return node.type === 1 && isTransitionTag(node.tag);
|
|
23777
23796
|
}
|
|
@@ -23810,6 +23829,8 @@ class TransformContext {
|
|
|
23810
23829
|
this.node = node;
|
|
23811
23830
|
this.selfName = null;
|
|
23812
23831
|
this.parent = null;
|
|
23832
|
+
// cached parent that skips template tags
|
|
23833
|
+
this.effectiveParent = null;
|
|
23813
23834
|
this.index = 0;
|
|
23814
23835
|
this.block = this.ir.block;
|
|
23815
23836
|
this.template = "";
|
|
@@ -23822,6 +23843,12 @@ class TransformContext {
|
|
|
23822
23843
|
this.component = this.ir.component;
|
|
23823
23844
|
this.directive = this.ir.directive;
|
|
23824
23845
|
this.slots = [];
|
|
23846
|
+
// whether this node is the last effective child of its parent
|
|
23847
|
+
// (all siblings after it are components, which don't appear in HTML template)
|
|
23848
|
+
this.isLastEffectiveChild = true;
|
|
23849
|
+
// whether this node is on the rightmost path of the tree
|
|
23850
|
+
// (all ancestors are also last effective children)
|
|
23851
|
+
this.isOnRightmostPath = true;
|
|
23825
23852
|
this.globalId = 0;
|
|
23826
23853
|
this.nextIdMap = null;
|
|
23827
23854
|
this.increaseId = () => {
|
|
@@ -23902,15 +23929,31 @@ class TransformContext {
|
|
|
23902
23929
|
this.block.operation.push(...node);
|
|
23903
23930
|
}
|
|
23904
23931
|
create(node, index) {
|
|
23932
|
+
let effectiveParent = this;
|
|
23933
|
+
while (effectiveParent && effectiveParent.node.type === 1 && effectiveParent.node.tagType === 3) {
|
|
23934
|
+
effectiveParent = effectiveParent.parent;
|
|
23935
|
+
}
|
|
23936
|
+
const isLastEffectiveChild = this.isEffectivelyLastChild(index);
|
|
23937
|
+
const isOnRightmostPath = this.isOnRightmostPath && isLastEffectiveChild;
|
|
23905
23938
|
return Object.assign(Object.create(TransformContext.prototype), this, {
|
|
23906
23939
|
node,
|
|
23907
23940
|
parent: this,
|
|
23908
23941
|
index,
|
|
23909
23942
|
template: "",
|
|
23910
23943
|
childrenTemplate: [],
|
|
23911
|
-
dynamic: newDynamic()
|
|
23944
|
+
dynamic: newDynamic(),
|
|
23945
|
+
effectiveParent,
|
|
23946
|
+
isLastEffectiveChild,
|
|
23947
|
+
isOnRightmostPath
|
|
23912
23948
|
});
|
|
23913
23949
|
}
|
|
23950
|
+
isEffectivelyLastChild(index) {
|
|
23951
|
+
const children = this.node.children;
|
|
23952
|
+
if (!children) return true;
|
|
23953
|
+
return children.every(
|
|
23954
|
+
(c, i) => i <= index || c.type === 1 && c.tagType === 1
|
|
23955
|
+
);
|
|
23956
|
+
}
|
|
23914
23957
|
}
|
|
23915
23958
|
const defaultOptions = {
|
|
23916
23959
|
filename: "",
|
|
@@ -24198,14 +24241,12 @@ const IRNodeTypes = {
|
|
|
24198
24241
|
"12": "SLOT_OUTLET_NODE",
|
|
24199
24242
|
"DIRECTIVE": 13,
|
|
24200
24243
|
"13": "DIRECTIVE",
|
|
24201
|
-
"
|
|
24202
|
-
"14": "
|
|
24203
|
-
"
|
|
24204
|
-
"15": "
|
|
24205
|
-
"
|
|
24206
|
-
"16": "
|
|
24207
|
-
"GET_TEXT_CHILD": 17,
|
|
24208
|
-
"17": "GET_TEXT_CHILD"
|
|
24244
|
+
"IF": 14,
|
|
24245
|
+
"14": "IF",
|
|
24246
|
+
"FOR": 15,
|
|
24247
|
+
"15": "FOR",
|
|
24248
|
+
"GET_TEXT_CHILD": 16,
|
|
24249
|
+
"16": "GET_TEXT_CHILD"
|
|
24209
24250
|
};
|
|
24210
24251
|
const DynamicFlag = {
|
|
24211
24252
|
"NONE": 0,
|
|
@@ -24219,7 +24260,7 @@ const DynamicFlag = {
|
|
|
24219
24260
|
};
|
|
24220
24261
|
function isBlockOperation(op) {
|
|
24221
24262
|
const type = op.type;
|
|
24222
|
-
return type === 11 || type === 12 || type ===
|
|
24263
|
+
return type === 11 || type === 12 || type === 14 || type === 15;
|
|
24223
24264
|
}
|
|
24224
24265
|
|
|
24225
24266
|
function genInsertNode({ parent, elements, anchor }, { helper }) {
|
|
@@ -24450,6 +24491,10 @@ function analyzeExpressions(expressions) {
|
|
|
24450
24491
|
end: id.end
|
|
24451
24492
|
});
|
|
24452
24493
|
});
|
|
24494
|
+
const parentOfMemberExp = parentStack[parentStack.length - 2];
|
|
24495
|
+
if (parentOfMemberExp && isCallExpression(parentOfMemberExp)) {
|
|
24496
|
+
return;
|
|
24497
|
+
}
|
|
24453
24498
|
registerVariable(
|
|
24454
24499
|
memberExp,
|
|
24455
24500
|
exp,
|
|
@@ -24666,6 +24711,8 @@ function extractMemberExpression(exp, onIdentifier) {
|
|
|
24666
24711
|
return `${extractMemberExpression(exp.left, onIdentifier)} ${exp.operator} ${extractMemberExpression(exp.right, onIdentifier)}`;
|
|
24667
24712
|
case "CallExpression":
|
|
24668
24713
|
return `${extractMemberExpression(exp.callee, onIdentifier)}(${exp.arguments.map((arg) => extractMemberExpression(arg, onIdentifier)).join(", ")})`;
|
|
24714
|
+
case "OptionalCallExpression":
|
|
24715
|
+
return `${extractMemberExpression(exp.callee, onIdentifier)}?.(${exp.arguments.map((arg) => extractMemberExpression(arg, onIdentifier)).join(", ")})`;
|
|
24669
24716
|
case "MemberExpression":
|
|
24670
24717
|
// foo[bar.baz]
|
|
24671
24718
|
case "OptionalMemberExpression":
|
|
@@ -24678,6 +24725,9 @@ function extractMemberExpression(exp, onIdentifier) {
|
|
|
24678
24725
|
return "";
|
|
24679
24726
|
}
|
|
24680
24727
|
}
|
|
24728
|
+
const isCallExpression = (node) => {
|
|
24729
|
+
return node.type === "CallExpression" || node.type === "OptionalCallExpression";
|
|
24730
|
+
};
|
|
24681
24731
|
const isMemberExpression = (node) => {
|
|
24682
24732
|
return node.type === "MemberExpression" || node.type === "OptionalMemberExpression" || node.type === "TSNonNullExpression";
|
|
24683
24733
|
};
|
|
@@ -25361,21 +25411,16 @@ function genSetTemplateRef(oper, context) {
|
|
|
25361
25411
|
const [refValue, refKey] = genRefValue(oper.value, context);
|
|
25362
25412
|
return [
|
|
25363
25413
|
NEWLINE,
|
|
25364
|
-
oper.effect && `r${oper.element} = `,
|
|
25365
25414
|
...genCall(
|
|
25366
25415
|
setTemplateRefIdent,
|
|
25367
25416
|
// will be generated in root scope
|
|
25368
25417
|
`n${oper.element}`,
|
|
25369
25418
|
refValue,
|
|
25370
|
-
oper.effect ? `r${oper.element}` : oper.refFor ? "void 0" : void 0,
|
|
25371
25419
|
oper.refFor && "true",
|
|
25372
25420
|
refKey
|
|
25373
25421
|
)
|
|
25374
25422
|
];
|
|
25375
25423
|
}
|
|
25376
|
-
function genDeclareOldRef(oper) {
|
|
25377
|
-
return [NEWLINE, `let r${oper.id}`];
|
|
25378
|
-
}
|
|
25379
25424
|
function genRefValue(value, context) {
|
|
25380
25425
|
if (value && context.options.inline) {
|
|
25381
25426
|
const binding = context.options.bindingMetadata[value.content];
|
|
@@ -25763,15 +25808,7 @@ function genDynamicProps(props, context) {
|
|
|
25763
25808
|
}
|
|
25764
25809
|
} else {
|
|
25765
25810
|
expr = genExpression(p.value, context);
|
|
25766
|
-
if (p.handler)
|
|
25767
|
-
expr = genCall(
|
|
25768
|
-
helper("toHandlers"),
|
|
25769
|
-
expr,
|
|
25770
|
-
`false`,
|
|
25771
|
-
// preserveCaseIfNecessary: false, not needed for component
|
|
25772
|
-
`true`
|
|
25773
|
-
// wrap handler values in functions
|
|
25774
|
-
);
|
|
25811
|
+
if (p.handler) expr = genCall(helper("toHandlers"), expr);
|
|
25775
25812
|
}
|
|
25776
25813
|
}
|
|
25777
25814
|
frags.push(["() => (", ...expr, ")"]);
|
|
@@ -25965,10 +26002,10 @@ function hasComponentOrSlotInDynamic(dynamic) {
|
|
|
25965
26002
|
if (type === 11 || type === 12) {
|
|
25966
26003
|
return true;
|
|
25967
26004
|
}
|
|
25968
|
-
if (type ===
|
|
26005
|
+
if (type === 14) {
|
|
25969
26006
|
if (hasComponentOrSlotInIf(dynamic.operation)) return true;
|
|
25970
26007
|
}
|
|
25971
|
-
if (type ===
|
|
26008
|
+
if (type === 15) {
|
|
25972
26009
|
if (hasComponentOrSlotInBlock(dynamic.operation.render))
|
|
25973
26010
|
return true;
|
|
25974
26011
|
}
|
|
@@ -25984,10 +26021,10 @@ function hasComponentOrSlotInOperations(operations) {
|
|
|
25984
26021
|
case 11:
|
|
25985
26022
|
case 12:
|
|
25986
26023
|
return true;
|
|
25987
|
-
case
|
|
26024
|
+
case 14:
|
|
25988
26025
|
if (hasComponentOrSlotInIf(op)) return true;
|
|
25989
26026
|
break;
|
|
25990
|
-
case
|
|
26027
|
+
case 15:
|
|
25991
26028
|
if (hasComponentOrSlotInBlock(op.render)) return true;
|
|
25992
26029
|
break;
|
|
25993
26030
|
}
|
|
@@ -26067,19 +26104,17 @@ function genOperation(oper, context) {
|
|
|
26067
26104
|
return genInsertNode(oper, context);
|
|
26068
26105
|
case 10:
|
|
26069
26106
|
return genPrependNode(oper, context);
|
|
26070
|
-
case
|
|
26107
|
+
case 14:
|
|
26071
26108
|
return genIf(oper, context);
|
|
26072
|
-
case
|
|
26109
|
+
case 15:
|
|
26073
26110
|
return genFor(oper, context);
|
|
26074
26111
|
case 11:
|
|
26075
26112
|
return genCreateComponent(oper, context);
|
|
26076
|
-
case 14:
|
|
26077
|
-
return genDeclareOldRef(oper);
|
|
26078
26113
|
case 12:
|
|
26079
26114
|
return genSlotOutlet(oper, context);
|
|
26080
26115
|
case 13:
|
|
26081
26116
|
return genBuiltinDirective(oper, context);
|
|
26082
|
-
case
|
|
26117
|
+
case 16:
|
|
26083
26118
|
return genGetTextChild(oper, context);
|
|
26084
26119
|
default:
|
|
26085
26120
|
const exhaustiveCheck = oper;
|
|
@@ -26280,7 +26315,7 @@ function genBlock(oper, context, args = [], root) {
|
|
|
26280
26315
|
}
|
|
26281
26316
|
function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
26282
26317
|
const [frag, push] = buildCodeFragment();
|
|
26283
|
-
const { dynamic, effect, operation, returns
|
|
26318
|
+
const { dynamic, effect, operation, returns } = block;
|
|
26284
26319
|
const resetBlock = context.enterBlock(block);
|
|
26285
26320
|
if (root) {
|
|
26286
26321
|
for (let name of context.ir.component) {
|
|
@@ -26313,12 +26348,6 @@ function genBlockContent(block, context, root, genEffectsExtraFrag) {
|
|
|
26313
26348
|
if (root && context.ir.hasDeferredVShow) {
|
|
26314
26349
|
push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`);
|
|
26315
26350
|
}
|
|
26316
|
-
if (dynamic.needsKey) {
|
|
26317
|
-
for (const child of dynamic.children) {
|
|
26318
|
-
const keyValue = key ? genExpression(key, context) : JSON.stringify(child.id);
|
|
26319
|
-
push(NEWLINE, `n${child.id}.$key = `, ...keyValue);
|
|
26320
|
-
}
|
|
26321
|
-
}
|
|
26322
26351
|
push(NEWLINE, `return `);
|
|
26323
26352
|
const returnNodes = returns.map((n) => `n${n}`);
|
|
26324
26353
|
const returnsCode = returnNodes.length > 1 ? genMulti(DELIMITERS_ARRAY, ...returnNodes) : [returnNodes[0] || "null"];
|
|
@@ -26657,7 +26686,10 @@ const transformElement = (node, context) => {
|
|
|
26657
26686
|
propsResult,
|
|
26658
26687
|
singleRoot,
|
|
26659
26688
|
context,
|
|
26660
|
-
getEffectIndex
|
|
26689
|
+
getEffectIndex,
|
|
26690
|
+
// Root-level elements generate dedicated templates
|
|
26691
|
+
// so closing tags can be omitted
|
|
26692
|
+
context.root === context.effectiveParent || canOmitEndTag(node, context)
|
|
26661
26693
|
);
|
|
26662
26694
|
}
|
|
26663
26695
|
if (parentSlots) {
|
|
@@ -26665,6 +26697,17 @@ const transformElement = (node, context) => {
|
|
|
26665
26697
|
}
|
|
26666
26698
|
};
|
|
26667
26699
|
};
|
|
26700
|
+
function canOmitEndTag(node, context) {
|
|
26701
|
+
const { block, parent } = context;
|
|
26702
|
+
if (!parent) return false;
|
|
26703
|
+
if (block !== parent.block) {
|
|
26704
|
+
return true;
|
|
26705
|
+
}
|
|
26706
|
+
if (isFormattingTag(node.tag) || parent.node.type === 1 && node.tag === parent.node.tag) {
|
|
26707
|
+
return context.isOnRightmostPath;
|
|
26708
|
+
}
|
|
26709
|
+
return context.isLastEffectiveChild;
|
|
26710
|
+
}
|
|
26668
26711
|
function isSingleRoot(context) {
|
|
26669
26712
|
if (context.inVFor) {
|
|
26670
26713
|
return false;
|
|
@@ -26754,7 +26797,8 @@ function resolveSetupReference(name, context) {
|
|
|
26754
26797
|
return bindings[name] ? name : bindings[camelName] ? camelName : bindings[PascalName] ? PascalName : void 0;
|
|
26755
26798
|
}
|
|
26756
26799
|
const dynamicKeys = ["indeterminate"];
|
|
26757
|
-
|
|
26800
|
+
const NEEDS_QUOTES_RE = /[\s"'`=<>]/;
|
|
26801
|
+
function transformNativeElement(node, propsResult, singleRoot, context, getEffectIndex, omitEndTag) {
|
|
26758
26802
|
const { tag } = node;
|
|
26759
26803
|
const { scopeId } = context.options;
|
|
26760
26804
|
let template = "";
|
|
@@ -26774,16 +26818,24 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
26774
26818
|
getEffectIndex
|
|
26775
26819
|
);
|
|
26776
26820
|
} else {
|
|
26821
|
+
let prevWasQuoted = false;
|
|
26777
26822
|
for (const prop of propsResult[1]) {
|
|
26778
26823
|
const { key, values } = prop;
|
|
26779
26824
|
if (context.imports.some(
|
|
26780
26825
|
(imported) => values[0].content.includes(imported.exp.content)
|
|
26781
26826
|
)) {
|
|
26782
|
-
template += `
|
|
26827
|
+
if (!prevWasQuoted) template += ` `;
|
|
26828
|
+
template += `${key.content}="${IMPORT_EXP_START}${values[0].content}${IMPORT_EXP_END}"`;
|
|
26829
|
+
prevWasQuoted = true;
|
|
26783
26830
|
} else if (key.isStatic && values.length === 1 && (values[0].isStatic || values[0].content === "''") && !dynamicKeys.includes(key.content)) {
|
|
26784
|
-
template += `
|
|
26785
|
-
|
|
26786
|
-
|
|
26831
|
+
if (!prevWasQuoted) template += ` `;
|
|
26832
|
+
const value = values[0].content === "''" ? "" : values[0].content;
|
|
26833
|
+
template += key.content;
|
|
26834
|
+
if (value) {
|
|
26835
|
+
template += (prevWasQuoted = NEEDS_QUOTES_RE.test(value)) ? `="${value.replace(/"/g, """)}"` : `=${value}`;
|
|
26836
|
+
} else {
|
|
26837
|
+
prevWasQuoted = false;
|
|
26838
|
+
}
|
|
26787
26839
|
} else {
|
|
26788
26840
|
dynamicProps.push(key.content);
|
|
26789
26841
|
context.registerEffect(
|
|
@@ -26800,7 +26852,7 @@ function transformNativeElement(node, propsResult, singleRoot, context, getEffec
|
|
|
26800
26852
|
}
|
|
26801
26853
|
}
|
|
26802
26854
|
template += `>` + context.childrenTemplate.join("");
|
|
26803
|
-
if (!isVoidTag(tag)) {
|
|
26855
|
+
if (!isVoidTag(tag) && !omitEndTag) {
|
|
26804
26856
|
template += `</${tag}>`;
|
|
26805
26857
|
}
|
|
26806
26858
|
if (singleRoot) {
|
|
@@ -27008,7 +27060,7 @@ const transformVText = (dir, node, context) => {
|
|
|
27008
27060
|
const isComponent = node.tagType === 1;
|
|
27009
27061
|
if (!isComponent) {
|
|
27010
27062
|
context.registerOperation({
|
|
27011
|
-
type:
|
|
27063
|
+
type: 16,
|
|
27012
27064
|
parent: context.reference()
|
|
27013
27065
|
});
|
|
27014
27066
|
}
|
|
@@ -27185,10 +27237,6 @@ const transformTemplateRef = (node, context) => {
|
|
|
27185
27237
|
return () => {
|
|
27186
27238
|
const id = context.reference();
|
|
27187
27239
|
const effect = !isConstantExpression(value);
|
|
27188
|
-
effect && context.registerOperation({
|
|
27189
|
-
type: 14,
|
|
27190
|
-
id
|
|
27191
|
-
});
|
|
27192
27240
|
context.registerEffect([value], {
|
|
27193
27241
|
type: 8,
|
|
27194
27242
|
element: id,
|
|
@@ -27273,7 +27321,7 @@ function processTextContainer(children, context) {
|
|
|
27273
27321
|
} else {
|
|
27274
27322
|
context.childrenTemplate = [" "];
|
|
27275
27323
|
context.registerOperation({
|
|
27276
|
-
type:
|
|
27324
|
+
type: 16,
|
|
27277
27325
|
parent: context.reference()
|
|
27278
27326
|
});
|
|
27279
27327
|
context.registerEffect(values, {
|
|
@@ -27462,7 +27510,7 @@ function processIf(node, dir, context) {
|
|
|
27462
27510
|
return () => {
|
|
27463
27511
|
onExit();
|
|
27464
27512
|
context.dynamic.operation = {
|
|
27465
|
-
type:
|
|
27513
|
+
type: 14,
|
|
27466
27514
|
id,
|
|
27467
27515
|
condition: dir.exp,
|
|
27468
27516
|
positive: branch,
|
|
@@ -27477,7 +27525,7 @@ function processIf(node, dir, context) {
|
|
|
27477
27525
|
if (siblings) {
|
|
27478
27526
|
let i = siblings.length;
|
|
27479
27527
|
while (i--) {
|
|
27480
|
-
if (siblings[i].operation && siblings[i].operation.type ===
|
|
27528
|
+
if (siblings[i].operation && siblings[i].operation.type === 14) {
|
|
27481
27529
|
lastIfNode = siblings[i].operation;
|
|
27482
27530
|
break;
|
|
27483
27531
|
}
|
|
@@ -27486,14 +27534,14 @@ function processIf(node, dir, context) {
|
|
|
27486
27534
|
if (
|
|
27487
27535
|
// check if v-if is the sibling node
|
|
27488
27536
|
!siblingIf || // check if IfNode is the last operation and get the root IfNode
|
|
27489
|
-
!lastIfNode || lastIfNode.type !==
|
|
27537
|
+
!lastIfNode || lastIfNode.type !== 14
|
|
27490
27538
|
) {
|
|
27491
27539
|
context.options.onError(
|
|
27492
27540
|
createCompilerError(30, node.loc)
|
|
27493
27541
|
);
|
|
27494
27542
|
return;
|
|
27495
27543
|
}
|
|
27496
|
-
while (lastIfNode.negative && lastIfNode.negative.type ===
|
|
27544
|
+
while (lastIfNode.negative && lastIfNode.negative.type === 14) {
|
|
27497
27545
|
lastIfNode = lastIfNode.negative;
|
|
27498
27546
|
}
|
|
27499
27547
|
if (dir.name === "else-if" && lastIfNode.negative) {
|
|
@@ -27513,7 +27561,7 @@ function processIf(node, dir, context) {
|
|
|
27513
27561
|
lastIfNode.negative = branch;
|
|
27514
27562
|
} else {
|
|
27515
27563
|
lastIfNode.negative = {
|
|
27516
|
-
type:
|
|
27564
|
+
type: 14,
|
|
27517
27565
|
id: -1,
|
|
27518
27566
|
condition: dir.exp,
|
|
27519
27567
|
positive: branch,
|
|
@@ -27528,7 +27576,6 @@ function createIfBranch(node, context) {
|
|
|
27528
27576
|
const branch = newBlock(node);
|
|
27529
27577
|
const exitBlock = context.enterBlock(branch);
|
|
27530
27578
|
context.reference();
|
|
27531
|
-
branch.dynamic.needsKey = isInTransition(context);
|
|
27532
27579
|
return [branch, exitBlock];
|
|
27533
27580
|
}
|
|
27534
27581
|
|
|
@@ -27566,7 +27613,7 @@ function processFor(node, dir, context) {
|
|
|
27566
27613
|
const { parent } = context;
|
|
27567
27614
|
const isOnlyChild = parent && parent.block.node !== parent.node && parent.node.children.length === 1;
|
|
27568
27615
|
context.dynamic.operation = {
|
|
27569
|
-
type:
|
|
27616
|
+
type: 15,
|
|
27570
27617
|
id,
|
|
27571
27618
|
source,
|
|
27572
27619
|
value,
|
|
@@ -27727,10 +27774,10 @@ function transformComponentSlot(node, dir, context) {
|
|
|
27727
27774
|
markNonTemplate(n, context);
|
|
27728
27775
|
});
|
|
27729
27776
|
}
|
|
27730
|
-
|
|
27777
|
+
const [block, onExit] = createSlotBlock(node, dir, context);
|
|
27731
27778
|
if (isTransitionNode(node) && nonSlotTemplateChildren.length) {
|
|
27732
27779
|
const nonCommentChild = nonSlotTemplateChildren.find(
|
|
27733
|
-
(n) => n
|
|
27780
|
+
(n) => !isCommentOrWhitespace(n)
|
|
27734
27781
|
);
|
|
27735
27782
|
if (nonCommentChild) {
|
|
27736
27783
|
const keyProp = findProp(
|
|
@@ -27738,11 +27785,10 @@ function transformComponentSlot(node, dir, context) {
|
|
|
27738
27785
|
"key"
|
|
27739
27786
|
);
|
|
27740
27787
|
if (keyProp) {
|
|
27741
|
-
|
|
27788
|
+
block.key = keyProp.exp;
|
|
27742
27789
|
}
|
|
27743
27790
|
}
|
|
27744
27791
|
}
|
|
27745
|
-
const [block, onExit] = createSlotBlock(node, dir, context, slotKey);
|
|
27746
27792
|
const { slots } = context;
|
|
27747
27793
|
return () => {
|
|
27748
27794
|
onExit();
|
|
@@ -27876,13 +27922,9 @@ function hasStaticSlot(slots, name) {
|
|
|
27876
27922
|
if (slot.slotType === 0) return !!slot.slots[name];
|
|
27877
27923
|
});
|
|
27878
27924
|
}
|
|
27879
|
-
function createSlotBlock(slotNode, dir, context
|
|
27925
|
+
function createSlotBlock(slotNode, dir, context) {
|
|
27880
27926
|
const block = newBlock(slotNode);
|
|
27881
27927
|
block.props = dir && dir.exp;
|
|
27882
|
-
if (key) {
|
|
27883
|
-
block.key = key;
|
|
27884
|
-
block.dynamic.needsKey = true;
|
|
27885
|
-
}
|
|
27886
27928
|
const exitBlock = context.enterBlock(block);
|
|
27887
27929
|
return [block, exitBlock];
|
|
27888
27930
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/compiler-vapor",
|
|
3
|
-
"version": "3.6.0-beta.
|
|
3
|
+
"version": "3.6.0-beta.3",
|
|
4
4
|
"description": "@vue/compiler-vapor",
|
|
5
5
|
"main": "dist/compiler-vapor.cjs.js",
|
|
6
6
|
"module": "dist/compiler-vapor.esm-bundler.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@babel/parser": "^7.28.5",
|
|
46
46
|
"estree-walker": "^2.0.2",
|
|
47
47
|
"source-map-js": "^1.2.1",
|
|
48
|
-
"@vue/
|
|
49
|
-
"@vue/
|
|
48
|
+
"@vue/shared": "3.6.0-beta.3",
|
|
49
|
+
"@vue/compiler-dom": "3.6.0-beta.3"
|
|
50
50
|
}
|
|
51
51
|
}
|