2020-07-09 09:11:57 +08:00
// Jest Snapshot v1, https://goo.gl/fbAQLP
2020-11-20 05:17:54 +08:00
exports[`SFC compile <script setup> <script> and <script setup> co-usage script first 1`] = `
"import { x } from './x'
export const n = 1
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-11-20 05:17:54 +08:00
x()
return { x }
}
}"
`;
exports[`SFC compile <script setup> <script> and <script setup> co-usage script setup first 1`] = `
"import { x } from './x'
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-11-20 05:17:54 +08:00
x()
return { x }
}
}
export const n = 1"
`;
2021-06-23 05:56:45 +08:00
exports[`SFC compile <script setup> defineEmit() (deprecated) 1`] = `
"export default {
emits: ['foo', 'bar'],
2021-06-26 01:14:49 +08:00
setup(__props, { expose, emit: myEmit }) {
expose()
2021-06-23 05:56:45 +08:00
return { myEmit }
}
}"
`;
2021-06-23 03:02:56 +08:00
exports[`SFC compile <script setup> defineEmits() 1`] = `
2020-11-14 06:38:28 +08:00
"export default {
2020-11-25 04:12:59 +08:00
emits: ['foo', 'bar'],
2021-06-26 01:14:49 +08:00
setup(__props, { expose, emit: myEmit }) {
expose()
2020-11-25 04:12:59 +08:00
2020-11-14 06:38:28 +08:00
2020-11-25 04:12:59 +08:00
return { myEmit }
}
}"
`;
2021-06-26 01:14:49 +08:00
exports[`SFC compile <script setup> defineExpose() 1`] = `
"export default {
setup(__props, { expose }) {
expose({ foo: 123 })
return { }
}
}"
`;
2021-06-26 02:05:59 +08:00
exports[`SFC compile <script setup> defineProps w/ external definition 1`] = `
"import { propsModel } from './props'
export default {
props: propsModel,
setup(__props, { expose }) {
expose()
const props = __props
return { props, propsModel }
}
}"
`;
2020-11-25 04:12:59 +08:00
exports[`SFC compile <script setup> defineProps() 1`] = `
"export default {
props: {
foo: String
},
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-11-25 04:12:59 +08:00
const props = __props
2020-11-14 06:38:28 +08:00
const bar = 1
2020-11-25 04:12:59 +08:00
return { props, bar }
2020-11-14 06:38:28 +08:00
}
}"
`;
2020-11-25 04:12:59 +08:00
exports[`SFC compile <script setup> errors should allow defineProps/Emit() referencing imported binding 1`] = `
2020-11-13 07:11:25 +08:00
"import { bar } from './bar'
2020-11-25 04:12:59 +08:00
2020-11-13 07:11:25 +08:00
export default {
props: {
2020-11-25 04:12:59 +08:00
foo: {
default: () => bar
}
},
emits: {
foo: () => bar > 1
},
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-11-25 04:12:59 +08:00
2020-11-13 07:11:25 +08:00
2020-10-30 03:03:39 +08:00
return { bar }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
`;
2020-11-25 04:12:59 +08:00
exports[`SFC compile <script setup> errors should allow defineProps/Emit() referencing scope var 1`] = `
2020-11-13 07:11:25 +08:00
"export default {
props: {
2020-11-25 04:12:59 +08:00
foo: {
default: bar => bar + 1
}
},
emits: {
foo: bar => bar > 1
},
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-11-13 07:11:25 +08:00
const bar = 1
2020-11-25 04:12:59 +08:00
2020-11-13 07:11:25 +08:00
return { bar }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> imports dedupe between user & helper 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
import { ref } from 'vue'
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-11-17 00:35:30 +08:00
const foo = _ref(1)
2020-11-13 07:11:25 +08:00
return { foo, ref }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> imports import dedupe between <script> and <script setup> 1`] = `
"import { x } from './x'
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-10-30 03:03:39 +08:00
x()
return { x }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2021-02-13 17:06:34 +08:00
exports[`SFC compile <script setup> imports should allow defineProps/Emit at the start of imports 1`] = `
"import { ref } from 'vue'
export default {
props: ['foo'],
emits: ['bar'],
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2021-02-13 17:06:34 +08:00
const r = ref(0)
return { r, ref }
}
}"
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> imports should extract comment for import or type declarations 1`] = `
"import a from 'a' // comment
2020-11-13 07:11:25 +08:00
import b from 'b'
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-11-13 07:11:25 +08:00
2020-10-30 03:03:39 +08:00
return { a, b }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> imports should hoist and expose imports 1`] = `
"import { ref } from 'vue'
2020-11-29 02:51:32 +08:00
import 'foo/css'
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-11-29 02:51:32 +08:00
2020-10-30 03:03:39 +08:00
return { ref }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
`;
exports[`SFC compile <script setup> inlineTemplate mode avoid unref() when necessary 1`] = `
2020-12-02 00:52:29 +08:00
"import { unref as _unref, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, withCtx as _withCtx, createVNode as _createVNode, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
2020-11-13 07:11:25 +08:00
import { ref } from 'vue'
2020-12-02 00:52:29 +08:00
import Foo, { bar } from './Foo.vue'
2020-11-13 07:11:25 +08:00
import other from './util'
export default {
2020-11-17 07:27:15 +08:00
setup(__props) {
2020-11-13 07:11:25 +08:00
const count = ref(0)
const constant = {}
2020-11-19 11:39:08 +08:00
const maybe = foo()
let lett = 1
2020-11-13 07:11:25 +08:00
function fn() {}
2020-11-17 07:27:15 +08:00
return (_ctx, _cache) => {
2020-11-13 07:11:25 +08:00
return (_openBlock(), _createBlock(_Fragment, null, [
2020-12-02 00:52:29 +08:00
_createVNode(Foo, null, {
default: _withCtx(() => [
_createTextVNode(_toDisplayString(_unref(bar)), 1 /* TEXT */)
]),
_: 1 /* STABLE */
}),
2020-11-19 11:39:08 +08:00
_createVNode(\\"div\\", { onClick: fn }, _toDisplayString(count.value) + \\" \\" + _toDisplayString(constant) + \\" \\" + _toDisplayString(_unref(maybe)) + \\" \\" + _toDisplayString(_unref(lett)) + \\" \\" + _toDisplayString(_unref(other)), 1 /* TEXT */)
2020-11-13 07:11:25 +08:00
], 64 /* STABLE_FRAGMENT */))
}
}
}"
`;
2020-11-24 05:32:24 +08:00
exports[`SFC compile <script setup> inlineTemplate mode referencing scope components and directives 1`] = `
"import { unref as _unref, createVNode as _createVNode, withDirectives as _withDirectives, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
import ChildComp from './Child.vue'
import SomeOtherComp from './Other.vue'
2020-11-25 08:04:03 +08:00
import myDir from './my-dir'
2020-11-24 05:32:24 +08:00
export default {
setup(__props) {
return (_ctx, _cache) => {
return (_openBlock(), _createBlock(_Fragment, null, [
_withDirectives(_createVNode(\\"div\\", null, null, 512 /* NEED_PATCH */), [
2020-11-25 08:04:03 +08:00
[_unref(myDir)]
2020-11-24 05:32:24 +08:00
]),
_createVNode(ChildComp),
_createVNode(SomeOtherComp)
], 64 /* STABLE_FRAGMENT */))
}
}
}"
`;
2021-04-02 06:11:04 +08:00
exports[`SFC compile <script setup> inlineTemplate mode should not wrap render fn with withId when having scoped styles 1`] = `
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
const _withId = /*#__PURE__*/_withScopeId(\\"data-v-xxxxxxxx\\")
export default {
setup(__props) {
const msg = 1
return (_ctx, _cache) => {
return (_openBlock(), _createBlock(\\"h1\\", null, _toDisplayString(msg)))
}
}
}"
`;
2020-11-13 07:11:25 +08:00
exports[`SFC compile <script setup> inlineTemplate mode should work 1`] = `
2020-11-19 11:39:08 +08:00
"import { toDisplayString as _toDisplayString, createVNode as _createVNode, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
2020-11-13 07:11:25 +08:00
const _hoisted_1 = /*#__PURE__*/_createVNode(\\"div\\", null, \\"static\\", -1 /* HOISTED */)
import { ref } from 'vue'
export default {
2020-11-17 07:27:15 +08:00
setup(__props) {
2020-11-13 07:11:25 +08:00
const count = ref(0)
2020-11-17 07:27:15 +08:00
return (_ctx, _cache) => {
2020-11-13 07:11:25 +08:00
return (_openBlock(), _createBlock(_Fragment, null, [
2020-11-19 11:39:08 +08:00
_createVNode(\\"div\\", null, _toDisplayString(count.value), 1 /* TEXT */),
2020-11-13 07:11:25 +08:00
_hoisted_1
], 64 /* STABLE_FRAGMENT */))
}
}
}"
2020-07-09 09:11:57 +08:00
`;
2020-11-21 03:22:51 +08:00
exports[`SFC compile <script setup> inlineTemplate mode ssr codegen 1`] = `
"import { useCssVars as _useCssVars, unref as _unref } from 'vue'
import { ssrRenderAttrs as _ssrRenderAttrs, ssrInterpolate as _ssrInterpolate } from \\"@vue/server-renderer\\"
import { ref } from 'vue'
export default {
__ssrInlineRender: true,
setup(__props) {
_useCssVars(_ctx => ({
\\"xxxxxxxx-count\\": (count.value)
}))
const count = ref(0)
return (_ctx, _push, _parent, _attrs) => {
const _cssVars = { style: {
\\"xxxxxxxx-count\\": (count.value)
}}
_push(\`<!--[--><div\${
_ssrRenderAttrs(_cssVars)
}>\${
_ssrInterpolate(count.value)
}</div><div\${
_ssrRenderAttrs(_cssVars)
}>static</div><!--]-->\`)
}
}
}"
`;
2020-11-19 08:38:18 +08:00
exports[`SFC compile <script setup> inlineTemplate mode template assignment expression codegen 1`] = `
2020-11-19 11:39:08 +08:00
"import { createVNode as _createVNode, isRef as _isRef, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
2020-11-18 04:59:09 +08:00
import { ref } from 'vue'
export default {
setup(__props) {
const count = ref(0)
2020-11-19 08:38:18 +08:00
const maybe = foo()
let lett = 1
2021-05-29 05:58:46 +08:00
let v = ref(1)
2020-11-18 04:59:09 +08:00
return (_ctx, _cache) => {
2020-11-19 08:38:18 +08:00
return (_openBlock(), _createBlock(_Fragment, null, [
_createVNode(\\"div\\", {
onClick: _cache[1] || (_cache[1] = $event => (count.value = 1))
}),
_createVNode(\\"div\\", {
2020-11-19 11:39:08 +08:00
onClick: _cache[2] || (_cache[2] = $event => (maybe.value = count.value))
}),
_createVNode(\\"div\\", {
onClick: _cache[3] || (_cache[3] = $event => (_isRef(lett) ? lett.value = count.value : lett = count.value))
2021-05-29 05:58:46 +08:00
}),
_createVNode(\\"div\\", {
onClick: _cache[4] || (_cache[4] = $event => (_isRef(v) ? v.value += 1 : v += 1))
}),
_createVNode(\\"div\\", {
onClick: _cache[5] || (_cache[5] = $event => (_isRef(v) ? v.value -= 1 : v -= 1))
2020-11-19 11:39:08 +08:00
})
], 64 /* STABLE_FRAGMENT */))
}
}
}"
`;
exports[`SFC compile <script setup> inlineTemplate mode template destructure assignment codegen 1`] = `
"import { createVNode as _createVNode, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
import { ref } from 'vue'
export default {
setup(__props) {
const val = {}
const count = ref(0)
const maybe = foo()
let lett = 1
return (_ctx, _cache) => {
return (_openBlock(), _createBlock(_Fragment, null, [
_createVNode(\\"div\\", {
onClick: _cache[1] || (_cache[1] = $event => (({ count: count.value } = val)))
}),
_createVNode(\\"div\\", {
onClick: _cache[2] || (_cache[2] = $event => ([maybe.value] = val))
2020-11-19 08:38:18 +08:00
}),
_createVNode(\\"div\\", {
2020-11-19 11:39:08 +08:00
onClick: _cache[3] || (_cache[3] = $event => (({ lett: lett } = val)))
2020-11-19 08:38:18 +08:00
})
], 64 /* STABLE_FRAGMENT */))
}
}
}"
`;
exports[`SFC compile <script setup> inlineTemplate mode template update expression codegen 1`] = `
"import { createVNode as _createVNode, isRef as _isRef, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
import { ref } from 'vue'
export default {
setup(__props) {
const count = ref(0)
const maybe = foo()
let lett = 1
return (_ctx, _cache) => {
return (_openBlock(), _createBlock(_Fragment, null, [
_createVNode(\\"div\\", {
onClick: _cache[1] || (_cache[1] = $event => (count.value++))
}),
_createVNode(\\"div\\", {
onClick: _cache[2] || (_cache[2] = $event => (--count.value))
}),
_createVNode(\\"div\\", {
2020-11-19 11:39:08 +08:00
onClick: _cache[3] || (_cache[3] = $event => (maybe.value++))
2020-11-19 08:38:18 +08:00
}),
_createVNode(\\"div\\", {
2020-11-19 11:39:08 +08:00
onClick: _cache[4] || (_cache[4] = $event => (--maybe.value))
2020-11-19 08:38:18 +08:00
}),
_createVNode(\\"div\\", {
onClick: _cache[5] || (_cache[5] = $event => (_isRef(lett) ? lett.value++ : lett++))
}),
_createVNode(\\"div\\", {
onClick: _cache[6] || (_cache[6] = $event => (_isRef(lett) ? --lett.value : --lett))
})
], 64 /* STABLE_FRAGMENT */))
}
}
}"
`;
exports[`SFC compile <script setup> inlineTemplate mode v-model codegen 1`] = `
2020-11-19 11:39:08 +08:00
"import { vModelText as _vModelText, createVNode as _createVNode, withDirectives as _withDirectives, unref as _unref, isRef as _isRef, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
2020-11-19 08:38:18 +08:00
import { ref } from 'vue'
export default {
setup(__props) {
const count = ref(0)
const maybe = foo()
let lett = 1
return (_ctx, _cache) => {
return (_openBlock(), _createBlock(_Fragment, null, [
_withDirectives(_createVNode(\\"input\\", {
\\"onUpdate:modelValue\\": _cache[1] || (_cache[1] = $event => (count.value = $event))
}, null, 512 /* NEED_PATCH */), [
2020-11-19 11:39:08 +08:00
[_vModelText, count.value]
2020-11-19 08:38:18 +08:00
]),
_withDirectives(_createVNode(\\"input\\", {
\\"onUpdate:modelValue\\": _cache[2] || (_cache[2] = $event => (_isRef(maybe) ? maybe.value = $event : null))
}, null, 512 /* NEED_PATCH */), [
[_vModelText, _unref(maybe)]
]),
_withDirectives(_createVNode(\\"input\\", {
\\"onUpdate:modelValue\\": _cache[3] || (_cache[3] = $event => (_isRef(lett) ? lett.value = $event : lett = $event))
}, null, 512 /* NEED_PATCH */), [
[_vModelText, _unref(lett)]
])
], 64 /* STABLE_FRAGMENT */))
2020-11-18 04:59:09 +08:00
}
}
}"
`;
2021-06-26 01:14:49 +08:00
exports[`SFC compile <script setup> inlineTemplate mode with defineExpose() 1`] = `
"export default {
setup(__props, { expose }) {
const count = ref(0)
expose({ count })
return () => {}
}
}"
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar accessing ref binding 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
2020-10-30 03:03:39 +08:00
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-11-17 00:35:30 +08:00
const a = _ref(1)
2020-10-30 03:03:39 +08:00
console.log(a.value)
function get() {
return a.value + 1
}
return { a, get }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar array destructure 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
2020-10-30 03:03:39 +08:00
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-10-30 03:03:39 +08:00
2020-11-17 00:35:30 +08:00
const n = _ref(1), [__a, __b = 1, ...__c] = useFoo()
const a = _ref(__a);
const b = _ref(__b);
const c = _ref(__c);
2020-10-30 03:03:39 +08:00
console.log(n.value, a.value, b.value, c.value)
return { n, a, b, c }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar convert ref declarations 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
2020-07-09 09:11:57 +08:00
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-10-30 03:03:39 +08:00
2020-11-17 00:35:30 +08:00
const foo = _ref()
const a = _ref(1)
const b = _ref({
2020-10-30 03:03:39 +08:00
count: 0
})
let c = () => {}
let d
2020-10-31 03:29:38 +08:00
return { foo, a, b, c, d }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar multi ref declarations 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
2020-10-30 03:03:39 +08:00
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-10-30 03:03:39 +08:00
2020-11-17 00:35:30 +08:00
const a = _ref(1), b = _ref(2), c = _ref({
2020-10-30 03:03:39 +08:00
count: 0
})
return { a, b, c }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar mutating ref binding 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
2020-10-30 03:03:39 +08:00
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-11-17 00:35:30 +08:00
const a = _ref(1)
const b = _ref({ count: 0 })
2020-10-30 03:03:39 +08:00
function inc() {
a.value++
a.value = a.value + 1
b.value.count++
b.value.count = b.value.count + 1
2020-11-19 11:39:08 +08:00
;({ a: a.value } = { a: 2 })
;[a.value] = [1]
2020-10-30 03:03:39 +08:00
}
return { a, b, inc }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar nested destructure 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
2020-07-09 09:11:57 +08:00
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-10-30 03:03:39 +08:00
const [{ a: { b: __b }}] = useFoo()
2020-11-17 00:35:30 +08:00
const b = _ref(__b);
2020-10-30 03:03:39 +08:00
const { c: [__d, __e] } = useBar()
2020-11-17 00:35:30 +08:00
const d = _ref(__d);
const e = _ref(__e);
2020-10-30 03:03:39 +08:00
console.log(b.value, d.value, e.value)
return { b, d, e }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar object destructure 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
2020-10-30 03:03:39 +08:00
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-10-30 03:03:39 +08:00
2020-11-17 00:35:30 +08:00
const n = _ref(1), { a: __a, b: __c, d: __d = 1, e: __f = 2, ...__g } = useFoo()
const a = _ref(__a);
const c = _ref(__c);
const d = _ref(__d);
const f = _ref(__f);
const g = _ref(__g);
2021-05-29 04:02:31 +08:00
const { foo: __foo } = useSomthing(() => 1);
const foo = _ref(__foo);
console.log(n.value, a.value, c.value, d.value, f.value, g.value, foo.value)
2020-10-30 03:03:39 +08:00
2021-05-29 04:02:31 +08:00
return { n, a, c, d, f, g, foo }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar should not convert non ref labels 1`] = `
2020-11-13 07:11:25 +08:00
"export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-10-30 03:03:39 +08:00
foo: a = 1, b = 2, c = {
count: 0
}
2020-07-09 09:11:57 +08:00
2020-09-15 22:39:27 +08:00
return { }
}
2020-11-13 07:11:25 +08:00
}"
2020-09-15 22:39:27 +08:00
`;
2021-03-26 04:16:48 +08:00
exports[`SFC compile <script setup> ref: syntax sugar should not rewrite scope variable 1`] = `
"import { ref as _ref } from 'vue'
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2021-03-26 04:16:48 +08:00
const a = _ref(1)
const b = _ref(1)
const d = _ref(1)
const e = 1
function test() {
const a = 2
console.log(a)
console.log(b.value)
let c = { c: 3 }
console.log(c)
let $d
console.log($d)
console.log(d.value)
console.log(e)
}
return { a, b, d, e, test }
}
}"
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> ref: syntax sugar using ref binding in property shorthand 1`] = `
2020-11-17 00:35:30 +08:00
"import { ref as _ref } from 'vue'
2020-09-15 22:39:27 +08:00
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-09-15 22:39:27 +08:00
2020-11-17 00:35:30 +08:00
const a = _ref(1)
2020-10-30 03:03:39 +08:00
const b = { a: a.value }
function test() {
const { a } = b
}
return { a, b, test }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
2020-07-09 09:11:57 +08:00
`;
2020-10-30 03:03:39 +08:00
exports[`SFC compile <script setup> should expose top level declarations 1`] = `
"import { x } from './x'
2020-11-13 07:11:25 +08:00
export default {
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-07-09 09:11:57 +08:00
2020-10-30 03:03:39 +08:00
let a = 1
const b = 2
function c() {}
class d {}
2020-11-13 07:11:25 +08:00
return { a, b, c, d, x }
}
}"
`;
2021-06-23 03:02:56 +08:00
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type (type literal w/ call signatures) 1`] = `
2020-11-17 00:35:30 +08:00
"import { defineComponent as _defineComponent } from 'vue'
2020-11-13 07:11:25 +08:00
2020-11-17 00:35:30 +08:00
export default _defineComponent({
2020-11-13 07:11:25 +08:00
emits: [\\"foo\\", \\"bar\\", \\"baz\\"] as unknown as undefined,
2021-06-26 01:14:49 +08:00
setup(__props, { expose, emit }: { emit: ({(e: 'foo' | 'bar'): void; (e: 'baz', id: number): void;}), expose: any, slots: any, attrs: any }) {
expose()
2020-11-13 07:11:25 +08:00
return { emit }
}
})"
`;
2021-06-23 03:02:56 +08:00
exports[`SFC compile <script setup> with TypeScript defineEmits w/ type 1`] = `
2020-11-25 04:12:59 +08:00
"import { defineComponent as _defineComponent } from 'vue'
2020-11-13 07:11:25 +08:00
2020-11-17 00:35:30 +08:00
export default _defineComponent({
2020-11-13 07:11:25 +08:00
emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
2021-06-26 01:14:49 +08:00
setup(__props, { expose, emit }: { emit: ((e: 'foo' | 'bar') => void), expose: any, slots: any, attrs: any }) {
expose()
2020-11-13 07:11:25 +08:00
return { emit }
}
})"
`;
2021-06-28 23:39:24 +08:00
exports[`SFC compile <script setup> with TypeScript defineProps w/ exported interface 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
export interface Props { x?: number }
export default _defineComponent({
props: {
x: { type: Number, required: false }
} as unknown as undefined,
setup(__props: { x?: number }, { expose }) {
expose()
return { }
}
})"
`;
exports[`SFC compile <script setup> with TypeScript defineProps w/ exported type alias 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
export type Props = { x?: number }
export default _defineComponent({
props: {
x: { type: Number, required: false }
} as unknown as undefined,
setup(__props: { x?: number }, { expose }) {
expose()
return { }
}
})"
`;
exports[`SFC compile <script setup> with TypeScript defineProps w/ interface 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
interface Props { x?: number }
export default _defineComponent({
props: {
x: { type: Number, required: false }
} as unknown as undefined,
setup(__props: { x?: number }, { expose }) {
expose()
return { }
}
})"
`;
2020-11-25 04:12:59 +08:00
exports[`SFC compile <script setup> with TypeScript defineProps w/ type 1`] = `
2020-11-17 00:35:30 +08:00
"import { defineComponent as _defineComponent } from 'vue'
2020-11-13 07:11:25 +08:00
interface Test {}
type Alias = number[]
2020-11-17 00:35:30 +08:00
export default _defineComponent({
2020-11-13 07:11:25 +08:00
props: {
string: { type: String, required: true },
number: { type: Number, required: true },
boolean: { type: Boolean, required: true },
object: { type: Object, required: true },
objectLiteral: { type: Object, required: true },
fn: { type: Function, required: true },
functionRef: { type: Function, required: true },
objectRef: { type: Object, required: true },
array: { type: Array, required: true },
arrayRef: { type: Array, required: true },
tuple: { type: Array, required: true },
set: { type: Set, required: true },
literal: { type: String, required: true },
optional: { type: null, required: false },
recordRef: { type: Object, required: true },
interface: { type: Object, required: true },
alias: { type: Array, required: true },
union: { type: [String, Number], required: true },
literalUnion: { type: [String, String], required: true },
literalUnionMixed: { type: [String, Number, Boolean], required: true },
intersection: { type: Object, required: true }
} as unknown as undefined,
2020-11-25 04:12:59 +08:00
setup(__props: {
string: string
number: number
boolean: boolean
object: object
objectLiteral: { a: number }
fn: (n: number) => void
functionRef: Function
objectRef: Object
array: string[]
arrayRef: Array<any>
tuple: [number, number]
set: Set<string>
literal: 'foo'
optional?: any
recordRef: Record<string, null>
interface: Test
alias: Alias
union: string | number
literalUnion: 'foo' | 'bar'
literalUnionMixed: 'foo' | 1 | boolean
intersection: Test & {}
2021-06-26 01:14:49 +08:00
}, { expose }) {
expose()
2020-11-13 07:11:25 +08:00
2021-06-28 23:39:24 +08:00
return { }
}
})"
`;
exports[`SFC compile <script setup> with TypeScript defineProps w/ type alias 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
type Props = { x?: number }
export default _defineComponent({
props: {
x: { type: Number, required: false }
} as unknown as undefined,
setup(__props: { x?: number }, { expose }) {
expose()
2020-11-14 06:38:28 +08:00
return { }
}
})"
`;
2020-11-25 04:12:59 +08:00
exports[`SFC compile <script setup> with TypeScript defineProps/Emit w/ runtime options 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
export default _defineComponent({
props: { foo: String },
emits: ['a', 'b'],
2021-06-26 01:14:49 +08:00
setup(__props, { expose, emit }) {
expose()
2020-11-25 04:12:59 +08:00
const props = __props
return { props, emit }
}
})"
`;
2020-11-14 06:38:28 +08:00
exports[`SFC compile <script setup> with TypeScript hoist type declarations 1`] = `
2020-11-17 00:35:30 +08:00
"import { defineComponent as _defineComponent } from 'vue'
2020-11-14 06:38:28 +08:00
export interface Foo {}
type Bar = {}
2020-11-17 00:35:30 +08:00
export default _defineComponent({
2021-06-26 01:14:49 +08:00
setup(__props, { expose }) {
expose()
2020-11-14 06:38:28 +08:00
2020-11-13 07:11:25 +08:00
return { }
}
})"
2020-07-09 09:11:57 +08:00
`;
2021-06-27 09:11:57 +08:00
exports[`SFC compile <script setup> with TypeScript withDefaults (dynamic) 1`] = `
"import { mergeDefaults as _mergeDefaults, defineComponent as _defineComponent } from 'vue'
import { defaults } from './foo'
export default _defineComponent({
props: _mergeDefaults({
foo: { type: String, required: false },
bar: { type: Number, required: false }
}, { ...defaults }) as unknown as undefined,
setup(__props: {
foo?: string
bar?: number
}, { expose }) {
expose()
const props = __props
return { props, defaults }
}
})"
`;
exports[`SFC compile <script setup> with TypeScript withDefaults (static) 1`] = `
"import { defineComponent as _defineComponent } from 'vue'
export default _defineComponent({
props: {
foo: { type: String, required: false, default: 'hi' },
bar: { type: Number, required: false }
} as unknown as undefined,
setup(__props: {
foo?: string
bar?: number
}, { expose }) {
expose()
const props = __props
return { props }
}
})"
`;