2020-07-09 09:11:57 +08:00
// Jest Snapshot v1, https://goo.gl/fbAQLP
2020-11-14 06:38:28 +08:00
exports[`SFC compile <script setup> defineOptions() 1`] = `
"export default {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-14 06:38:28 +08:00
props: {
foo: String
},
emit: ['a', 'b'],
setup(__props, { props, emit }) {
const bar = 1
return { props, emit, bar }
}
}"
`;
exports[`SFC compile <script setup> errors should allow defineOptions() referencing imported binding 1`] = `
2020-11-13 07:11:25 +08:00
"import { bar } from './bar'
export default {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-13 07:11:25 +08:00
props: {
2020-07-09 09:11:57 +08:00
foo: {
default: () => bar
}
2020-11-13 07:11:25 +08:00
},
2020-11-17 07:27:15 +08:00
setup(__props) {
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 { bar }
2020-07-09 09:11:57 +08:00
}
2020-11-13 07:11:25 +08:00
}"
`;
2020-11-14 06:38:28 +08:00
exports[`SFC compile <script setup> errors should allow defineOptions() referencing scope var 1`] = `
2020-11-13 07:11:25 +08:00
"export default {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-13 07:11:25 +08:00
props: {
2020-07-09 09:11:57 +08:00
foo: {
default: bar => bar + 1
}
2020-11-13 07:11:25 +08:00
},
2020-11-17 07:27:15 +08:00
setup(__props) {
2020-07-09 09:11:57 +08:00
2020-11-13 07:11:25 +08:00
const bar = 1
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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
`;
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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-13 07:11:25 +08:00
export default {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
2020-07-09 09:11:57 +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`] = `
"import { createVNode as _createVNode, unref as _unref, toDisplayString as _toDisplayString, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
import { ref } from 'vue'
import Foo from './Foo.vue'
import other from './util'
export default {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
2020-11-13 07:11:25 +08:00
const count = ref(0)
const constant = {}
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, [
_createVNode(Foo),
_createVNode(\\"div\\", { onClick: fn }, _toDisplayString(_unref(count)) + \\" \\" + _toDisplayString(constant) + \\" \\" + _toDisplayString(_unref(other)), 1 /* TEXT */)
], 64 /* STABLE_FRAGMENT */))
}
}
}"
`;
exports[`SFC compile <script setup> inlineTemplate mode should work 1`] = `
"import { unref as _unref, toDisplayString as _toDisplayString, createVNode as _createVNode, Fragment as _Fragment, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
const _hoisted_1 = /*#__PURE__*/_createVNode(\\"div\\", null, \\"static\\", -1 /* HOISTED */)
import { ref } from 'vue'
export default {
2020-11-17 00:35:30 +08:00
expose: [],
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, [
_createVNode(\\"div\\", null, _toDisplayString(_unref(count)), 1 /* TEXT */),
_hoisted_1
], 64 /* STABLE_FRAGMENT */))
}
}
}"
2020-07-09 09:11:57 +08:00
`;
2020-11-18 04:59:09 +08:00
exports[`SFC compile <script setup> inlineTemplate mode v-model codegen with unref() 1`] = `
"import { unref as _unref, isRef as _isRef, vModelText as _vModelText, createVNode as _createVNode, withDirectives as _withDirectives, openBlock as _openBlock, createBlock as _createBlock } from \\"vue\\"
import { ref } from 'vue'
export default {
expose: [],
setup(__props) {
const count = ref(0)
return (_ctx, _cache) => {
return _withDirectives((_openBlock(), _createBlock(\\"input\\", {
\\"onUpdate:modelValue\\": _cache[1] || (_cache[1] = $event => (_isRef(count) ? (count.value = $event) : (count = $event)))
}, null, 512 /* NEED_PATCH */)), [
[_vModelText, _unref(count)]
])
}
}
}"
`;
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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
}
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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);
2020-10-30 03:03:39 +08:00
console.log(n.value, a.value, c.value, d.value, f.value, g.value)
return { n, a, c, d, f, g }
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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
`;
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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 {
2020-11-17 00:35:30 +08:00
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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 }
}
}"
`;
2020-11-14 06:38:28 +08:00
exports[`SFC compile <script setup> with TypeScript defineOptions w/ runtime options 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({
expose: [],
2020-11-13 07:11:25 +08:00
props: { foo: String },
emits: ['a', 'b'],
setup(__props, { props, emit }) {
return { props, emit }
}
})"
`;
2020-11-14 06:38:28 +08:00
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract emits (union) 1`] = `
2020-11-17 00:35:30 +08:00
"import { Slots as _Slots, defineComponent as _defineComponent } from 'vue'
2020-11-13 07:11:25 +08:00
2020-11-17 00:35:30 +08:00
export default _defineComponent({
expose: [],
2020-11-13 07:11:25 +08:00
emits: [\\"foo\\", \\"bar\\", \\"baz\\"] as unknown as undefined,
setup(__props, { emit }: {
props: {},
emit: ((e: 'foo' | 'bar') => void) | ((e: 'baz', id: number) => void),
slots: Slots,
attrs: Record<string, any>
}) {
return { emit }
}
})"
`;
2020-11-14 06:38:28 +08:00
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract emits 1`] = `
2020-11-17 00:35:30 +08:00
"import { Slots as _Slots, defineComponent as _defineComponent } from 'vue'
2020-11-13 07:11:25 +08:00
2020-11-17 00:35:30 +08:00
export default _defineComponent({
expose: [],
2020-11-13 07:11:25 +08:00
emits: [\\"foo\\", \\"bar\\"] as unknown as undefined,
setup(__props, { emit }: {
props: {},
emit: (e: 'foo' | 'bar') => void,
slots: Slots,
attrs: Record<string, any>
}) {
return { emit }
}
})"
`;
2020-11-14 06:38:28 +08:00
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract props 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({
expose: [],
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-17 07:27:15 +08:00
setup(__props) {
2020-11-13 07:11:25 +08:00
2020-11-14 06:38:28 +08:00
return { }
}
})"
`;
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({
expose: [],
2020-11-17 07:27:15 +08:00
setup(__props) {
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
`;