@vue/compiler-core 3.5.16 → 3.6.0-alpha.1
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 +118 -44
- package/dist/compiler-core.cjs.prod.js +118 -44
- package/dist/compiler-core.d.ts +38 -15
- package/dist/compiler-core.esm-bundler.js +105 -37
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @vue/compiler-core v3.
|
|
2
|
+
* @vue/compiler-core v3.6.0-alpha.1
|
|
3
3
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
4
4
|
* @license MIT
|
|
5
5
|
**/
|
|
@@ -1063,7 +1063,7 @@ class Tokenizer {
|
|
|
1063
1063
|
this.buffer = input;
|
|
1064
1064
|
while (this.index < this.buffer.length) {
|
|
1065
1065
|
const c = this.buffer.charCodeAt(this.index);
|
|
1066
|
-
if (c === 10) {
|
|
1066
|
+
if (c === 10 && this.state !== 33) {
|
|
1067
1067
|
this.newlines.push(this.index);
|
|
1068
1068
|
}
|
|
1069
1069
|
switch (this.state) {
|
|
@@ -1731,7 +1731,7 @@ function markScopeIdentifier(node, child, knownIds) {
|
|
|
1731
1731
|
const isFunctionType = (node) => {
|
|
1732
1732
|
return /Function(?:Expression|Declaration)$|Method$/.test(node.type);
|
|
1733
1733
|
};
|
|
1734
|
-
const isStaticProperty = (node) => node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
|
|
1734
|
+
const isStaticProperty = (node) => !!node && (node.type === "ObjectProperty" || node.type === "ObjectMethod") && !node.computed;
|
|
1735
1735
|
const isStaticPropertyKey = (node, parent) => isStaticProperty(parent) && parent.key === node;
|
|
1736
1736
|
function isReferenced(node, parent, grandparent) {
|
|
1737
1737
|
switch (parent.type) {
|
|
@@ -1890,6 +1890,59 @@ function unwrapTSNode(node) {
|
|
|
1890
1890
|
return node;
|
|
1891
1891
|
}
|
|
1892
1892
|
}
|
|
1893
|
+
function isStaticNode(node) {
|
|
1894
|
+
node = unwrapTSNode(node);
|
|
1895
|
+
switch (node.type) {
|
|
1896
|
+
case "UnaryExpression":
|
|
1897
|
+
return isStaticNode(node.argument);
|
|
1898
|
+
case "LogicalExpression":
|
|
1899
|
+
// 1 > 2
|
|
1900
|
+
case "BinaryExpression":
|
|
1901
|
+
return isStaticNode(node.left) && isStaticNode(node.right);
|
|
1902
|
+
case "ConditionalExpression": {
|
|
1903
|
+
return isStaticNode(node.test) && isStaticNode(node.consequent) && isStaticNode(node.alternate);
|
|
1904
|
+
}
|
|
1905
|
+
case "SequenceExpression":
|
|
1906
|
+
// (1, 2)
|
|
1907
|
+
case "TemplateLiteral":
|
|
1908
|
+
return node.expressions.every((expr) => isStaticNode(expr));
|
|
1909
|
+
case "ParenthesizedExpression":
|
|
1910
|
+
return isStaticNode(node.expression);
|
|
1911
|
+
case "StringLiteral":
|
|
1912
|
+
case "NumericLiteral":
|
|
1913
|
+
case "BooleanLiteral":
|
|
1914
|
+
case "NullLiteral":
|
|
1915
|
+
case "BigIntLiteral":
|
|
1916
|
+
return true;
|
|
1917
|
+
}
|
|
1918
|
+
return false;
|
|
1919
|
+
}
|
|
1920
|
+
function isConstantNode(node, bindings) {
|
|
1921
|
+
if (isStaticNode(node)) return true;
|
|
1922
|
+
node = unwrapTSNode(node);
|
|
1923
|
+
switch (node.type) {
|
|
1924
|
+
case "Identifier":
|
|
1925
|
+
const type = bindings[node.name];
|
|
1926
|
+
return type === "literal-const";
|
|
1927
|
+
case "RegExpLiteral":
|
|
1928
|
+
return true;
|
|
1929
|
+
case "ObjectExpression":
|
|
1930
|
+
return node.properties.every((prop) => {
|
|
1931
|
+
if (prop.type === "ObjectMethod") return false;
|
|
1932
|
+
if (prop.type === "SpreadElement")
|
|
1933
|
+
return isConstantNode(prop.argument, bindings);
|
|
1934
|
+
return (!prop.computed || isConstantNode(prop.key, bindings)) && isConstantNode(prop.value, bindings);
|
|
1935
|
+
});
|
|
1936
|
+
case "ArrayExpression":
|
|
1937
|
+
return node.elements.every((element) => {
|
|
1938
|
+
if (element === null) return true;
|
|
1939
|
+
if (element.type === "SpreadElement")
|
|
1940
|
+
return isConstantNode(element.argument, bindings);
|
|
1941
|
+
return isConstantNode(element, bindings);
|
|
1942
|
+
});
|
|
1943
|
+
}
|
|
1944
|
+
return false;
|
|
1945
|
+
}
|
|
1893
1946
|
|
|
1894
1947
|
const isStaticExp = (p) => p.type === 4 && p.isStatic;
|
|
1895
1948
|
function isCoreComponent(tag) {
|
|
@@ -2779,7 +2832,7 @@ function isUpperCase(c) {
|
|
|
2779
2832
|
return c > 64 && c < 91;
|
|
2780
2833
|
}
|
|
2781
2834
|
const windowsNewlineRE = /\r\n/g;
|
|
2782
|
-
function condenseWhitespace(nodes
|
|
2835
|
+
function condenseWhitespace(nodes) {
|
|
2783
2836
|
const shouldCondense = currentOptions.whitespace !== "preserve";
|
|
2784
2837
|
let removedWhitespace = false;
|
|
2785
2838
|
for (let i = 0; i < nodes.length; i++) {
|
|
@@ -2958,12 +3011,12 @@ function cacheStatic(root, context) {
|
|
|
2958
3011
|
context,
|
|
2959
3012
|
// Root node is unfortunately non-hoistable due to potential parent
|
|
2960
3013
|
// fallthrough attributes.
|
|
2961
|
-
|
|
3014
|
+
!!getSingleElementRoot(root)
|
|
2962
3015
|
);
|
|
2963
3016
|
}
|
|
2964
|
-
function
|
|
2965
|
-
const
|
|
2966
|
-
return children.length === 1 &&
|
|
3017
|
+
function getSingleElementRoot(root) {
|
|
3018
|
+
const children = root.children.filter((x) => x.type !== 3);
|
|
3019
|
+
return children.length === 1 && children[0].type === 1 && !isSlotOutlet(children[0]) ? children[0] : null;
|
|
2967
3020
|
}
|
|
2968
3021
|
function walk(node, parent, context, doNotHoistNode = false, inFor = false) {
|
|
2969
3022
|
const { children } = node;
|
|
@@ -3248,6 +3301,10 @@ function getNodeProps(node) {
|
|
|
3248
3301
|
}
|
|
3249
3302
|
}
|
|
3250
3303
|
|
|
3304
|
+
function getSelfName(filename) {
|
|
3305
|
+
const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
|
|
3306
|
+
return nameMatch ? shared.capitalize(shared.camelize(nameMatch[1])) : null;
|
|
3307
|
+
}
|
|
3251
3308
|
function createTransformContext(root, {
|
|
3252
3309
|
filename = "",
|
|
3253
3310
|
prefixIdentifiers = false,
|
|
@@ -3272,11 +3329,10 @@ function createTransformContext(root, {
|
|
|
3272
3329
|
onWarn = defaultOnWarn,
|
|
3273
3330
|
compatConfig
|
|
3274
3331
|
}) {
|
|
3275
|
-
const nameMatch = filename.replace(/\?.*$/, "").match(/([^/\\]+)\.\w+$/);
|
|
3276
3332
|
const context = {
|
|
3277
3333
|
// options
|
|
3278
3334
|
filename,
|
|
3279
|
-
selfName:
|
|
3335
|
+
selfName: getSelfName(filename),
|
|
3280
3336
|
prefixIdentifiers,
|
|
3281
3337
|
hoistStatic,
|
|
3282
3338
|
hmr,
|
|
@@ -3443,15 +3499,15 @@ function createRootCodegen(root, context) {
|
|
|
3443
3499
|
const { helper } = context;
|
|
3444
3500
|
const { children } = root;
|
|
3445
3501
|
if (children.length === 1) {
|
|
3446
|
-
const
|
|
3447
|
-
if (
|
|
3448
|
-
const codegenNode =
|
|
3502
|
+
const singleElementRootChild = getSingleElementRoot(root);
|
|
3503
|
+
if (singleElementRootChild && singleElementRootChild.codegenNode) {
|
|
3504
|
+
const codegenNode = singleElementRootChild.codegenNode;
|
|
3449
3505
|
if (codegenNode.type === 13) {
|
|
3450
3506
|
convertToBlock(codegenNode, context);
|
|
3451
3507
|
}
|
|
3452
3508
|
root.codegenNode = codegenNode;
|
|
3453
3509
|
} else {
|
|
3454
|
-
root.codegenNode =
|
|
3510
|
+
root.codegenNode = children[0];
|
|
3455
3511
|
}
|
|
3456
3512
|
} else if (children.length > 1) {
|
|
3457
3513
|
let patchFlag = 64;
|
|
@@ -3558,6 +3614,16 @@ function createStructuralDirectiveTransform(name, fn) {
|
|
|
3558
3614
|
|
|
3559
3615
|
const PURE_ANNOTATION = `/*@__PURE__*/`;
|
|
3560
3616
|
const aliasHelper = (s) => `${helperNameMap[s]}: _${helperNameMap[s]}`;
|
|
3617
|
+
const NewlineType = {
|
|
3618
|
+
"Start": 0,
|
|
3619
|
+
"0": "Start",
|
|
3620
|
+
"End": -1,
|
|
3621
|
+
"-1": "End",
|
|
3622
|
+
"None": -2,
|
|
3623
|
+
"-2": "None",
|
|
3624
|
+
"Unknown": -3,
|
|
3625
|
+
"-3": "Unknown"
|
|
3626
|
+
};
|
|
3561
3627
|
function createCodegenContext(ast, {
|
|
3562
3628
|
mode = "function",
|
|
3563
3629
|
prefixIdentifiers = mode === "module",
|
|
@@ -3596,7 +3662,7 @@ function createCodegenContext(ast, {
|
|
|
3596
3662
|
helper(key) {
|
|
3597
3663
|
return `_${helperNameMap[key]}`;
|
|
3598
3664
|
},
|
|
3599
|
-
push(code, newlineIndex = -2
|
|
3665
|
+
push(code, newlineIndex = -2, node) {
|
|
3600
3666
|
context.code += code;
|
|
3601
3667
|
if (context.map) {
|
|
3602
3668
|
if (node) {
|
|
@@ -3611,14 +3677,14 @@ function createCodegenContext(ast, {
|
|
|
3611
3677
|
addMapping(node.loc.start, name);
|
|
3612
3678
|
}
|
|
3613
3679
|
}
|
|
3614
|
-
if (newlineIndex === -3
|
|
3680
|
+
if (newlineIndex === -3) {
|
|
3615
3681
|
advancePositionWithMutation(context, code);
|
|
3616
3682
|
} else {
|
|
3617
3683
|
context.offset += code.length;
|
|
3618
|
-
if (newlineIndex === -2
|
|
3684
|
+
if (newlineIndex === -2) {
|
|
3619
3685
|
context.column += code.length;
|
|
3620
3686
|
} else {
|
|
3621
|
-
if (newlineIndex === -1
|
|
3687
|
+
if (newlineIndex === -1) {
|
|
3622
3688
|
newlineIndex = code.length - 1;
|
|
3623
3689
|
}
|
|
3624
3690
|
context.line++;
|
|
@@ -3645,7 +3711,7 @@ function createCodegenContext(ast, {
|
|
|
3645
3711
|
}
|
|
3646
3712
|
};
|
|
3647
3713
|
function newline(n) {
|
|
3648
|
-
context.push("\n" + ` `.repeat(n), 0
|
|
3714
|
+
context.push("\n" + ` `.repeat(n), 0);
|
|
3649
3715
|
}
|
|
3650
3716
|
function addMapping(loc, name = null) {
|
|
3651
3717
|
const { _names, _mappings } = context.map;
|
|
@@ -3710,7 +3776,7 @@ function generate(ast, options = {}) {
|
|
|
3710
3776
|
push(
|
|
3711
3777
|
`const { ${helpers.map(aliasHelper).join(", ")} } = _Vue
|
|
3712
3778
|
`,
|
|
3713
|
-
-1
|
|
3779
|
+
-1
|
|
3714
3780
|
);
|
|
3715
3781
|
newline();
|
|
3716
3782
|
}
|
|
@@ -3740,7 +3806,7 @@ function generate(ast, options = {}) {
|
|
|
3740
3806
|
}
|
|
3741
3807
|
if (ast.components.length || ast.directives.length || ast.temps) {
|
|
3742
3808
|
push(`
|
|
3743
|
-
`, 0
|
|
3809
|
+
`, 0);
|
|
3744
3810
|
newline();
|
|
3745
3811
|
}
|
|
3746
3812
|
if (!ssr) {
|
|
@@ -3761,7 +3827,8 @@ function generate(ast, options = {}) {
|
|
|
3761
3827
|
ast,
|
|
3762
3828
|
code: context.code,
|
|
3763
3829
|
preamble: isSetupInlined ? preambleContext.code : ``,
|
|
3764
|
-
map: context.map ? context.map.toJSON() : void 0
|
|
3830
|
+
map: context.map ? context.map.toJSON() : void 0,
|
|
3831
|
+
helpers: ast.helpers
|
|
3765
3832
|
};
|
|
3766
3833
|
}
|
|
3767
3834
|
function genFunctionPreamble(ast, context) {
|
|
@@ -3781,11 +3848,11 @@ function genFunctionPreamble(ast, context) {
|
|
|
3781
3848
|
push(
|
|
3782
3849
|
`const { ${helpers.map(aliasHelper).join(", ")} } = ${VueBinding}
|
|
3783
3850
|
`,
|
|
3784
|
-
-1
|
|
3851
|
+
-1
|
|
3785
3852
|
);
|
|
3786
3853
|
} else {
|
|
3787
3854
|
push(`const _Vue = ${VueBinding}
|
|
3788
|
-
`, -1
|
|
3855
|
+
`, -1);
|
|
3789
3856
|
if (ast.hoists.length) {
|
|
3790
3857
|
const staticHelpers = [
|
|
3791
3858
|
CREATE_VNODE,
|
|
@@ -3795,7 +3862,7 @@ function genFunctionPreamble(ast, context) {
|
|
|
3795
3862
|
CREATE_STATIC
|
|
3796
3863
|
].filter((helper) => helpers.includes(helper)).map(aliasHelper).join(", ");
|
|
3797
3864
|
push(`const { ${staticHelpers} } = _Vue
|
|
3798
|
-
`, -1
|
|
3865
|
+
`, -1);
|
|
3799
3866
|
}
|
|
3800
3867
|
}
|
|
3801
3868
|
}
|
|
@@ -3803,7 +3870,7 @@ function genFunctionPreamble(ast, context) {
|
|
|
3803
3870
|
push(
|
|
3804
3871
|
`const { ${ast.ssrHelpers.map(aliasHelper).join(", ")} } = require("${ssrRuntimeModuleName}")
|
|
3805
3872
|
`,
|
|
3806
|
-
-1
|
|
3873
|
+
-1
|
|
3807
3874
|
);
|
|
3808
3875
|
}
|
|
3809
3876
|
genHoists(ast.hoists, context);
|
|
@@ -3824,20 +3891,20 @@ function genModulePreamble(ast, context, genScopeId, inline) {
|
|
|
3824
3891
|
push(
|
|
3825
3892
|
`import { ${helpers.map((s) => helperNameMap[s]).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
|
|
3826
3893
|
`,
|
|
3827
|
-
-1
|
|
3894
|
+
-1
|
|
3828
3895
|
);
|
|
3829
3896
|
push(
|
|
3830
3897
|
`
|
|
3831
3898
|
// Binding optimization for webpack code-split
|
|
3832
3899
|
const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(", ")}
|
|
3833
3900
|
`,
|
|
3834
|
-
-1
|
|
3901
|
+
-1
|
|
3835
3902
|
);
|
|
3836
3903
|
} else {
|
|
3837
3904
|
push(
|
|
3838
3905
|
`import { ${helpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from ${JSON.stringify(runtimeModuleName)}
|
|
3839
3906
|
`,
|
|
3840
|
-
-1
|
|
3907
|
+
-1
|
|
3841
3908
|
);
|
|
3842
3909
|
}
|
|
3843
3910
|
}
|
|
@@ -3845,7 +3912,7 @@ const ${helpers.map((s) => `_${helperNameMap[s]} = ${helperNameMap[s]}`).join(",
|
|
|
3845
3912
|
push(
|
|
3846
3913
|
`import { ${ast.ssrHelpers.map((s) => `${helperNameMap[s]} as _${helperNameMap[s]}`).join(", ")} } from "${ssrRuntimeModuleName}"
|
|
3847
3914
|
`,
|
|
3848
|
-
-1
|
|
3915
|
+
-1
|
|
3849
3916
|
);
|
|
3850
3917
|
}
|
|
3851
3918
|
if (ast.imports.length) {
|
|
@@ -3920,7 +3987,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
|
|
|
3920
3987
|
for (let i = 0; i < nodes.length; i++) {
|
|
3921
3988
|
const node = nodes[i];
|
|
3922
3989
|
if (shared.isString(node)) {
|
|
3923
|
-
push(node, -3
|
|
3990
|
+
push(node, -3);
|
|
3924
3991
|
} else if (shared.isArray(node)) {
|
|
3925
3992
|
genNodeListAsArray(node, context);
|
|
3926
3993
|
} else {
|
|
@@ -3938,7 +4005,7 @@ function genNodeList(nodes, context, multilines = false, comma = true) {
|
|
|
3938
4005
|
}
|
|
3939
4006
|
function genNode(node, context) {
|
|
3940
4007
|
if (shared.isString(node)) {
|
|
3941
|
-
context.push(node, -3
|
|
4008
|
+
context.push(node, -3);
|
|
3942
4009
|
return;
|
|
3943
4010
|
}
|
|
3944
4011
|
if (shared.isSymbol(node)) {
|
|
@@ -4012,13 +4079,13 @@ function genNode(node, context) {
|
|
|
4012
4079
|
}
|
|
4013
4080
|
}
|
|
4014
4081
|
function genText(node, context) {
|
|
4015
|
-
context.push(JSON.stringify(node.content), -3
|
|
4082
|
+
context.push(JSON.stringify(node.content), -3, node);
|
|
4016
4083
|
}
|
|
4017
4084
|
function genExpression(node, context) {
|
|
4018
4085
|
const { content, isStatic } = node;
|
|
4019
4086
|
context.push(
|
|
4020
4087
|
isStatic ? JSON.stringify(content) : content,
|
|
4021
|
-
-3
|
|
4088
|
+
-3,
|
|
4022
4089
|
node
|
|
4023
4090
|
);
|
|
4024
4091
|
}
|
|
@@ -4033,7 +4100,7 @@ function genCompoundExpression(node, context) {
|
|
|
4033
4100
|
for (let i = 0; i < node.children.length; i++) {
|
|
4034
4101
|
const child = node.children[i];
|
|
4035
4102
|
if (shared.isString(child)) {
|
|
4036
|
-
context.push(child, -3
|
|
4103
|
+
context.push(child, -3);
|
|
4037
4104
|
} else {
|
|
4038
4105
|
genNode(child, context);
|
|
4039
4106
|
}
|
|
@@ -4047,9 +4114,9 @@ function genExpressionAsPropertyKey(node, context) {
|
|
|
4047
4114
|
push(`]`);
|
|
4048
4115
|
} else if (node.isStatic) {
|
|
4049
4116
|
const text = isSimpleIdentifier(node.content) ? node.content : JSON.stringify(node.content);
|
|
4050
|
-
push(text, -2
|
|
4117
|
+
push(text, -2, node);
|
|
4051
4118
|
} else {
|
|
4052
|
-
push(`[${node.content}]`, -3
|
|
4119
|
+
push(`[${node.content}]`, -3, node);
|
|
4053
4120
|
}
|
|
4054
4121
|
}
|
|
4055
4122
|
function genComment(node, context) {
|
|
@@ -4059,7 +4126,7 @@ function genComment(node, context) {
|
|
|
4059
4126
|
}
|
|
4060
4127
|
push(
|
|
4061
4128
|
`${helper(CREATE_COMMENT)}(${JSON.stringify(node.content)})`,
|
|
4062
|
-
-3
|
|
4129
|
+
-3,
|
|
4063
4130
|
node
|
|
4064
4131
|
);
|
|
4065
4132
|
}
|
|
@@ -4092,7 +4159,7 @@ function genVNodeCall(node, context) {
|
|
|
4092
4159
|
push(PURE_ANNOTATION);
|
|
4093
4160
|
}
|
|
4094
4161
|
const callHelper = isBlock ? getVNodeBlockHelper(context.inSSR, isComponent) : getVNodeHelper(context.inSSR, isComponent);
|
|
4095
|
-
push(helper(callHelper) + `(`, -2
|
|
4162
|
+
push(helper(callHelper) + `(`, -2, node);
|
|
4096
4163
|
genNodeList(
|
|
4097
4164
|
genNullableArgs([tag, props, children, patchFlagString, dynamicProps]),
|
|
4098
4165
|
context
|
|
@@ -4120,7 +4187,7 @@ function genCallExpression(node, context) {
|
|
|
4120
4187
|
if (pure) {
|
|
4121
4188
|
push(PURE_ANNOTATION);
|
|
4122
4189
|
}
|
|
4123
|
-
push(callee + `(`, -2
|
|
4190
|
+
push(callee + `(`, -2, node);
|
|
4124
4191
|
genNodeList(node.arguments, context);
|
|
4125
4192
|
push(`)`);
|
|
4126
4193
|
}
|
|
@@ -4128,7 +4195,7 @@ function genObjectExpression(node, context) {
|
|
|
4128
4195
|
const { push, indent, deindent, newline } = context;
|
|
4129
4196
|
const { properties } = node;
|
|
4130
4197
|
if (!properties.length) {
|
|
4131
|
-
push(`{}`, -2
|
|
4198
|
+
push(`{}`, -2, node);
|
|
4132
4199
|
return;
|
|
4133
4200
|
}
|
|
4134
4201
|
const multilines = properties.length > 1 || properties.some((p) => p.value.type !== 4);
|
|
@@ -4156,7 +4223,7 @@ function genFunctionExpression(node, context) {
|
|
|
4156
4223
|
if (isSlot) {
|
|
4157
4224
|
push(`_${helperNameMap[WITH_CTX]}(`);
|
|
4158
4225
|
}
|
|
4159
|
-
push(`(`, -2
|
|
4226
|
+
push(`(`, -2, node);
|
|
4160
4227
|
if (shared.isArray(params)) {
|
|
4161
4228
|
genNodeList(params, context);
|
|
4162
4229
|
} else if (params) {
|
|
@@ -4263,7 +4330,7 @@ function genTemplateLiteral(node, context) {
|
|
|
4263
4330
|
for (let i = 0; i < l; i++) {
|
|
4264
4331
|
const e = node.elements[i];
|
|
4265
4332
|
if (shared.isString(e)) {
|
|
4266
|
-
push(e.replace(/(`|\$|\\)/g, "\\$1"), -3
|
|
4333
|
+
push(e.replace(/(`|\$|\\)/g, "\\$1"), -3);
|
|
4267
4334
|
} else {
|
|
4268
4335
|
push("${");
|
|
4269
4336
|
if (multilines) indent();
|
|
@@ -5205,7 +5272,7 @@ function buildSlots(node, context, buildSlotFn = buildClientSlotFn) {
|
|
|
5205
5272
|
let prev;
|
|
5206
5273
|
while (j--) {
|
|
5207
5274
|
prev = children[j];
|
|
5208
|
-
if (prev.type !== 3) {
|
|
5275
|
+
if (prev.type !== 3 && isNonWhitespaceContent(prev)) {
|
|
5209
5276
|
break;
|
|
5210
5277
|
}
|
|
5211
5278
|
}
|
|
@@ -6591,6 +6658,7 @@ exports.NORMALIZE_CLASS = NORMALIZE_CLASS;
|
|
|
6591
6658
|
exports.NORMALIZE_PROPS = NORMALIZE_PROPS;
|
|
6592
6659
|
exports.NORMALIZE_STYLE = NORMALIZE_STYLE;
|
|
6593
6660
|
exports.Namespaces = Namespaces;
|
|
6661
|
+
exports.NewlineType = NewlineType;
|
|
6594
6662
|
exports.NodeTypes = NodeTypes;
|
|
6595
6663
|
exports.OPEN_BLOCK = OPEN_BLOCK;
|
|
6596
6664
|
exports.POP_SCOPE_ID = POP_SCOPE_ID;
|
|
@@ -6644,6 +6712,8 @@ exports.createStructuralDirectiveTransform = createStructuralDirectiveTransform;
|
|
|
6644
6712
|
exports.createTemplateLiteral = createTemplateLiteral;
|
|
6645
6713
|
exports.createTransformContext = createTransformContext;
|
|
6646
6714
|
exports.createVNodeCall = createVNodeCall;
|
|
6715
|
+
exports.defaultOnError = defaultOnError;
|
|
6716
|
+
exports.defaultOnWarn = defaultOnWarn;
|
|
6647
6717
|
exports.errorMessages = errorMessages;
|
|
6648
6718
|
exports.extractIdentifiers = extractIdentifiers;
|
|
6649
6719
|
exports.findDir = findDir;
|
|
@@ -6653,12 +6723,14 @@ exports.generate = generate;
|
|
|
6653
6723
|
exports.getBaseTransformPreset = getBaseTransformPreset;
|
|
6654
6724
|
exports.getConstantType = getConstantType;
|
|
6655
6725
|
exports.getMemoedVNodeCall = getMemoedVNodeCall;
|
|
6726
|
+
exports.getSelfName = getSelfName;
|
|
6656
6727
|
exports.getVNodeBlockHelper = getVNodeBlockHelper;
|
|
6657
6728
|
exports.getVNodeHelper = getVNodeHelper;
|
|
6658
6729
|
exports.hasDynamicKeyVBind = hasDynamicKeyVBind;
|
|
6659
6730
|
exports.hasScopeRef = hasScopeRef;
|
|
6660
6731
|
exports.helperNameMap = helperNameMap;
|
|
6661
6732
|
exports.injectProp = injectProp;
|
|
6733
|
+
exports.isConstantNode = isConstantNode;
|
|
6662
6734
|
exports.isCoreComponent = isCoreComponent;
|
|
6663
6735
|
exports.isFnExpression = isFnExpression;
|
|
6664
6736
|
exports.isFnExpressionBrowser = isFnExpressionBrowser;
|
|
@@ -6666,6 +6738,7 @@ exports.isFnExpressionNode = isFnExpressionNode;
|
|
|
6666
6738
|
exports.isFunctionType = isFunctionType;
|
|
6667
6739
|
exports.isInDestructureAssignment = isInDestructureAssignment;
|
|
6668
6740
|
exports.isInNewExpression = isInNewExpression;
|
|
6741
|
+
exports.isLiteralWhitelisted = isLiteralWhitelisted;
|
|
6669
6742
|
exports.isMemberExpression = isMemberExpression;
|
|
6670
6743
|
exports.isMemberExpressionBrowser = isMemberExpressionBrowser;
|
|
6671
6744
|
exports.isMemberExpressionNode = isMemberExpressionNode;
|
|
@@ -6674,6 +6747,7 @@ exports.isSimpleIdentifier = isSimpleIdentifier;
|
|
|
6674
6747
|
exports.isSlotOutlet = isSlotOutlet;
|
|
6675
6748
|
exports.isStaticArgOf = isStaticArgOf;
|
|
6676
6749
|
exports.isStaticExp = isStaticExp;
|
|
6750
|
+
exports.isStaticNode = isStaticNode;
|
|
6677
6751
|
exports.isStaticProperty = isStaticProperty;
|
|
6678
6752
|
exports.isStaticPropertyKey = isStaticPropertyKey;
|
|
6679
6753
|
exports.isTemplateNode = isTemplateNode;
|
package/dist/compiler-core.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare function baseParse(input: string, options?: ParserOptions): RootN
|
|
|
59
59
|
type CompilerCompatConfig = Partial<Record<CompilerDeprecationTypes, boolean | 'suppress-warning'>> & {
|
|
60
60
|
MODE?: 2 | 3;
|
|
61
61
|
};
|
|
62
|
-
interface CompilerCompatOptions {
|
|
62
|
+
export interface CompilerCompatOptions {
|
|
63
63
|
compatConfig?: CompilerCompatConfig;
|
|
64
64
|
}
|
|
65
65
|
export declare enum CompilerDeprecationTypes {
|
|
@@ -124,6 +124,7 @@ export interface TransformContext extends Required<Omit<TransformOptions, keyof
|
|
|
124
124
|
constantCache: WeakMap<TemplateChildNode, ConstantTypes>;
|
|
125
125
|
filters?: Set<string>;
|
|
126
126
|
}
|
|
127
|
+
export declare function getSelfName(filename: string): string | null;
|
|
127
128
|
export declare function createTransformContext(root: RootNode, { filename, prefixIdentifiers, hoistStatic, hmr, cacheHandlers, nodeTransforms, directiveTransforms, transformHoist, isBuiltInComponent, isCustomElement, expressionPlugins, scopeId, slotted, ssr, inSSR, ssrCssVars, bindingMetadata, inline, isTS, onError, onWarn, compatConfig, }: TransformOptions): TransformContext;
|
|
128
129
|
export declare function transform(root: RootNode, options: TransformOptions): void;
|
|
129
130
|
export declare function traverseNode(node: RootNode | TemplateChildNode, context: TransformContext): void;
|
|
@@ -196,6 +197,7 @@ export interface Position {
|
|
|
196
197
|
line: number;
|
|
197
198
|
column: number;
|
|
198
199
|
}
|
|
200
|
+
export type AllNode = ParentNode | ExpressionNode | TemplateChildNode | AttributeNode | DirectiveNode;
|
|
199
201
|
export type ParentNode = RootNode | ElementNode | IfBranchNode | ForNode;
|
|
200
202
|
export type ExpressionNode = SimpleExpressionNode | CompoundExpressionNode;
|
|
201
203
|
export type TemplateChildNode = ElementNode | InterpolationNode | CompoundExpressionNode | TextNode | CommentNode | IfNode | IfBranchNode | ForNode | TextCallNode;
|
|
@@ -565,6 +567,8 @@ export interface CompilerError extends SyntaxError {
|
|
|
565
567
|
export interface CoreCompilerError extends CompilerError {
|
|
566
568
|
code: ErrorCodes;
|
|
567
569
|
}
|
|
570
|
+
export declare function defaultOnError(error: CompilerError): never;
|
|
571
|
+
export declare function defaultOnWarn(msg: CompilerError): void;
|
|
568
572
|
type InferCompilerError<T> = T extends ErrorCodes ? CoreCompilerError : CompilerError;
|
|
569
573
|
export declare function createCompilerError<T extends number>(code: T, loc?: SourceLocation, messages?: {
|
|
570
574
|
[code: number]: string;
|
|
@@ -772,6 +776,12 @@ interface SharedTransformCodegenOptions {
|
|
|
772
776
|
* @default mode === 'module'
|
|
773
777
|
*/
|
|
774
778
|
prefixIdentifiers?: boolean;
|
|
779
|
+
/**
|
|
780
|
+
* A list of parser plugins to enable for `@babel/parser`, which is used to
|
|
781
|
+
* parse expressions in bindings and interpolations.
|
|
782
|
+
* https://babeljs.io/docs/en/next/babel-parser#plugins
|
|
783
|
+
*/
|
|
784
|
+
expressionPlugins?: ParserPlugin[];
|
|
775
785
|
/**
|
|
776
786
|
* Control whether generate SSR-optimized render functions instead.
|
|
777
787
|
* The resulting function must be attached to the component via the
|
|
@@ -866,12 +876,6 @@ export interface TransformOptions extends SharedTransformCodegenOptions, ErrorHa
|
|
|
866
876
|
* @default false
|
|
867
877
|
*/
|
|
868
878
|
cacheHandlers?: boolean;
|
|
869
|
-
/**
|
|
870
|
-
* A list of parser plugins to enable for `@babel/parser`, which is used to
|
|
871
|
-
* parse expressions in bindings and interpolations.
|
|
872
|
-
* https://babeljs.io/docs/en/next/babel-parser#plugins
|
|
873
|
-
*/
|
|
874
|
-
expressionPlugins?: ParserPlugin[];
|
|
875
879
|
/**
|
|
876
880
|
* SFC scoped styles ID
|
|
877
881
|
*/
|
|
@@ -976,13 +980,28 @@ interface MappingItem {
|
|
|
976
980
|
name: string | null;
|
|
977
981
|
}
|
|
978
982
|
type CodegenNode = TemplateChildNode | JSChildNode | SSRCodegenNode;
|
|
979
|
-
export interface
|
|
983
|
+
export interface BaseCodegenResult {
|
|
980
984
|
code: string;
|
|
981
985
|
preamble: string;
|
|
982
|
-
ast:
|
|
986
|
+
ast: unknown;
|
|
983
987
|
map?: RawSourceMap;
|
|
988
|
+
helpers?: Set<string> | Set<symbol>;
|
|
989
|
+
}
|
|
990
|
+
export interface CodegenResult extends BaseCodegenResult {
|
|
991
|
+
ast: RootNode;
|
|
992
|
+
helpers: Set<symbol>;
|
|
984
993
|
}
|
|
985
|
-
export
|
|
994
|
+
export declare enum NewlineType {
|
|
995
|
+
/** Start with `\n` */
|
|
996
|
+
Start = 0,
|
|
997
|
+
/** Ends with `\n` */
|
|
998
|
+
End = -1,
|
|
999
|
+
/** No `\n` included */
|
|
1000
|
+
None = -2,
|
|
1001
|
+
/** Don't know, calc it */
|
|
1002
|
+
Unknown = -3
|
|
1003
|
+
}
|
|
1004
|
+
export interface CodegenContext extends Omit<Required<CodegenOptions>, 'bindingMetadata' | 'inline' | 'vaporRuntimeModuleName' | 'expressionPlugins'> {
|
|
986
1005
|
source: string;
|
|
987
1006
|
code: string;
|
|
988
1007
|
line: number;
|
|
@@ -1018,14 +1037,15 @@ export declare const isSimpleIdentifier: (name: string) => boolean;
|
|
|
1018
1037
|
* expressions and false positives are invalid expressions in the first place.
|
|
1019
1038
|
*/
|
|
1020
1039
|
export declare const isMemberExpressionBrowser: (exp: ExpressionNode) => boolean;
|
|
1021
|
-
export declare const isMemberExpressionNode: (exp: ExpressionNode, context: TransformContext) => boolean;
|
|
1022
|
-
export declare const isMemberExpression: (exp: ExpressionNode, context: TransformContext) => boolean;
|
|
1040
|
+
export declare const isMemberExpressionNode: (exp: ExpressionNode, context: Pick<TransformContext, 'expressionPlugins'>) => boolean;
|
|
1041
|
+
export declare const isMemberExpression: (exp: ExpressionNode, context: Pick<TransformContext, 'expressionPlugins'>) => boolean;
|
|
1023
1042
|
export declare const isFnExpressionBrowser: (exp: ExpressionNode) => boolean;
|
|
1024
|
-
export declare const isFnExpressionNode: (exp: ExpressionNode, context: TransformContext) => boolean;
|
|
1025
|
-
export declare const isFnExpression: (exp: ExpressionNode, context: TransformContext) => boolean;
|
|
1043
|
+
export declare const isFnExpressionNode: (exp: ExpressionNode, context: Pick<TransformContext, 'expressionPlugins'>) => boolean;
|
|
1044
|
+
export declare const isFnExpression: (exp: ExpressionNode, context: Pick<TransformContext, 'expressionPlugins'>) => boolean;
|
|
1026
1045
|
export declare function advancePositionWithClone(pos: Position, source: string, numberOfCharacters?: number): Position;
|
|
1027
1046
|
export declare function advancePositionWithMutation(pos: Position, source: string, numberOfCharacters?: number): Position;
|
|
1028
1047
|
export declare function assert(condition: boolean, msg?: string): void;
|
|
1048
|
+
/** find directive */
|
|
1029
1049
|
export declare function findDir(node: ElementNode, name: string | RegExp, allowEmpty?: boolean): DirectiveNode | undefined;
|
|
1030
1050
|
export declare function findProp(node: ElementNode, name: string, dynamicOnly?: boolean, allowEmpty?: boolean): ElementNode['props'][0] | undefined;
|
|
1031
1051
|
export declare function isStaticArgOf(arg: DirectiveNode['arg'], name: string): boolean;
|
|
@@ -1051,10 +1071,12 @@ export declare function walkFunctionParams(node: Function, onIdent: (id: Identif
|
|
|
1051
1071
|
export declare function walkBlockDeclarations(block: BlockStatement$1 | Program, onIdent: (node: Identifier) => void): void;
|
|
1052
1072
|
export declare function extractIdentifiers(param: Node$1, nodes?: Identifier[]): Identifier[];
|
|
1053
1073
|
export declare const isFunctionType: (node: Node$1) => node is Function;
|
|
1054
|
-
export declare const isStaticProperty: (node
|
|
1074
|
+
export declare const isStaticProperty: (node?: Node$1) => node is ObjectProperty;
|
|
1055
1075
|
export declare const isStaticPropertyKey: (node: Node$1, parent: Node$1) => boolean;
|
|
1056
1076
|
export declare const TS_NODE_TYPES: string[];
|
|
1057
1077
|
export declare function unwrapTSNode(node: Node$1): Node$1;
|
|
1078
|
+
export declare function isStaticNode(node: Node$1): boolean;
|
|
1079
|
+
export declare function isConstantNode(node: Node$1, bindings: BindingMetadata): boolean;
|
|
1058
1080
|
|
|
1059
1081
|
export declare const transformModel: DirectiveTransform;
|
|
1060
1082
|
|
|
@@ -1069,6 +1091,7 @@ export declare function processIf(node: ElementNode, dir: DirectiveNode, context
|
|
|
1069
1091
|
export declare function processFor(node: ElementNode, dir: DirectiveNode, context: TransformContext, processCodegen?: (forNode: ForNode) => (() => void) | undefined): (() => void) | undefined;
|
|
1070
1092
|
export declare function createForLoopParams({ value, key, index }: ForParseResult, memoArgs?: ExpressionNode[]): ExpressionNode[];
|
|
1071
1093
|
|
|
1094
|
+
export declare const isLiteralWhitelisted: (key: string) => boolean;
|
|
1072
1095
|
export declare const transformExpression: NodeTransform;
|
|
1073
1096
|
export declare function processExpression(node: SimpleExpressionNode, context: TransformContext, asParams?: boolean, asRawStatements?: boolean, localVars?: Record<string, number>): ExpressionNode;
|
|
1074
1097
|
export declare function stringifyExpression(exp: ExpressionNode | string): string;
|