Skip to content

Commit 904020a

Browse files
committed
chore: minor tweaks
2 parents 4b1a872 + 4bf546f commit 904020a

File tree

2 files changed

+246
-24
lines changed

2 files changed

+246
-24
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

Lines changed: 235 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,28 @@ return (_ctx, _cache) => {
823823
}"
824824
`;
825825

826-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > should alias $props to __props when $props is used 1`] = `
826+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > should alias __emit to $emit when defineEmits is used 1`] = `
827+
"import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
828+
829+
830+
export default {
831+
emits: ['click'],
832+
setup(__props, { emit: __emit }) {
833+
const $emit = __emit
834+
835+
const emit = __emit
836+
837+
return (_ctx, _cache) => {
838+
return (_openBlock(), _createElementBlock("div", {
839+
onClick: _cache[0] || (_cache[0] = $event => ($emit('click')))
840+
}))
841+
}
842+
}
843+
844+
}"
845+
`;
846+
847+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > should alias __props to $props when $props is used 1`] = `
827848
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
828849

829850

@@ -839,7 +860,192 @@ return (_ctx, _cache) => {
839860
}"
840861
`;
841862

842-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > should alias __emit to $emit when defineEmits is used 1`] = `
863+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > should extract all built-in properties when they are used 1`] = `
864+
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
865+
866+
867+
export default {
868+
setup(__props, { emit: $emit, attrs: $attrs, slots: $slots }) {
869+
const $props = __props
870+
/* ... */
871+
return (_ctx, _cache) => {
872+
return (_openBlock(), _createElementBlock("div", null, _toDisplayString($props) + _toDisplayString($slots) + _toDisplayString($emit) + _toDisplayString($attrs), 1 /* TEXT */))
873+
}
874+
}
875+
876+
}"
877+
`;
878+
879+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > should extract attrs when $attrs is used 1`] = `
880+
"import { normalizeProps as _normalizeProps, guardReactiveProps as _guardReactiveProps, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
881+
882+
883+
export default {
884+
setup(__props, { attrs: $attrs }) {
885+
/* ... */
886+
return (_ctx, _cache) => {
887+
return (_openBlock(), _createElementBlock("div", _normalizeProps(_guardReactiveProps($attrs)), null, 16 /* FULL_PROPS */))
888+
}
889+
}
890+
891+
}"
892+
`;
893+
894+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > should extract emit when $emit is used 1`] = `
895+
"import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
896+
897+
898+
export default {
899+
setup(__props, { emit: $emit }) {
900+
/* ... */
901+
return (_ctx, _cache) => {
902+
return (_openBlock(), _createElementBlock("div", {
903+
onClick: _cache[0] || (_cache[0] = $event => ($emit('click')))
904+
}))
905+
}
906+
}
907+
908+
}"
909+
`;
910+
911+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > should extract slots when $slots is used 1`] = `
912+
"import { resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock } from "vue"
913+
914+
915+
export default {
916+
setup(__props, { slots: $slots }) {
917+
/* ... */
918+
return (_ctx, _cache) => {
919+
const _component_Comp = _resolveComponent("Comp")
920+
921+
return (_openBlock(), _createBlock(_component_Comp, {
922+
foo: $slots.foo
923+
}, null, 8 /* PROPS */, ["foo"]))
924+
}
925+
}
926+
927+
}"
928+
`;
929+
930+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > should not extract built-in properties when neither is used 1`] = `
931+
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
932+
933+
934+
export default {
935+
setup(__props) {
936+
/* ... */
937+
return (_ctx, _cache) => {
938+
return (_openBlock(), _createElementBlock("div", null, _toDisplayString(_ctx.msg), 1 /* TEXT */))
939+
}
940+
}
941+
942+
}"
943+
`;
944+
945+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > user-defined properties override > should handle mixed defineEmits and user-defined $emit 1`] = `
946+
"import { unref as _unref, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
947+
948+
949+
export default {
950+
emits: ['click'],
951+
setup(__props, { emit: __emit }) {
952+
953+
const emit = __emit
954+
let $emit
955+
956+
return (_ctx, _cache) => {
957+
return (_openBlock(), _createElementBlock("div", {
958+
onClick: _cache[0] || (_cache[0] = $event => (_unref($emit)('click')))
959+
}, "click"))
960+
}
961+
}
962+
963+
}"
964+
`;
965+
966+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > user-defined properties override > should not extract $attrs when user defines it 1`] = `
967+
"import { unref as _unref, normalizeProps as _normalizeProps, guardReactiveProps as _guardReactiveProps, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
968+
969+
970+
export default {
971+
setup(__props) {
972+
let $attrs
973+
return (_ctx, _cache) => {
974+
return (_openBlock(), _createElementBlock("div", _normalizeProps(_guardReactiveProps(_unref($attrs))), null, 16 /* FULL_PROPS */))
975+
}
976+
}
977+
978+
}"
979+
`;
980+
981+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > user-defined properties override > should not extract $emit when user defines it 1`] = `
982+
"import { unref as _unref, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
983+
984+
985+
export default {
986+
setup(__props) {
987+
let $emit
988+
return (_ctx, _cache) => {
989+
return (_openBlock(), _createElementBlock("div", {
990+
onClick: _cache[0] || (_cache[0] = $event => (_unref($emit)('click')))
991+
}, "click"))
992+
}
993+
}
994+
995+
}"
996+
`;
997+
998+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > user-defined properties override > should not extract $slots when user defines it 1`] = `
999+
"import { unref as _unref, resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock } from "vue"
1000+
1001+
1002+
export default {
1003+
setup(__props) {
1004+
let $slots
1005+
return (_ctx, _cache) => {
1006+
const _component_Comp = _resolveComponent("Comp")
1007+
1008+
return (_openBlock(), _createBlock(_component_Comp, {
1009+
foo: _unref($slots).foo
1010+
}, null, 8 /* PROPS */, ["foo"]))
1011+
}
1012+
}
1013+
1014+
}"
1015+
`;
1016+
1017+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > user-defined properties override > should not generate $props alias when user defines it 1`] = `
1018+
"import { unref as _unref, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
1019+
1020+
1021+
export default {
1022+
setup(__props) {
1023+
let $props
1024+
return (_ctx, _cache) => {
1025+
return (_openBlock(), _createElementBlock("div", null, _toDisplayString(_unref($props).msg), 1 /* TEXT */))
1026+
}
1027+
}
1028+
1029+
}"
1030+
`;
1031+
1032+
exports[`SFC compile <script setup> > inlineTemplate mode > destructure setup context for built-in properties > user-defined properties override > should only extract non-user-defined properties 1`] = `
1033+
"import { unref as _unref, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
1034+
1035+
1036+
export default {
1037+
setup(__props, { emit: $emit, slots: $slots }) {
1038+
const $props = __props
1039+
let $attrs
1040+
return (_ctx, _cache) => {
1041+
return (_openBlock(), _createElementBlock("div", null, _toDisplayString(_unref($attrs)) + _toDisplayString($slots) + _toDisplayString($emit) + _toDisplayString($props), 1 /* TEXT */))
1042+
}
1043+
}
1044+
1045+
}"
1046+
`;
1047+
1048+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > should alias __emit to $emit when defineEmits is used 1`] = `
8431049
"import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
8441050

8451051

@@ -860,7 +1066,23 @@ return (_ctx, _cache) => {
8601066
}"
8611067
`;
8621068

