@vue/compiler-sfc 3.3.0-alpha.6 → 3.3.0-alpha.7
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-sfc.cjs.js +74 -36
- package/dist/compiler-sfc.esm-browser.js +75 -37
- package/package.json +6 -6
package/dist/compiler-sfc.cjs.js
CHANGED
|
@@ -3384,7 +3384,7 @@ function specifierEnd(s, end, nodeEnd) {
|
|
|
3384
3384
|
return hasCommas ? end : oldEnd;
|
|
3385
3385
|
}
|
|
3386
3386
|
|
|
3387
|
-
function transformDestructuredProps(ast, s, offset = 0, knownProps, error,
|
|
3387
|
+
function transformDestructuredProps(ast, s, offset = 0, knownProps, error, vueImportAliases) {
|
|
3388
3388
|
const rootScope = {};
|
|
3389
3389
|
const scopeStack = [rootScope];
|
|
3390
3390
|
let currentScope = rootScope;
|
|
@@ -3465,6 +3465,17 @@ function transformDestructuredProps(ast, s, offset = 0, knownProps, error, watch
|
|
|
3465
3465
|
}
|
|
3466
3466
|
return false;
|
|
3467
3467
|
}
|
|
3468
|
+
function checkUsage(node, method, alias = method) {
|
|
3469
|
+
if (compilerCore.isCallOf(node, alias)) {
|
|
3470
|
+
const arg = compilerCore.unwrapTSNode(node.arguments[0]);
|
|
3471
|
+
if (arg.type === "Identifier") {
|
|
3472
|
+
error(
|
|
3473
|
+
`"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
|
|
3474
|
+
arg
|
|
3475
|
+
);
|
|
3476
|
+
}
|
|
3477
|
+
}
|
|
3478
|
+
}
|
|
3468
3479
|
walkScope(ast, true);
|
|
3469
3480
|
estreeWalker.walk(ast, {
|
|
3470
3481
|
enter(node, parent) {
|
|
@@ -3472,15 +3483,8 @@ function transformDestructuredProps(ast, s, offset = 0, knownProps, error, watch
|
|
|
3472
3483
|
if (parent && parent.type.startsWith("TS") && parent.type !== "TSAsExpression" && parent.type !== "TSNonNullExpression" && parent.type !== "TSTypeAssertion") {
|
|
3473
3484
|
return this.skip();
|
|
3474
3485
|
}
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
if (arg.type === "Identifier") {
|
|
3478
|
-
error(
|
|
3479
|
-
`"${arg.name}" is a destructured prop and cannot be directly watched. Use a getter () => ${arg.name} instead.`,
|
|
3480
|
-
arg
|
|
3481
|
-
);
|
|
3482
|
-
}
|
|
3483
|
-
}
|
|
3486
|
+
checkUsage(node, "watch", vueImportAliases.watch);
|
|
3487
|
+
checkUsage(node, "toRef", vueImportAliases.toRef);
|
|
3484
3488
|
if (compilerCore.isFunctionType(node)) {
|
|
3485
3489
|
scopeStack.push(currentScope = {});
|
|
3486
3490
|
compilerCore.walkFunctionParams(node, registerLocalBinding);
|
|
@@ -3528,6 +3532,7 @@ const DEFINE_EMITS = "defineEmits";
|
|
|
3528
3532
|
const DEFINE_EXPOSE = "defineExpose";
|
|
3529
3533
|
const WITH_DEFAULTS = "withDefaults";
|
|
3530
3534
|
const DEFINE_OPTIONS = "defineOptions";
|
|
3535
|
+
const DEFINE_SLOTS = "defineSlots";
|
|
3531
3536
|
const isBuiltInDir = shared.makeMap(
|
|
3532
3537
|
`once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`
|
|
3533
3538
|
);
|
|
@@ -3657,6 +3662,7 @@ export default ${defaultVar}`;
|
|
|
3657
3662
|
let hasDefaultExportName = false;
|
|
3658
3663
|
let hasDefaultExportRender = false;
|
|
3659
3664
|
let hasDefineOptionsCall = false;
|
|
3665
|
+
let hasDefineSlotsCall = false;
|
|
3660
3666
|
let propsRuntimeDecl;
|
|
3661
3667
|
let propsRuntimeDefaults;
|
|
3662
3668
|
let propsDestructureDecl;
|
|
@@ -3666,7 +3672,6 @@ export default ${defaultVar}`;
|
|
|
3666
3672
|
let propsIdentifier;
|
|
3667
3673
|
let emitsRuntimeDecl;
|
|
3668
3674
|
let emitsTypeDecl;
|
|
3669
|
-
let emitsTypeDeclRaw;
|
|
3670
3675
|
let emitIdentifier;
|
|
3671
3676
|
let optionsRuntimeDecl;
|
|
3672
3677
|
let hasAwait = false;
|
|
@@ -3808,13 +3813,10 @@ ${shared.generateCodeFrame(
|
|
|
3808
3813
|
}
|
|
3809
3814
|
return true;
|
|
3810
3815
|
}
|
|
3811
|
-
function processWithDefaults(node, declId
|
|
3816
|
+
function processWithDefaults(node, declId) {
|
|
3812
3817
|
if (!CompilerDOM.isCallOf(node, WITH_DEFAULTS)) {
|
|
3813
3818
|
return false;
|
|
3814
3819
|
}
|
|
3815
|
-
warnOnce(
|
|
3816
|
-
`withDefaults() has been deprecated. Props destructure is now reactive by default - use destructure with default values instead.`
|
|
3817
|
-
);
|
|
3818
3820
|
if (processDefineProps(node.arguments[0], declId)) {
|
|
3819
3821
|
if (propsRuntimeDecl) {
|
|
3820
3822
|
error(
|
|
@@ -3830,11 +3832,8 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
3830
3832
|
);
|
|
3831
3833
|
}
|
|
3832
3834
|
propsRuntimeDefaults = node.arguments[1];
|
|
3833
|
-
if (!propsRuntimeDefaults
|
|
3834
|
-
error(
|
|
3835
|
-
`The 2nd argument of ${WITH_DEFAULTS} must be an object literal.`,
|
|
3836
|
-
propsRuntimeDefaults || node
|
|
3837
|
-
);
|
|
3835
|
+
if (!propsRuntimeDefaults) {
|
|
3836
|
+
error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
|
|
3838
3837
|
}
|
|
3839
3838
|
} else {
|
|
3840
3839
|
error(
|
|
@@ -3860,7 +3859,7 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
3860
3859
|
node
|
|
3861
3860
|
);
|
|
3862
3861
|
}
|
|
3863
|
-
emitsTypeDeclRaw = node.typeParameters.params[0];
|
|
3862
|
+
const emitsTypeDeclRaw = node.typeParameters.params[0];
|
|
3864
3863
|
emitsTypeDecl = resolveQualifiedType(
|
|
3865
3864
|
emitsTypeDeclRaw,
|
|
3866
3865
|
(node2) => node2.type === "TSFunctionType" || node2.type === "TSTypeLiteral"
|
|
@@ -3877,6 +3876,26 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
3877
3876
|
}
|
|
3878
3877
|
return true;
|
|
3879
3878
|
}
|
|
3879
|
+
function processDefineSlots(node, declId) {
|
|
3880
|
+
if (!CompilerDOM.isCallOf(node, DEFINE_SLOTS)) {
|
|
3881
|
+
return false;
|
|
3882
|
+
}
|
|
3883
|
+
if (hasDefineSlotsCall) {
|
|
3884
|
+
error(`duplicate ${DEFINE_SLOTS}() call`, node);
|
|
3885
|
+
}
|
|
3886
|
+
hasDefineSlotsCall = true;
|
|
3887
|
+
if (node.arguments.length > 0) {
|
|
3888
|
+
error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
|
|
3889
|
+
}
|
|
3890
|
+
if (declId) {
|
|
3891
|
+
s.overwrite(
|
|
3892
|
+
startOffset + node.start,
|
|
3893
|
+
startOffset + node.end,
|
|
3894
|
+
`${helper("useSlots")}()`
|
|
3895
|
+
);
|
|
3896
|
+
}
|
|
3897
|
+
return true;
|
|
3898
|
+
}
|
|
3880
3899
|
function getAstBody() {
|
|
3881
3900
|
return scriptAst ? [...scriptSetupAst.body, ...scriptAst.body] : scriptSetupAst.body;
|
|
3882
3901
|
}
|
|
@@ -3941,6 +3960,7 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
3941
3960
|
let propsOption = void 0;
|
|
3942
3961
|
let emitsOption = void 0;
|
|
3943
3962
|
let exposeOption = void 0;
|
|
3963
|
+
let slotsOption = void 0;
|
|
3944
3964
|
if (optionsRuntimeDecl.type === "ObjectExpression") {
|
|
3945
3965
|
for (const prop of optionsRuntimeDecl.properties) {
|
|
3946
3966
|
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
|
|
@@ -3950,6 +3970,8 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
3950
3970
|
emitsOption = prop;
|
|
3951
3971
|
if (prop.key.name === "expose")
|
|
3952
3972
|
exposeOption = prop;
|
|
3973
|
+
if (prop.key.name === "slots")
|
|
3974
|
+
slotsOption = prop;
|
|
3953
3975
|
}
|
|
3954
3976
|
}
|
|
3955
3977
|
}
|
|
@@ -3971,6 +3993,12 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
3971
3993
|
exposeOption
|
|
3972
3994
|
);
|
|
3973
3995
|
}
|
|
3996
|
+
if (slotsOption) {
|
|
3997
|
+
error(
|
|
3998
|
+
`${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
|
|
3999
|
+
slotsOption
|
|
4000
|
+
);
|
|
4001
|
+
}
|
|
3974
4002
|
return true;
|
|
3975
4003
|
}
|
|
3976
4004
|
function resolveQualifiedType(node, qualifier) {
|
|
@@ -4049,7 +4077,7 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
4049
4077
|
}
|
|
4050
4078
|
function hasStaticWithDefaults() {
|
|
4051
4079
|
return propsRuntimeDefaults && propsRuntimeDefaults.type === "ObjectExpression" && propsRuntimeDefaults.properties.every(
|
|
4052
|
-
(node) => node.type
|
|
4080
|
+
(node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
|
|
4053
4081
|
);
|
|
4054
4082
|
}
|
|
4055
4083
|
function genRuntimeProps(props) {
|
|
@@ -4339,7 +4367,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
|
|
|
4339
4367
|
}
|
|
4340
4368
|
if (node.type === "ExpressionStatement") {
|
|
4341
4369
|
const expr = CompilerDOM.unwrapTSNode(node.expression);
|
|
4342
|
-
if (processDefineProps(expr) || processDefineEmits(expr) || processDefineOptions(expr) || processWithDefaults(expr)) {
|
|
4370
|
+
if (processDefineProps(expr) || processDefineEmits(expr) || processDefineOptions(expr) || processWithDefaults(expr) || processDefineSlots(expr)) {
|
|
4343
4371
|
s.remove(node.start + startOffset, node.end + startOffset);
|
|
4344
4372
|
} else if (processDefineExpose(expr)) {
|
|
4345
4373
|
const callee = expr.callee;
|
|
@@ -4364,8 +4392,9 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
|
|
|
4364
4392
|
node
|
|
4365
4393
|
);
|
|
4366
4394
|
}
|
|
4367
|
-
const isDefineProps = processDefineProps(init, decl.id) || processWithDefaults(init, decl.id
|
|
4368
|
-
const isDefineEmits = processDefineEmits(init, decl.id);
|
|
4395
|
+
const isDefineProps = processDefineProps(init, decl.id) || processWithDefaults(init, decl.id);
|
|
4396
|
+
const isDefineEmits = !isDefineProps && processDefineEmits(init, decl.id);
|
|
4397
|
+
!isDefineEmits && processDefineSlots(init, decl.id);
|
|
4369
4398
|
if (isDefineProps || isDefineEmits) {
|
|
4370
4399
|
if (left === 1) {
|
|
4371
4400
|
s.remove(node.start + startOffset, node.end + startOffset);
|
|
@@ -4444,7 +4473,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
|
|
|
4444
4473
|
startOffset,
|
|
4445
4474
|
propsDestructuredBindings,
|
|
4446
4475
|
error,
|
|
4447
|
-
vueImportAliases
|
|
4476
|
+
vueImportAliases
|
|
4448
4477
|
);
|
|
4449
4478
|
}
|
|
4450
4479
|
if (enableReactivityTransform && // normal <script> had ref bindings that maybe used in <script setup>
|
|
@@ -4464,7 +4493,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
|
|
|
4464
4493
|
extractRuntimeProps(propsTypeDecl, typeDeclaredProps, declaredTypes);
|
|
4465
4494
|
}
|
|
4466
4495
|
if (emitsTypeDecl) {
|
|
4467
|
-
extractRuntimeEmits(emitsTypeDecl, typeDeclaredEmits);
|
|
4496
|
+
extractRuntimeEmits(emitsTypeDecl, typeDeclaredEmits, error);
|
|
4468
4497
|
}
|
|
4469
4498
|
checkInvalidScopeReference(propsRuntimeDecl, DEFINE_PROPS);
|
|
4470
4499
|
checkInvalidScopeReference(propsRuntimeDefaults, DEFINE_PROPS);
|
|
@@ -4573,13 +4602,6 @@ let __temp${any}, __restore${any}
|
|
|
4573
4602
|
}
|
|
4574
4603
|
if (destructureElements.length) {
|
|
4575
4604
|
args += `, { ${destructureElements.join(", ")} }`;
|
|
4576
|
-
if (emitsTypeDecl) {
|
|
4577
|
-
const content = emitsTypeDecl.__fromNormalScript ? script.content : scriptSetup.content;
|
|
4578
|
-
args += `: { emit: (${content.slice(
|
|
4579
|
-
emitsTypeDecl.start,
|
|
4580
|
-
emitsTypeDecl.end
|
|
4581
|
-
)}), expose: any, slots: any, attrs: any }`;
|
|
4582
|
-
}
|
|
4583
4605
|
}
|
|
4584
4606
|
let returned;
|
|
4585
4607
|
if (!options.inlineTemplate || !sfc.template && hasDefaultExportRender) {
|
|
@@ -5080,14 +5102,30 @@ function inferValueType(node) {
|
|
|
5080
5102
|
return "Function";
|
|
5081
5103
|
}
|
|
5082
5104
|
}
|
|
5083
|
-
function extractRuntimeEmits(node, emits) {
|
|
5105
|
+
function extractRuntimeEmits(node, emits, error) {
|
|
5084
5106
|
if (node.type === "TSTypeLiteral" || node.type === "TSInterfaceBody") {
|
|
5085
5107
|
const members = node.type === "TSTypeLiteral" ? node.members : node.body;
|
|
5108
|
+
let hasCallSignature = false;
|
|
5109
|
+
let hasProperty = false;
|
|
5086
5110
|
for (let t of members) {
|
|
5087
5111
|
if (t.type === "TSCallSignatureDeclaration") {
|
|
5088
5112
|
extractEventNames(t.parameters[0], emits);
|
|
5113
|
+
hasCallSignature = true;
|
|
5114
|
+
}
|
|
5115
|
+
if (t.type === "TSPropertySignature") {
|
|
5116
|
+
if (t.key.type !== "Identifier" || t.computed) {
|
|
5117
|
+
error(`defineEmits() type cannot use computed keys.`, t.key);
|
|
5118
|
+
}
|
|
5119
|
+
emits.add(t.key.name);
|
|
5120
|
+
hasProperty = true;
|
|
5089
5121
|
}
|
|
5090
5122
|
}
|
|
5123
|
+
if (hasCallSignature && hasProperty) {
|
|
5124
|
+
error(
|
|
5125
|
+
`defineEmits() type cannot mixed call signature and property syntax.`,
|
|
5126
|
+
node
|
|
5127
|
+
);
|
|
5128
|
+
}
|
|
5091
5129
|
return;
|
|
5092
5130
|
} else {
|
|
5093
5131
|
extractEventNames(node.parameters[0], emits);
|
|
@@ -14280,7 +14318,7 @@ function preprocess(options, preprocessor) {
|
|
|
14280
14318
|
);
|
|
14281
14319
|
}
|
|
14282
14320
|
|
|
14283
|
-
const version = "3.3.0-alpha.
|
|
14321
|
+
const version = "3.3.0-alpha.7";
|
|
14284
14322
|
const walk = estreeWalker.walk;
|
|
14285
14323
|
|
|
14286
14324
|
exports.MagicString = MagicString;
|
|
@@ -26017,7 +26017,7 @@ function stringifyElement(node, context) {
|
|
|
26017
26017
|
}
|
|
26018
26018
|
function evaluateConstant(exp) {
|
|
26019
26019
|
if (exp.type === 4) {
|
|
26020
|
-
return new Function(`return ${exp.content}`)();
|
|
26020
|
+
return new Function(`return (${exp.content})`)();
|
|
26021
26021
|
} else {
|
|
26022
26022
|
let res = ``;
|
|
26023
26023
|
exp.children.forEach((c) => {
|
|
@@ -34489,7 +34489,7 @@ function warn(msg) {
|
|
|
34489
34489
|
);
|
|
34490
34490
|
}
|
|
34491
34491
|
|
|
34492
|
-
function transformDestructuredProps(ast, s, offset = 0, knownProps, error,
|
|
34492
|
+
function transformDestructuredProps(ast, s, offset = 0, knownProps, error, vueImportAliases) {
|
|
34493
34493
|
const rootScope = {};
|
|
34494
34494
|
const scopeStack = [rootScope];
|
|
34495
34495
|
let currentScope = rootScope;
|
|
@@ -34570,6 +34570,17 @@ function transformDestructuredProps(ast, s, offset = 0, knownProps, error, watch
|
|
|
34570
34570
|
}
|
|
34571
34571
|
return false;
|
|
34572
34572
|
}
|
|
34573
|
+
function checkUsage(node, method, alias = method) {
|
|
34574
|
+
if (isCallOf(node, alias)) {
|
|
34575
|
+
const arg = unwrapTSNode(node.arguments[0]);
|
|
34576
|
+
if (arg.type === "Identifier") {
|
|
34577
|
+
error(
|
|
34578
|
+
`"${arg.name}" is a destructured prop and should not be passed directly to ${method}(). Pass a getter () => ${arg.name} instead.`,
|
|
34579
|
+
arg
|
|
34580
|
+
);
|
|
34581
|
+
}
|
|
34582
|
+
}
|
|
34583
|
+
}
|
|
34573
34584
|
walkScope(ast, true);
|
|
34574
34585
|
walk$1(ast, {
|
|
34575
34586
|
enter(node, parent) {
|
|
@@ -34577,15 +34588,8 @@ function transformDestructuredProps(ast, s, offset = 0, knownProps, error, watch
|
|
|
34577
34588
|
if (parent && parent.type.startsWith("TS") && parent.type !== "TSAsExpression" && parent.type !== "TSNonNullExpression" && parent.type !== "TSTypeAssertion") {
|
|
34578
34589
|
return this.skip();
|
|
34579
34590
|
}
|
|
34580
|
-
|
|
34581
|
-
|
|
34582
|
-
if (arg.type === "Identifier") {
|
|
34583
|
-
error(
|
|
34584
|
-
`"${arg.name}" is a destructured prop and cannot be directly watched. Use a getter () => ${arg.name} instead.`,
|
|
34585
|
-
arg
|
|
34586
|
-
);
|
|
34587
|
-
}
|
|
34588
|
-
}
|
|
34591
|
+
checkUsage(node, "watch", vueImportAliases.watch);
|
|
34592
|
+
checkUsage(node, "toRef", vueImportAliases.toRef);
|
|
34589
34593
|
if (isFunctionType(node)) {
|
|
34590
34594
|
scopeStack.push(currentScope = {});
|
|
34591
34595
|
walkFunctionParams(node, registerLocalBinding);
|
|
@@ -34652,6 +34656,7 @@ const DEFINE_EMITS = "defineEmits";
|
|
|
34652
34656
|
const DEFINE_EXPOSE = "defineExpose";
|
|
34653
34657
|
const WITH_DEFAULTS = "withDefaults";
|
|
34654
34658
|
const DEFINE_OPTIONS = "defineOptions";
|
|
34659
|
+
const DEFINE_SLOTS = "defineSlots";
|
|
34655
34660
|
const isBuiltInDir = makeMap(
|
|
34656
34661
|
`once,memo,if,for,else,else-if,slot,text,html,on,bind,model,show,cloak,is`
|
|
34657
34662
|
);
|
|
@@ -34780,6 +34785,7 @@ export default ${defaultVar}`;
|
|
|
34780
34785
|
let hasDefaultExportName = false;
|
|
34781
34786
|
let hasDefaultExportRender = false;
|
|
34782
34787
|
let hasDefineOptionsCall = false;
|
|
34788
|
+
let hasDefineSlotsCall = false;
|
|
34783
34789
|
let propsRuntimeDecl;
|
|
34784
34790
|
let propsRuntimeDefaults;
|
|
34785
34791
|
let propsDestructureDecl;
|
|
@@ -34789,7 +34795,6 @@ export default ${defaultVar}`;
|
|
|
34789
34795
|
let propsIdentifier;
|
|
34790
34796
|
let emitsRuntimeDecl;
|
|
34791
34797
|
let emitsTypeDecl;
|
|
34792
|
-
let emitsTypeDeclRaw;
|
|
34793
34798
|
let emitIdentifier;
|
|
34794
34799
|
let optionsRuntimeDecl;
|
|
34795
34800
|
let hasAwait = false;
|
|
@@ -34931,13 +34936,10 @@ ${generateCodeFrame(
|
|
|
34931
34936
|
}
|
|
34932
34937
|
return true;
|
|
34933
34938
|
}
|
|
34934
|
-
function processWithDefaults(node, declId
|
|
34939
|
+
function processWithDefaults(node, declId) {
|
|
34935
34940
|
if (!isCallOf(node, WITH_DEFAULTS)) {
|
|
34936
34941
|
return false;
|
|
34937
34942
|
}
|
|
34938
|
-
warnOnce$4(
|
|
34939
|
-
`withDefaults() has been deprecated. Props destructure is now reactive by default - use destructure with default values instead.`
|
|
34940
|
-
);
|
|
34941
34943
|
if (processDefineProps(node.arguments[0], declId)) {
|
|
34942
34944
|
if (propsRuntimeDecl) {
|
|
34943
34945
|
error(
|
|
@@ -34953,11 +34955,8 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
34953
34955
|
);
|
|
34954
34956
|
}
|
|
34955
34957
|
propsRuntimeDefaults = node.arguments[1];
|
|
34956
|
-
if (!propsRuntimeDefaults
|
|
34957
|
-
error(
|
|
34958
|
-
`The 2nd argument of ${WITH_DEFAULTS} must be an object literal.`,
|
|
34959
|
-
propsRuntimeDefaults || node
|
|
34960
|
-
);
|
|
34958
|
+
if (!propsRuntimeDefaults) {
|
|
34959
|
+
error(`The 2nd argument of ${WITH_DEFAULTS} is required.`, node);
|
|
34961
34960
|
}
|
|
34962
34961
|
} else {
|
|
34963
34962
|
error(
|
|
@@ -34983,7 +34982,7 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
34983
34982
|
node
|
|
34984
34983
|
);
|
|
34985
34984
|
}
|
|
34986
|
-
emitsTypeDeclRaw = node.typeParameters.params[0];
|
|
34985
|
+
const emitsTypeDeclRaw = node.typeParameters.params[0];
|
|
34987
34986
|
emitsTypeDecl = resolveQualifiedType(
|
|
34988
34987
|
emitsTypeDeclRaw,
|
|
34989
34988
|
(node2) => node2.type === "TSFunctionType" || node2.type === "TSTypeLiteral"
|
|
@@ -35000,6 +34999,26 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
35000
34999
|
}
|
|
35001
35000
|
return true;
|
|
35002
35001
|
}
|
|
35002
|
+
function processDefineSlots(node, declId) {
|
|
35003
|
+
if (!isCallOf(node, DEFINE_SLOTS)) {
|
|
35004
|
+
return false;
|
|
35005
|
+
}
|
|
35006
|
+
if (hasDefineSlotsCall) {
|
|
35007
|
+
error(`duplicate ${DEFINE_SLOTS}() call`, node);
|
|
35008
|
+
}
|
|
35009
|
+
hasDefineSlotsCall = true;
|
|
35010
|
+
if (node.arguments.length > 0) {
|
|
35011
|
+
error(`${DEFINE_SLOTS}() cannot accept arguments`, node);
|
|
35012
|
+
}
|
|
35013
|
+
if (declId) {
|
|
35014
|
+
s.overwrite(
|
|
35015
|
+
startOffset + node.start,
|
|
35016
|
+
startOffset + node.end,
|
|
35017
|
+
`${helper("useSlots")}()`
|
|
35018
|
+
);
|
|
35019
|
+
}
|
|
35020
|
+
return true;
|
|
35021
|
+
}
|
|
35003
35022
|
function getAstBody() {
|
|
35004
35023
|
return scriptAst ? [...scriptSetupAst.body, ...scriptAst.body] : scriptSetupAst.body;
|
|
35005
35024
|
}
|
|
@@ -35064,6 +35083,7 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
35064
35083
|
let propsOption = void 0;
|
|
35065
35084
|
let emitsOption = void 0;
|
|
35066
35085
|
let exposeOption = void 0;
|
|
35086
|
+
let slotsOption = void 0;
|
|
35067
35087
|
if (optionsRuntimeDecl.type === "ObjectExpression") {
|
|
35068
35088
|
for (const prop of optionsRuntimeDecl.properties) {
|
|
35069
35089
|
if ((prop.type === "ObjectProperty" || prop.type === "ObjectMethod") && prop.key.type === "Identifier") {
|
|
@@ -35073,6 +35093,8 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
35073
35093
|
emitsOption = prop;
|
|
35074
35094
|
if (prop.key.name === "expose")
|
|
35075
35095
|
exposeOption = prop;
|
|
35096
|
+
if (prop.key.name === "slots")
|
|
35097
|
+
slotsOption = prop;
|
|
35076
35098
|
}
|
|
35077
35099
|
}
|
|
35078
35100
|
}
|
|
@@ -35094,6 +35116,12 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
35094
35116
|
exposeOption
|
|
35095
35117
|
);
|
|
35096
35118
|
}
|
|
35119
|
+
if (slotsOption) {
|
|
35120
|
+
error(
|
|
35121
|
+
`${DEFINE_OPTIONS}() cannot be used to declare slots. Use ${DEFINE_SLOTS}() instead.`,
|
|
35122
|
+
slotsOption
|
|
35123
|
+
);
|
|
35124
|
+
}
|
|
35097
35125
|
return true;
|
|
35098
35126
|
}
|
|
35099
35127
|
function resolveQualifiedType(node, qualifier) {
|
|
@@ -35172,7 +35200,7 @@ Prefer using destructure default values, e.g. const { foo = 1 } = defineProps(..
|
|
|
35172
35200
|
}
|
|
35173
35201
|
function hasStaticWithDefaults() {
|
|
35174
35202
|
return propsRuntimeDefaults && propsRuntimeDefaults.type === "ObjectExpression" && propsRuntimeDefaults.properties.every(
|
|
35175
|
-
(node) => node.type
|
|
35203
|
+
(node) => node.type !== "SpreadElement" && (!node.computed || node.key.type.endsWith("Literal"))
|
|
35176
35204
|
);
|
|
35177
35205
|
}
|
|
35178
35206
|
function genRuntimeProps(props) {
|
|
@@ -35462,7 +35490,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
|
|
|
35462
35490
|
}
|
|
35463
35491
|
if (node.type === "ExpressionStatement") {
|
|
35464
35492
|
const expr = unwrapTSNode(node.expression);
|
|
35465
|
-
if (processDefineProps(expr) || processDefineEmits(expr) || processDefineOptions(expr) || processWithDefaults(expr)) {
|
|
35493
|
+
if (processDefineProps(expr) || processDefineEmits(expr) || processDefineOptions(expr) || processWithDefaults(expr) || processDefineSlots(expr)) {
|
|
35466
35494
|
s.remove(node.start + startOffset, node.end + startOffset);
|
|
35467
35495
|
} else if (processDefineExpose(expr)) {
|
|
35468
35496
|
const callee = expr.callee;
|
|
@@ -35487,8 +35515,9 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
|
|
|
35487
35515
|
node
|
|
35488
35516
|
);
|
|
35489
35517
|
}
|
|
35490
|
-
const isDefineProps = processDefineProps(init, decl.id) || processWithDefaults(init, decl.id
|
|
35491
|
-
const isDefineEmits = processDefineEmits(init, decl.id);
|
|
35518
|
+
const isDefineProps = processDefineProps(init, decl.id) || processWithDefaults(init, decl.id);
|
|
35519
|
+
const isDefineEmits = !isDefineProps && processDefineEmits(init, decl.id);
|
|
35520
|
+
!isDefineEmits && processDefineSlots(init, decl.id);
|
|
35492
35521
|
if (isDefineProps || isDefineEmits) {
|
|
35493
35522
|
if (left === 1) {
|
|
35494
35523
|
s.remove(node.start + startOffset, node.end + startOffset);
|
|
@@ -35567,7 +35596,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
|
|
|
35567
35596
|
startOffset,
|
|
35568
35597
|
propsDestructuredBindings,
|
|
35569
35598
|
error,
|
|
35570
|
-
vueImportAliases
|
|
35599
|
+
vueImportAliases
|
|
35571
35600
|
);
|
|
35572
35601
|
}
|
|
35573
35602
|
if (enableReactivityTransform && // normal <script> had ref bindings that maybe used in <script setup>
|
|
@@ -35587,7 +35616,7 @@ const ${normalScriptDefaultVar} = ${defaultSpecifier.local.name}
|
|
|
35587
35616
|
extractRuntimeProps(propsTypeDecl, typeDeclaredProps, declaredTypes);
|
|
35588
35617
|
}
|
|
35589
35618
|
if (emitsTypeDecl) {
|
|
35590
|
-
extractRuntimeEmits(emitsTypeDecl, typeDeclaredEmits);
|
|
35619
|
+
extractRuntimeEmits(emitsTypeDecl, typeDeclaredEmits, error);
|
|
35591
35620
|
}
|
|
35592
35621
|
checkInvalidScopeReference(propsRuntimeDecl, DEFINE_PROPS);
|
|
35593
35622
|
checkInvalidScopeReference(propsRuntimeDefaults, DEFINE_PROPS);
|
|
@@ -35696,13 +35725,6 @@ let __temp${any}, __restore${any}
|
|
|
35696
35725
|
}
|
|
35697
35726
|
if (destructureElements.length) {
|
|
35698
35727
|
args += `, { ${destructureElements.join(", ")} }`;
|
|
35699
|
-
if (emitsTypeDecl) {
|
|
35700
|
-
const content = emitsTypeDecl.__fromNormalScript ? script.content : scriptSetup.content;
|
|
35701
|
-
args += `: { emit: (${content.slice(
|
|
35702
|
-
emitsTypeDecl.start,
|
|
35703
|
-
emitsTypeDecl.end
|
|
35704
|
-
)}), expose: any, slots: any, attrs: any }`;
|
|
35705
|
-
}
|
|
35706
35728
|
}
|
|
35707
35729
|
let returned;
|
|
35708
35730
|
if (!options.inlineTemplate || !sfc.template && hasDefaultExportRender) {
|
|
@@ -36198,14 +36220,30 @@ function inferValueType(node) {
|
|
|
36198
36220
|
return "Function";
|
|
36199
36221
|
}
|
|
36200
36222
|
}
|
|
36201
|
-
function extractRuntimeEmits(node, emits) {
|
|
36223
|
+
function extractRuntimeEmits(node, emits, error) {
|
|
36202
36224
|
if (node.type === "TSTypeLiteral" || node.type === "TSInterfaceBody") {
|
|
36203
36225
|
const members = node.type === "TSTypeLiteral" ? node.members : node.body;
|
|
36226
|
+
let hasCallSignature = false;
|
|
36227
|
+
let hasProperty = false;
|
|
36204
36228
|
for (let t of members) {
|
|
36205
36229
|
if (t.type === "TSCallSignatureDeclaration") {
|
|
36206
36230
|
extractEventNames(t.parameters[0], emits);
|
|
36231
|
+
hasCallSignature = true;
|
|
36232
|
+
}
|
|
36233
|
+
if (t.type === "TSPropertySignature") {
|
|
36234
|
+
if (t.key.type !== "Identifier" || t.computed) {
|
|
36235
|
+
error(`defineEmits() type cannot use computed keys.`, t.key);
|
|
36236
|
+
}
|
|
36237
|
+
emits.add(t.key.name);
|
|
36238
|
+
hasProperty = true;
|
|
36207
36239
|
}
|
|
36208
36240
|
}
|
|
36241
|
+
if (hasCallSignature && hasProperty) {
|
|
36242
|
+
error(
|
|
36243
|
+
`defineEmits() type cannot mixed call signature and property syntax.`,
|
|
36244
|
+
node
|
|
36245
|
+
);
|
|
36246
|
+
}
|
|
36209
36247
|
return;
|
|
36210
36248
|
} else {
|
|
36211
36249
|
extractEventNames(node.parameters[0], emits);
|
|
@@ -49190,7 +49228,7 @@ function preprocess(options, preprocessor) {
|
|
|
49190
49228
|
);
|
|
49191
49229
|
}
|
|
49192
49230
|
|
|
49193
|
-
const version = "3.3.0-alpha.
|
|
49231
|
+
const version = "3.3.0-alpha.7";
|
|
49194
49232
|
const walk = walk$1;
|
|
49195
49233
|
|
|
49196
49234
|
export { MagicString, parse_1$1 as babelParse, compileScript, compileStyle, compileStyleAsync, compileTemplate, extractIdentifiers, generateCodeFrame, isInDestructureAssignment, isStaticProperty, parse$5 as parse, rewriteDefault, rewriteDefaultAST, shouldTransform as shouldTransformRef, transform as transformRef, transformAST as transformRefAST, version, walk, walkIdentifiers };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/compiler-sfc",
|
|
3
|
-
"version": "3.3.0-alpha.
|
|
3
|
+
"version": "3.3.0-alpha.7",
|
|
4
4
|
"description": "@vue/compiler-sfc",
|
|
5
5
|
"main": "dist/compiler-sfc.cjs.js",
|
|
6
6
|
"module": "dist/compiler-sfc.esm-browser.js",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"homepage": "https://github.com/vuejs/core/tree/main/packages/compiler-sfc#readme",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/parser": "^7.20.15",
|
|
36
|
-
"@vue/compiler-core": "3.3.0-alpha.
|
|
37
|
-
"@vue/compiler-dom": "3.3.0-alpha.
|
|
38
|
-
"@vue/compiler-ssr": "3.3.0-alpha.
|
|
39
|
-
"@vue/reactivity-transform": "3.3.0-alpha.
|
|
40
|
-
"@vue/shared": "3.3.0-alpha.
|
|
36
|
+
"@vue/compiler-core": "3.3.0-alpha.7",
|
|
37
|
+
"@vue/compiler-dom": "3.3.0-alpha.7",
|
|
38
|
+
"@vue/compiler-ssr": "3.3.0-alpha.7",
|
|
39
|
+
"@vue/reactivity-transform": "3.3.0-alpha.7",
|
|
40
|
+
"@vue/shared": "3.3.0-alpha.7",
|
|
41
41
|
"estree-walker": "^2.0.2",
|
|
42
42
|
"magic-string": "^0.30.0",
|
|
43
43
|
"postcss": "^8.1.10",
|