@vue/compiler-dom 3.5.0-alpha.1 → 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-dom.cjs.js +36 -24
- package/dist/compiler-dom.cjs.prod.js +34 -20
- package/dist/compiler-dom.esm-browser.js +258 -233
- 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 +258 -233
- 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.3
|
|
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",
|
|
@@ -2085,11 +2084,10 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2085
2084
|
}
|
|
2086
2085
|
},
|
|
2087
2086
|
onselfclosingtag(end) {
|
|
2088
|
-
var _a;
|
|
2089
2087
|
const name = currentOpenTag.tag;
|
|
2090
2088
|
currentOpenTag.isSelfClosing = true;
|
|
2091
2089
|
endOpenTag(end);
|
|
2092
|
-
if (
|
|
2090
|
+
if (stack[0] && stack[0].tag === name) {
|
|
2093
2091
|
onCloseTag(stack.shift(), end);
|
|
2094
2092
|
}
|
|
2095
2093
|
},
|
|
@@ -2139,8 +2137,7 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2139
2137
|
}
|
|
2140
2138
|
},
|
|
2141
2139
|
ondirarg(start, end) {
|
|
2142
|
-
if (start === end)
|
|
2143
|
-
return;
|
|
2140
|
+
if (start === end) return;
|
|
2144
2141
|
const arg = getSlice(start, end);
|
|
2145
2142
|
if (inVPre) {
|
|
2146
2143
|
currentProp.name += arg;
|
|
@@ -2172,14 +2169,12 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2172
2169
|
},
|
|
2173
2170
|
onattribdata(start, end) {
|
|
2174
2171
|
currentAttrValue += getSlice(start, end);
|
|
2175
|
-
if (currentAttrStartIndex < 0)
|
|
2176
|
-
currentAttrStartIndex = start;
|
|
2172
|
+
if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
|
2177
2173
|
currentAttrEndIndex = end;
|
|
2178
2174
|
},
|
|
2179
2175
|
onattribentity(char, start, end) {
|
|
2180
2176
|
currentAttrValue += char;
|
|
2181
|
-
if (currentAttrStartIndex < 0)
|
|
2182
|
-
currentAttrStartIndex = start;
|
|
2177
|
+
if (currentAttrStartIndex < 0) currentAttrStartIndex = start;
|
|
2183
2178
|
currentAttrEndIndex = end;
|
|
2184
2179
|
},
|
|
2185
2180
|
onattribnameend(end) {
|
|
@@ -2326,8 +2321,7 @@ function parseForExpression(input) {
|
|
|
2326
2321
|
const loc = input.loc;
|
|
2327
2322
|
const exp = input.content;
|
|
2328
2323
|
const inMatch = exp.match(forAliasRE);
|
|
2329
|
-
if (!inMatch)
|
|
2330
|
-
return;
|
|
2324
|
+
if (!inMatch) return;
|
|
2331
2325
|
const [, LHS, RHS] = inMatch;
|
|
2332
2326
|
const createAliasExpression = (content, offset, asParam = false) => {
|
|
2333
2327
|
const start = loc.start.offset + offset;
|
|
@@ -2400,16 +2394,15 @@ function endOpenTag(end) {
|
|
|
2400
2394
|
currentOpenTag = null;
|
|
2401
2395
|
}
|
|
2402
2396
|
function onText(content, start, end) {
|
|
2403
|
-
var _a;
|
|
2404
2397
|
{
|
|
2405
|
-
const tag =
|
|
2398
|
+
const tag = stack[0] && stack[0].tag;
|
|
2406
2399
|
if (tag !== "script" && tag !== "style" && content.includes("&")) {
|
|
2407
2400
|
content = currentOptions.decodeEntities(content, false);
|
|
2408
2401
|
}
|
|
2409
2402
|
}
|
|
2410
2403
|
const parent = stack[0] || currentRoot;
|
|
2411
2404
|
const lastNode = parent.children[parent.children.length - 1];
|
|
2412
|
-
if (
|
|
2405
|
+
if (lastNode && lastNode.type === 2) {
|
|
2413
2406
|
lastNode.content += content;
|
|
2414
2407
|
setLocEnd(lastNode.loc, end);
|
|
2415
2408
|
} else {
|
|
@@ -2521,14 +2514,12 @@ function onCloseTag(el, end, isImplied = false) {
|
|
|
2521
2514
|
}
|
|
2522
2515
|
function lookAhead(index, c) {
|
|
2523
2516
|
let i = index;
|
|
2524
|
-
while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1)
|
|
2525
|
-
i++;
|
|
2517
|
+
while (currentInput.charCodeAt(i) !== c && i < currentInput.length - 1) i++;
|
|
2526
2518
|
return i;
|
|
2527
2519
|
}
|
|
2528
2520
|
function backTrack(index, c) {
|
|
2529
2521
|
let i = index;
|
|
2530
|
-
while (currentInput.charCodeAt(i) !== c && i >= 0)
|
|
2531
|
-
i--;
|
|
2522
|
+
while (currentInput.charCodeAt(i) !== c && i >= 0) i--;
|
|
2532
2523
|
return i;
|
|
2533
2524
|
}
|
|
2534
2525
|
const specialTemplateDir = /* @__PURE__ */ new Set(["if", "else", "else-if", "for", "slot"]);
|
|
@@ -2543,11 +2534,10 @@ function isFragmentTemplate({ tag, props }) {
|
|
|
2543
2534
|
return false;
|
|
2544
2535
|
}
|
|
2545
2536
|
function isComponent({ tag, props }) {
|
|
2546
|
-
var _a;
|
|
2547
2537
|
if (currentOptions.isCustomElement(tag)) {
|
|
2548
2538
|
return false;
|
|
2549
2539
|
}
|
|
2550
|
-
if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) ||
|
|
2540
|
+
if (tag === "component" || isUpperCase(tag.charCodeAt(0)) || isCoreComponent(tag) || currentOptions.isBuiltInComponent && currentOptions.isBuiltInComponent(tag) || currentOptions.isNativeTag && !currentOptions.isNativeTag(tag)) {
|
|
2551
2541
|
return true;
|
|
2552
2542
|
}
|
|
2553
2543
|
for (let i = 0; i < props.length; i++) {
|
|
@@ -2580,7 +2570,6 @@ function isUpperCase(c) {
|
|
|
2580
2570
|
}
|
|
2581
2571
|
const windowsNewlineRE = /\r\n/g;
|
|
2582
2572
|
function condenseWhitespace(nodes, tag) {
|
|
2583
|
-
var _a, _b;
|
|
2584
2573
|
const shouldCondense = currentOptions.whitespace !== "preserve";
|
|
2585
2574
|
let removedWhitespace = false;
|
|
2586
2575
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -2588,8 +2577,8 @@ function condenseWhitespace(nodes, tag) {
|
|
|
2588
2577
|
if (node.type === 2) {
|
|
2589
2578
|
if (!inPre) {
|
|
2590
2579
|
if (isAllWhitespace(node.content)) {
|
|
2591
|
-
const prev =
|
|
2592
|
-
const next =
|
|
2580
|
+
const prev = nodes[i - 1] && nodes[i - 1].type;
|
|
2581
|
+
const next = nodes[i + 1] && nodes[i + 1].type;
|
|
2593
2582
|
if (!prev || !next || shouldCondense && (prev === 3 && (next === 3 || next === 1) || prev === 1 && (next === 3 || next === 1 && hasNewlineChar(node.content)))) {
|
|
2594
2583
|
removedWhitespace = true;
|
|
2595
2584
|
nodes[i] = null;
|
|
@@ -2727,7 +2716,7 @@ function baseParse(input, options) {
|
|
|
2727
2716
|
}
|
|
2728
2717
|
tokenizer.mode = currentOptions.parseMode === "html" ? 1 : currentOptions.parseMode === "sfc" ? 2 : 0;
|
|
2729
2718
|
tokenizer.inXML = currentOptions.ns === 1 || currentOptions.ns === 2;
|
|
2730
|
-
const delimiters = options
|
|
2719
|
+
const delimiters = options && options.delimiters;
|
|
2731
2720
|
if (delimiters) {
|
|
2732
2721
|
tokenizer.delimiterOpen = toCharCodes(delimiters[0]);
|
|
2733
2722
|
tokenizer.delimiterClose = toCharCodes(delimiters[1]);
|
|
@@ -2740,9 +2729,10 @@ function baseParse(input, options) {
|
|
|
2740
2729
|
return root;
|
|
2741
2730
|
}
|
|
2742
2731
|
|
|
2743
|
-
function
|
|
2732
|
+
function cacheStatic(root, context) {
|
|
2744
2733
|
walk(
|
|
2745
2734
|
root,
|
|
2735
|
+
void 0,
|
|
2746
2736
|
context,
|
|
2747
2737
|
// Root node is unfortunately non-hoistable due to potential parent
|
|
2748
2738
|
// fallthrough attributes.
|
|
@@ -2753,26 +2743,24 @@ function isSingleElementRoot(root, child) {
|
|
|
2753
2743
|
const { children } = root;
|
|
2754
2744
|
return children.length === 1 && child.type === 1 && !isSlotOutlet(child);
|
|
2755
2745
|
}
|
|
2756
|
-
function walk(node, context, doNotHoistNode = false) {
|
|
2746
|
+
function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
2757
2747
|
const { children } = node;
|
|
2758
|
-
const
|
|
2759
|
-
let hoistedCount = 0;
|
|
2748
|
+
const toCache = [];
|
|
2760
2749
|
for (let i = 0; i < children.length; i++) {
|
|
2761
2750
|
const child = children[i];
|
|
2762
2751
|
if (child.type === 1 && child.tagType === 0) {
|
|
2763
2752
|
const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
|
2764
2753
|
if (constantType > 0) {
|
|
2765
2754
|
if (constantType >= 2) {
|
|
2766
|
-
child.codegenNode.patchFlag = -1
|
|
2767
|
-
|
|
2768
|
-
hoistedCount++;
|
|
2755
|
+
child.codegenNode.patchFlag = -1;
|
|
2756
|
+
toCache.push(child);
|
|
2769
2757
|
continue;
|
|
2770
2758
|
}
|
|
2771
2759
|
} else {
|
|
2772
2760
|
const codegenNode = child.codegenNode;
|
|
2773
2761
|
if (codegenNode.type === 13) {
|
|
2774
|
-
const flag =
|
|
2775
|
-
if ((
|
|
2762
|
+
const flag = codegenNode.patchFlag;
|
|
2763
|
+
if ((flag === void 0 || flag === 512 || flag === 1) && getGeneratedPropsConstantType(child, context) >= 2) {
|
|
2776
2764
|
const props = getNodeProps(child);
|
|
2777
2765
|
if (props) {
|
|
2778
2766
|
codegenNode.props = context.hoist(props);
|
|
@@ -2783,39 +2771,84 @@ function walk(node, context, doNotHoistNode = false) {
|
|
|
2783
2771
|
}
|
|
2784
2772
|
}
|
|
2785
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
|
+
}
|
|
2786
2780
|
}
|
|
2787
2781
|
if (child.type === 1) {
|
|
2788
2782
|
const isComponent = child.tagType === 1;
|
|
2789
2783
|
if (isComponent) {
|
|
2790
2784
|
context.scopes.vSlot++;
|
|
2791
2785
|
}
|
|
2792
|
-
walk(child, context);
|
|
2786
|
+
walk(child, node, context, false, inFor);
|
|
2793
2787
|
if (isComponent) {
|
|
2794
2788
|
context.scopes.vSlot--;
|
|
2795
2789
|
}
|
|
2796
2790
|
} else if (child.type === 11) {
|
|
2797
|
-
walk(child, context, child.children.length === 1);
|
|
2791
|
+
walk(child, node, context, child.children.length === 1, true);
|
|
2798
2792
|
} else if (child.type === 9) {
|
|
2799
2793
|
for (let i2 = 0; i2 < child.branches.length; i2++) {
|
|
2800
2794
|
walk(
|
|
2801
2795
|
child.branches[i2],
|
|
2796
|
+
node,
|
|
2802
2797
|
context,
|
|
2803
|
-
child.branches[i2].children.length === 1
|
|
2798
|
+
child.branches[i2].children.length === 1,
|
|
2799
|
+
inFor
|
|
2804
2800
|
);
|
|
2805
2801
|
}
|
|
2806
2802
|
}
|
|
2807
2803
|
}
|
|
2808
|
-
|
|
2809
|
-
|
|
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
|
+
}
|
|
2810
2829
|
}
|
|
2811
|
-
if (
|
|
2812
|
-
const
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
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;
|
|
2817
2848
|
}
|
|
2818
|
-
|
|
2849
|
+
}
|
|
2850
|
+
if (toCache.length && context.transformHoist) {
|
|
2851
|
+
context.transformHoist(children, context, node);
|
|
2819
2852
|
}
|
|
2820
2853
|
}
|
|
2821
2854
|
function getConstantType(node, context) {
|
|
@@ -2833,11 +2866,10 @@ function getConstantType(node, context) {
|
|
|
2833
2866
|
if (codegenNode.type !== 13) {
|
|
2834
2867
|
return 0;
|
|
2835
2868
|
}
|
|
2836
|
-
if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject") {
|
|
2869
|
+
if (codegenNode.isBlock && node.tag !== "svg" && node.tag !== "foreignObject" && node.tag !== "math") {
|
|
2837
2870
|
return 0;
|
|
2838
2871
|
}
|
|
2839
|
-
|
|
2840
|
-
if (!flag) {
|
|
2872
|
+
if (codegenNode.patchFlag === void 0) {
|
|
2841
2873
|
let returnType2 = 3;
|
|
2842
2874
|
const generatedPropsType = getGeneratedPropsConstantType(node, context);
|
|
2843
2875
|
if (generatedPropsType === 0) {
|
|
@@ -2920,6 +2952,8 @@ function getConstantType(node, context) {
|
|
|
2920
2952
|
}
|
|
2921
2953
|
}
|
|
2922
2954
|
return returnType;
|
|
2955
|
+
case 20:
|
|
2956
|
+
return 2;
|
|
2923
2957
|
default:
|
|
2924
2958
|
return 0;
|
|
2925
2959
|
}
|
|
@@ -2979,15 +3013,11 @@ function getNodeProps(node) {
|
|
|
2979
3013
|
return codegenNode.props;
|
|
2980
3014
|
}
|
|
2981
3015
|
}
|
|
2982
|
-
function getPatchFlag(node) {
|
|
2983
|
-
const flag = node.patchFlag;
|
|
2984
|
-
return flag ? parseInt(flag, 10) : void 0;
|
|
2985
|
-
}
|
|
2986
3016
|
|
|
2987
3017
|
function createTransformContext(root, {
|
|
2988
3018
|
filename = "",
|
|
2989
3019
|
prefixIdentifiers = false,
|
|
2990
|
-
hoistStatic
|
|
3020
|
+
hoistStatic = false,
|
|
2991
3021
|
hmr = false,
|
|
2992
3022
|
cacheHandlers = false,
|
|
2993
3023
|
nodeTransforms = [],
|
|
@@ -3014,7 +3044,7 @@ function createTransformContext(root, {
|
|
|
3014
3044
|
filename,
|
|
3015
3045
|
selfName: nameMatch && capitalize(camelize(nameMatch[1])),
|
|
3016
3046
|
prefixIdentifiers,
|
|
3017
|
-
hoistStatic
|
|
3047
|
+
hoistStatic,
|
|
3018
3048
|
hmr,
|
|
3019
3049
|
cacheHandlers,
|
|
3020
3050
|
nodeTransforms,
|
|
@@ -3041,9 +3071,9 @@ function createTransformContext(root, {
|
|
|
3041
3071
|
directives: /* @__PURE__ */ new Set(),
|
|
3042
3072
|
hoists: [],
|
|
3043
3073
|
imports: [],
|
|
3074
|
+
cached: [],
|
|
3044
3075
|
constantCache: /* @__PURE__ */ new WeakMap(),
|
|
3045
3076
|
temps: 0,
|
|
3046
|
-
cached: 0,
|
|
3047
3077
|
identifiers: /* @__PURE__ */ Object.create(null),
|
|
3048
3078
|
scopes: {
|
|
3049
3079
|
vFor: 0,
|
|
@@ -3113,8 +3143,7 @@ function createTransformContext(root, {
|
|
|
3113
3143
|
removeIdentifiers(exp) {
|
|
3114
3144
|
},
|
|
3115
3145
|
hoist(exp) {
|
|
3116
|
-
if (isString(exp))
|
|
3117
|
-
exp = createSimpleExpression(exp);
|
|
3146
|
+
if (isString(exp)) exp = createSimpleExpression(exp);
|
|
3118
3147
|
context.hoists.push(exp);
|
|
3119
3148
|
const identifier = createSimpleExpression(
|
|
3120
3149
|
`_hoisted_${context.hoists.length}`,
|
|
@@ -3126,7 +3155,13 @@ function createTransformContext(root, {
|
|
|
3126
3155
|
return identifier;
|
|
3127
3156
|
},
|
|
3128
3157
|
cache(exp, isVNode = false) {
|
|
3129
|
-
|
|
3158
|
+
const cacheExp = createCacheExpression(
|
|
3159
|
+
context.cached.length,
|
|
3160
|
+
exp,
|
|
3161
|
+
isVNode
|
|
3162
|
+
);
|
|
3163
|
+
context.cached.push(cacheExp);
|
|
3164
|
+
return cacheExp;
|
|
3130
3165
|
}
|
|
3131
3166
|
};
|
|
3132
3167
|
{
|
|
@@ -3138,7 +3173,7 @@ function transform(root, options) {
|
|
|
3138
3173
|
const context = createTransformContext(root, options);
|
|
3139
3174
|
traverseNode(root, context);
|
|
3140
3175
|
if (options.hoistStatic) {
|
|
3141
|
-
|
|
3176
|
+
cacheStatic(root, context);
|
|
3142
3177
|
}
|
|
3143
3178
|
if (!options.ssr) {
|
|
3144
3179
|
createRootCodegen(root, context);
|
|
@@ -3181,7 +3216,7 @@ function createRootCodegen(root, context) {
|
|
|
3181
3216
|
helper(FRAGMENT),
|
|
3182
3217
|
void 0,
|
|
3183
3218
|
root.children,
|
|
3184
|
-
patchFlag
|
|
3219
|
+
patchFlag,
|
|
3185
3220
|
void 0,
|
|
3186
3221
|
void 0,
|
|
3187
3222
|
true,
|
|
@@ -3197,8 +3232,7 @@ function traverseChildren(parent, context) {
|
|
|
3197
3232
|
};
|
|
3198
3233
|
for (; i < parent.children.length; i++) {
|
|
3199
3234
|
const child = parent.children[i];
|
|
3200
|
-
if (isString(child))
|
|
3201
|
-
continue;
|
|
3235
|
+
if (isString(child)) continue;
|
|
3202
3236
|
context.grandParent = context.parent;
|
|
3203
3237
|
context.parent = parent;
|
|
3204
3238
|
context.childIndex = i;
|
|
@@ -3269,8 +3303,7 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
|
3269
3303
|
props.splice(i, 1);
|
|
3270
3304
|
i--;
|
|
3271
3305
|
const onExit = fn(node, prop, context);
|
|
3272
|
-
if (onExit)
|
|
3273
|
-
exitFns.push(onExit);
|
|
3306
|
+
if (onExit) exitFns.push(onExit);
|
|
3274
3307
|
}
|
|
3275
3308
|
}
|
|
3276
3309
|
return exitFns;
|
|
@@ -3342,8 +3375,7 @@ function createCodegenContext(ast, {
|
|
|
3342
3375
|
}
|
|
3343
3376
|
function generate(ast, options = {}) {
|
|
3344
3377
|
const context = createCodegenContext(ast, options);
|
|
3345
|
-
if (options.onContextCreated)
|
|
3346
|
-
options.onContextCreated(context);
|
|
3378
|
+
if (options.onContextCreated) options.onContextCreated(context);
|
|
3347
3379
|
const {
|
|
3348
3380
|
mode,
|
|
3349
3381
|
push,
|
|
@@ -3485,14 +3517,12 @@ function genHoists(hoists, context) {
|
|
|
3485
3517
|
return;
|
|
3486
3518
|
}
|
|
3487
3519
|
context.pure = true;
|
|
3488
|
-
const { push, newline
|
|
3520
|
+
const { push, newline } = context;
|
|
3489
3521
|
newline();
|
|
3490
3522
|
for (let i = 0; i < hoists.length; i++) {
|
|
3491
3523
|
const exp = hoists[i];
|
|
3492
3524
|
if (exp) {
|
|
3493
|
-
push(
|
|
3494
|
-
`const _hoisted_${i + 1} = ${``}`
|
|
3495
|
-
);
|
|
3525
|
+
push(`const _hoisted_${i + 1} = `);
|
|
3496
3526
|
genNode(exp, context);
|
|
3497
3527
|
newline();
|
|
3498
3528
|
}
|
|
@@ -3625,8 +3655,7 @@ function genExpression(node, context) {
|
|
|
3625
3655
|
}
|
|
3626
3656
|
function genInterpolation(node, context) {
|
|
3627
3657
|
const { push, helper, pure } = context;
|
|
3628
|
-
if (pure)
|
|
3629
|
-
push(PURE_ANNOTATION);
|
|
3658
|
+
if (pure) push(PURE_ANNOTATION);
|
|
3630
3659
|
push(`${helper(TO_DISPLAY_STRING)}(`);
|
|
3631
3660
|
genNode(node.content, context);
|
|
3632
3661
|
push(`)`);
|
|
@@ -3678,6 +3707,17 @@ function genVNodeCall(node, context) {
|
|
|
3678
3707
|
disableTracking,
|
|
3679
3708
|
isComponent
|
|
3680
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
|
+
}
|
|
3681
3721
|
if (directives) {
|
|
3682
3722
|
push(helper(WITH_DIRECTIVES) + `(`);
|
|
3683
3723
|
}
|
|
@@ -3690,7 +3730,7 @@ function genVNodeCall(node, context) {
|
|
|
3690
3730
|
const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
|
|
3691
3731
|
push(helper(callHelper) + `(`, -2 /* None */, node);
|
|
3692
3732
|
genNodeList(
|
|
3693
|
-
genNullableArgs([tag, props, children,
|
|
3733
|
+
genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
|
|
3694
3734
|
context
|
|
3695
3735
|
);
|
|
3696
3736
|
push(`)`);
|
|
@@ -3706,8 +3746,7 @@ function genVNodeCall(node, context) {
|
|
|
3706
3746
|
function genNullableArgs(args) {
|
|
3707
3747
|
let i = args.length;
|
|
3708
3748
|
while (i--) {
|
|
3709
|
-
if (args[i] != null)
|
|
3710
|
-
break;
|
|
3749
|
+
if (args[i] != null) break;
|
|
3711
3750
|
}
|
|
3712
3751
|
return args.slice(0, i + 1).map((arg) => arg || `null`);
|
|
3713
3752
|
}
|
|
@@ -3824,16 +3863,21 @@ function genConditionalExpression(node, context) {
|
|
|
3824
3863
|
}
|
|
3825
3864
|
function genCacheExpression(node, context) {
|
|
3826
3865
|
const { push, helper, indent, deindent, newline } = context;
|
|
3866
|
+
const { needPauseTracking, needArraySpread } = node;
|
|
3867
|
+
if (needArraySpread) {
|
|
3868
|
+
push(`[...(`);
|
|
3869
|
+
}
|
|
3827
3870
|
push(`_cache[${node.index}] || (`);
|
|
3828
|
-
if (
|
|
3871
|
+
if (needPauseTracking) {
|
|
3829
3872
|
indent();
|
|
3830
3873
|
push(`${helper(SET_BLOCK_TRACKING)}(-1),`);
|
|
3831
3874
|
newline();
|
|
3875
|
+
push(`(`);
|
|
3832
3876
|
}
|
|
3833
3877
|
push(`_cache[${node.index}] = `);
|
|
3834
3878
|
genNode(node.value, context);
|
|
3835
|
-
if (
|
|
3836
|
-
push(
|
|
3879
|
+
if (needPauseTracking) {
|
|
3880
|
+
push(`).cacheIndex = ${node.index},`);
|
|
3837
3881
|
newline();
|
|
3838
3882
|
push(`${helper(SET_BLOCK_TRACKING)}(1),`);
|
|
3839
3883
|
newline();
|
|
@@ -3841,6 +3885,9 @@ function genCacheExpression(node, context) {
|
|
|
3841
3885
|
deindent();
|
|
3842
3886
|
}
|
|
3843
3887
|
push(`)`);
|
|
3888
|
+
if (needArraySpread) {
|
|
3889
|
+
push(`)]`);
|
|
3890
|
+
}
|
|
3844
3891
|
}
|
|
3845
3892
|
|
|
3846
3893
|
const prohibitedKeywordRE = new RegExp(
|
|
@@ -4017,8 +4064,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
4017
4064
|
sibling.branches.push(branch);
|
|
4018
4065
|
const onExit = processCodegen && processCodegen(sibling, branch, false);
|
|
4019
4066
|
traverseNode(branch, context);
|
|
4020
|
-
if (onExit)
|
|
4021
|
-
onExit();
|
|
4067
|
+
if (onExit) onExit();
|
|
4022
4068
|
context.currentNode = null;
|
|
4023
4069
|
} else {
|
|
4024
4070
|
context.onError(
|
|
@@ -4087,7 +4133,7 @@ function createChildrenCodegenNode(branch, keyIndex, context) {
|
|
|
4087
4133
|
helper(FRAGMENT),
|
|
4088
4134
|
createObjectExpression([keyProperty]),
|
|
4089
4135
|
children,
|
|
4090
|
-
patchFlag
|
|
4136
|
+
patchFlag,
|
|
4091
4137
|
void 0,
|
|
4092
4138
|
void 0,
|
|
4093
4139
|
true,
|
|
@@ -4140,6 +4186,80 @@ function getParentCondition(node) {
|
|
|
4140
4186
|
}
|
|
4141
4187
|
}
|
|
4142
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
|
+
|
|
4143
4263
|
const transformFor = createStructuralDirectiveTransform(
|
|
4144
4264
|
"for",
|
|
4145
4265
|
(node, dir, context) => {
|
|
@@ -4150,9 +4270,12 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4150
4270
|
]);
|
|
4151
4271
|
const isTemplate = isTemplateNode(node);
|
|
4152
4272
|
const memo = findDir(node, "memo");
|
|
4153
|
-
const keyProp = findProp(node, `key
|
|
4154
|
-
|
|
4155
|
-
|
|
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;
|
|
4156
4279
|
const isStableFragment = forNode.source.type === 4 && forNode.source.constType > 0;
|
|
4157
4280
|
const fragmentFlag = isStableFragment ? 64 : keyProp ? 128 : 256;
|
|
4158
4281
|
forNode.codegenNode = createVNodeCall(
|
|
@@ -4160,7 +4283,7 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4160
4283
|
helper(FRAGMENT),
|
|
4161
4284
|
void 0,
|
|
4162
4285
|
renderExp,
|
|
4163
|
-
fragmentFlag
|
|
4286
|
+
fragmentFlag,
|
|
4164
4287
|
void 0,
|
|
4165
4288
|
void 0,
|
|
4166
4289
|
true,
|
|
@@ -4200,7 +4323,7 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4200
4323
|
helper(FRAGMENT),
|
|
4201
4324
|
keyProperty ? createObjectExpression([keyProperty]) : void 0,
|
|
4202
4325
|
node.children,
|
|
4203
|
-
64
|
|
4326
|
+
64,
|
|
4204
4327
|
void 0,
|
|
4205
4328
|
void 0,
|
|
4206
4329
|
true,
|
|
@@ -4254,8 +4377,9 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4254
4377
|
renderExp.arguments.push(
|
|
4255
4378
|
loop,
|
|
4256
4379
|
createSimpleExpression(`_cache`),
|
|
4257
|
-
createSimpleExpression(String(context.cached
|
|
4380
|
+
createSimpleExpression(String(context.cached.length))
|
|
4258
4381
|
);
|
|
4382
|
+
context.cached.push(null);
|
|
4259
4383
|
} else {
|
|
4260
4384
|
renderExp.arguments.push(
|
|
4261
4385
|
createFunctionExpression(
|
|
@@ -4301,13 +4425,11 @@ function processFor(node, dir, context, processCodegen) {
|
|
|
4301
4425
|
const onExit = processCodegen && processCodegen(forNode);
|
|
4302
4426
|
return () => {
|
|
4303
4427
|
scopes.vFor--;
|
|
4304
|
-
if (onExit)
|
|
4305
|
-
onExit();
|
|
4428
|
+
if (onExit) onExit();
|
|
4306
4429
|
};
|
|
4307
4430
|
}
|
|
4308
4431
|
function finalizeForParseResult(result, context) {
|
|
4309
|
-
if (result.finalized)
|
|
4310
|
-
return;
|
|
4432
|
+
if (result.finalized) return;
|
|
4311
4433
|
{
|
|
4312
4434
|
validateBrowserExpression(result.source, context);
|
|
4313
4435
|
if (result.key) {
|
|
@@ -4340,8 +4462,7 @@ function createForLoopParams({ value, key, index }, memoArgs = []) {
|
|
|
4340
4462
|
function createParamsList(args) {
|
|
4341
4463
|
let i = args.length;
|
|
4342
4464
|
while (i--) {
|
|
4343
|
-
if (args[i])
|
|
4344
|
-
break;
|
|
4465
|
+
if (args[i]) break;
|
|
4345
4466
|
}
|
|
4346
4467
|
return args.slice(0, i + 1).map((arg, i2) => arg || createSimpleExpression(`_`.repeat(i2 + 1), false));
|
|
4347
4468
|
}
|
|
@@ -4464,9 +4585,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
4464
4585
|
break;
|
|
4465
4586
|
}
|
|
4466
4587
|
}
|
|
4467
|
-
if (prev && isTemplateNode(prev) && findDir(prev,
|
|
4468
|
-
children.splice(i, 1);
|
|
4469
|
-
i--;
|
|
4588
|
+
if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
|
|
4470
4589
|
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
4471
4590
|
while (conditional.alternate.type === 19) {
|
|
4472
4591
|
conditional = conditional.alternate;
|
|
@@ -4603,13 +4722,11 @@ function hasForwardedSlots(children) {
|
|
|
4603
4722
|
}
|
|
4604
4723
|
break;
|
|
4605
4724
|
case 9:
|
|
4606
|
-
if (hasForwardedSlots(child.branches))
|
|
4607
|
-
return true;
|
|
4725
|
+
if (hasForwardedSlots(child.branches)) return true;
|
|
4608
4726
|
break;
|
|
4609
4727
|
case 10:
|
|
4610
4728
|
case 11:
|
|
4611
|
-
if (hasForwardedSlots(child.children))
|
|
4612
|
-
return true;
|
|
4729
|
+
if (hasForwardedSlots(child.children)) return true;
|
|
4613
4730
|
break;
|
|
4614
4731
|
}
|
|
4615
4732
|
}
|
|
@@ -4634,7 +4751,6 @@ const transformElement = (node, context) => {
|
|
|
4634
4751
|
const isDynamicComponent = isObject(vnodeTag) && vnodeTag.callee === RESOLVE_DYNAMIC_COMPONENT;
|
|
4635
4752
|
let vnodeProps;
|
|
4636
4753
|
let vnodeChildren;
|
|
4637
|
-
let vnodePatchFlag;
|
|
4638
4754
|
let patchFlag = 0;
|
|
4639
4755
|
let vnodeDynamicProps;
|
|
4640
4756
|
let dynamicPropNames;
|
|
@@ -4645,7 +4761,7 @@ const transformElement = (node, context) => {
|
|
|
4645
4761
|
// updates inside get proper isSVG flag at runtime. (#639, #643)
|
|
4646
4762
|
// This is technically web-specific, but splitting the logic out of core
|
|
4647
4763
|
// leads to too much unnecessary complexity.
|
|
4648
|
-
(tag === "svg" || tag === "foreignObject")
|
|
4764
|
+
(tag === "svg" || tag === "foreignObject" || tag === "math")
|
|
4649
4765
|
);
|
|
4650
4766
|
if (props.length > 0) {
|
|
4651
4767
|
const propsBuildResult = buildProps(
|
|
@@ -4705,25 +4821,15 @@ const transformElement = (node, context) => {
|
|
|
4705
4821
|
vnodeChildren = node.children;
|
|
4706
4822
|
}
|
|
4707
4823
|
}
|
|
4708
|
-
if (
|
|
4709
|
-
|
|
4710
|
-
if (patchFlag < 0) {
|
|
4711
|
-
vnodePatchFlag = patchFlag + ` /* ${PatchFlagNames[patchFlag]} */`;
|
|
4712
|
-
} else {
|
|
4713
|
-
const flagNames = Object.keys(PatchFlagNames).map(Number).filter((n) => n > 0 && patchFlag & n).map((n) => PatchFlagNames[n]).join(`, `);
|
|
4714
|
-
vnodePatchFlag = patchFlag + ` /* ${flagNames} */`;
|
|
4715
|
-
}
|
|
4716
|
-
}
|
|
4717
|
-
if (dynamicPropNames && dynamicPropNames.length) {
|
|
4718
|
-
vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
|
4719
|
-
}
|
|
4824
|
+
if (dynamicPropNames && dynamicPropNames.length) {
|
|
4825
|
+
vnodeDynamicProps = stringifyDynamicPropNames(dynamicPropNames);
|
|
4720
4826
|
}
|
|
4721
4827
|
node.codegenNode = createVNodeCall(
|
|
4722
4828
|
context,
|
|
4723
4829
|
vnodeTag,
|
|
4724
4830
|
vnodeProps,
|
|
4725
4831
|
vnodeChildren,
|
|
4726
|
-
|
|
4832
|
+
patchFlag === 0 ? void 0 : patchFlag,
|
|
4727
4833
|
vnodeDynamicProps,
|
|
4728
4834
|
vnodeDirectives,
|
|
4729
4835
|
!!shouldUseBlock,
|
|
@@ -4768,8 +4874,7 @@ function resolveComponentType(node, context, ssr = false) {
|
|
|
4768
4874
|
}
|
|
4769
4875
|
const builtIn = isCoreComponent(tag) || context.isBuiltInComponent(tag);
|
|
4770
4876
|
if (builtIn) {
|
|
4771
|
-
if (!ssr)
|
|
4772
|
-
context.helper(builtIn);
|
|
4877
|
+
if (!ssr) context.helper(builtIn);
|
|
4773
4878
|
return builtIn;
|
|
4774
4879
|
}
|
|
4775
4880
|
context.helper(RESOLVE_COMPONENT);
|
|
@@ -4798,8 +4903,7 @@ function buildProps(node, context, props = node.props, isComponent, isDynamicCom
|
|
|
4798
4903
|
);
|
|
4799
4904
|
properties = [];
|
|
4800
4905
|
}
|
|
4801
|
-
if (arg)
|
|
4802
|
-
mergeArgs.push(arg);
|
|
4906
|
+
if (arg) mergeArgs.push(arg);
|
|
4803
4907
|
};
|
|
4804
4908
|
const pushRefVForMarker = () => {
|
|
4805
4909
|
if (context.scopes.vFor > 0) {
|
|
@@ -5136,8 +5240,7 @@ function buildDirectiveArgs(dir, context) {
|
|
|
5136
5240
|
}
|
|
5137
5241
|
}
|
|
5138
5242
|
const { loc } = dir;
|
|
5139
|
-
if (dir.exp)
|
|
5140
|
-
dirArgs.push(dir.exp);
|
|
5243
|
+
if (dir.exp) dirArgs.push(dir.exp);
|
|
5141
5244
|
if (dir.arg) {
|
|
5142
5245
|
if (!dir.exp) {
|
|
5143
5246
|
dirArgs.push(`void 0`);
|
|
@@ -5167,8 +5270,7 @@ function stringifyDynamicPropNames(props) {
|
|
|
5167
5270
|
let propsNamesString = `[`;
|
|
5168
5271
|
for (let i = 0, l = props.length; i < l; i++) {
|
|
5169
5272
|
propsNamesString += JSON.stringify(props[i]);
|
|
5170
|
-
if (i < l - 1)
|
|
5171
|
-
propsNamesString += ", ";
|
|
5273
|
+
if (i < l - 1) propsNamesString += ", ";
|
|
5172
5274
|
}
|
|
5173
5275
|
return propsNamesString + `]`;
|
|
5174
5276
|
}
|
|
@@ -5262,7 +5364,7 @@ function processSlotOutlet(node, context) {
|
|
|
5262
5364
|
};
|
|
5263
5365
|
}
|
|
5264
5366
|
|
|
5265
|
-
const fnExpRE = /^\s*(
|
|
5367
|
+
const fnExpRE = /^\s*(async\s*)?(\([^)]*?\)|[\w$_]+)\s*(:[^=]+)?=>|^\s*(async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
5266
5368
|
const transformOn$1 = (dir, node, context, augmentor) => {
|
|
5267
5369
|
const { loc, modifiers, arg } = dir;
|
|
5268
5370
|
if (!dir.exp && !modifiers.length) {
|
|
@@ -5343,75 +5445,6 @@ const transformOn$1 = (dir, node, context, augmentor) => {
|
|
|
5343
5445
|
return ret;
|
|
5344
5446
|
};
|
|
5345
5447
|
|
|
5346
|
-
const transformBind = (dir, _node, context) => {
|
|
5347
|
-
const { modifiers, loc } = dir;
|
|
5348
|
-
const arg = dir.arg;
|
|
5349
|
-
let { exp } = dir;
|
|
5350
|
-
if (exp && exp.type === 4 && !exp.content.trim()) {
|
|
5351
|
-
{
|
|
5352
|
-
exp = void 0;
|
|
5353
|
-
}
|
|
5354
|
-
}
|
|
5355
|
-
if (!exp) {
|
|
5356
|
-
if (arg.type !== 4 || !arg.isStatic) {
|
|
5357
|
-
context.onError(
|
|
5358
|
-
createCompilerError(
|
|
5359
|
-
52,
|
|
5360
|
-
arg.loc
|
|
5361
|
-
)
|
|
5362
|
-
);
|
|
5363
|
-
return {
|
|
5364
|
-
props: [
|
|
5365
|
-
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
5366
|
-
]
|
|
5367
|
-
};
|
|
5368
|
-
}
|
|
5369
|
-
const propName = camelize(arg.content);
|
|
5370
|
-
exp = dir.exp = createSimpleExpression(propName, false, arg.loc);
|
|
5371
|
-
}
|
|
5372
|
-
if (arg.type !== 4) {
|
|
5373
|
-
arg.children.unshift(`(`);
|
|
5374
|
-
arg.children.push(`) || ""`);
|
|
5375
|
-
} else if (!arg.isStatic) {
|
|
5376
|
-
arg.content = `${arg.content} || ""`;
|
|
5377
|
-
}
|
|
5378
|
-
if (modifiers.includes("camel")) {
|
|
5379
|
-
if (arg.type === 4) {
|
|
5380
|
-
if (arg.isStatic) {
|
|
5381
|
-
arg.content = camelize(arg.content);
|
|
5382
|
-
} else {
|
|
5383
|
-
arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
|
5384
|
-
}
|
|
5385
|
-
} else {
|
|
5386
|
-
arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
|
5387
|
-
arg.children.push(`)`);
|
|
5388
|
-
}
|
|
5389
|
-
}
|
|
5390
|
-
if (!context.inSSR) {
|
|
5391
|
-
if (modifiers.includes("prop")) {
|
|
5392
|
-
injectPrefix(arg, ".");
|
|
5393
|
-
}
|
|
5394
|
-
if (modifiers.includes("attr")) {
|
|
5395
|
-
injectPrefix(arg, "^");
|
|
5396
|
-
}
|
|
5397
|
-
}
|
|
5398
|
-
return {
|
|
5399
|
-
props: [createObjectProperty(arg, exp)]
|
|
5400
|
-
};
|
|
5401
|
-
};
|
|
5402
|
-
const injectPrefix = (arg, prefix) => {
|
|
5403
|
-
if (arg.type === 4) {
|
|
5404
|
-
if (arg.isStatic) {
|
|
5405
|
-
arg.content = prefix + arg.content;
|
|
5406
|
-
} else {
|
|
5407
|
-
arg.content = `\`${prefix}\${${arg.content}}\``;
|
|
5408
|
-
}
|
|
5409
|
-
} else {
|
|
5410
|
-
arg.children.unshift(`'${prefix}' + (`);
|
|
5411
|
-
arg.children.push(`)`);
|
|
5412
|
-
}
|
|
5413
|
-
};
|
|
5414
|
-
|
|
5415
5448
|
const transformText = (node, context) => {
|
|
5416
5449
|
if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
|
|
5417
5450
|
return () => {
|
|
@@ -5575,8 +5608,7 @@ const transformFilter = (node, context) => {
|
|
|
5575
5608
|
}
|
|
5576
5609
|
if (node.type === 5) {
|
|
5577
5610
|
rewriteFilter(node.content, context);
|
|
5578
|
-
}
|
|
5579
|
-
if (node.type === 1) {
|
|
5611
|
+
} else if (node.type === 1) {
|
|
5580
5612
|
node.props.forEach((prop) => {
|
|
5581
5613
|
if (prop.type === 7 && prop.name !== "for" && prop.exp) {
|
|
5582
5614
|
rewriteFilter(prop.exp, context);
|
|
@@ -5590,8 +5622,7 @@ function rewriteFilter(node, context) {
|
|
|
5590
5622
|
} else {
|
|
5591
5623
|
for (let i = 0; i < node.children.length; i++) {
|
|
5592
5624
|
const child = node.children[i];
|
|
5593
|
-
if (typeof child !== "object")
|
|
5594
|
-
continue;
|
|
5625
|
+
if (typeof child !== "object") continue;
|
|
5595
5626
|
if (child.type === 4) {
|
|
5596
5627
|
parseFilter(child, context);
|
|
5597
5628
|
} else if (child.type === 8) {
|
|
@@ -5617,17 +5648,13 @@ function parseFilter(node, context) {
|
|
|
5617
5648
|
prev = c;
|
|
5618
5649
|
c = exp.charCodeAt(i);
|
|
5619
5650
|
if (inSingle) {
|
|
5620
|
-
if (c === 39 && prev !== 92)
|
|
5621
|
-
inSingle = false;
|
|
5651
|
+
if (c === 39 && prev !== 92) inSingle = false;
|
|
5622
5652
|
} else if (inDouble) {
|
|
5623
|
-
if (c === 34 && prev !== 92)
|
|
5624
|
-
inDouble = false;
|
|
5653
|
+
if (c === 34 && prev !== 92) inDouble = false;
|
|
5625
5654
|
} else if (inTemplateString) {
|
|
5626
|
-
if (c === 96 && prev !== 92)
|
|
5627
|
-
inTemplateString = false;
|
|
5655
|
+
if (c === 96 && prev !== 92) inTemplateString = false;
|
|
5628
5656
|
} else if (inRegex) {
|
|
5629
|
-
if (c === 47 && prev !== 92)
|
|
5630
|
-
inRegex = false;
|
|
5657
|
+
if (c === 47 && prev !== 92) inRegex = false;
|
|
5631
5658
|
} else if (c === 124 && // pipe
|
|
5632
5659
|
exp.charCodeAt(i + 1) !== 124 && exp.charCodeAt(i - 1) !== 124 && !curly && !square && !paren) {
|
|
5633
5660
|
if (expression === void 0) {
|
|
@@ -5671,8 +5698,7 @@ function parseFilter(node, context) {
|
|
|
5671
5698
|
let p;
|
|
5672
5699
|
for (; j >= 0; j--) {
|
|
5673
5700
|
p = exp.charAt(j);
|
|
5674
|
-
if (p !== " ")
|
|
5675
|
-
break;
|
|
5701
|
+
if (p !== " ") break;
|
|
5676
5702
|
}
|
|
5677
5703
|
if (!p || !validDivisionCharRE.test(p)) {
|
|
5678
5704
|
inRegex = true;
|
|
@@ -5699,6 +5725,7 @@ function parseFilter(node, context) {
|
|
|
5699
5725
|
expression = wrapFilter(expression, filters[i], context);
|
|
5700
5726
|
}
|
|
5701
5727
|
node.content = expression;
|
|
5728
|
+
node.ast = void 0;
|
|
5702
5729
|
}
|
|
5703
5730
|
}
|
|
5704
5731
|
function wrapFilter(exp, filter, context) {
|
|
@@ -5733,8 +5760,9 @@ const transformMemo = (node, context) => {
|
|
|
5733
5760
|
dir.exp,
|
|
5734
5761
|
createFunctionExpression(void 0, codegenNode),
|
|
5735
5762
|
`_cache`,
|
|
5736
|
-
String(context.cached
|
|
5763
|
+
String(context.cached.length)
|
|
5737
5764
|
]);
|
|
5765
|
+
context.cached.push(null);
|
|
5738
5766
|
}
|
|
5739
5767
|
};
|
|
5740
5768
|
}
|
|
@@ -6170,8 +6198,7 @@ const transformClick = (key, event) => {
|
|
|
6170
6198
|
const transformOn = (dir, node, context) => {
|
|
6171
6199
|
return transformOn$1(dir, node, context, (baseResult) => {
|
|
6172
6200
|
const { modifiers } = dir;
|
|
6173
|
-
if (!modifiers.length)
|
|
6174
|
-
return baseResult;
|
|
6201
|
+
if (!modifiers.length) return baseResult;
|
|
6175
6202
|
let { key, value: handlerExp } = baseResult.props[0];
|
|
6176
6203
|
const { keyModifiers, nonKeyModifiers, eventOptionModifiers } = resolveModifiers(key, modifiers, context, dir.loc);
|
|
6177
6204
|
if (nonKeyModifiers.includes("right")) {
|
|
@@ -6282,12 +6309,10 @@ function isValidHTMLNesting(parent, child) {
|
|
|
6282
6309
|
return onlyValidParents[child].has(parent);
|
|
6283
6310
|
}
|
|
6284
6311
|
if (parent in knownInvalidChildren) {
|
|
6285
|
-
if (knownInvalidChildren[parent].has(child))
|
|
6286
|
-
return false;
|
|
6312
|
+
if (knownInvalidChildren[parent].has(child)) return false;
|
|
6287
6313
|
}
|
|
6288
6314
|
if (child in knownInvalidParents) {
|
|
6289
|
-
if (knownInvalidParents[child].has(parent))
|
|
6290
|
-
return false;
|
|
6315
|
+
if (knownInvalidParents[child].has(parent)) return false;
|
|
6291
6316
|
}
|
|
6292
6317
|
return true;
|
|
6293
6318
|
}
|