863-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > should destructure all built-in properties when they are used 1`] = `
1069+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > should alias __props to $props when $props is used 1`] = `
1070+
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
1071+
1072+
1073+
export default {
1074+
setup(__props) {
1075+
const $props = __props
1076+
/* ... */
1077+
return (_ctx, _cache) => {
1078+
return (_openBlock(), _createElementBlock("div", null, _toDisplayString($props), 1 /* TEXT */))
1079+
}
1080+
}
1081+
1082+
}"
1083+
`;
1084+
1085+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > should extract all built-in properties when they are used 1`] = `
8641086
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
8651087

8661088

@@ -876,7 +1098,7 @@ return (_ctx, _cache) => {
8761098
}"
8771099
`;
8781100

879-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > should destructure attrs when $attrs is used 1`] = `
1101+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > should extract attrs when $attrs is used 1`] = `
8801102
"import { normalizeProps as _normalizeProps, guardReactiveProps as _guardReactiveProps, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
8811103

8821104

@@ -891,7 +1113,7 @@ return (_ctx, _cache) => {
8911113
}"
8921114
`;
8931115

894-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > should destructure emit when $emit is used 1`] = `
1116+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > should extract emit when $emit is used 1`] = `
8951117
"import { openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
8961118

8971119

@@ -908,7 +1130,7 @@ return (_ctx, _cache) => {
9081130
}"
9091131
`;
9101132

