@vue/compiler-dom 3.5.0-alpha.2 → 3.5.0-alpha.4
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-dom.cjs.js +36 -24
- package/dist/compiler-dom.cjs.prod.js +34 -20
- package/dist/compiler-dom.esm-browser.js +251 -222
- package/dist/compiler-dom.esm-browser.prod.js +8 -4
- package/dist/compiler-dom.esm-bundler.js +4 -7
- package/dist/compiler-dom.global.js +251 -222
- package/dist/compiler-dom.global.prod.js +8 -4
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-dom v3.5.0-alpha.
|
|
2
|
+
* @vue/compiler-dom v3.5.0-alpha.4
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -72,6 +72,9 @@ const slotFlagsText = {
|
|
|
72
72
|
|
|
73
73
|
const range = 2;
|
|
74
74
|
function generateCodeFrame(source, start = 0, end = source.length) {
|
|
75
|
+
start = Math.max(0, Math.min(start, source.length));
|
|
76
|
+
end = Math.max(0, Math.min(end, source.length));
|
|
77
|
+
if (start > end) return "";
|
|
75
78
|
let lines = source.split(/(\r?\n)/);
|
|
76
79
|
const newlineSequences = lines.filter((_, idx) => idx % 2 === 1);
|
|
77
80
|
lines = lines.filter((_, idx) => idx % 2 === 0);
|
|
@@ -81,8 +84,7 @@ function generateCodeFrame(source, start = 0, end = source.length) {
|
|
|
81
84
|
count += lines[i].length + (newlineSequences[i] && newlineSequences[i].length || 0);
|
|
82
85
|
if (count >= start) {
|
|
83
86
|
for (let j = i - range; j <= i + range || end > count; j++) {
|
|
84
|
-
if (j < 0 || j >= lines.length)
|
|
85
|
-
continue;
|
|
87
|
+
if (j < 0 || j >= lines.length) continue;
|
|
86
88
|
const line = j + 1;
|
|
87
89
|
res.push(
|
|
88
90
|
`${line}${" ".repeat(Math.max(3 - String(line).length, 0))}| ${lines[j]}`
|
|
@@ -300,8 +302,8 @@ const ConstantTypes = {
|
|
|
300
302
|
"0": "NOT_CONSTANT",
|
|
301
303
|
"CAN_SKIP_PATCH": 1,
|
|
302
304
|
"1": "CAN_SKIP_PATCH",
|
|
303
|
-
"
|
|
304
|
-
"2": "
|
|
305
|
+
"CAN_CACHE": 2,
|
|
306
|
+
"2": "CAN_CACHE",
|
|
305
307
|
"CAN_STRINGIFY": 3,
|
|
306
308
|
"3": "CAN_STRINGIFY"
|
|
307
309
|
};
|
|
@@ -320,7 +322,7 @@ function createRoot(children, source = "") {
|
|
|
320
322
|
directives: [],
|
|
321
323
|
hoists: [],
|
|
322
324
|
imports: [],
|
|
323
|
-
cached:
|
|
325
|
+
cached: [],
|
|
324
326
|
temps: 0,
|
|
325
327
|
codegenNode: void 0,
|
|
326
328
|
loc: locStub
|
|
@@ -425,12 +427,13 @@ function createConditionalExpression(test, consequent, alternate, newline = true
|
|
|
425
427
|
loc: locStub
|
|
426
428
|
};
|
|
427
429
|
}
|
|
428
|
-
function createCacheExpression(index, value,
|
|
430
|
+
function createCacheExpression(index, value, needPauseTracking = false) {
|
|
429
431
|
return {
|
|
430
432
|
type: 20,
|
|
431
433
|
index,
|
|
432
434
|
value,
|
|
433
|
-
|
|
435
|
+
needPauseTracking,
|
|
436
|
+
needArraySpread: false,
|
|
434
437
|
loc: locStub
|
|
435
438
|
};
|
|
436
439
|
}
|
|
@@ -1371,8 +1374,7 @@ function warnDeprecation(key, context, loc, ...args) {
|
|
|
1371
1374
|
Details: ${link}` : ``}`;
|
|
1372
1375
|
const err = new SyntaxError(msg);
|
|
1373
1376
|
err.code = key;
|
|
1374
|
-
if (loc)
|
|
1375
|
-
err.loc = loc;
|
|
1377
|
+
if (loc) err.loc = loc;
|
|
1376
1378
|
context.onWarn(err);
|
|
1377
1379
|
}
|
|
1378
1380
|
|
|
@@ -1608,16 +1610,14 @@ function walkFunctionParams(node, onIdent) {
|
|
|
1608
1610
|
function walkBlockDeclarations(block, onIdent) {
|
|
1609
1611
|
for (const stmt of block.body) {
|
|
1610
1612
|
if (stmt.type === "VariableDeclaration") {
|
|
1611
|
-
if (stmt.declare)
|
|
1612
|
-
continue;
|
|
1613
|
+
if (stmt.declare) continue;
|
|
1613
1614
|
for (const decl of stmt.declarations) {
|
|
1614
1615
|
for (const id of extractIdentifiers(decl.id)) {
|
|
1615
1616
|
onIdent(id);
|
|
1616
1617
|
}
|
|
1617
1618
|
}
|
|
1618
1619
|
} else if (stmt.type === "FunctionDeclaration" || stmt.type === "ClassDeclaration") {
|
|
1619
|
-
if (stmt.declare || !stmt.id)
|
|
1620
|
-
continue;
|
|
1620
|
+
if (stmt.declare || !stmt.id) continue;
|
|
1621
1621
|
onIdent(stmt.id);
|
|
1622
1622
|
} else if (stmt.type === "ForOfStatement" || stmt.type === "ForInStatement" || stmt.type === "ForStatement") {
|
|
1623
1623
|
const variable = stmt.type === "ForStatement" ? stmt.init : stmt.left;
|
|
@@ -1654,8 +1654,7 @@ function extractIdentifiers(param, nodes = []) {
|
|
|
1654
1654
|
break;
|
|
1655
1655
|
case "ArrayPattern":
|
|
1656
1656
|
param.elements.forEach((element) => {
|
|
1657
|
-
if (element)
|
|
1658
|
-
extractIdentifiers(element, nodes);
|
|
1657
|
+
if (element) extractIdentifiers(element, nodes);
|
|
1659
1658
|
});
|
|
1660
1659
|
break;
|
|
1661
1660
|
case "RestElement":
|
|
@@ -1709,7 +1708,7 @@ function isCoreComponent(tag) {
|
|
|
1709
1708
|
return BASE_TRANSITION;
|
|
1710
1709
|
}
|
|
1711
1710
|
}
|
|
1712
|
-
const nonIdentifierRE = /^\d|[^\$\w]/;
|
|
1711
|
+
const nonIdentifierRE = /^\d|[^\$\w\xA0-\uFFFF]/;
|
|
1713
1712
|
const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
|
|
1714
1713
|
const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
|
|
1715
1714
|
const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
|
|
@@ -1820,8 +1819,7 @@ function findProp(node, name, dynamicOnly = false, allowEmpty = false) {
|
|
|
1820
1819
|
for (let i = 0; i < node.props.length; i++) {
|
|
1821
1820
|
const p = node.props[i];
|
|
1822
1821
|
if (p.type === 6) {
|
|
1823
|
-
if (dynamicOnly)
|
|
1824
|
-
continue;
|
|
1822
|
+
if (dynamicOnly) continue;
|
|
1825
1823
|
if (p.name === name && (p.value || allowEmpty)) {
|
|
1826
1824
|
return p;
|
|
1827
1825
|
}
|
|
@@ -1973,6 +1971,7 @@ function hasScopeRef(node, ids) {
|
|
|
1973
1971
|
return hasScopeRef(node.content, ids);
|
|
1974
1972
|
case 2:
|
|
1975
1973
|
case 3:
|
|
1974
|
+
case 20:
|
|
1976
1975
|
return false;
|
|
1977
1976
|
default:
|
|
1978
1977
|
return false;
|
|
@@ -1985,7 +1984,7 @@ function getMemoedVNodeCall(node) {
|
|
|
1985
1984
|
return node;
|
|
1986
1985
|
}
|
|
1987
1986
|
}
|
|
1988
|
-
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
|
|
1987
|
+
const forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+(\S[\s\S]*)/;
|
|
1989
1988
|
|
|
1990
1989
|
const defaultParserOptions = {
|
|
1991
1990
|
parseMode: "base",
|
|
@@ -2138,8 +2137,7 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2138
2137
|
}
|
|
2139
2138
|
},
|
|
2140
2139
|
ondirarg(start, end) {
|
|
2141
|
-
if (start === end)
|
|
2142
|
-
return;
|
|
2140
|
+
if (start === end) return;
|
|
2143
2141
|
const arg = getSlice(start, end);
|
|
2144
2142
|
if (inVPre) {
|
|
2145
2143
|
currentProp.name += arg;
|
|
@@ -2171,14 +2169,12 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2171
2169
|
},
|
|
2172
2170
|
onattribdata(start, end) {
|
|
2173
2171
|
currentAttrValue += getSlice(start, end);
|
|
2174
|
-
if (currentAttrStartIndex < 0)
|
|
2175
|
-
currentAttrStartIndex = start;
|
|
2172
|
+
if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
|
2176
2173
|
currentAttrEndIndex = end;
|
|
2177
2174
|
},
|
|
2178
2175
|
onattribentity(char, start, end) {
|
|
2179
2176
|
currentAttrValue += char;
|
|
2180
|
-
if (currentAttrStartIndex < 0)
|
|
2181
|
-
currentAttrStartIndex = start;
|
|
2177
|
+
if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
|
2182
2178
|
currentAttrEndIndex = end;
|
|
2183
2179
|
},
|
|
2184
2180
|
onattribnameend(end) {
|
|
@@ -2325,8 +2321,7 @@ function parseForExpression(input) {
|
|
|
2325
2321
|
const loc = input.loc;
|
|
2326
2322
|
const exp = input.content;
|
|
2327
2323
|
const inMatch = exp.match(forAliasRE);
|
|
2328
|
-
if (!inMatch)
|
|
2329
|
-
return;
|
|
2324
|
+
if (!inMatch) return;
|
|
2330
2325
|
const [, LHS, RHS] = inMatch;
|
|
2331
2326
|
const createAliasExpression = (content, offset, asParam = false) => {
|
|
2332
2327
|
const start = loc.start.offset + offset;
|
|
@@ -2519,14 +2514,12 @@ function onCloseTag(el, end, isImplied = false) {
|
|
|
2519
2514
|
}
|
|
2520
2515
|
function lookAhead(index, c) {
|
|
2521
2516
|
let i = index;
|
|
2522
|
-
while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1)
|
|
2523
|
-
i++;
|
|
2517
|
+
while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
|
|
2524
2518
|
return i;
|
|
2525
2519
|
}
|
|
2526
2520
|
function backTrack(index, c) {
|
|
2527
2521
|
let i = index;
|
|
2528
|
-
while (currentInput.charCodeAt(i) !== c && i >= 0)
|
|
2529
|
-
i--;
|
|
2522
|
+
while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
|
|
2530
2523
|
return i;
|
|
2531
2524
|
}
|
|
2532
2525
|
const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
|
|
@@ -2736,9 +2729,10 @@ function baseParse(input, options) {
|
|
|
2736
2729
|
return root;
|
|
2737
2730
|
}
|
|
2738
2731
|
|
|
2739
|
-
function
|
|
2732
|
+
function cacheStatic(root, context) {
|
|
2740
2733
|
walk(
|
|
2741
2734
|
root,
|
|
2735
|
+
void 0,
|
|
2742
2736
|
context,
|
|
2743
2737
|
// Root node is unfortunately non-hoistable due to potential parent
|
|
2744
2738
|
// fallthrough attributes.
|
|
@@ -2749,26 +2743,24 @@ function isSingleElementRoot(root, child) {
|
|
|
2749
2743
|
const { children } = root;
|
|
2750
2744
|
return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
|
|
2751
2745
|
}
|
|
2752
|
-
function walk(node, context, doNotHoistNode = false) {
|
|
2746
|
+
function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
2753
2747
|
const { children } = node;
|
|
2754
|
-
const
|
|
2755
|
-
let hoistedCount = 0;
|
|
2748
|
+
const toCache = [];
|
|
2756
2749
|
for (let i = 0; i < children.length; i++) {
|
|
2757
2750
|
const child = children[i];
|
|
2758
2751
|
if (child.type === 1 && child.tagType === 0) {
|
|
2759
2752
|
const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
|
2760
2753
|
if (constantType > 0) {
|
|
2761
2754
|
if (constantType >= 2) {
|
|
2762
|
-
child.codegenNode.patchFlag = -1
|
|
2763
|
-
|
|
2764
|
-
hoistedCount++;
|
|
2755
|
+
child.codegenNode.patchFlag = -1;
|
|
2756
|
+
toCache.push(child);
|
|
2765
2757
|
continue;
|
|
2766
2758
|
}
|
|
2767
2759
|
} else {
|
|
2768
2760
|
const codegenNode = child.codegenNode;
|
|
2769
2761
|
if (codegenNode.type === 13) {
|
|
2770
|
-
const flag =
|
|
2771
|
-
if ((
|
|
2762
|
+
const flag = codegenNode.patchFlag;
|
|
2763
|
+
if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
|
|
2772
2764
|
const props = getNodeProps(child);
|
|
2773
2765
|
if (props) {
|
|
2774
2766
|
codegenNode.props = context.hoist(props);
|
|
@@ -2779,39 +2771,84 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
2779
2771
|
}
|
|
2780
2772
|
}
|
|
2781
2773
|
}
|
|
2774
|
+
} else if (child.type === 12) {
|
|
2775
|
+
const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
|
2776
|
+
if (constantType >= 2) {
|
|
2777
|
+
toCache.push(child);
|
|
2778
|
+
continue;
|
|
2779
|
+
}
|
|
2782
2780
|
}
|
|
2783
2781
|
if (child.type === 1) {
|
|
2784
2782
|
const isComponent = child.tagType === 1;
|
|
2785
2783
|
if (isComponent) {
|
|
2786
2784
|
context.scopes.vSlot++;
|
|
2787
2785
|
}
|
|
2788
|
-
walk(child, context);
|
|
2786
|
+
walk(child, node, context, false, inFor);
|
|
2789
2787
|
if (isComponent) {
|
|
2790
2788
|
context.scopes.vSlot--;
|
|
2791
2789
|
}
|
|
2792
2790
|
} else if (child.type === 11) {
|
|
2793
|
-
walk(child, context, child.children.length === 1);
|
|
2791
|
+
walk(child, node, context, child.children.length === 1, true);
|
|
2794
2792
|
} else if (child.type === 9) {
|
|
2795
2793
|
for (let i2 = 0; i2 < child.branches.length; i2++) {
|
|
2796
2794
|
walk(
|
|
2797
2795
|
child.branches[i2],
|
|
2796
|
+
node,
|
|
2798
2797
|
context,
|
|
2799
|
-
child.branches[i2].children.length === 1
|
|
2798
|
+
child.branches[i2].children.length === 1,
|
|
2799
|
+
inFor
|
|
2800
2800
|
);
|
|
2801
2801
|
}
|
|
2802
2802
|
}
|
|
2803
2803
|
}
|
|
2804
|
-
|
|
2805
|
-
|
|
2804
|
+
let cachedAsArray = false;
|
|
2805
|
+
if (toCache.length === children.length && node.type === 1) {
|
|
2806
|
+
if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && isArray(node.codegenNode.children)) {
|
|
2807
|
+
node.codegenNode.children = getCacheExpression(
|
|
2808
|
+
createArrayExpression(node.codegenNode.children)
|
|
2809
|
+
);
|
|
2810
|
+
cachedAsArray = true;
|
|
2811
|
+
} else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
|
|
2812
|
+
const slot = getSlotNode(node.codegenNode, "default");
|
|
2813
|
+
if (slot) {
|
|
2814
|
+
slot.returns = getCacheExpression(
|
|
2815
|
+
createArrayExpression(slot.returns)
|
|
2816
|
+
);
|
|
2817
|
+
cachedAsArray = true;
|
|
2818
|
+
}
|
|
2819
|
+
} else if (node.tagType === 3 && parent && parent.type === 1 && parent.tagType === 1 && parent.codegenNode && parent.codegenNode.type === 13 && parent.codegenNode.children && !isArray(parent.codegenNode.children) && parent.codegenNode.children.type === 15) {
|
|
2820
|
+
const slotName = findDir(node, "slot", true);
|
|
2821
|
+
const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
|
|
2822
|
+
if (slot) {
|
|
2823
|
+
slot.returns = getCacheExpression(
|
|
2824
|
+
createArrayExpression(slot.returns)
|
|
2825
|
+
);
|
|
2826
|
+
cachedAsArray = true;
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2806
2829
|
}
|
|
2807
|
-
if (
|
|
2808
|
-
const
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2830
|
+
if (!cachedAsArray) {
|
|
2831
|
+
for (const child of toCache) {
|
|
2832
|
+
child.codegenNode = context.cache(child.codegenNode);
|
|
2833
|
+
}
|
|
2834
|
+
}
|
|
2835
|
+
function getCacheExpression(value) {
|
|
2836
|
+
const exp = context.cache(value);
|
|
2837
|
+
if (inFor && context.hmr) {
|
|
2838
|
+
exp.needArraySpread = true;
|
|
2839
|
+
}
|
|
2840
|
+
return exp;
|
|
2841
|
+
}
|
|
2842
|
+
function getSlotNode(node2, name) {
|
|
2843
|
+
if (node2.children && !isArray(node2.children) && node2.children.type === 15) {
|
|
2844
|
+
const slot = node2.children.properties.find(
|
|
2845
|
+
(p) => p.key === name || p.key.content === name
|
|
2846
|
+
);
|
|
2847
|
+
return slot && slot.value;
|
|
2813
2848
|
}
|
|
2814
|
-
|
|
2849
|
+
}
|
|
2850
|
+
if (toCache.length && context.transformHoist) {
|
|
2851
|
+
context.transformHoist(children, context, node);
|
|
2815
2852
|
}
|
|
2816
2853
|
}
|
|
2817
2854
|
function getConstantType(node, context) {
|
|
@@ -2829,11 +2866,10 @@ function getConstantType(node, context) {
|
|
|
2829
2866
|
if (codegenNode.type !== 13) {
|
|
2830
2867
|
return 0;
|
|
2831
2868
|
}
|
|
2832
|
-
if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
|
|
2869
|
+
if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
|
|
2833
2870
|
return 0;
|
|
2834
2871
|
}
|
|
2835
|
-
|
|
2836
|
-
if (!flag) {
|
|
2872
|
+
if (codegenNode.patchFlag === void 0) {
|
|
2837
2873
|
let returnType2 = 3;
|
|
2838
2874
|
const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
|
2839
2875
|
if (generatedPropsType === 0) {
|
|
@@ -2916,6 +2952,8 @@ function getConstantType(node, context) {
|
|
|
2916
2952
|
}
|
|
2917
2953
|
}
|
|
2918
2954
|
return returnType;
|
|
2955
|
+
case 20:
|
|
2956
|
+
return 2;
|
|
2919
2957
|
default:
|
|
2920
2958
|
return 0;
|
|
2921
2959
|
}
|
|
@@ -2975,15 +3013,11 @@ function getNodeProps(node) {
|
|
|
2975
3013
|
return codegenNode.props;
|
|
2976
3014
|
}
|
|
2977
3015
|
}
|
|
2978
|
-
function getPatchFlag(node) {
|
|
2979
|
-
const flag = node.patchFlag;
|
|
2980
|
-
return flag ? parseInt(flag, 10) : void 0;
|
|
2981
|
-
}
|
|
2982
3016
|
|
|
2983
3017
|
function createTransformContext(root, {
|
|
2984
3018
|
filename = "",
|
|
2985
3019
|
prefixIdentifiers = false,
|
|
2986
|
-
hoistStatic
|
|
3020
|
+
hoistStatic = false,
|
|
2987
3021
|
hmr = false,
|
|
2988
3022
|
cacheHandlers = false,
|
|
2989
3023
|
nodeTransforms = [],
|
|
@@ -3010,7 +3044,7 @@ function createTransformContext(root, {
|
|
|
3010
3044
|
filename,
|
|
3011
3045
|
selfName: nameMatch && capitalize(camelize(nameMatch[1])),
|
|
3012
3046
|
prefixIdentifiers,
|
|
3013
|
-
hoistStatic
|
|
3047
|
+
hoistStatic,
|
|
3014
3048
|
hmr,
|
|
3015
3049
|
cacheHandlers,
|
|
3016
3050
|
nodeTransforms,
|
|
@@ -3037,9 +3071,9 @@ function createTransformContext(root, {
|
|
|
3037
3071
|
directives: /* @__PURE__ */ new Set(),
|
|
3038
3072
|
hoists: [],
|
|
3039
3073
|
imports: [],
|
|
3074
|
+
cached: [],
|
|
3040
3075
|
constantCache: /* @__PURE__ */ new WeakMap(),
|
|
3041
3076
|
temps: 0,
|
|
3042
|
-
cached: 0,
|
|
3043
3077
|
identifiers: /* @__PURE__ */ Object.create(null),
|
|
3044
3078
|
scopes: {
|
|
3045
3079
|
vFor: 0,
|
|
@@ -3109,8 +3143,7 @@ function createTransformContext(root, {
|
|
|
3109
3143
|
removeIdentifiers(exp) {
|
|
3110
3144
|
},
|
|
3111
3145
|
hoist(exp) {
|
|
3112
|
-
if (isString(exp))
|
|
3113
|
-
exp = createSimpleExpression(exp);
|
|
3146
|
+
if (isString(exp)) exp = createSimpleExpression(exp);
|
|
3114
3147
|
context.hoists.push(exp);
|
|
3115
3148
|
const identifier = createSimpleExpression(
|
|
3116
3149
|
`_hoisted_${context.hoists.length}`,
|
|
@@ -3122,7 +3155,13 @@ function createTransformContext(root, {
|
|
|
3122
3155
|
return identifier;
|
|
3123
3156
|
},
|
|
3124
3157
|
cache(exp, isVNode = false) {
|
|
3125
|
-
|
|
3158
|
+
const cacheExp = createCacheExpression(
|
|
3159
|
+
context.cached.length,
|
|
3160
|
+
exp,
|
|
3161
|
+
isVNode
|
|
3162
|
+
);
|
|
3163
|
+
context.cached.push(cacheExp);
|
|
3164
|
+
return cacheExp;
|
|
3126
3165
|
}
|
|
3127
3166
|
};
|
|
3128
3167
|
{
|
|
@@ -3134,7 +3173,7 @@ function transform(root, options) {
|
|
|
3134
3173
|
const context = createTransformContext(root, options);
|
|
3135
3174
|
traverseNode(root, context);
|
|
3136
3175
|
if (options.hoistStatic) {
|
|
3137
|
-
|
|
3176
|
+
cacheStatic(root, context);
|
|
3138
3177
|
}
|
|
3139
3178
|
if (!options.ssr) {
|
|
3140
3179
|
createRootCodegen(root, context);
|
|
@@ -3177,7 +3216,7 @@ function createRootCodegen(root, context) {
|
|
|
3177
3216
|
helper(FRAGMENT),
|
|
3178
3217
|
void 0,
|
|
3179
3218
|
root.children,
|
|
3180
|
-
patchFlag
|
|
3219
|
+
patchFlag,
|
|
3181
3220
|
void 0,
|
|
3182
3221
|
void 0,
|
|
3183
3222
|
true,
|
|
@@ -3193,8 +3232,7 @@ function traverseChildren(parent, context) {
|
|
|
3193
3232
|
};
|
|
3194
3233
|
for (; i < parent.children.length; i++) {
|
|
3195
3234
|
const child = parent.children[i];
|
|
3196
|
-
if (isString(child))
|
|
3197
|
-
continue;
|
|
3235
|
+
if (isString(child)) continue;
|
|
3198
3236
|
context.grandParent = context.parent;
|
|
3199
3237
|
context.parent = parent;
|
|
3200
3238
|
context.childIndex = i;
|
|
@@ -3265,8 +3303,7 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
|
3265
3303
|
props.splice(i, 1);
|
|
3266
3304
|
i--;
|
|
3267
3305
|
const onExit = fn(node, prop, context);
|
|
3268
|
-
if (onExit)
|
|
3269
|
-
exitFns.push(onExit);
|
|
3306
|
+
if (onExit) exitFns.push(onExit);
|
|
3270
3307
|
}
|
|
3271
3308
|
}
|
|
3272
3309
|
return exitFns;
|
|
@@ -3338,8 +3375,7 @@ function createCodegenContext(ast, {
|
|
|
3338
3375
|
}
|
|
3339
3376
|
function generate(ast, options = {}) {
|
|
3340
3377
|
const context = createCodegenContext(ast, options);
|
|
3341
|
-
if (options.onContextCreated)
|
|
3342
|
-
options.onContextCreated(context);
|
|
3378
|
+
if (options.onContextCreated) options.onContextCreated(context);
|
|
3343
3379
|
const {
|
|
3344
3380
|
mode,
|
|
3345
3381
|
push,
|
|
@@ -3481,14 +3517,12 @@ function genHoists(hoists, context) {
|
|
|
3481
3517
|
return;
|
|
3482
3518
|
}
|
|
3483
3519
|
context.pure = true;
|
|
3484
|
-
const { push, newline
|
|
3520
|
+
const { push, newline } = context;
|
|
3485
3521
|
newline();
|
|
3486
3522
|
for (let i = 0; i < hoists.length; i++) {
|
|
3487
3523
|
const exp = hoists[i];
|
|
3488
3524
|
if (exp) {
|
|
3489
|
-
push(
|
|
3490
|
-
`const _hoisted_${i + 1} = ${``}`
|
|
3491
|
-
);
|
|
3525
|
+
push(`const _hoisted_${i + 1} = `);
|
|
3492
3526
|
genNode(exp, context);
|
|
3493
3527
|
newline();
|
|
3494
3528
|
}
|
|
@@ -3621,8 +3655,7 @@ function genExpression(node, context) {
|
|
|
3621
3655
|
}
|
|
3622
3656
|
function genInterpolation(node, context) {
|
|
3623
3657
|
const { push, helper, pure } = context;
|
|
3624
|
-
if (pure)
|
|
3625
|
-
push(PURE_ANNOTATION);
|
|
3658
|
+
if (pure) push(PURE_ANNOTATION);
|
|
3626
3659
|
push(`${helper(TO_DISPLAY_STRING)}(`);
|
|
3627
3660
|
genNode(node.content, context);
|
|
3628
3661
|
push(`)`);
|
|
@@ -3674,6 +3707,17 @@ function genVNodeCall(node, context) {
|
|
|
3674
3707
|
disableTracking,
|
|
3675
3708
|
isComponent
|
|
3676
3709
|
} = node;
|
|
3710
|
+
let patchFlagString;
|
|
3711
|
+
if (patchFlag) {
|
|
3712
|
+
{
|
|
3713
|
+
if (patchFlag < 0) {
|
|
3714
|
+
patchFlagString = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
|
|
3715
|
+
} else {
|
|
3716
|
+
const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
|
|
3717
|
+
patchFlagString = patchFlag + ` /* ${flagNames} */`;
|
|
3718
|
+
}
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3677
3721
|
if (directives) {
|
|
3678
3722
|
push(helper(WITH_DIRECTIVES) + `(`);
|
|
3679
3723
|
}
|
|
@@ -3686,7 +3730,7 @@ function genVNodeCall(node, context) {
|
|
|
3686
3730
|
const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
|
|
3687
3731
|
push(helper(callHelper) + `(`, -2 /* None */, node);
|
|
3688
3732
|
genNodeList(
|
|
3689
|
-
genNullableArgs([tag, props, children,
|
|
3733
|
+
genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
|
|
3690
3734
|
context
|
|
3691
3735
|
);
|
|
3692
3736
|
push(`)`);
|
|
@@ -3702,8 +3746,7 @@ function genVNodeCall(node, context) {
|
|
|
3702
3746
|
function genNullableArgs(args) {
|
|
3703
3747
|
let i = args.length;
|
|
3704
3748
|
while (i--) {
|
|
3705
|
-
if (args[i] != null)
|
|
3706
|
-
break;
|
|
3749
|
+
if (args[i] != null) break;
|
|
3707
3750
|
}
|
|
3708
3751
|
return args.slice(0, i + 1).map((arg) => arg || `null`);
|
|
3709
3752
|
}
|
|
@@ -3820,16 +3863,21 @@ function genConditionalExpression(node, context) {
|
|
|
3820
3863
|
}
|
|
3821
3864
|
function genCacheExpression(node, context) {
|
|
3822
3865
|
const { push, helper, indent, deindent, newline } = context;
|
|
3866
|
+
const { needPauseTracking, needArraySpread } = node;
|
|
3867
|
+
if (needArraySpread) {
|
|
3868
|
+
push(`[...(`);
|
|
3869
|
+
}
|
|
3823
3870
|
push(`_cache[${node.index}] || (`);
|
|
3824
|
-
if (
|
|
3871
|
+
if (needPauseTracking) {
|
|
3825
3872
|
indent();
|
|
3826
3873
|
push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
|
|
3827
3874
|
newline();
|
|
3875
|
+
push(`(`);
|
|
3828
3876
|
}
|
|
3829
3877
|
push(`_cache[${node.index}] = `);
|
|
3830
3878
|
genNode(node.value, context);
|
|
3831
|
-
if (
|
|
3832
|
-
push(
|
|
3879
|
+
if (needPauseTracking) {
|
|
3880
|
+
push(`).cacheIndex = ${node.index},`);
|
|
3833
3881
|
newline();
|
|
3834
3882
|
push(`${helper(SET_BLOCK_TRACKING)}(1),`);
|
|
3835
3883
|
newline();
|
|
@@ -3837,6 +3885,9 @@ function genCacheExpression(node, context) {
|
|
|
3837
3885
|
deindent();
|
|
3838
3886
|
}
|
|
3839
3887
|
push(`)`);
|
|
3888
|
+
if (needArraySpread) {
|
|
3889
|
+
push(`)]`);
|
|
3890
|
+
}
|
|
3840
3891
|
}
|
|
3841
3892
|
|
|
3842
3893
|
const prohibitedKeywordRE = new RegExp(
|
|
@@ -4013,8 +4064,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
4013
4064
|
sibling.branches.push(branch);
|
|
4014
4065
|
const onExit = processCodegen && processCodegen(sibling, branch, false);
|
|
4015
4066
|
traverseNode(branch, context);
|
|
4016
|
-
if (onExit)
|
|
4017
|
-
onExit();
|
|
4067
|
+
if (onExit) onExit();
|
|
4018
4068
|
context.currentNode = null;
|
|
4019
4069
|
} else {
|
|
4020
4070
|
context.onError(
|
|
@@ -4083,7 +4133,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
|
4083
4133
|
helper(FRAGMENT),
|
|
4084
4134
|
createObjectExpression([keyProperty]),
|
|
4085
4135
|
children,
|
|
4086
|
-
patchFlag
|
|
4136
|
+
patchFlag,
|
|
4087
4137
|
void 0,
|
|
4088
4138
|
void 0,
|
|
4089
4139
|
true,
|
|
@@ -4136,6 +4186,80 @@ function getParentCondition(node) {
|
|
|
4136
4186
|
}
|
|
4137
4187
|
}
|
|
4138
4188
|
|
|
4189
|
+
const transformBind = (dir, _node, context) => {
|
|
4190
|
+
const { modifiers, loc } = dir;
|
|
4191
|
+
const arg = dir.arg;
|
|
4192
|
+
let { exp } = dir;
|
|
4193
|
+
if (exp && exp.type === 4 && !exp.content.trim()) {
|
|
4194
|
+
{
|
|
4195
|
+
exp = void 0;
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
if (!exp) {
|
|
4199
|
+
if (arg.type !== 4 || !arg.isStatic) {
|
|
4200
|
+
context.onError(
|
|
4201
|
+
createCompilerError(
|
|
4202
|
+
52,
|
|
4203
|
+
arg.loc
|
|
4204
|
+
)
|
|
4205
|
+
);
|
|
4206
|
+
return {
|
|
4207
|
+
props: [
|
|
4208
|
+
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
4209
|
+
]
|
|
4210
|
+
};
|
|
4211
|
+
}
|
|
4212
|
+
transformBindShorthand(dir);
|
|
4213
|
+
exp = dir.exp;
|
|
4214
|
+
}
|
|
4215
|
+
if (arg.type !== 4) {
|
|
4216
|
+
arg.children.unshift(`(`);
|
|
4217
|
+
arg.children.push(`) || ""`);
|
|
4218
|
+
} else if (!arg.isStatic) {
|
|
4219
|
+
arg.content = `${arg.content} || ""`;
|
|
4220
|
+
}
|
|
4221
|
+
if (modifiers.includes("camel")) {
|
|
4222
|
+
if (arg.type === 4) {
|
|
4223
|
+
if (arg.isStatic) {
|
|
4224
|
+
arg.content = camelize(arg.content);
|
|
4225
|
+
} else {
|
|
4226
|
+
arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
|
4227
|
+
}
|
|
4228
|
+
} else {
|
|
4229
|
+
arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
|
4230
|
+
arg.children.push(`)`);
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
if (!context.inSSR) {
|
|
4234
|
+
if (modifiers.includes("prop")) {
|
|
4235
|
+
injectPrefix(arg, ".");
|
|
4236
|
+
}
|
|
4237
|
+
if (modifiers.includes("attr")) {
|
|
4238
|
+
injectPrefix(arg, "^");
|
|
4239
|
+
}
|
|
4240
|
+
}
|
|
4241
|
+
return {
|
|
4242
|
+
props: [createObjectProperty(arg, exp)]
|
|
4243
|
+
};
|
|
4244
|
+
};
|
|
4245
|
+
const transformBindShorthand = (dir, context) => {
|
|
4246
|
+
const arg = dir.arg;
|
|
4247
|
+
const propName = camelize(arg.content);
|
|
4248
|
+
dir.exp = createSimpleExpression(propName, false, arg.loc);
|
|
4249
|
+
};
|
|
4250
|
+
const injectPrefix = (arg, prefix) => {
|
|
4251
|
+
if (arg.type === 4) {
|
|
4252
|
+
if (arg.isStatic) {
|
|
4253
|
+
arg.content = prefix + arg.content;
|
|
4254
|
+
} else {
|
|
4255
|
+
arg.content = `\`${prefix}\${${arg.content}}\``;
|
|
4256
|
+
}
|
|
4257
|
+
} else {
|
|
4258
|
+
arg.children.unshift(`'${prefix}' + (`);
|
|
4259
|
+
arg.children.push(`)`);
|
|
4260
|
+
}
|
|
4261
|
+
};
|
|
4262
|
+
|
|
4139
4263
|
const transformFor = createStructuralDirectiveTransform(
|
|
4140
4264
|
"for",
|
|
4141
4265
|
(node, dir, context) => {
|
|
@@ -4146,9 +4270,12 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4146
4270
|
]);
|
|
4147
4271
|
const isTemplate = isTemplateNode(node);
|
|
4148
4272
|
const memo = findDir(node, "memo");
|
|
4149
|
-
const keyProp = findProp(node, `key
|
|
4150
|
-
|
|
4151
|
-
|
|
4273
|
+
const keyProp = findProp(node, `key`, false, true);
|
|
4274
|
+
if (keyProp && keyProp.type === 7 && !keyProp.exp) {
|
|
4275
|
+
transformBindShorthand(keyProp);
|
|
4276
|
+
}
|
|
4277
|
+
const keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
|
|
4278
|
+
const keyProperty = keyProp && keyExp ? createObjectProperty(`key`, keyExp) : null;
|
|
4152
4279
|
const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
|
|
4153
4280
|
const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
|
|
4154
4281
|
forNode.codegenNode = createVNodeCall(
|
|
@@ -4156,7 +4283,7 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4156
4283
|
helper(FRAGMENT),
|
|
4157
4284
|
void 0,
|
|
4158
4285
|
renderExp,
|
|
4159
|
-
fragmentFlag
|
|
4286
|
+
fragmentFlag,
|
|
4160
4287
|
void 0,
|
|
4161
4288
|
void 0,
|
|
4162
4289
|
true,
|
|
@@ -4196,7 +4323,7 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4196
4323
|
helper(FRAGMENT),
|
|
4197
4324
|
keyProperty ? createObjectExpression([keyProperty]) : void 0,
|
|
4198
4325
|
node.children,
|
|
4199
|
-
64
|
|
4326
|
+
64,
|
|
4200
4327
|
void 0,
|
|
4201
4328
|
void 0,
|
|
4202
4329
|
true,
|
|
@@ -4250,8 +4377,9 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4250
4377
|
renderExp.arguments.push(
|
|
4251
4378
|
loop,
|
|
4252
4379
|
createSimpleExpression(`_cache`),
|
|
4253
|
-
createSimpleExpression(String(context.cached
|
|
4380
|
+
createSimpleExpression(String(context.cached.length))
|
|
4254
4381
|
);
|
|
4382
|
+
context.cached.push(null);
|
|
4255
4383
|
} else {
|
|
4256
4384
|
renderExp.arguments.push(
|
|
4257
4385
|
createFunctionExpression(
|
|
@@ -4297,13 +4425,11 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
4297
4425
|
const onExit = processCodegen && processCodegen(forNode);
|
|
4298
4426
|
return () => {
|
|
4299
4427
|
scopes.vFor--;
|
|
4300
|
-
if (onExit)
|
|
4301
|
-
onExit();
|
|
4428
|
+
if (onExit) onExit();
|
|
4302
4429
|
};
|
|
4303
4430
|
}
|
|
4304
4431
|
function finalizeForParseResult(result, context) {
|
|
4305
|
-
if (result.finalized)
|
|
4306
|
-
return;
|
|
4432
|
+
if (result.finalized) return;
|
|
4307
4433
|
{
|
|
4308
4434
|
validateBrowserExpression(result.source, context);
|
|
4309
4435
|
if (result.key) {
|
|
@@ -4336,8 +4462,7 @@ function createForLoopParams({ value, key, index }, memoArgs = []) {
|
|
|
4336
4462
|
function createParamsList(args) {
|
|
4337
4463
|
let i = args.length;
|
|
4338
4464
|
while (i--) {
|
|
4339
|
-
if (args[i])
|
|
4340
|
-
break;
|
|
4465
|
+
if (args[i]) break;
|
|
4341
4466
|
}
|
|
4342
4467
|
return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
|
|
4343
4468
|
}
|
|
@@ -4460,9 +4585,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4460
4585
|
break;
|
|
4461
4586
|
}
|
|
4462
4587
|
}
|
|
4463
|
-
if (prev && isTemplateNode(prev) && findDir(prev,
|
|
4464
|
-
children.splice(i, 1);
|
|
4465
|
-
i--;
|
|
4588
|
+
if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
|
|
4466
4589
|
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
4467
4590
|
while (conditional.alternate.type === 19) {
|
|
4468
4591
|
conditional = conditional.alternate;
|
|
@@ -4599,13 +4722,11 @@ function hasForwardedSlots(children) {
|
|
|
4599
4722
|
}
|
|
4600
4723
|
break;
|
|
4601
4724
|
case 9:
|
|
4602
|
-
if (hasForwardedSlots(child.branches))
|
|
4603
|
-
return true;
|
|
4725
|
+
if (hasForwardedSlots(child.branches)) return true;
|
|
4604
4726
|
break;
|
|
4605
4727
|
case 10:
|
|
4606
4728
|
case 11:
|
|
4607
|
-
if (hasForwardedSlots(child.children))
|
|
4608
|
-
return true;
|
|
4729
|
+
if (hasForwardedSlots(child.children)) return true;
|
|
4609
4730
|
break;
|
|
4610
4731
|
}
|
|
4611
4732
|
}
|
|
@@ -4630,7 +4751,6 @@ const transformElement = (node, context) => {
|
|
|
4630
4751
|
const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
|
|
4631
4752
|
let vnodeProps;
|
|
4632
4753
|
let vnodeChildren;
|
|
4633
|
-
let vnodePatchFlag;
|
|
4634
4754
|
let patchFlag = 0;
|
|
4635
4755
|
let vnodeDynamicProps;
|
|
4636
4756
|
let dynamicPropNames;
|
|
@@ -4641,7 +4761,7 @@ const transformElement = (node, context) => {
|
|
|
4641
4761
|
// updates inside get proper isSVG flag at runtime. (#639, #643)
|
|
4642
4762
|
// This is technically web-specific, but splitting the logic out of core
|
|
4643
4763
|
// leads to too much unnecessary complexity.
|
|
4644
|
-
(tag === "svg" || tag === "foreignObject")
|
|
4764
|
+
(tag === "svg" || tag === "foreignObject" || tag === "math")
|
|
4645
4765
|
);
|
|
4646
4766
|
if (props.length > 0) {
|
|
4647
4767
|
const propsBuildResult = buildProps(
|
|
@@ -4701,25 +4821,15 @@ const transformElement = (node, context) => {
|
|
|
4701
4821
|
vnodeChildren = node.children;
|
|
4702
4822
|
}
|
|
4703
4823
|
}
|
|
4704
|
-
if (
|
|
4705
|
-
|
|
4706
|
-
if (patchFlag < 0) {
|
|
4707
|
-
vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
|
|
4708
|
-
} else {
|
|
4709
|
-
const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
|
|
4710
|
-
vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
|
|
4711
|
-
}
|
|
4712
|
-
}
|
|
4713
|
-
if (dynamicPropNames && dynamicPropNames.length) {
|
|
4714
|
-
vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
|
4715
|
-
}
|
|
4824
|
+
if (dynamicPropNames && dynamicPropNames.length) {
|
|
4825
|
+
vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
|
4716
4826
|
}
|
|
4717
4827
|
node.codegenNode = createVNodeCall(
|
|
4718
4828
|
context,
|
|
4719
4829
|
vnodeTag,
|
|
4720
4830
|
vnodeProps,
|
|
4721
4831
|
vnodeChildren,
|
|
4722
|
-
|
|
4832
|
+
patchFlag === 0 ? void 0 : patchFlag,
|
|
4723
4833
|
vnodeDynamicProps,
|
|
4724
4834
|
vnodeDirectives,
|
|
4725
4835
|
!!shouldUseBlock,
|
|
@@ -4764,8 +4874,7 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
4764
4874
|
}
|
|
4765
4875
|
const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
|
|
4766
4876
|
if (builtIn) {
|
|
4767
|
-
if (!ssr)
|
|
4768
|
-
context.helper(builtIn);
|
|
4877
|
+
if (!ssr) context.helper(builtIn);
|
|
4769
4878
|
return builtIn;
|
|
4770
4879
|
}
|
|
4771
4880
|
context.helper(RESOLVE_COMPONENT);
|
|
@@ -4794,8 +4903,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4794
4903
|
);
|
|
4795
4904
|
properties = [];
|
|
4796
4905
|
}
|
|
4797
|
-
if (arg)
|
|
4798
|
-
mergeArgs.push(arg);
|
|
4906
|
+
if (arg) mergeArgs.push(arg);
|
|
4799
4907
|
};
|
|
4800
4908
|
const pushRefVForMarker = () => {
|
|
4801
4909
|
if (context.scopes.vFor > 0) {
|
|
@@ -5132,8 +5240,7 @@ function buildDirectiveArgs(dir, context) {
|
|
|
5132
5240
|
}
|
|
5133
5241
|
}
|
|
5134
5242
|
const { loc } = dir;
|
|
5135
|
-
if (dir.exp)
|
|
5136
|
-
dirArgs.push(dir.exp);
|
|
5243
|
+
if (dir.exp) dirArgs.push(dir.exp);
|
|
5137
5244
|
if (dir.arg) {
|
|
5138
5245
|
if (!dir.exp) {
|
|
5139
5246
|
dirArgs.push(`void 0`);
|
|
@@ -5163,8 +5270,7 @@ function stringifyDynamicPropNames(props) {
|
|
|
5163
5270
|
let propsNamesString = `[`;
|
|
5164
5271
|
for (let i = 0, l = props.length; i < l; i++) {
|
|
5165
5272
|
propsNamesString += JSON.stringify(props[i]);
|
|
5166
|
-
if (i < l - 1)
|
|
5167
|
-
propsNamesString += ", ";
|
|
5273
|
+
if (i < l - 1) propsNamesString += ", ";
|
|
5168
5274
|
}
|
|
5169
5275
|
return propsNamesString + `]`;
|
|
5170
5276
|
}
|
|
@@ -5258,7 +5364,7 @@ function processSlotOutlet(node, context) {
|
|
|
5258
5364
|
};
|
|
5259
5365
|
}
|
|
5260
5366
|
|
|
5261
|
-
const fnExpRE = /^\s*(
|
|
5367
|
+
const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
5262
5368
|
const transformOn$1 = (dir, node, context, augmentor) => {
|
|
5263
5369
|
const { loc, modifiers, arg } = dir;
|
|
5264
5370
|
if (!dir.exp && !modifiers.length) {
|
|
@@ -5339,75 +5445,6 @@ const transformOn$1 = (dir, node, context, augmentor) => {
|
|
|
5339
5445
|
return ret;
|
|
5340
5446
|
};
|
|
5341
5447
|
|
|
5342
|
-
const transformBind = (dir, _node, context) => {
|
|
5343
|
-
const { modifiers, loc } = dir;
|
|
5344
|
-
const arg = dir.arg;
|
|
5345
|
-
let { exp } = dir;
|
|
5346
|
-
if (exp && exp.type === 4 && !exp.content.trim()) {
|
|
5347
|
-
{
|
|
5348
|
-
exp = void 0;
|
|
5349
|
-
}
|
|
5350
|
-
}
|
|
5351
|
-
if (!exp) {
|
|
5352
|
-
if (arg.type !== 4 || !arg.isStatic) {
|
|
5353
|
-
context.onError(
|
|
5354
|
-
createCompilerError(
|
|
5355
|
-
52,
|
|
5356
|
-
arg.loc
|
|
5357
|
-
)
|
|
5358
|
-
);
|
|
5359
|
-
return {
|
|
5360
|
-
props: [
|
|
5361
|
-
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
5362
|
-
]
|
|
5363
|
-
};
|
|
5364
|
-
}
|
|
5365
|
-
const propName = camelize(arg.content);
|
|
5366
|
-
exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
|
|
5367
|
-
}
|
|
5368
|
-
if (arg.type !== 4) {
|
|
5369
|
-
arg.children.unshift(`(`);
|
|
5370
|
-
arg.children.push(`) || ""`);
|
|
5371
|
-
} else if (!arg.isStatic) {
|
|
5372
|
-
arg.content = `${arg.content} || ""`;
|
|
5373
|
-
}
|
|
5374
|
-
if (modifiers.includes("camel")) {
|
|
5375
|
-
if (arg.type === 4) {
|
|
5376
|
-
if (arg.isStatic) {
|
|
5377
|
-
arg.content = camelize(arg.content);
|
|
5378
|
-
} else {
|
|
5379
|
-
arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
|
5380
|
-
}
|
|
5381
|
-
} else {
|
|
5382
|
-
arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
|
5383
|
-
arg.children.push(`)`);
|
|
5384
|
-
}
|
|
5385
|
-
}
|
|
5386
|
-
if (!context.inSSR) {
|
|
5387
|
-
if (modifiers.includes("prop")) {
|
|
5388
|
-
injectPrefix(arg, ".");
|
|
5389
|
-
}
|
|
5390
|
-
if (modifiers.includes("attr")) {
|
|
5391
|
-
injectPrefix(arg, "^");
|
|
5392
|
-
}
|
|
5393
|
-
}
|
|
5394
|
-
return {
|
|
5395
|
-
props: [createObjectProperty(arg, exp)]
|
|
5396
|
-
};
|
|
5397
|
-
};
|
|
5398
|
-
const injectPrefix = (arg, prefix) => {
|
|
5399
|
-
if (arg.type === 4) {
|
|
5400
|
-
if (arg.isStatic) {
|
|
5401
|
-
arg.content = prefix + arg.content;
|
|
5402
|
-
} else {
|
|
5403
|
-
arg.content = `\`${prefix}\${${arg.content}}\``;
|
|
5404
|
-
}
|
|
5405
|
-
} else {
|
|
5406
|
-
arg.children.unshift(`'${prefix}' + (`);
|
|
5407
|
-
arg.children.push(`)`);
|
|
5408
|
-
}
|
|
5409
|
-
};
|
|
5410
|
-
|
|
5411
5448
|
const transformText = (node, context) => {
|
|
5412
5449
|
if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
|
|
5413
5450
|
return () => {
|
|
@@ -5571,8 +5608,7 @@ const transformFilter = (node, context) => {
|
|
|
5571
5608
|
}
|
|
5572
5609
|
if (node.type === 5) {
|
|
5573
5610
|
rewriteFilter(node.content, context);
|
|
5574
|
-
}
|
|
5575
|
-
if (node.type === 1) {
|
|
5611
|
+
} else if (node.type === 1) {
|
|
5576
5612
|
node.props.forEach((prop) => {
|
|
5577
5613
|
if (prop.type === 7 && prop.name !== "for" && prop.exp) {
|
|
5578
5614
|
rewriteFilter(prop.exp, context);
|
|
@@ -5586,8 +5622,7 @@ function rewriteFilter(node, context) {
|
|
|
5586
5622
|
} else {
|
|
5587
5623
|
for (let i = 0; i < node.children.length; i++) {
|
|
5588
5624
|
const child = node.children[i];
|
|
5589
|
-
if (typeof child !== "object")
|
|
5590
|
-
continue;
|
|
5625
|
+
if (typeof child !== "object") continue;
|
|
5591
5626
|
if (child.type === 4) {
|
|
5592
5627
|
parseFilter(child, context);
|
|
5593
5628
|
} else if (child.type === 8) {
|
|
@@ -5613,17 +5648,13 @@ function parseFilter(node, context) {
|
|
|
5613
5648
|
prev = c;
|
|
5614
5649
|
c = exp.charCodeAt(i);
|
|
5615
5650
|
if (inSingle) {
|
|
5616
|
-
if (c === 39 && prev !== 92)
|
|
5617
|
-
inSingle = false;
|
|
5651
|
+
if (c === 39 && prev !== 92) inSingle = false;
|
|
5618
5652
|
} else if (inDouble) {
|
|
5619
|
-
if (c === 34 && prev !== 92)
|
|
5620
|
-
inDouble = false;
|
|
5653
|
+
if (c === 34 && prev !== 92) inDouble = false;
|
|
5621
5654
|
} else if (inTemplateString) {
|
|
5622
|
-
if (c === 96 && prev !== 92)
|
|
5623
|
-
inTemplateString = false;
|
|
5655
|
+
if (c === 96 && prev !== 92) inTemplateString = false;
|
|
5624
5656
|
} else if (inRegex) {
|
|
5625
|
-
if (c === 47 && prev !== 92)
|
|
5626
|
-
inRegex = false;
|
|
5657
|
+
if (c === 47 && prev !== 92) inRegex = false;
|
|
5627
5658
|
} else if (c === 124 && // pipe
|
|
5628
5659
|
exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
|
|
5629
5660
|
if (expression === void 0) {
|
|
@@ -5667,8 +5698,7 @@ function parseFilter(node, context) {
|
|
|
5667
5698
|
let p;
|
|
5668
5699
|
for (; j >= 0; j--) {
|
|
5669
5700
|
p = exp.charAt(j);
|
|
5670
|
-
if (p !== " ")
|
|
5671
|
-
break;
|
|
5701
|
+
if (p !== " ") break;
|
|
5672
5702
|
}
|
|
5673
5703
|
if (!p || !validDivisionCharRE.test(p)) {
|
|
5674
5704
|
inRegex = true;
|
|
@@ -5695,6 +5725,7 @@ function parseFilter(node, context) {
|
|
|
5695
5725
|
expression = wrapFilter(expression, filters[i], context);
|
|
5696
5726
|
}
|
|
5697
5727
|
node.content = expression;
|
|
5728
|
+
node.ast = void 0;
|
|
5698
5729
|
}
|
|
5699
5730
|
}
|
|
5700
5731
|
function wrapFilter(exp, filter, context) {
|
|
@@ -5729,8 +5760,9 @@ const transformMemo = (node, context) => {
|
|
|
5729
5760
|
dir.exp,
|
|
5730
5761
|
createFunctionExpression(void 0, codegenNode),
|
|
5731
5762
|
`_cache`,
|
|
5732
|
-
String(context.cached
|
|
5763
|
+
String(context.cached.length)
|
|
5733
5764
|
]);
|
|
5765
|
+
context.cached.push(null);
|
|
5734
5766
|
}
|
|
5735
5767
|
};
|
|
5736
5768
|
}
|
|
@@ -6166,8 +6198,7 @@ const transformClick = (key, event) => {
|
|
|
6166
6198
|
const transformOn = (dir, node, context) => {
|
|
6167
6199
|
return transformOn$1(dir, node, context, (baseResult) => {
|
|
6168
6200
|
const { modifiers } = dir;
|
|
6169
|
-
if (!modifiers.length)
|
|
6170
|
-
return baseResult;
|
|
6201
|
+
if (!modifiers.length) return baseResult;
|
|
6171
6202
|
let { key, value: handlerExp } = baseResult.props[0];
|
|
6172
6203
|
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
|
|
6173
6204
|
if (nonKeyModifiers.includes("right")) {
|
|
@@ -6278,12 +6309,10 @@ function isValidHTMLNesting(parent, child) {
|
|
|
6278
6309
|
return onlyValidParents[child].has(parent);
|
|
6279
6310
|
}
|
|
6280
6311
|
if (parent in knownInvalidChildren) {
|
|
6281
|
-
if (knownInvalidChildren[parent].has(child))
|
|
6282
|
-
return false;
|
|
6312
|
+
if (knownInvalidChildren[parent].has(child)) return false;
|
|
6283
6313
|
}
|
|
6284
6314
|
if (child in knownInvalidParents) {
|
|
6285
|
-
if (knownInvalidParents[child].has(parent))
|
|
6286
|
-
return false;
|
|
6315
|
+
if (knownInvalidParents[child].has(parent)) return false;
|
|
6287
6316
|
}
|
|
6288
6317
|
return true;
|
|
6289
6318
|
}
|