@vue/compiler-core 3.6.0-alpha.1 → 3.6.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 +168 -128
- package/dist/compiler-core.cjs.prod.js +168 -128
- package/dist/compiler-core.d.ts +6 -2
- package/dist/compiler-core.esm-bundler.js +119 -106
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-core v3.6.0-alpha.
|
|
2
|
+
* @vue/compiler-core v3.6.0-alpha.3
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -1570,16 +1570,34 @@ function walkIdentifiers(root, onIdentifier, includeAll = false, parentStack = [
|
|
|
1570
1570
|
(id) => markScopeIdentifier(node, id, knownIds)
|
|
1571
1571
|
);
|
|
1572
1572
|
}
|
|
1573
|
+
} else if (node.type === "SwitchStatement") {
|
|
1574
|
+
if (node.scopeIds) {
|
|
1575
|
+
node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
|
|
1576
|
+
} else {
|
|
1577
|
+
walkSwitchStatement(
|
|
1578
|
+
node,
|
|
1579
|
+
false,
|
|
1580
|
+
(id) => markScopeIdentifier(node, id, knownIds)
|
|
1581
|
+
);
|
|
1582
|
+
}
|
|
1573
1583
|
} else if (node.type === "CatchClause" && node.param) {
|
|
1574
|
-
|
|
1575
|
-
|
|
1584
|
+
if (node.scopeIds) {
|
|
1585
|
+
node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
|
|
1586
|
+
} else {
|
|
1587
|
+
for (const id of extractIdentifiers(node.param)) {
|
|
1588
|
+
markScopeIdentifier(node, id, knownIds);
|
|
1589
|
+
}
|
|
1576
1590
|
}
|
|
1577
1591
|
} else if (isForStatement(node)) {
|
|
1578
|
-
|
|
1579
|
-
node,
|
|
1580
|
-
|
|
1581
|
-
(
|
|
1582
|
-
|
|
1592
|
+
if (node.scopeIds) {
|
|
1593
|
+
node.scopeIds.forEach((id) => markKnownIds(id, knownIds));
|
|
1594
|
+
} else {
|
|
1595
|
+
walkForStatement(
|
|
1596
|
+
node,
|
|
1597
|
+
false,
|
|
1598
|
+
(id) => markScopeIdentifier(node, id, knownIds)
|
|
1599
|
+
);
|
|
1600
|
+
}
|
|
1583
1601
|
}
|
|
1584
1602
|
},
|
|
1585
1603
|
leave(node, parent) {
|
|
@@ -1602,14 +1620,15 @@ function isReferencedIdentifier(id, parent, parentStack) {
|
|
|
1602
1620
|
if (id.name === "arguments") {
|
|
1603
1621
|
return false;
|
|
1604
1622
|
}
|
|
1605
|
-
if (isReferenced(id, parent)) {
|
|
1623
|
+
if (isReferenced(id, parent, parentStack[parentStack.length - 2])) {
|
|
1606
1624
|
return true;
|
|
1607
1625
|
}
|
|
1608
1626
|
switch (parent.type) {
|
|
1609
1627
|
case "AssignmentExpression":
|
|
1610
1628
|
case "AssignmentPattern":
|
|
1611
1629
|
return true;
|
|
1612
|
-
case "
|
|
1630
|
+
case "ObjectProperty":
|
|
1631
|
+
return parent.key !== id && isInDestructureAssignment(parent, parentStack);
|
|
1613
1632
|
case "ArrayPattern":
|
|
1614
1633
|
return isInDestructureAssignment(parent, parentStack);
|
|
1615
1634
|
}
|
|
@@ -1649,7 +1668,8 @@ function walkFunctionParams(node, onIdent) {
|
|
|
1649
1668
|
}
|
|
1650
1669
|
}
|
|
1651
1670
|
function walkBlockDeclarations(block, onIdent) {
|
|
1652
|
-
|
|
1671
|
+
const body = block.type === "SwitchCase" ? block.consequent : block.body;
|
|
1672
|
+
for (const stmt of body) {
|
|
1653
1673
|
if (stmt.type === "VariableDeclaration") {
|
|
1654
1674
|
if (stmt.declare) continue;
|
|
1655
1675
|
for (const decl of stmt.declarations) {
|
|
@@ -1662,6 +1682,8 @@ function walkBlockDeclarations(block, onIdent) {
|
|
|
1662
1682
|
onIdent(stmt.id);
|
|
1663
1683
|
} else if (isForStatement(stmt)) {
|
|
1664
1684
|
walkForStatement(stmt, true, onIdent);
|
|
1685
|
+
} else if (stmt.type === "SwitchStatement") {
|
|
1686
|
+
walkSwitchStatement(stmt, true, onIdent);
|
|
1665
1687
|
}
|
|
1666
1688
|
}
|
|
1667
1689
|
}
|
|
@@ -1678,6 +1700,20 @@ function walkForStatement(stmt, isVar, onIdent) {
|
|
|
1678
1700
|
}
|
|
1679
1701
|
}
|
|
1680
1702
|
}
|
|
1703
|
+
function walkSwitchStatement(stmt, isVar, onIdent) {
|
|
1704
|
+
for (const cs of stmt.cases) {
|
|
1705
|
+
for (const stmt2 of cs.consequent) {
|
|
1706
|
+
if (stmt2.type === "VariableDeclaration" && (stmt2.kind === "var" ? isVar : !isVar)) {
|
|
1707
|
+
for (const decl of stmt2.declarations) {
|
|
1708
|
+
for (const id of extractIdentifiers(decl.id)) {
|
|
1709
|
+
onIdent(id);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
walkBlockDeclarations(cs, onIdent);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1681
1717
|
function extractIdentifiers(param, nodes = []) {
|
|
1682
1718
|
switch (param.type) {
|
|
1683
1719
|
case "Identifier":
|
|
@@ -1778,7 +1814,7 @@ function isReferenced(node, parent, grandparent) {
|
|
|
1778
1814
|
if (parent.key === node) {
|
|
1779
1815
|
return !!parent.computed;
|
|
1780
1816
|
}
|
|
1781
|
-
return
|
|
1817
|
+
return !grandparent || grandparent.type !== "ObjectPattern";
|
|
1782
1818
|
// no: class { NODE = value; }
|
|
1783
1819
|
// yes: class { [NODE] = value; }
|
|
1784
1820
|
// yes: class { key = NODE; }
|
|
@@ -1828,6 +1864,9 @@ function isReferenced(node, parent, grandparent) {
|
|
|
1828
1864
|
// yes: export { NODE as foo };
|
|
1829
1865
|
// no: export { NODE as foo } from "foo";
|
|
1830
1866
|
case "ExportSpecifier":
|
|
1867
|
+
if (grandparent == null ? void 0 : grandparent.source) {
|
|
1868
|
+
return false;
|
|
1869
|
+
}
|
|
1831
1870
|
return parent.local === node;
|
|
1832
1871
|
// no: import NODE from "foo";
|
|
1833
1872
|
// no: import * as NODE from "foo";
|
|
@@ -1961,7 +2000,7 @@ function isCoreComponent(tag) {
|
|
|
1961
2000
|
return BASE_TRANSITION;
|
|
1962
2001
|
}
|
|
1963
2002
|
}
|
|
1964
|
-
const nonIdentifierRE =
|
|
2003
|
+
const nonIdentifierRE = /^$|^\d|[^\$\w\xA0-\uFFFF]/;
|
|
1965
2004
|
const isSimpleIdentifier = (name) => !nonIdentifierRE.test(name);
|
|
1966
2005
|
const validFirstIdentCharRE = /[A-Za-z_$\xA0-\uFFFF]/;
|
|
1967
2006
|
const validIdentCharRE = /[\.\?\w$\xA0-\uFFFF]/;
|
|
@@ -2041,7 +2080,7 @@ const isMemberExpressionNode = (exp, context) => {
|
|
|
2041
2080
|
}
|
|
2042
2081
|
};
|
|
2043
2082
|
const isMemberExpression = isMemberExpressionNode;
|
|
2044
|
-
const fnExpRE = /^\s*(async\s*)?(
|
|
2083
|
+
const fnExpRE = /^\s*(?:async\s*)?(?:\([^)]*?\)|[\w$_]+)\s*(?::[^=]+)?=>|^\s*(?:async\s+)?function(?:\s+[\w$]+)?\s*\(/;
|
|
2045
2084
|
const isFnExpressionBrowser = (exp) => fnExpRE.test(getExpSource(exp));
|
|
2046
2085
|
const isFnExpressionNode = (exp, context) => {
|
|
2047
2086
|
try {
|
|
@@ -2126,6 +2165,9 @@ function hasDynamicKeyVBind(node) {
|
|
|
2126
2165
|
function isText$1(node) {
|
|
2127
2166
|
return node.type === 5 || node.type === 2;
|
|
2128
2167
|
}
|
|
2168
|
+
function isVPre(p) {
|
|
2169
|
+
return p.type === 7 && p.name === "pre";
|
|
2170
|
+
}
|
|
2129
2171
|
function isVSlot(p) {
|
|
2130
2172
|
return p.type === 7 && p.name === "slot";
|
|
2131
2173
|
}
|
|
@@ -2424,7 +2466,7 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2424
2466
|
ondirarg(start, end) {
|
|
2425
2467
|
if (start === end) return;
|
|
2426
2468
|
const arg = getSlice(start, end);
|
|
2427
|
-
if (inVPre) {
|
|
2469
|
+
if (inVPre && !isVPre(currentProp)) {
|
|
2428
2470
|
currentProp.name += arg;
|
|
2429
2471
|
setLocEnd(currentProp.nameLoc, end);
|
|
2430
2472
|
} else {
|
|
@@ -2439,7 +2481,7 @@ const tokenizer = new Tokenizer(stack, {
|
|
|
2439
2481
|
},
|
|
2440
2482
|
ondirmodifier(start, end) {
|
|
2441
2483
|
const mod = getSlice(start, end);
|
|
2442
|
-
if (inVPre) {
|
|
2484
|
+
if (inVPre && !isVPre(currentProp)) {
|
|
2443
2485
|
currentProp.name += "." + mod;
|
|
2444
2486
|
setLocEnd(currentProp.nameLoc, end);
|
|
2445
2487
|
} else if (currentProp.name === "slot") {
|
|
@@ -3049,6 +3091,11 @@ function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
|
3049
3091
|
} else if (child.type === 12) {
|
|
3050
3092
|
const constantType = doNotHoistNode ? 0 : getConstantType(child, context);
|
|
3051
3093
|
if (constantType >= 2) {
|
|
3094
|
+
if (child.codegenNode.type === 14 && child.codegenNode.arguments.length > 0) {
|
|
3095
|
+
child.codegenNode.arguments.push(
|
|
3096
|
+
-1 + (``)
|
|
3097
|
+
);
|
|
3098
|
+
}
|
|
3052
3099
|
toCache.push(child);
|
|
3053
3100
|
continue;
|
|
3054
3101
|
}
|
|
@@ -3077,7 +3124,6 @@ function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
|
3077
3124
|
}
|
|
3078
3125
|
}
|
|
3079
3126
|
let cachedAsArray = false;
|
|
3080
|
-
const slotCacheKeys = [];
|
|
3081
3127
|
if (toCache.length === children.length && node.type === 1) {
|
|
3082
3128
|
if (node.tagType === 0 && node.codegenNode && node.codegenNode.type === 13 && shared.isArray(node.codegenNode.children)) {
|
|
3083
3129
|
node.codegenNode.children = getCacheExpression(
|
|
@@ -3087,7 +3133,6 @@ function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
|
3087
3133
|
} else if (node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !shared.isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
|
|
3088
3134
|
const slot = getSlotNode(node.codegenNode, "default");
|
|
3089
3135
|
if (slot) {
|
|
3090
|
-
slotCacheKeys.push(context.cached.length);
|
|
3091
3136
|
slot.returns = getCacheExpression(
|
|
3092
3137
|
createArrayExpression(slot.returns)
|
|
3093
3138
|
);
|
|
@@ -3097,7 +3142,6 @@ function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
|
3097
3142
|
const slotName = findDir(node, "slot", true);
|
|
3098
3143
|
const slot = slotName && slotName.arg && getSlotNode(parent.codegenNode, slotName.arg);
|
|
3099
3144
|
if (slot) {
|
|
3100
|
-
slotCacheKeys.push(context.cached.length);
|
|
3101
3145
|
slot.returns = getCacheExpression(
|
|
3102
3146
|
createArrayExpression(slot.returns)
|
|
3103
3147
|
);
|
|
@@ -3107,23 +3151,12 @@ function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
|
3107
3151
|
}
|
|
3108
3152
|
if (!cachedAsArray) {
|
|
3109
3153
|
for (const child of toCache) {
|
|
3110
|
-
slotCacheKeys.push(context.cached.length);
|
|
3111
3154
|
child.codegenNode = context.cache(child.codegenNode);
|
|
3112
3155
|
}
|
|
3113
3156
|
}
|
|
3114
|
-
if (slotCacheKeys.length && node.type === 1 && node.tagType === 1 && node.codegenNode && node.codegenNode.type === 13 && node.codegenNode.children && !shared.isArray(node.codegenNode.children) && node.codegenNode.children.type === 15) {
|
|
3115
|
-
node.codegenNode.children.properties.push(
|
|
3116
|
-
createObjectProperty(
|
|
3117
|
-
`__`,
|
|
3118
|
-
createSimpleExpression(JSON.stringify(slotCacheKeys), false)
|
|
3119
|
-
)
|
|
3120
|
-
);
|
|
3121
|
-
}
|
|
3122
3157
|
function getCacheExpression(value) {
|
|
3123
3158
|
const exp = context.cache(value);
|
|
3124
|
-
|
|
3125
|
-
exp.needArraySpread = true;
|
|
3126
|
-
}
|
|
3159
|
+
exp.needArraySpread = true;
|
|
3127
3160
|
return exp;
|
|
3128
3161
|
}
|
|
3129
3162
|
function getSlotNode(node2, name) {
|
|
@@ -4553,14 +4586,17 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
|
|
|
4553
4586
|
knownIds
|
|
4554
4587
|
);
|
|
4555
4588
|
const children = [];
|
|
4589
|
+
const isTSNode = TS_NODE_TYPES.includes(ast.type);
|
|
4556
4590
|
ids.sort((a, b) => a.start - b.start);
|
|
4557
4591
|
ids.forEach((id, i) => {
|
|
4558
4592
|
const start = id.start - 1;
|
|
4559
4593
|
const end = id.end - 1;
|
|
4560
4594
|
const last = ids[i - 1];
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4595
|
+
if (!(isTSNode && i === 0)) {
|
|
4596
|
+
const leadingText = rawExp.slice(last ? last.end - 1 : 0, start);
|
|
4597
|
+
if (leadingText.length || id.prefix) {
|
|
4598
|
+
children.push(leadingText + (id.prefix || ``));
|
|
4599
|
+
}
|
|
4564
4600
|
}
|
|
4565
4601
|
const source = rawExp.slice(start, end);
|
|
4566
4602
|
children.push(
|
|
@@ -4575,7 +4611,7 @@ function processExpression(node, context, asParams = false, asRawStatements = fa
|
|
|
4575
4611
|
id.isConstant ? 3 : 0
|
|
4576
4612
|
)
|
|
4577
4613
|
);
|
|
4578
|
-
if (i === ids.length - 1 && end < rawExp.length) {
|
|
4614
|
+
if (i === ids.length - 1 && end < rawExp.length && !isTSNode) {
|
|
4579
4615
|
children.push(rawExp.slice(end));
|
|
4580
4616
|
}
|
|
4581
4617
|
});
|
|
@@ -4613,7 +4649,7 @@ function isConst(type) {
|
|
|
4613
4649
|
}
|
|
4614
4650
|
|
|
4615
4651
|
const transformIf = createStructuralDirectiveTransform(
|
|
4616
|
-
/^(if|else|else-if)$/,
|
|
4652
|
+
/^(?:if|else|else-if)$/,
|
|
4617
4653
|
(node, dir, context) => {
|
|
4618
4654
|
return processIf(node, dir, context, (ifNode, branch, isRoot) => {
|
|
4619
4655
|
const siblings = context.parent.children;
|
|
@@ -4680,7 +4716,7 @@ function processIf(node, dir, context, processCodegen) {
|
|
|
4680
4716
|
continue;
|
|
4681
4717
|
}
|
|
4682
4718
|
if (sibling && sibling.type === 9) {
|
|
4683
|
-
if (dir.name === "else-if" && sibling.branches[sibling.branches.length - 1].condition === void 0) {
|
|
4719
|
+
if ((dir.name === "else-if" || dir.name === "else") && sibling.branches[sibling.branches.length - 1].condition === void 0) {
|
|
4684
4720
|
context.onError(
|
|
4685
4721
|
createCompilerError(30, node.loc)
|
|
4686
4722
|
);
|
|
@@ -4822,90 +4858,6 @@ function getParentCondition(node) {
|
|
|
4822
4858
|
}
|
|
4823
4859
|
}
|
|
4824
4860
|
|
|
4825
|
-
const transformBind = (dir, _node, context) => {
|
|
4826
|
-
const { modifiers, loc } = dir;
|
|
4827
|
-
const arg = dir.arg;
|
|
4828
|
-
let { exp } = dir;
|
|
4829
|
-
if (exp && exp.type === 4 && !exp.content.trim()) {
|
|
4830
|
-
{
|
|
4831
|
-
context.onError(
|
|
4832
|
-
createCompilerError(34, loc)
|
|
4833
|
-
);
|
|
4834
|
-
return {
|
|
4835
|
-
props: [
|
|
4836
|
-
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
4837
|
-
]
|
|
4838
|
-
};
|
|
4839
|
-
}
|
|
4840
|
-
}
|
|
4841
|
-
if (!exp) {
|
|
4842
|
-
if (arg.type !== 4 || !arg.isStatic) {
|
|
4843
|
-
context.onError(
|
|
4844
|
-
createCompilerError(
|
|
4845
|
-
52,
|
|
4846
|
-
arg.loc
|
|
4847
|
-
)
|
|
4848
|
-
);
|
|
4849
|
-
return {
|
|
4850
|
-
props: [
|
|
4851
|
-
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
4852
|
-
]
|
|
4853
|
-
};
|
|
4854
|
-
}
|
|
4855
|
-
transformBindShorthand(dir, context);
|
|
4856
|
-
exp = dir.exp;
|
|
4857
|
-
}
|
|
4858
|
-
if (arg.type !== 4) {
|
|
4859
|
-
arg.children.unshift(`(`);
|
|
4860
|
-
arg.children.push(`) || ""`);
|
|
4861
|
-
} else if (!arg.isStatic) {
|
|
4862
|
-
arg.content = `${arg.content} || ""`;
|
|
4863
|
-
}
|
|
4864
|
-
if (modifiers.some((mod) => mod.content === "camel")) {
|
|
4865
|
-
if (arg.type === 4) {
|
|
4866
|
-
if (arg.isStatic) {
|
|
4867
|
-
arg.content = shared.camelize(arg.content);
|
|
4868
|
-
} else {
|
|
4869
|
-
arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
|
4870
|
-
}
|
|
4871
|
-
} else {
|
|
4872
|
-
arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
|
4873
|
-
arg.children.push(`)`);
|
|
4874
|
-
}
|
|
4875
|
-
}
|
|
4876
|
-
if (!context.inSSR) {
|
|
4877
|
-
if (modifiers.some((mod) => mod.content === "prop")) {
|
|
4878
|
-
injectPrefix(arg, ".");
|
|
4879
|
-
}
|
|
4880
|
-
if (modifiers.some((mod) => mod.content === "attr")) {
|
|
4881
|
-
injectPrefix(arg, "^");
|
|
4882
|
-
}
|
|
4883
|
-
}
|
|
4884
|
-
return {
|
|
4885
|
-
props: [createObjectProperty(arg, exp)]
|
|
4886
|
-
};
|
|
4887
|
-
};
|
|
4888
|
-
const transformBindShorthand = (dir, context) => {
|
|
4889
|
-
const arg = dir.arg;
|
|
4890
|
-
const propName = shared.camelize(arg.content);
|
|
4891
|
-
dir.exp = createSimpleExpression(propName, false, arg.loc);
|
|
4892
|
-
{
|
|
4893
|
-
dir.exp = processExpression(dir.exp, context);
|
|
4894
|
-
}
|
|
4895
|
-
};
|
|
4896
|
-
const injectPrefix = (arg, prefix) => {
|
|
4897
|
-
if (arg.type === 4) {
|
|
4898
|
-
if (arg.isStatic) {
|
|
4899
|
-
arg.content = prefix + arg.content;
|
|
4900
|
-
} else {
|
|
4901
|
-
arg.content = `\`${prefix}\${${arg.content}}\``;
|
|
4902
|
-
}
|
|
4903
|
-
} else {
|
|
4904
|
-
arg.children.unshift(`'${prefix}' + (`);
|
|
4905
|
-
arg.children.push(`)`);
|
|
4906
|
-
}
|
|
4907
|
-
};
|
|
4908
|
-
|
|
4909
4861
|
const transformFor = createStructuralDirectiveTransform(
|
|
4910
4862
|
"for",
|
|
4911
4863
|
(node, dir, context) => {
|
|
@@ -4918,9 +4870,6 @@ const transformFor = createStructuralDirectiveTransform(
|
|
|
4918
4870
|
const memo = findDir(node, "memo");
|
|
4919
4871
|
const keyProp = findProp(node, `key`, false, true);
|
|
4920
4872
|
const isDirKey = keyProp && keyProp.type === 7;
|
|
4921
|
-
if (isDirKey && !keyProp.exp) {
|
|
4922
|
-
transformBindShorthand(keyProp, context);
|
|
4923
|
-
}
|
|
4924
4873
|
let keyExp = keyProp && (keyProp.type === 6 ? keyProp.value ? createSimpleExpression(keyProp.value.content, true) : void 0 : keyProp.exp);
|
|
4925
4874
|
if (memo && keyExp && isDirKey) {
|
|
4926
4875
|
{
|
|
@@ -5201,7 +5150,9 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
5201
5150
|
const dynamicSlots = [];
|
|
5202
5151
|
let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0;
|
|
5203
5152
|
if (!context.ssr && context.prefixIdentifiers) {
|
|
5204
|
-
hasDynamicSlots =
|
|
5153
|
+
hasDynamicSlots = node.props.some(
|
|
5154
|
+
(prop) => isVSlot(prop) && (hasScopeRef(prop.arg, context.identifiers) || hasScopeRef(prop.exp, context.identifiers))
|
|
5155
|
+
) || children.some((child) => hasScopeRef(child, context.identifiers));
|
|
5205
5156
|
}
|
|
5206
5157
|
const onComponentSlot = findDir(node, "slot", true);
|
|
5207
5158
|
if (onComponentSlot) {
|
|
@@ -5264,7 +5215,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
5264
5215
|
);
|
|
5265
5216
|
} else if (vElse = findDir(
|
|
5266
5217
|
slotElement,
|
|
5267
|
-
/^else(
|
|
5218
|
+
/^else(?:-if)?$/,
|
|
5268
5219
|
true
|
|
5269
5220
|
/* allowEmpty */
|
|
5270
5221
|
)) {
|
|
@@ -5276,7 +5227,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
5276
5227
|
break;
|
|
5277
5228
|
}
|
|
5278
5229
|
}
|
|
5279
|
-
if (prev && isTemplateNode(prev) && findDir(prev, /^(else-)?if$/)) {
|
|
5230
|
+
if (prev && isTemplateNode(prev) && findDir(prev, /^(?:else-)?if$/)) {
|
|
5280
5231
|
let conditional = dynamicSlots[dynamicSlots.length - 1];
|
|
5281
5232
|
while (conditional.alternate.type === 19) {
|
|
5282
5233
|
conditional = conditional.alternate;
|
|
@@ -6201,6 +6152,65 @@ const transformOn = (dir, node, context, augmentor) => {
|
|
|
6201
6152
|
return ret;
|
|
6202
6153
|
};
|
|
6203
6154
|
|
|
6155
|
+
const transformBind = (dir, _node, context) => {
|
|
6156
|
+
const { modifiers, loc } = dir;
|
|
6157
|
+
const arg = dir.arg;
|
|
6158
|
+
let { exp } = dir;
|
|
6159
|
+
if (exp && exp.type === 4 && !exp.content.trim()) {
|
|
6160
|
+
{
|
|
6161
|
+
context.onError(
|
|
6162
|
+
createCompilerError(34, loc)
|
|
6163
|
+
);
|
|
6164
|
+
return {
|
|
6165
|
+
props: [
|
|
6166
|
+
createObjectProperty(arg, createSimpleExpression("", true, loc))
|
|
6167
|
+
]
|
|
6168
|
+
};
|
|
6169
|
+
}
|
|
6170
|
+
}
|
|
6171
|
+
if (arg.type !== 4) {
|
|
6172
|
+
arg.children.unshift(`(`);
|
|
6173
|
+
arg.children.push(`) || ""`);
|
|
6174
|
+
} else if (!arg.isStatic) {
|
|
6175
|
+
arg.content = arg.content ? `${arg.content} || ""` : `""`;
|
|
6176
|
+
}
|
|
6177
|
+
if (modifiers.some((mod) => mod.content === "camel")) {
|
|
6178
|
+
if (arg.type === 4) {
|
|
6179
|
+
if (arg.isStatic) {
|
|
6180
|
+
arg.content = shared.camelize(arg.content);
|
|
6181
|
+
} else {
|
|
6182
|
+
arg.content = `${context.helperString(CAMELIZE)}(${arg.content})`;
|
|
6183
|
+
}
|
|
6184
|
+
} else {
|
|
6185
|
+
arg.children.unshift(`${context.helperString(CAMELIZE)}(`);
|
|
6186
|
+
arg.children.push(`)`);
|
|
6187
|
+
}
|
|
6188
|
+
}
|
|
6189
|
+
if (!context.inSSR) {
|
|
6190
|
+
if (modifiers.some((mod) => mod.content === "prop")) {
|
|
6191
|
+
injectPrefix(arg, ".");
|
|
6192
|
+
}
|
|
6193
|
+
if (modifiers.some((mod) => mod.content === "attr")) {
|
|
6194
|
+
injectPrefix(arg, "^");
|
|
6195
|
+
}
|
|
6196
|
+
}
|
|
6197
|
+
return {
|
|
6198
|
+
props: [createObjectProperty(arg, exp)]
|
|
6199
|
+
};
|
|
6200
|
+
};
|
|
6201
|
+
const injectPrefix = (arg, prefix) => {
|
|
6202
|
+
if (arg.type === 4) {
|
|
6203
|
+
if (arg.isStatic) {
|
|
6204
|
+
arg.content = prefix + arg.content;
|
|
6205
|
+
} else {
|
|
6206
|
+
arg.content = `\`${prefix}\${${arg.content}}\``;
|
|
6207
|
+
}
|
|
6208
|
+
} else {
|
|
6209
|
+
arg.children.unshift(`'${prefix}' + (`);
|
|
6210
|
+
arg.children.push(`)`);
|
|
6211
|
+
}
|
|
6212
|
+
};
|
|
6213
|
+
|
|
6204
6214
|
const transformText = (node, context) => {
|
|
6205
6215
|
if (node.type === 0 || node.type === 1 || node.type === 11 || node.type === 10) {
|
|
6206
6216
|
return () => {
|
|
@@ -6529,7 +6539,7 @@ const seen = /* @__PURE__ */ new WeakSet();
|
|
|
6529
6539
|
const transformMemo = (node, context) => {
|
|
6530
6540
|
if (node.type === 1) {
|
|
6531
6541
|
const dir = findDir(node, "memo");
|
|
6532
|
-
if (!dir || seen.has(node)) {
|
|
6542
|
+
if (!dir || seen.has(node) || context.inSSR) {
|
|
6533
6543
|
return;
|
|
6534
6544
|
}
|
|
6535
6545
|
seen.add(node);
|
|
@@ -6551,9 +6561,36 @@ const transformMemo = (node, context) => {
|
|
|
6551
6561
|
}
|
|
6552
6562
|
};
|
|
6553
6563
|
|
|
6564
|
+
const transformVBindShorthand = (node, context) => {
|
|
6565
|
+
if (node.type === 1) {
|
|
6566
|
+
for (const prop of node.props) {
|
|
6567
|
+
if (prop.type === 7 && prop.name === "bind" && (!prop.exp || // #13930 :foo in in-DOM templates will be parsed into :foo="" by browser
|
|
6568
|
+
false) && prop.arg) {
|
|
6569
|
+
const arg = prop.arg;
|
|
6570
|
+
if (arg.type !== 4 || !arg.isStatic) {
|
|
6571
|
+
context.onError(
|
|
6572
|
+
createCompilerError(
|
|
6573
|
+
52,
|
|
6574
|
+
arg.loc
|
|
6575
|
+
)
|
|
6576
|
+
);
|
|
6577
|
+
prop.exp = createSimpleExpression("", true, arg.loc);
|
|
6578
|
+
} else {
|
|
6579
|
+
const propName = shared.camelize(arg.content);
|
|
6580
|
+
if (validFirstIdentCharRE.test(propName[0]) || // allow hyphen first char for https://github.com/vuejs/language-tools/pull/3424
|
|
6581
|
+
propName[0] === "-") {
|
|
6582
|
+
prop.exp = createSimpleExpression(propName, false, arg.loc);
|
|
6583
|
+
}
|
|
6584
|
+
}
|
|
6585
|
+
}
|
|
6586
|
+
}
|
|
6587
|
+
}
|
|
6588
|
+
};
|
|
6589
|
+
|
|
6554
6590
|
function getBaseTransformPreset(prefixIdentifiers) {
|
|
6555
6591
|
return [
|
|
6556
6592
|
[
|
|
6593
|
+
transformVBindShorthand,
|
|
6557
6594
|
transformOnce,
|
|
6558
6595
|
transformIf,
|
|
6559
6596
|
transformMemo,
|
|
@@ -6752,6 +6789,7 @@ exports.isStaticProperty = isStaticProperty;
|
|
|
6752
6789
|
exports.isStaticPropertyKey = isStaticPropertyKey;
|
|
6753
6790
|
exports.isTemplateNode = isTemplateNode;
|
|
6754
6791
|
exports.isText = isText$1;
|
|
6792
|
+
exports.isVPre = isVPre;
|
|
6755
6793
|
exports.isVSlot = isVSlot;
|
|
6756
6794
|
exports.locStub = locStub;
|
|
6757
6795
|
exports.noopDirectiveTransform = noopDirectiveTransform;
|
|
@@ -6771,8 +6809,10 @@ exports.transformElement = transformElement;
|
|
|
6771
6809
|
exports.transformExpression = transformExpression;
|
|
6772
6810
|
exports.transformModel = transformModel;
|
|
6773
6811
|
exports.transformOn = transformOn;
|
|
6812
|
+
exports.transformVBindShorthand = transformVBindShorthand;
|
|
6774
6813
|
exports.traverseNode = traverseNode;
|
|
6775
6814
|
exports.unwrapTSNode = unwrapTSNode;
|
|
6815
|
+
exports.validFirstIdentCharRE = validFirstIdentCharRE;
|
|
6776
6816
|
exports.walkBlockDeclarations = walkBlockDeclarations;
|
|
6777
6817
|
exports.walkFunctionParams = walkFunctionParams;
|
|
6778
6818
|
exports.walkIdentifiers = walkIdentifiers;
|
package/dist/compiler-core.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PatchFlags } from '@vue/shared';
|
|
2
2
|
export { generateCodeFrame } from '@vue/shared';
|
|
3
|
-
import { Node as Node$1, Identifier, Function, BlockStatement as BlockStatement$1, Program, ObjectProperty } from '@babel/types';
|
|
3
|
+
import { Node as Node$1, Identifier, Function, BlockStatement as BlockStatement$1, SwitchCase, Program, ObjectProperty } from '@babel/types';
|
|
4
4
|
import { ParserPlugin } from '@babel/parser';
|
|
5
5
|
|
|
6
6
|
export declare const FRAGMENT: unique symbol;
|
|
@@ -1030,6 +1030,7 @@ export declare function baseCompile(source: string | RootNode, options?: Compile
|
|
|
1030
1030
|
export declare const isStaticExp: (p: JSChildNode) => p is SimpleExpressionNode;
|
|
1031
1031
|
export declare function isCoreComponent(tag: string): symbol | void;
|
|
1032
1032
|
export declare const isSimpleIdentifier: (name: string) => boolean;
|
|
1033
|
+
export declare const validFirstIdentCharRE: RegExp;
|
|
1033
1034
|
/**
|
|
1034
1035
|
* Simple lexer to check if an expression is a member expression. This is
|
|
1035
1036
|
* lax and only checks validity at the root level (i.e. does not validate exps
|
|
@@ -1051,6 +1052,7 @@ export declare function findProp(node: ElementNode, name: string, dynamicOnly?:
|
|
|
1051
1052
|
export declare function isStaticArgOf(arg: DirectiveNode['arg'], name: string): boolean;
|
|
1052
1053
|
export declare function hasDynamicKeyVBind(node: ElementNode): boolean;
|
|
1053
1054
|
export declare function isText(node: TemplateChildNode): node is TextNode | InterpolationNode;
|
|
1055
|
+
export declare function isVPre(p: ElementNode['props'][0]): p is DirectiveNode;
|
|
1054
1056
|
export declare function isVSlot(p: ElementNode['props'][0]): p is DirectiveNode;
|
|
1055
1057
|
export declare function isTemplateNode(node: RootNode | TemplateChildNode): node is TemplateNode;
|
|
1056
1058
|
export declare function isSlotOutlet(node: RootNode | TemplateChildNode): node is SlotOutletNode;
|
|
@@ -1068,7 +1070,7 @@ export declare function isReferencedIdentifier(id: Identifier, parent: Node$1 |
|
|
|
1068
1070
|
export declare function isInDestructureAssignment(parent: Node$1, parentStack: Node$1[]): boolean;
|
|
1069
1071
|
export declare function isInNewExpression(parentStack: Node$1[]): boolean;
|
|
1070
1072
|
export declare function walkFunctionParams(node: Function, onIdent: (id: Identifier) => void): void;
|
|
1071
|
-
export declare function walkBlockDeclarations(block: BlockStatement$1 | Program, onIdent: (node: Identifier) => void): void;
|
|
1073
|
+
export declare function walkBlockDeclarations(block: BlockStatement$1 | SwitchCase | Program, onIdent: (node: Identifier) => void): void;
|
|
1072
1074
|
export declare function extractIdentifiers(param: Node$1, nodes?: Identifier[]): Identifier[];
|
|
1073
1075
|
export declare const isFunctionType: (node: Node$1) => node is Function;
|
|
1074
1076
|
export declare const isStaticProperty: (node?: Node$1) => node is ObjectProperty;
|
|
@@ -1104,6 +1106,8 @@ export declare function buildSlots(node: ElementNode, context: TransformContext,
|
|
|
1104
1106
|
hasDynamicSlots: boolean;
|
|
1105
1107
|
};
|
|
1106
1108
|
|
|
1109
|
+
export declare const transformVBindShorthand: NodeTransform;
|
|
1110
|
+
|
|
1107
1111
|
interface SlotOutletProcessResult {
|
|
1108
1112
|
slotName: string | ExpressionNode;
|
|
1109
1113
|
slotProps: PropsExpression | undefined;
|