911-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > should destructure slots when $slots is used 1`] = `
1133+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > should extract slots when $slots is used 1`] = `
9121134
"import { resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock } from "vue"
9131135

9141136

@@ -927,7 +1149,7 @@ return (_ctx, _cache) => {
9271149
}"
9281150
`;
9291151

930-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > should not destructure built-in properties when neither is used 1`] = `
1152+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > should not extract built-in properties when neither is used 1`] = `
9311153
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
9321154

9331155

@@ -942,7 +1164,7 @@ return (_ctx, _cache) => {
9421164
}"
9431165
`;
9441166

945-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > user-defined properties override > should handle mixed defineEmits and user-defined $emit 1`] = `
1167+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > user-defined properties override > should handle mixed defineEmits and user-defined $emit 1`] = `
9461168
"import { unref as _unref, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
9471169

9481170

@@ -963,7 +1185,7 @@ return (_ctx, _cache) => {
9631185
}"
9641186
`;
9651187

966-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > user-defined properties override > should not destructure $attrs when user defines it 1`] = `
1188+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > user-defined properties override > should not extract $attrs when user defines it 1`] = `
9671189
"import { unref as _unref, normalizeProps as _normalizeProps, guardReactiveProps as _guardReactiveProps, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
9681190

9691191

@@ -978,7 +1200,7 @@ return (_ctx, _cache) => {
9781200
}"
9791201
`;
9801202

981-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > user-defined properties override > should not destructure $emit when user defines it 1`] = `
1203+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > user-defined properties override > should not extract $emit when user defines it 1`] = `
9821204
"import { unref as _unref, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
9831205

9841206

@@ -995,7 +1217,7 @@ return (_ctx, _cache) => {
9951217
}"
9961218
`;
9971219

998-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > user-defined properties override > should not destructure $slots when user defines it 1`] = `
1220+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > user-defined properties override > should not extract $slots when user defines it 1`] = `
9991221
"import { unref as _unref, resolveComponent as _resolveComponent, openBlock as _openBlock, createBlock as _createBlock } from "vue"
10001222

10011223

@@ -1014,7 +1236,7 @@ return (_ctx, _cache) => {
10141236
}"
10151237
`;
10161238

1017-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > user-defined properties override > should not generate $props alias when user defines it 1`] = `
1239+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > user-defined properties override > should not generate $props alias when user defines it 1`] = `
10181240
"import { unref as _unref, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
10191241

10201242

@@ -1029,7 +1251,7 @@ return (_ctx, _cache) => {
10291251
}"
10301252
`;
10311253

1032-
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring component instance for built-in properties > user-defined properties override > should only destructure non-user-defined properties 1`] = `
1254+
exports[`SFC compile <script setup> > inlineTemplate mode > destructuring setup context for built-in properties > user-defined properties override > should only extract non-user-defined properties 1`] = `
10331255
"import { unref as _unref, toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock } from "vue"
10341256

10351257

0 commit comments

Comments
 (0)