@vue/compiler-core 3.5.0-alpha.2 → 3.5.0-alpha.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-core.cjs.js +260 -249
- package/dist/compiler-core.cjs.prod.js +255 -244
- package/dist/compiler-core.d.ts +25 -16
- package/dist/compiler-core.esm-bundler.js +246 -216
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-core v3.5.0-alpha.
|
|
2
|
+
* @vue/compiler-core v3.5.0-alpha.3
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -180,8 +180,8 @@ const ConstantTypes = {
|
|
|
180
180
|
"0": "NOT_CONSTANT",
|
|
181
181
|
"CAN_SKIP_PATCH": 1,
|
|
182
182
|
"1": "CAN_SKIP_PATCH",
|
|
183
|
-
"
|
|
184
|
-
"2": "
|
|
183
|
+
"CAN_CACHE": 2,
|
|
184
|
+
"2": "CAN_CACHE",
|
|
185
185
|
"CAN_STRINGIFY": 3,
|
|
186
186
|
"3": "CAN_STRINGIFY"
|
|
187
187
|
};
|
|
@@ -200,7 +200,7 @@ function createRoot(children, source = "") {
|
|
|
200
200
|
directives: [],
|
|
201
201
|
hoists: [],
|
|
202
202
|
imports: [],
|
|
203
|
-
cached:
|
|
203
|
+
cached: [],
|
|
204
204
|
temps: 0,
|
|
205
205
|
codegenNode: void 0,
|
|
206
206
|
loc: locStub
|
|
@@ -305,12 +305,13 @@ function createConditionalExpression(test, consequent, alternate, newline = true
|
|
|
305
305
|
loc: locStub
|
|
306
306
|
};
|
|
307
307
|
}
|
|
308
|
-
function createCacheExpression(index, value,
|
|
308
|
+
function createCacheExpression(index, value, needPauseTracking = false) {
|
|
309
309
|
return {
|
|
310
310
|
type: 20,
|
|
311
311
|
index,
|
|
312
312
|
value,
|
|
313
|
-
|
|
313
|
+
needPauseTracking,
|
|
314
|
+
needArraySpread: false,
|
|
314
315
|
loc: locStub
|
|
315
316
|
};
|
|
316
317
|
}
|
|
@@ -1313,8 +1314,7 @@ function warnDeprecation(key, context, loc, ...args) {
|
|
|
1313
1314
|
Details: ${link}` : ``}`;
|
|
1314
1315
|
const err = new SyntaxError(msg);
|
|
1315
1316
|
err.code = key;
|
|
1316
|
-
if (loc)
|
|
1317
|
-
err.loc = loc;
|
|
1317
|
+
if (loc) err.loc = loc;
|
|
1318
1318
|
context.onWarn(err);
|
|
1319
1319
|
}
|
|
1320
1320
|
|
|
@@ -1518,7 +1518,8 @@ function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [
|
|
|
1518
1518
|
if (includeAll || isRefed && !isLocal) {
|
|
1519
1519
|
onIdentifier(node, parent, parentStack, isRefed, isLocal);
|
|
1520
1520
|
}
|
|
1521
|
-
} else if (node.type === "ObjectProperty" &&
|
|
1521
|
+
} else if (node.type === "ObjectProperty" && // eslint-disable-next-line no-restricted-syntax
|
|
1522
|
+
(parent == null ? void 0 : parent.type) === "ObjectPattern") {
|
|
1522
1523
|
node.inPattern = true;
|
|
1523
1524
|
} else if (isFunctionType(node)) {
|
|
1524
1525
|
if (node.scopeIds) {
|
|
@@ -1609,16 +1610,14 @@ function walkFunctionParams(node, onIdent) {
|
|
|
1609
1610
|
function walkBlockDeclarations(block, onIdent) {
|
|
1610
1611
|
for (const stmt of block.body) {
|
|
1611
1612
|
if (stmt.type === "VariableDeclaration") {
|
|
1612
|
-
if (stmt.declare)
|
|
1613
|
-
continue;
|
|
1613
|
+
if (stmt.declare) continue;
|
|
1614
1614
|
for (const decl of stmt.declarations) {
|
|
1615
1615
|
for (const id of extractIdentifiers(decl.id)) {
|
|
1616
1616
|
onIdent(id);
|
|
1617
1617
|
}
|
|
1618
1618
|
}
|
|
1619
1619
|
} else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
|
|
1620
|
-
if (stmt.declare || !stmt.id)
|
|
1621
|
-
continue;
|
|
1620
|
+
if (stmt.declare || !stmt.id) continue;
|
|
1622
1621
|
onIdent(stmt.id);
|
|
1623
1622
|
} else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
|
|
1624
1623
|
const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
|
|
@@ -1655,8 +1654,7 @@ function extractIdentifiers(param, nodes = []) {
|
|
|
1655
1654
|
break;
|
|
1656
1655
|
case "ArrayPattern":
|
|
1657
1656
|
param.elements.forEach((element) => {
|
|
1658
|
-
if (element)
|
|
1659
|
-
extractIdentifiers(element, nodes);
|
|
1657
|
+
if (element) extractIdentifiers(element, nodes);
|
|
1660
1658
|
});
|
|
1661
1659
|
break;
|
|
1662
1660
|
case "RestElement":
|
|
@@ -1809,7 +1807,7 @@ function isCoreComponent(tag) {
|
|
|
1809
1807
|
return BASE_TRANSITION;
|
|
1810
1808
|
}
|
|
1811
1809
|
}
|
|
1812
|
-
const nonIdentifierRE = /^\d|[^\$\w]/;
|
|
1810
|
+
const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/;
|
|
1813
1811
|
const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
|
|
1814
1812
|
const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
|
|
1815
1813
|
const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
|
|
@@ -1930,8 +1928,7 @@ function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
|
|
|
1930
1928
|
for (let i = 0; i < node.props.length; i++) {
|
|
1931
1929
|
const p = node.props[i];
|
|
1932
1930
|
if (p.type === 6) {
|
|
1933
|
-
if (dynamicOnly)
|
|
1934
|
-
continue;
|
|
1931
|
+
if (dynamicOnly) continue;
|
|
1935
1932
|
if (p.name === name && (p.value || allowEmpty)) {
|
|
1936
1933
|
return p;
|
|
1937
1934
|
}
|
|
@@ -2083,6 +2080,7 @@ function hasScopeRef(node, ids) {
|
|
|
2083
2080
|
return hasScopeRef(node.content, ids);
|
|
2084
2081
|
case 2:
|
|
2085
2082
|
case 3:
|
|
2083
|
+
case 20:
|
|
2086
2084
|
return false;
|
|
2087
2085
|
default:
|
|
2088
2086
|
return false;
|
|
@@ -2095,7 +2093,7 @@ function getMemoedVNodeCall(node) {
|
|
|
2095
2093
|
return node;
|
|
2096
2094
|
}
|
|
2097
2095
|
}
|
|
2098
|
-
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
|
|
2096
|
+
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
|
|
2099
2097
|
|
|
2100
2098
|
const defaultParserOptions = {
|
|
2101
2099
|
parseMode: "base",
|
|
@@ -2248,8 +2246,7 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2248
2246
|
}
|
|
2249
2247
|
},
|
|
2250
2248
|
ondirarg(start, end) {
|
|
2251
|
-
if (start === end)
|
|
2252
|
-
return;
|
|
2249
|
+
if (start === end) return;
|
|
2253
2250
|
const arg = getSlice(start, end);
|
|
2254
2251
|
if (inVPre) {
|
|
2255
2252
|
currentProp.name += arg;
|
|
@@ -2281,14 +2278,12 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2281
2278
|
},
|
|
2282
2279
|
onattribdata(start, end) {
|
|
2283
2280
|
currentAttrValue += getSlice(start, end);
|
|
2284
|
-
if (currentAttrStartIndex < 0)
|
|
2285
|
-
currentAttrStartIndex = start;
|
|
2281
|
+
if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
|
2286
2282
|
currentAttrEndIndex = end;
|
|
2287
2283
|
},
|
|
2288
2284
|
onattribentity(char, start, end) {
|
|
2289
2285
|
currentAttrValue += char;
|
|
2290
|
-
if (currentAttrStartIndex < 0)
|
|
2291
|
-
currentAttrStartIndex = start;
|
|
2286
|
+
if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
|
2292
2287
|
currentAttrEndIndex = end;
|
|
2293
2288
|
},
|
|
2294
2289
|
onattribnameend(end) {
|
|
@@ -2438,8 +2433,7 @@ function parseForExpression(input) {
|
|
|
2438
2433
|
const loc = input.loc;
|
|
2439
2434
|
const exp = input.content;
|
|
2440
2435
|
const inMatch = exp.match(forAliasRE);
|
|
2441
|
-
if (!inMatch)
|
|
2442
|
-
return;
|
|
2436
|
+
if (!inMatch) return;
|
|
2443
2437
|
const [, LHS, RHS] = inMatch;
|
|
2444
2438
|
const createAliasExpression = (content, offset, asParam = false) => {
|
|
2445
2439
|
const start = loc.start.offset + offset;
|
|
@@ -2626,14 +2620,12 @@ function onCloseTag(el, end, isImplied = false) {
|
|
|
2626
2620
|
}
|
|
2627
2621
|
function lookAhead(index, c) {
|
|
2628
2622
|
let i = index;
|
|
2629
|
-
while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1)
|
|
2630
|
-
i++;
|
|
2623
|
+
while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
|
|
2631
2624
|
return i;
|
|
2632
2625
|
}
|
|
2633
2626
|
function backTrack(index, c) {
|
|
2634
2627
|
let i = index;
|
|
2635
|
-
while (currentInput.charCodeAt(i) !== c && i >= 0)
|
|
2636
|
-
i--;
|
|
2628
|
+
while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
|
|
2637
2629
|
return i;
|
|
2638
2630
|
}
|
|
2639
2631
|
const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
|
|
@@ -2865,9 +2857,10 @@ function baseParse(input, options) {
|
|
|
2865
2857
|
return root;
|
|
2866
2858
|
}
|
|
2867
2859
|
|
|
2868
|
-
function
|
|
2860
|
+
function cacheStatic(root, context) {
|
|
2869
2861
|
walk(
|
|
2870
2862
|
root,
|
|
2863
|
+
void 0,
|
|
2871
2864
|
context,
|
|
2872
2865
|
// Root node is unfortunately non-hoistable due to potential parent
|
|
2873
2866
|
// fallthrough attributes.
|
|
@@ -2878,26 +2871,24 @@ function isSingleElementRoot(root, child) {
|
|
|
2878
2871
|
const { children } = root;
|
|
2879
2872
|
return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
|
|
2880
2873
|
}
|
|
2881
|
-
function walk(node, context, doNotHoistNode = false) {
|
|
2874
|
+
function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
2882
2875
|
const { children } = node;
|
|
2883
|
-
const
|
|
2884
|
-
let hoistedCount = 0;
|
|
2876
|
+
const toCache = [];
|
|
2885
2877
|
for (let i = 0; i < children.length; i++) {
|
|
2886
2878
|
const child = children[i];
|
|
2887
2879
|
if (child.type === 1 && child.tagType === 0) {
|
|
2888
2880
|
const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
|
2889
2881
|
if (constantType > 0) {
|
|
2890
2882
|
if (constantType >= 2) {
|
|
2891
|
-
child.codegenNode.patchFlag = -1
|
|
2892
|
-
|
|
2893
|
-
hoistedCount++;
|
|
2883
|
+
child.codegenNode.patchFlag = -1;
|
|
2884
|
+
toCache.push(child);
|
|
2894
2885
|
continue;
|
|
2895
2886
|
}
|
|
2896
2887
|
} else {
|
|
2897
2888
|
const codegenNode = child.codegenNode;
|
|
2898
2889
|
if (codegenNode.type === 13) {
|
|
2899
|
-
const flag =
|
|
2900
|
-
if ((
|
|
2890
|
+
const flag = codegenNode.patchFlag;
|
|
2891
|
+
if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
|
|
2901
2892
|
const props = getNodeProps(child);
|
|
2902
2893
|
if (props) {
|
|
2903
2894
|
codegenNode.props = context.hoist(props);
|
|
@@ -2908,39 +2899,84 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
2908
2899
|
}
|
|
2909
2900
|
}
|
|
2910
2901
|
}
|
|
2902
|
+
} else if (child.type === 12) {
|
|
2903
|
+
const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
|
2904
|
+
if (constantType >= 2) {
|
|
2905
|
+
toCache.push(child);
|
|
2906
|
+
continue;
|
|
2907
|
+
}
|
|
2911
2908
|
}
|
|
2912
2909
|
if (child.type === 1) {
|
|
2913
2910
|
const isComponent = child.tagType === 1;
|
|
2914
2911
|
if (isComponent) {
|
|
2915
2912
|
context.scopes.vSlot++;
|
|
2916
2913
|
}
|
|
2917
|
-
walk(child, context);
|
|
2914
|
+
walk(child, node, context, false, inFor);
|
|
2918
2915
|
if (isComponent) {
|
|
2919
2916
|
context.scopes.vSlot--;
|
|
2920
2917
|
}
|
|
2921
2918
|
} else if (child.type === 11) {
|
|
2922
|
-
walk(child, context, child.children.length === 1);
|
|
2919
|
+
walk(child, node, context, child.children.length === 1, true);
|
|
2923
2920
|
} else if (child.type === 9) {
|
|
2924
2921
|
for (let i2 = 0; i2 < child.branches.length; i2++) {
|
|
2925
2922
|
walk(
|
|
2926
2923
|
child.branches[i2],
|
|
2924
|
+
node,
|
|
2927
2925
|
context,
|
|
2928
|
-
child.branches[i2].children.length === 1
|
|
2926
|
+
child.branches[i2].children.length === 1,
|
|
2927
|
+
inFor
|
|
2929
2928
|
);
|
|
2930
2929
|
}
|
|
2931
2930
|
}
|
|
2932
2931
|
}
|
|
2933
|
-
|
|
2934
|
-
|
|
2932
|
+
let cachedAsArray = false;
|
|
2933
|
+
if (toCache.length === children.length && node.type === 1) {
|
|
2934
|
+
if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
|
|
2935
|
+
node.codegenNode.children = getCacheExpression(
|
|
2936
|
+
createArrayExpression(node.codegenNode.children)
|
|
2937
|
+
);
|
|
2938
|
+
cachedAsArray = true;
|
|
2939
|
+
} else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !shared.isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
|
|
2940
|
+
const slot = getSlotNode(node.codegenNode, "default");
|
|
2941
|
+
if (slot) {
|
|
2942
|
+
slot.returns = getCacheExpression(
|
|
2943
|
+
createArrayExpression(slot.returns)
|
|
2944
|
+
);
|
|
2945
|
+
cachedAsArray = true;
|
|
2946
|
+
}
|
|
2947
|
+
} else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !shared.isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
|
|
2948
|
+
const slotName = findDir(node, "slot", true);
|
|
2949
|
+
const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
|
|
2950
|
+
if (slot) {
|
|
2951
|
+
slot.returns = getCacheExpression(
|
|
2952
|
+
createArrayExpression(slot.returns)
|
|
2953
|
+
);
|
|
2954
|
+
cachedAsArray = true;
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2935
2957
|
}
|
|
2936
|
-
if (
|
|
2937
|
-
const
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2958
|
+
if (!cachedAsArray) {
|
|
2959
|
+
for (const child of toCache) {
|
|
2960
|
+
child.codegenNode = context.cache(child.codegenNode);
|
|
2961
|
+
}
|
|
2962
|
+
}
|
|
2963
|
+
function getCacheExpression(value) {
|
|
2964
|
+
const exp = context.cache(value);
|
|
2965
|
+
if (inFor && context.hmr) {
|
|
2966
|
+
exp.needArraySpread = true;
|
|
2967
|
+
}
|
|
2968
|
+
return exp;
|
|
2969
|
+
}
|
|
2970
|
+
function getSlotNode(node2, name) {
|
|
2971
|
+
if (node2.children && !shared.isArray(node2.children) && node2.children.type === 15) {
|
|
2972
|
+
const slot = node2.children.properties.find(
|
|
2973
|
+
(p) => p.key === name || p.key.content === name
|
|
2974
|
+
);
|
|
2975
|
+
return slot && slot.value;
|
|
2942
2976
|
}
|
|
2943
|
-
|
|
2977
|
+
}
|
|
2978
|
+
if (toCache.length && context.transformHoist) {
|
|
2979
|
+
context.transformHoist(children, context, node);
|
|
2944
2980
|
}
|
|
2945
2981
|
}
|
|
2946
2982
|
function getConstantType(node, context) {
|
|
@@ -2958,11 +2994,10 @@ function getConstantType(node, context) {
|
|
|
2958
2994
|
if (codegenNode.type !== 13) {
|
|
2959
2995
|
return 0;
|
|
2960
2996
|
}
|
|
2961
|
-
if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
|
|
2997
|
+
if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
|
|
2962
2998
|
return 0;
|
|
2963
2999
|
}
|
|
2964
|
-
|
|
2965
|
-
if (!flag) {
|
|
3000
|
+
if (codegenNode.patchFlag === void 0) {
|
|
2966
3001
|
let returnType2 = 3;
|
|
2967
3002
|
const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
|
2968
3003
|
if (generatedPropsType === 0) {
|
|
@@ -3045,6 +3080,8 @@ function getConstantType(node, context) {
|
|
|
3045
3080
|
}
|
|
3046
3081
|
}
|
|
3047
3082
|
return returnType;
|
|
3083
|
+
case 20:
|
|
3084
|
+
return 2;
|
|
3048
3085
|
default:
|
|
3049
3086
|
return 0;
|
|
3050
3087
|
}
|
|
@@ -3104,15 +3141,11 @@ function getNodeProps(node) {
|
|
|
3104
3141
|
return codegenNode.props;
|
|
3105
3142
|
}
|
|
3106
3143
|
}
|
|
3107
|
-
function getPatchFlag(node) {
|
|
3108
|
-
const flag = node.patchFlag;
|
|
3109
|
-
return flag ? parseInt(flag, 10) : void 0;
|
|
3110
|
-
}
|
|
3111
3144
|
|
|
3112
3145
|
function createTransformContext(root, {
|
|
3113
3146
|
filename = "",
|
|
3114
3147
|
prefixIdentifiers = false,
|
|
3115
|
-
hoistStatic
|
|
3148
|
+
hoistStatic = false,
|
|
3116
3149
|
hmr = false,
|
|
3117
3150
|
cacheHandlers = false,
|
|
3118
3151
|
nodeTransforms = [],
|
|
@@ -3139,7 +3172,7 @@ function createTransformContext(root, {
|
|
|
3139
3172
|
filename,
|
|
3140
3173
|
selfName: nameMatch && shared.capitalize(shared.camelize(nameMatch[1])),
|
|
3141
3174
|
prefixIdentifiers,
|
|
3142
|
-
hoistStatic
|
|
3175
|
+
hoistStatic,
|
|
3143
3176
|
hmr,
|
|
3144
3177
|
cacheHandlers,
|
|
3145
3178
|
nodeTransforms,
|
|
@@ -3166,9 +3199,9 @@ function createTransformContext(root, {
|
|
|
3166
3199
|
directives: /* @__PURE__ */ new Set(),
|
|
3167
3200
|
hoists: [],
|
|
3168
3201
|
imports: [],
|
|
3202
|
+
cached: [],
|
|
3169
3203
|
constantCache: /* @__PURE__ */ new WeakMap(),
|
|
3170
3204
|
temps: 0,
|
|
3171
|
-
cached: 0,
|
|
3172
3205
|
identifiers: /* @__PURE__ */ Object.create(null),
|
|
3173
3206
|
scopes: {
|
|
3174
3207
|
vFor: 0,
|
|
@@ -3256,8 +3289,7 @@ function createTransformContext(root, {
|
|
|
3256
3289
|
}
|
|
3257
3290
|
},
|
|
3258
3291
|
hoist(exp) {
|
|
3259
|
-
if (shared.isString(exp))
|
|
3260
|
-
exp = createSimpleExpression(exp);
|
|
3292
|
+
if (shared.isString(exp)) exp = createSimpleExpression(exp);
|
|
3261
3293
|
context.hoists.push(exp);
|
|
3262
3294
|
const identifier = createSimpleExpression(
|
|
3263
3295
|
`_hoisted_${context.hoists.length}`,
|
|
@@ -3269,7 +3301,13 @@ function createTransformContext(root, {
|
|
|
3269
3301
|
return identifier;
|
|
3270
3302
|
},
|
|
3271
3303
|
cache(exp, isVNode = false) {
|
|
3272
|
-
|
|
3304
|
+
const cacheExp = createCacheExpression(
|
|
3305
|
+
context.cached.length,
|
|
3306
|
+
exp,
|
|
3307
|
+
isVNode
|
|
3308
|
+
);
|
|
3309
|
+
context.cached.push(cacheExp);
|
|
3310
|
+
return cacheExp;
|
|
3273
3311
|
}
|
|
3274
3312
|
};
|
|
3275
3313
|
{
|
|
@@ -3291,7 +3329,7 @@ function transform(root, options) {
|
|
|
3291
3329
|
const context = createTransformContext(root, options);
|
|
3292
3330
|
traverseNode(root, context);
|
|
3293
3331
|
if (options.hoistStatic) {
|
|
3294
|
-
|
|
3332
|
+
cacheStatic(root, context);
|
|
3295
3333
|
}
|
|
3296
3334
|
if (!options.ssr) {
|
|
3297
3335
|
createRootCodegen(root, context);
|
|
@@ -3334,7 +3372,7 @@ function createRootCodegen(root, context) {
|
|
|
3334
3372
|
helper(FRAGMENT),
|
|
3335
3373
|
void 0,
|
|
3336
3374
|
root.children,
|
|
3337
|
-
patchFlag
|
|
3375
|
+
patchFlag,
|
|
3338
3376
|
void 0,
|
|
3339
3377
|
void 0,
|
|
3340
3378
|
true,
|
|
@@ -3350,8 +3388,7 @@ function traverseChildren(parent, context) {
|
|
|
3350
3388
|
};
|
|
3351
3389
|
for (; i < parent.children.length; i++) {
|
|
3352
3390
|
const child = parent.children[i];
|
|
3353
|
-
if (shared.isString(child))
|
|
3354
|
-
continue;
|
|
3391
|
+
if (shared.isString(child)) continue;
|
|
3355
3392
|
context.grandParent = context.parent;
|
|
3356
3393
|
context.parent = parent;
|
|
3357
3394
|
context.childIndex = i;
|
|
@@ -3422,8 +3459,7 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
|
3422
3459
|
props.splice(i, 1);
|
|
3423
3460
|
i--;
|
|
3424
3461
|
const onExit = fn(node, prop, context);
|
|
3425
|
-
if (onExit)
|
|
3426
|
-
exitFns.push(onExit);
|
|
3462
|
+
if (onExit) exitFns.push(onExit);
|
|
3427
3463
|
}
|
|
3428
3464
|
}
|
|
3429
3465
|
return exitFns;
|
|
@@ -3522,8 +3558,7 @@ function createCodegenContext(ast, {
|
|
|
3522
3558
|
}
|
|
3523
3559
|
function addMapping(loc, name = null) {
|
|
3524
3560
|
const { _names, _mappings } = context.map;
|
|
3525
|
-
if (name !== null && !_names.has(name))
|
|
3526
|
-
_names.add(name);
|
|
3561
|
+
if (name !== null && !_names.has(name)) _names.add(name);
|
|
3527
3562
|
_mappings.add({
|
|
3528
3563
|
originalLine: loc.line,
|
|
3529
3564
|
originalColumn: loc.column - 1,
|
|
@@ -3543,8 +3578,7 @@ function createCodegenContext(ast, {
|
|
|
3543
3578
|
}
|
|
3544
3579
|
function generate(ast, options = {}) {
|
|
3545
3580
|
const context = createCodegenContext(ast, options);
|
|
3546
|
-
if (options.onContextCreated)
|
|
3547
|
-
options.onContextCreated(context);
|
|
3581
|
+
if (options.onContextCreated) options.onContextCreated(context);
|
|
3548
3582
|
const {
|
|
3549
3583
|
mode,
|
|
3550
3584
|
push,
|
|
@@ -3693,10 +3727,6 @@ function genModulePreamble(ast, context, genScopeId, inline) {
|
|
|
3693
3727
|
runtimeModuleName,
|
|
3694
3728
|
ssrRuntimeModuleName
|
|
3695
3729
|
} = context;
|
|
3696
|
-
if (genScopeId && ast.hoists.length) {
|
|
3697
|
-
ast.helpers.add(PUSH_SCOPE_ID);
|
|
3698
|
-
ast.helpers.add(POP_SCOPE_ID);
|
|
3699
|
-
}
|
|
3700
3730
|
if (ast.helpers.size) {
|
|
3701
3731
|
const helpers = Array.from(ast.helpers);
|
|
3702
3732
|
if (optimizeImports) {
|
|
@@ -3760,28 +3790,13 @@ function genHoists(hoists, context) {
|
|
|
3760
3790
|
return;
|
|
3761
3791
|
}
|
|
3762
3792
|
context.pure = true;
|
|
3763
|
-
const { push, newline
|
|
3764
|
-
const genScopeId = scopeId != null && mode !== "function";
|
|
3793
|
+
const { push, newline } = context;
|
|
3765
3794
|
newline();
|
|
3766
|
-
if (genScopeId) {
|
|
3767
|
-
push(
|
|
3768
|
-
`const _withScopeId = n => (${helper(
|
|
3769
|
-
PUSH_SCOPE_ID
|
|
3770
|
-
)}("${scopeId}"),n=n(),${helper(POP_SCOPE_ID)}(),n)`
|
|
3771
|
-
);
|
|
3772
|
-
newline();
|
|
3773
|
-
}
|
|
3774
3795
|
for (let i = 0; i < hoists.length; i++) {
|
|
3775
3796
|
const exp = hoists[i];
|
|
3776
3797
|
if (exp) {
|
|
3777
|
-
const
|
|
3778
|
-
push(
|
|
3779
|
-
`const _hoisted_${i + 1} = ${needScopeIdWrapper ? `${PURE_ANNOTATION} _withScopeId(() => ` : ``}`
|
|
3780
|
-
);
|
|
3798
|
+
push(`const _hoisted_${i + 1} = `);
|
|
3781
3799
|
genNode(exp, context);
|
|
3782
|
-
if (needScopeIdWrapper) {
|
|
3783
|
-
push(`)`);
|
|
3784
|
-
}
|
|
3785
3800
|
newline();
|
|
3786
3801
|
}
|
|
3787
3802
|
}
|
|
@@ -3929,8 +3944,7 @@ function genExpression(node, context) {
|
|
|
3929
3944
|
}
|
|
3930
3945
|
function genInterpolation(node, context) {
|
|
3931
3946
|
const { push, helper, pure } = context;
|
|
3932
|
-
if (pure)
|
|
3933
|
-
push(PURE_ANNOTATION);
|
|
3947
|
+
if (pure) push(PURE_ANNOTATION);
|
|
3934
3948
|
push(`${helper(TO_DISPLAY_STRING)}(`);
|
|
3935
3949
|
genNode(node.content, context);
|
|
3936
3950
|
push(`)`);
|
|
@@ -3982,6 +3996,17 @@ function genVNodeCall(node, context) {
|
|
|
3982
3996
|
disableTracking,
|
|
3983
3997
|
isComponent
|
|
3984
3998
|
} = node;
|
|
3999
|
+
let patchFlagString;
|
|
4000
|
+
if (patchFlag) {
|
|
4001
|
+
{
|
|
4002
|
+
if (patchFlag < 0) {
|
|
4003
|
+
patchFlagString = patchFlag + ` /* ${shared.PatchFlagNames[patchFlag]} */`;
|
|
4004
|
+
} else {
|
|
4005
|
+
const flagNames = Object.keys(shared.PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => shared.PatchFlagNames[n]).join(`, `);
|
|
4006
|
+
patchFlagString = patchFlag + ` /* ${flagNames} */`;
|
|
4007
|
+
}
|
|
4008
|
+
}
|
|
4009
|
+
}
|
|
3985
4010
|
if (directives) {
|
|
3986
4011
|
push(helper(WITH_DIRECTIVES) + `(`);
|
|
3987
4012
|
}
|
|
@@ -3994,7 +4019,7 @@ function genVNodeCall(node, context) {
|
|
|
3994
4019
|
const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
|
|
3995
4020
|
push(helper(callHelper) + `(`, -2 /* None */, node);
|
|
3996
4021
|
genNodeList(
|
|
3997
|
-
genNullableArgs([tag, props, children,
|
|
4022
|
+
genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
|
|
3998
4023
|
context
|
|
3999
4024
|
);
|
|
4000
4025
|
push(`)`);
|
|
@@ -4010,8 +4035,7 @@ function genVNodeCall(node, context) {
|
|
|
4010
4035
|
function genNullableArgs(args) {
|
|
4011
4036
|
let i = args.length;
|
|
4012
4037
|
while (i--) {
|
|
4013
|
-
if (args[i] != null)
|
|
4014
|
-
break;
|
|
4038
|
+
if (args[i] != null) break;
|
|
4015
4039
|
}
|
|
4016
4040
|
return args.slice(0, i + 1).map((arg) => arg || `null`);
|
|
4017
4041
|
}
|
|
@@ -4128,16 +4152,21 @@ function genConditionalExpression(node, context) {
|
|
|
4128
4152
|
}
|
|
4129
4153
|
function genCacheExpression(node, context) {
|
|
4130
4154
|
const { push, helper, indent, deindent, newline } = context;
|
|
4155
|
+
const { needPauseTracking, needArraySpread } = node;
|
|
4156
|
+
if (needArraySpread) {
|
|
4157
|
+
push(`[...(`);
|
|
4158
|
+
}
|
|
4131
4159
|
push(`_cache[${node.index}] || (`);
|
|
4132
|
-
if (
|
|
4160
|
+
if (needPauseTracking) {
|
|
4133
4161
|
indent();
|
|
4134
4162
|
push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
|
|
4135
4163
|
newline();
|
|
4164
|
+
push(`(`);
|
|
4136
4165
|
}
|
|
4137
4166
|
push(`_cache[${node.index}] = `);
|
|
4138
4167
|
genNode(node.value, context);
|
|
4139
|
-
if (
|
|
4140
|
-
push(
|
|
4168
|
+
if (needPauseTracking) {
|
|
4169
|
+
push(`).cacheIndex = ${node.index},`);
|
|
4141
4170
|
newline();
|
|
4142
4171
|
push(`${helper(SET_BLOCK_TRACKING)}(1),`);
|
|
4143
4172
|
newline();
|
|
@@ -4145,6 +4174,9 @@ function genCacheExpression(node, context) {
|
|
|
4145
4174
|
deindent();
|
|
4146
4175
|
}
|
|
4147
4176
|
push(`)`);
|
|
4177
|
+
if (needArraySpread) {
|
|
4178
|
+
push(`)]`);
|
|
4179
|
+
}
|
|
4148
4180
|
}
|
|
4149
4181
|
function genTemplateLiteral(node, context) {
|
|
4150
4182
|
const { push, indent, deindent } = context;
|
|
@@ -4157,11 +4189,9 @@ function genTemplateLiteral(node, context) {
|
|
|
4157
4189
|
push(e.replace(/(`|\$|\\)/g, "\\$1"), -3 /* Unknown */);
|
|
4158
4190
|
} else {
|
|
4159
4191
|
push("${");
|
|
4160
|
-
if (multilines)
|
|
4161
|
-
indent();
|
|
4192
|
+
if (multilines) indent();
|
|
4162
4193
|
genNode(e, context);
|
|
4163
|
-
if (multilines)
|
|
4164
|
-
deindent();
|
|
4194
|
+
if (multilines) deindent();
|
|
4165
4195
|
push("}");
|
|
4166
4196
|
}
|
|
4167
4197
|
}
|
|
@@ -4365,7 +4395,7 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
|
|
|
4365
4395
|
node2.name = rewriteIdentifier(node2.name, parent, node2);
|
|
4366
4396
|
ids.push(node2);
|
|
4367
4397
|
} else {
|
|
4368
|
-
if (!(needPrefix && isLocal) && parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression") {
|
|
4398
|
+
if (!(needPrefix && isLocal) && (!parent || parent.type !== "CallExpression" && parent.type !== "NewExpression" && parent.type !== "MemberExpression")) {
|
|
4369
4399
|
node2.isConstant = true;
|
|
4370
4400
|
}
|
|
4371
4401
|
ids.push(node2);
|
|
@@ -4535,8 +4565,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
4535
4565
|
sibling.branches.push(branch);
|
|
4536
4566
|
const onExit = processCodegen && processCodegen(sibling, branch, false);
|
|
4537
4567
|
traverseNode(branch, context);
|
|
4538
|
-
if (onExit)
|
|
4539
|
-
onExit();
|
|
4568
|
+
if (onExit) onExit();
|
|
4540
4569
|
context.currentNode = null;
|
|
4541
4570
|
} else {
|
|
4542
4571
|
context.onError(
|
|
@@ -4605,7 +4634,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
|
4605
4634
|
helper(FRAGMENT),
|
|
4606
4635
|
createObjectExpression([keyProperty]),
|
|
4607
4636
|
children,
|
|
4608
|
-
patchFlag
|
|
4637
|
+
patchFlag,
|
|
4609
4638
|
void 0,
|
|
4610
4639
|
void 0,
|
|
4611
4640
|
true,
|
|
@@ -4658,6 +4687,90 @@ function getParentCondition(node) {
|
|
|
4658
4687
|
}
|
|
4659
4688
|
}
|
|
4660
4689
|
|
|
4690
|
+
const transformBind = (dir, _node, context) => {
|
|
4691
|
+
const { modifiers, loc } = dir;
|
|
4692
|
+
const arg = dir.arg;
|
|
4693
|
+
let { exp } = dir;
|
|
4694
|
+
if (exp && exp.type === 4 && !exp.content.trim()) {
|
|
4695
|
+
{
|
|
4696
|
+
context.onError(
|
|
4697
|
+
createCompilerError(34, loc)
|
|
4698
|
+
);
|
|
4699
|
+
return {
|
|
4700
|
+
props: [
|
|
4701
|
+
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
4702
|
+
]
|
|
4703
|
+
};
|
|
4704
|
+
}
|
|
4705
|
+
}
|
|
4706
|
+
if (!exp) {
|
|
4707
|
+
if (arg.type !== 4 || !arg.isStatic) {
|
|
4708
|
+
context.onError(
|
|
4709
|
+
createCompilerError(
|
|
4710
|
+
52,
|
|
4711
|
+
arg.loc
|
|
4712
|
+
)
|
|
4713
|
+
);
|
|
4714
|
+
return {
|
|
4715
|
+
props: [
|
|
4716
|
+
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
4717
|
+
]
|
|
4718
|
+
};
|
|
4719
|
+
}
|
|
4720
|
+
transformBindShorthand(dir, context);
|
|
4721
|
+
exp = dir.exp;
|
|
4722
|
+
}
|
|
4723
|
+
if (arg.type !== 4) {
|
|
4724
|
+
arg.children.unshift(`(`);
|
|
4725
|
+
arg.children.push(`) || ""`);
|
|
4726
|
+
} else if (!arg.isStatic) {
|
|
4727
|
+
arg.content = `${arg.content} || ""`;
|
|
4728
|
+
}
|
|
4729
|
+
if (modifiers.includes("camel")) {
|
|
4730
|
+
if (arg.type === 4) {
|
|
4731
|
+
if (arg.isStatic) {
|
|
4732
|
+
arg.content = shared.camelize(arg.content);
|
|
4733
|
+
} else {
|
|
4734
|
+
arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
|
4735
|
+
}
|
|
4736
|
+
} else {
|
|
4737
|
+
arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
|
4738
|
+
arg.children.push(`)`);
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
if (!context.inSSR) {
|
|
4742
|
+
if (modifiers.includes("prop")) {
|
|
4743
|
+
injectPrefix(arg, ".");
|
|
4744
|
+
}
|
|
4745
|
+
if (modifiers.includes("attr")) {
|
|
4746
|
+
injectPrefix(arg, "^");
|
|
4747
|
+
}
|
|
4748
|
+
}
|
|
4749
|
+
return {
|
|
4750
|
+
props: [createObjectProperty(arg, exp)]
|
|
4751
|
+
};
|
|
4752
|
+
};
|
|
4753
|
+
const transformBindShorthand = (dir, context) => {
|
|
4754
|
+
const arg = dir.arg;
|
|
4755
|
+
const propName = shared.camelize(arg.content);
|
|
4756
|
+
dir.exp = createSimpleExpression(propName, false, arg.loc);
|
|
4757
|
+
{
|
|
4758
|
+
dir.exp = processExpression(dir.exp, context);
|
|
4759
|
+
}
|
|
4760
|
+
};
|
|
4761
|
+
const injectPrefix = (arg, prefix) => {
|
|
4762
|
+
if (arg.type === 4) {
|
|
4763
|
+
if (arg.isStatic) {
|
|
4764
|
+
arg.content = prefix + arg.content;
|
|
4765
|
+
} else {
|
|
4766
|
+
arg.content = `\`${prefix}\${${arg.content}}\``;
|
|
4767
|
+
}
|
|
4768
|
+
} else {
|
|
4769
|
+
arg.children.unshift(`'${prefix}' + (`);
|
|
4770
|
+
arg.children.push(`)`);
|
|
4771
|
+
}
|
|
4772
|
+
};
|
|
4773
|
+
|
|
4661
4774
|
const transformFor = createStructuralDirectiveTransform(
|
|
4662
4775
|
"for",
|
|
4663
4776
|
(node, dir, context) => {
|
|
@@ -4668,9 +4781,12 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4668
4781
|
]);
|
|
4669
4782
|
const isTemplate = isTemplateNode(node);
|
|
4670
4783
|
const memo = findDir(node, "memo");
|
|
4671
|
-
const keyProp = findProp(node, `key
|
|
4672
|
-
|
|
4673
|
-
|
|
4784
|
+
const keyProp = findProp(node, `key`, false, true);
|
|
4785
|
+
if (keyProp && keyProp.type === 7 && !keyProp.exp) {
|
|
4786
|
+
transformBindShorthand(keyProp, context);
|
|
4787
|
+
}
|
|
4788
|
+
const keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
|
|
4789
|
+
const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
|
|
4674
4790
|
if (isTemplate) {
|
|
4675
4791
|
if (memo) {
|
|
4676
4792
|
memo.exp = processExpression(
|
|
@@ -4692,7 +4808,7 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4692
4808
|
helper(FRAGMENT),
|
|
4693
4809
|
void 0,
|
|
4694
4810
|
renderExp,
|
|
4695
|
-
fragmentFlag
|
|
4811
|
+
fragmentFlag,
|
|
4696
4812
|
void 0,
|
|
4697
4813
|
void 0,
|
|
4698
4814
|
true,
|
|
@@ -4732,7 +4848,7 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4732
4848
|
helper(FRAGMENT),
|
|
4733
4849
|
keyProperty ? createObjectExpression([keyProperty]) : void 0,
|
|
4734
4850
|
node.children,
|
|
4735
|
-
64
|
|
4851
|
+
64,
|
|
4736
4852
|
void 0,
|
|
4737
4853
|
void 0,
|
|
4738
4854
|
true,
|
|
@@ -4786,8 +4902,9 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4786
4902
|
renderExp.arguments.push(
|
|
4787
4903
|
loop,
|
|
4788
4904
|
createSimpleExpression(`_cache`),
|
|
4789
|
-
createSimpleExpression(String(context.cached
|
|
4905
|
+
createSimpleExpression(String(context.cached.length))
|
|
4790
4906
|
);
|
|
4907
|
+
context.cached.push(null);
|
|
4791
4908
|
} else {
|
|
4792
4909
|
renderExp.arguments.push(
|
|
4793
4910
|
createFunctionExpression(
|
|
@@ -4843,13 +4960,11 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
4843
4960
|
key && removeIdentifiers(key);
|
|
4844
4961
|
index && removeIdentifiers(index);
|
|
4845
4962
|
}
|
|
4846
|
-
if (onExit)
|
|
4847
|
-
onExit();
|
|
4963
|
+
if (onExit) onExit();
|
|
4848
4964
|
};
|
|
4849
4965
|
}
|
|
4850
4966
|
function finalizeForParseResult(result, context) {
|
|
4851
|
-
if (result.finalized)
|
|
4852
|
-
return;
|
|
4967
|
+
if (result.finalized) return;
|
|
4853
4968
|
if (context.prefixIdentifiers) {
|
|
4854
4969
|
result.source = processExpression(
|
|
4855
4970
|
result.source,
|
|
@@ -4885,8 +5000,7 @@ function createForLoopParams({ value, key, index }, memoArgs = []) {
|
|
|
4885
5000
|
function createParamsList(args) {
|
|
4886
5001
|
let i = args.length;
|
|
4887
5002
|
while (i--) {
|
|
4888
|
-
if (args[i])
|
|
4889
|
-
break;
|
|
5003
|
+
if (args[i]) break;
|
|
4890
5004
|
}
|
|
4891
5005
|
return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
|
|
4892
5006
|
}
|
|
@@ -5018,9 +5132,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
5018
5132
|
break;
|
|
5019
5133
|
}
|
|
5020
5134
|
}
|
|
5021
|
-
if (prev && isTemplateNode(prev) && findDir(prev,
|
|
5022
|
-
children.splice(i, 1);
|
|
5023
|
-
i--;
|
|
5135
|
+
if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
|
|
5024
5136
|
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
5025
5137
|
while (conditional.alternate.type === 19) {
|
|
5026
5138
|
conditional = conditional.alternate;
|
|
@@ -5157,13 +5269,11 @@ function hasForwardedSlots(children) {
|
|
|
5157
5269
|
}
|
|
5158
5270
|
break;
|
|
5159
5271
|
case 9:
|
|
5160
|
-
if (hasForwardedSlots(child.branches))
|
|
5161
|
-
return true;
|
|
5272
|
+
if (hasForwardedSlots(child.branches)) return true;
|
|
5162
5273
|
break;
|
|
5163
5274
|
case 10:
|
|
5164
5275
|
case 11:
|
|
5165
|
-
if (hasForwardedSlots(child.children))
|
|
5166
|
-
return true;
|
|
5276
|
+
if (hasForwardedSlots(child.children)) return true;
|
|
5167
5277
|
break;
|
|
5168
5278
|
}
|
|
5169
5279
|
}
|
|
@@ -5188,7 +5298,6 @@ const transformElement = (node, context) => {
|
|
|
5188
5298
|
const isDynamicComponent = shared.isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
|
|
5189
5299
|
let vnodeProps;
|
|
5190
5300
|
let vnodeChildren;
|
|
5191
|
-
let vnodePatchFlag;
|
|
5192
5301
|
let patchFlag = 0;
|
|
5193
5302
|
let vnodeDynamicProps;
|
|
5194
5303
|
let dynamicPropNames;
|
|
@@ -5199,7 +5308,7 @@ const transformElement = (node, context) => {
|
|
|
5199
5308
|
// updates inside get proper isSVG flag at runtime. (#639, #643)
|
|
5200
5309
|
// This is technically web-specific, but splitting the logic out of core
|
|
5201
5310
|
// leads to too much unnecessary complexity.
|
|
5202
|
-
(tag === "svg" || tag === "foreignObject")
|
|
5311
|
+
(tag === "svg" || tag === "foreignObject" || tag === "math")
|
|
5203
5312
|
);
|
|
5204
5313
|
if (props.length > 0) {
|
|
5205
5314
|
const propsBuildResult = buildProps(
|
|
@@ -5259,25 +5368,15 @@ const transformElement = (node, context) => {
|
|
|
5259
5368
|
vnodeChildren = node.children;
|
|
5260
5369
|
}
|
|
5261
5370
|
}
|
|
5262
|
-
if (
|
|
5263
|
-
|
|
5264
|
-
if (patchFlag < 0) {
|
|
5265
|
-
vnodePatchFlag = patchFlag + ` /* ${shared.PatchFlagNames[patchFlag]} */`;
|
|
5266
|
-
} else {
|
|
5267
|
-
const flagNames = Object.keys(shared.PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => shared.PatchFlagNames[n]).join(`, `);
|
|
5268
|
-
vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
|
|
5269
|
-
}
|
|
5270
|
-
}
|
|
5271
|
-
if (dynamicPropNames && dynamicPropNames.length) {
|
|
5272
|
-
vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
|
5273
|
-
}
|
|
5371
|
+
if (dynamicPropNames && dynamicPropNames.length) {
|
|
5372
|
+
vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
|
5274
5373
|
}
|
|
5275
5374
|
node.codegenNode = createVNodeCall(
|
|
5276
5375
|
context,
|
|
5277
5376
|
vnodeTag,
|
|
5278
5377
|
vnodeProps,
|
|
5279
5378
|
vnodeChildren,
|
|
5280
|
-
|
|
5379
|
+
patchFlag === 0 ? void 0 : patchFlag,
|
|
5281
5380
|
vnodeDynamicProps,
|
|
5282
5381
|
vnodeDirectives,
|
|
5283
5382
|
!!shouldUseBlock,
|
|
@@ -5325,8 +5424,7 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
5325
5424
|
}
|
|
5326
5425
|
const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
|
|
5327
5426
|
if (builtIn) {
|
|
5328
|
-
if (!ssr)
|
|
5329
|
-
context.helper(builtIn);
|
|
5427
|
+
if (!ssr) context.helper(builtIn);
|
|
5330
5428
|
return builtIn;
|
|
5331
5429
|
}
|
|
5332
5430
|
{
|
|
@@ -5410,8 +5508,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
5410
5508
|
);
|
|
5411
5509
|
properties = [];
|
|
5412
5510
|
}
|
|
5413
|
-
if (arg)
|
|
5414
|
-
mergeArgs.push(arg);
|
|
5511
|
+
if (arg) mergeArgs.push(arg);
|
|
5415
5512
|
};
|
|
5416
5513
|
const pushRefVForMarker = () => {
|
|
5417
5514
|
if (context.scopes.vFor > 0) {
|
|
@@ -5763,8 +5860,7 @@ function buildDirectiveArgs(dir, context) {
|
|
|
5763
5860
|
}
|
|
5764
5861
|
}
|
|
5765
5862
|
const { loc } = dir;
|
|
5766
|
-
if (dir.exp)
|
|
5767
|
-
dirArgs.push(dir.exp);
|
|
5863
|
+
if (dir.exp) dirArgs.push(dir.exp);
|
|
5768
5864
|
if (dir.arg) {
|
|
5769
5865
|
if (!dir.exp) {
|
|
5770
5866
|
dirArgs.push(`void 0`);
|
|
@@ -5794,8 +5890,7 @@ function stringifyDynamicPropNames(props) {
|
|
|
5794
5890
|
let propsNamesString = `[`;
|
|
5795
5891
|
for (let i = 0, l = props.length; i < l; i++) {
|
|
5796
5892
|
propsNamesString += JSON.stringify(props[i]);
|
|
5797
|
-
if (i < l - 1)
|
|
5798
|
-
propsNamesString += ", ";
|
|
5893
|
+
if (i < l - 1) propsNamesString += ", ";
|
|
5799
5894
|
}
|
|
5800
5895
|
return propsNamesString + `]`;
|
|
5801
5896
|
}
|
|
@@ -5892,7 +5987,7 @@ function processSlotOutlet(node, context) {
|
|
|
5892
5987
|
};
|
|
5893
5988
|
}
|
|
5894
5989
|
|
|
5895
|
-
const fnExpRE = /^\s*(
|
|
5990
|
+
const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
5896
5991
|
const transformOn = (dir, node, context, augmentor) => {
|
|
5897
5992
|
const { loc, modifiers, arg } = dir;
|
|
5898
5993
|
if (!dir.exp && !modifiers.length) {
|
|
@@ -5995,85 +6090,6 @@ const transformOn = (dir, node, context, augmentor) => {
|
|
|
5995
6090
|
return ret;
|
|
5996
6091
|
};
|
|
5997
6092
|
|
|
5998
|
-
const transformBind = (dir, _node, context) => {
|
|
5999
|
-
const { modifiers, loc } = dir;
|
|
6000
|
-
const arg = dir.arg;
|
|
6001
|
-
let { exp } = dir;
|
|
6002
|
-
if (exp && exp.type === 4 && !exp.content.trim()) {
|
|
6003
|
-
{
|
|
6004
|
-
context.onError(
|
|
6005
|
-
createCompilerError(34, loc)
|
|
6006
|
-
);
|
|
6007
|
-
return {
|
|
6008
|
-
props: [
|
|
6009
|
-
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
6010
|
-
]
|
|
6011
|
-
};
|
|
6012
|
-
}
|
|
6013
|
-
}
|
|
6014
|
-
if (!exp) {
|
|
6015
|
-
if (arg.type !== 4 || !arg.isStatic) {
|
|
6016
|
-
context.onError(
|
|
6017
|
-
createCompilerError(
|
|
6018
|
-
52,
|
|
6019
|
-
arg.loc
|
|
6020
|
-
)
|
|
6021
|
-
);
|
|
6022
|
-
return {
|
|
6023
|
-
props: [
|
|
6024
|
-
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
6025
|
-
]
|
|
6026
|
-
};
|
|
6027
|
-
}
|
|
6028
|
-
const propName = shared.camelize(arg.content);
|
|
6029
|
-
exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
|
|
6030
|
-
{
|
|
6031
|
-
exp = dir.exp = processExpression(exp, context);
|
|
6032
|
-
}
|
|
6033
|
-
}
|
|
6034
|
-
if (arg.type !== 4) {
|
|
6035
|
-
arg.children.unshift(`(`);
|
|
6036
|
-
arg.children.push(`) || ""`);
|
|
6037
|
-
} else if (!arg.isStatic) {
|
|
6038
|
-
arg.content = `${arg.content} || ""`;
|
|
6039
|
-
}
|
|
6040
|
-
if (modifiers.includes("camel")) {
|
|
6041
|
-
if (arg.type === 4) {
|
|
6042
|
-
if (arg.isStatic) {
|
|
6043
|
-
arg.content = shared.camelize(arg.content);
|
|
6044
|
-
} else {
|
|
6045
|
-
arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
|
6046
|
-
}
|
|
6047
|
-
} else {
|
|
6048
|
-
arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
|
6049
|
-
arg.children.push(`)`);
|
|
6050
|
-
}
|
|
6051
|
-
}
|
|
6052
|
-
if (!context.inSSR) {
|
|
6053
|
-
if (modifiers.includes("prop")) {
|
|
6054
|
-
injectPrefix(arg, ".");
|
|
6055
|
-
}
|
|
6056
|
-
if (modifiers.includes("attr")) {
|
|
6057
|
-
injectPrefix(arg, "^");
|
|
6058
|
-
}
|
|
6059
|
-
}
|
|
6060
|
-
return {
|
|
6061
|
-
props: [createObjectProperty(arg, exp)]
|
|
6062
|
-
};
|
|
6063
|
-
};
|
|
6064
|
-
const injectPrefix = (arg, prefix) => {
|
|
6065
|
-
if (arg.type === 4) {
|
|
6066
|
-
if (arg.isStatic) {
|
|
6067
|
-
arg.content = prefix + arg.content;
|
|
6068
|
-
} else {
|
|
6069
|
-
arg.content = `\`${prefix}\${${arg.content}}\``;
|
|
6070
|
-
}
|
|
6071
|
-
} else {
|
|
6072
|
-
arg.children.unshift(`'${prefix}' + (`);
|
|
6073
|
-
arg.children.push(`)`);
|
|
6074
|
-
}
|
|
6075
|
-
};
|
|
6076
|
-
|
|
6077
6093
|
const transformText = (node, context) => {
|
|
6078
6094
|
if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
|
|
6079
6095
|
return () => {
|
|
@@ -6261,8 +6277,7 @@ const transformFilter = (node, context) => {
|
|
|
6261
6277
|
}
|
|
6262
6278
|
if (node.type === 5) {
|
|
6263
6279
|
rewriteFilter(node.content, context);
|
|
6264
|
-
}
|
|
6265
|
-
if (node.type === 1) {
|
|
6280
|
+
} else if (node.type === 1) {
|
|
6266
6281
|
node.props.forEach((prop) => {
|
|
6267
6282
|
if (prop.type === 7 && prop.name !== "for" && prop.exp) {
|
|
6268
6283
|
rewriteFilter(prop.exp, context);
|
|
@@ -6276,8 +6291,7 @@ function rewriteFilter(node, context) {
|
|
|
6276
6291
|
} else {
|
|
6277
6292
|
for (let i = 0; i < node.children.length; i++) {
|
|
6278
6293
|
const child = node.children[i];
|
|
6279
|
-
if (typeof child !== "object")
|
|
6280
|
-
continue;
|
|
6294
|
+
if (typeof child !== "object") continue;
|
|
6281
6295
|
if (child.type === 4) {
|
|
6282
6296
|
parseFilter(child, context);
|
|
6283
6297
|
} else if (child.type === 8) {
|
|
@@ -6303,17 +6317,13 @@ function parseFilter(node, context) {
|
|
|
6303
6317
|
prev = c;
|
|
6304
6318
|
c = exp.charCodeAt(i);
|
|
6305
6319
|
if (inSingle) {
|
|
6306
|
-
if (c === 39 && prev !== 92)
|
|
6307
|
-
inSingle = false;
|
|
6320
|
+
if (c === 39 && prev !== 92) inSingle = false;
|
|
6308
6321
|
} else if (inDouble) {
|
|
6309
|
-
if (c === 34 && prev !== 92)
|
|
6310
|
-
inDouble = false;
|
|
6322
|
+
if (c === 34 && prev !== 92) inDouble = false;
|
|
6311
6323
|
} else if (inTemplateString) {
|
|
6312
|
-
if (c === 96 && prev !== 92)
|
|
6313
|
-
inTemplateString = false;
|
|
6324
|
+
if (c === 96 && prev !== 92) inTemplateString = false;
|
|
6314
6325
|
} else if (inRegex) {
|
|
6315
|
-
if (c === 47 && prev !== 92)
|
|
6316
|
-
inRegex = false;
|
|
6326
|
+
if (c === 47 && prev !== 92) inRegex = false;
|
|
6317
6327
|
} else if (c === 124 && // pipe
|
|
6318
6328
|
exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
|
|
6319
6329
|
if (expression === void 0) {
|
|
@@ -6357,8 +6367,7 @@ function parseFilter(node, context) {
|
|
|
6357
6367
|
let p;
|
|
6358
6368
|
for (; j >= 0; j--) {
|
|
6359
6369
|
p = exp.charAt(j);
|
|
6360
|
-
if (p !== " ")
|
|
6361
|
-
break;
|
|
6370
|
+
if (p !== " ") break;
|
|
6362
6371
|
}
|
|
6363
6372
|
if (!p || !validDivisionCharRE.test(p)) {
|
|
6364
6373
|
inRegex = true;
|
|
@@ -6385,6 +6394,7 @@ function parseFilter(node, context) {
|
|
|
6385
6394
|
expression = wrapFilter(expression, filters[i], context);
|
|
6386
6395
|
}
|
|
6387
6396
|
node.content = expression;
|
|
6397
|
+
node.ast = void 0;
|
|
6388
6398
|
}
|
|
6389
6399
|
}
|
|
6390
6400
|
function wrapFilter(exp, filter, context) {
|
|
@@ -6419,8 +6429,9 @@ const transformMemo = (node, context) => {
|
|
|
6419
6429
|
dir.exp,
|
|
6420
6430
|
createFunctionExpression(void 0, codegenNode),
|
|
6421
6431
|
`_cache`,
|
|
6422
|
-
String(context.cached
|
|
6432
|
+
String(context.cached.length)
|
|
6423
6433
|
]);
|
|
6434
|
+
context.cached.push(null);
|
|
6424
6435
|
}
|
|
6425
6436
|
};
|
|
6426
6437
|
}
|