Skip to content

Commit 1ff5960

Browse files
committed
wip: useOptions -> defineOptions
1 parent 91d990d commit 1ff5960

File tree

6 files changed

+123
-124
lines changed

6 files changed

+123
-124
lines changed

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

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,25 @@ return { color }
5656
}"
5757
`;
5858
59-
exports[`SFC compile <script setup> errors should allow useOptions() referencing imported binding 1`] = `
59+
exports[`SFC compile <script setup> defineOptions() 1`] = `
60+
"export default {
61+
props: {
62+
foo: String
63+
},
64+
emit: ['a', 'b'],
65+
setup(__props, { props, emit }) {
66+
67+
68+
69+
const bar = 1
70+
71+
return { props, emit, bar }
72+
}
73+
74+
}"
75+
`;
76+
77+
exports[`SFC compile <script setup> errors should allow defineOptions() referencing imported binding 1`] = `
6078
"import { bar } from './bar'
6179
6280
export default {
@@ -75,7 +93,7 @@ return { bar }
7593
}"
7694
`;
7795
78-
exports[`SFC compile <script setup> errors should allow useOptions() referencing scope var 1`] = `
96+
exports[`SFC compile <script setup> errors should allow defineOptions() referencing scope var 1`] = `
7997
"export default {
8098
props: {
8199
foo: {
@@ -375,40 +393,7 @@ return { a, b, c, d, x }
375393
}"
376394
`;
377395
378-
exports[`SFC compile <script setup> useOptions() 1`] = `
379-
"export default {
380-
props: {
381-
foo: String
382-
},
383-
emit: ['a', 'b'],
384-
setup(__props, { props, emit }) {
385-
386-
387-
388-
const bar = 1
389-
390-
return { props, emit, bar }
391-
}
392-
393-
}"
394-
`;
395-
396-
exports[`SFC compile <script setup> with TypeScript hoist type declarations 1`] = `
397-
"import { defineComponent } from 'vue'
398-
export interface Foo {}
399-
type Bar = {}
400-
401-
export default defineComponent({
402-
setup() {
403-
404-
405-
return { }
406-
}
407-
408-
})"
409-
`;
410-
411-
exports[`SFC compile <script setup> with TypeScript useOptions w/ runtime options 1`] = `
396+
exports[`SFC compile <script setup> with TypeScript defineOptions w/ runtime options 1`] = `
412397
"import { defineComponent } from 'vue'
413398
414399
@@ -425,7 +410,7 @@ return { props, emit }
425410
})"
426411
`;
427412
428-
exports[`SFC compile <script setup> with TypeScript useOptions w/ type / extract emits (union) 1`] = `
413+
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract emits (union) 1`] = `
429414
"import { Slots, defineComponent } from 'vue'
430415
431416
@@ -446,7 +431,7 @@ return { emit }
446431
})"
447432
`;
448433
449-
exports[`SFC compile <script setup> with TypeScript useOptions w/ type / extract emits 1`] = `
434+
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract emits 1`] = `
450435
"import { Slots, defineComponent } from 'vue'
451436
452437
@@ -467,7 +452,7 @@ return { emit }
467452
})"
468453
`;
469454
470-
exports[`SFC compile <script setup> with TypeScript useOptions w/ type / extract props 1`] = `
455+
exports[`SFC compile <script setup> with TypeScript defineOptions w/ type / extract props 1`] = `
471456
"import { defineComponent } from 'vue'
472457
473458
interface Test {}
@@ -503,6 +488,21 @@ export default defineComponent({
503488
504489
505490
491+
return { }
492+
}
493+
494+
})"
495+
`;
496+
497+
exports[`SFC compile <script setup> with TypeScript hoist type declarations 1`] = `
498+
"import { defineComponent } from 'vue'
499+
export interface Foo {}
500+
type Bar = {}
501+
502+
export default defineComponent({
503+
setup() {
504+
505+
506506
return { }
507507
}
508508

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ describe('SFC compile <script setup>', () => {
3636
expect(content).toMatch('return { a, b, c, d, x }')
3737
})
3838

39-
test('useOptions()', () => {
39+
test('defineOptions()', () => {
4040
const { content, bindings } = compile(`
4141
<script setup>
42-
import { useOptions } from 'vue'
43-
const { props, emit } = useOptions({
42+
import { defineOptions } from 'vue'
43+
const { props, emit } = defineOptions({
4444
props: {
4545
foo: String
4646
},
@@ -60,8 +60,8 @@ const bar = 1
6060
emit: 'const'
6161
})
6262

63-
// should remove useOptions import and call
64-
expect(content).not.toMatch('useOptions')
63+
// should remove defineOptions import and call
64+
expect(content).not.toMatch('defineOptions')
6565
// should generate correct setup signature
6666
expect(content).toMatch(`setup(__props, { props, emit }) {`)
6767
// should include context options in default export
@@ -143,7 +143,7 @@ const bar = 1
143143
const { content } = compile(
144144
`
145145
<script setup>
146-
import { ref, useOptions } from 'vue'
146+
import { ref, defineOptions } from 'vue'
147147
import Foo from './Foo.vue'
148148
import other from './util'
149149
const count = ref(0)
@@ -183,11 +183,11 @@ const bar = 1
183183
assertCode(content)
184184
})
185185

186-
test('useOptions w/ runtime options', () => {
186+
test('defineOptions w/ runtime options', () => {
187187
const { content } = compile(`
188188
<script setup lang="ts">
189-
import { useOptions } from 'vue'
190-
const { props, emit } = useOptions({
189+
import { defineOptions } from 'vue'
190+
const { props, emit } = defineOptions({
191191
props: { foo: String },
192192
emits: ['a', 'b']
193193
})
@@ -200,15 +200,15 @@ const { props, emit } = useOptions({
200200
setup(__props, { props, emit }) {`)
201201
})
202202

203-
test('useOptions w/ type / extract props', () => {
203+
test('defineOptions w/ type / extract props', () => {
204204
const { content, bindings } = compile(`
205205
<script setup lang="ts">
206-
import { useOptions } from 'vue'
206+
import { defineOptions } from 'vue'
207207
interface Test {}
208208
209209
type Alias = number[]
210210
211-
useOptions<{
211+
defineOptions<{
212212
props: {
213213
string: string
214214
number: number
@@ -288,11 +288,11 @@ const { props, emit } = useOptions({
288288
})
289289
})
290290

291-
test('useOptions w/ type / extract emits', () => {
291+
test('defineOptions w/ type / extract emits', () => {
292292
const { content } = compile(`
293293
<script setup lang="ts">
294-
import { useOptions } from 'vue'
295-
const { emit } = useOptions<{
294+
import { defineOptions } from 'vue'
295+
const { emit } = defineOptions<{
296296
emit: (e: 'foo' | 'bar') => void
297297
}>()
298298
</script>
@@ -302,11 +302,11 @@ const { props, emit } = useOptions({
302302
expect(content).toMatch(`emits: ["foo", "bar"] as unknown as undefined`)
303303
})
304304

305-
test('useOptions w/ type / extract emits (union)', () => {
305+
test('defineOptions w/ type / extract emits (union)', () => {
306306
const { content } = compile(`
307307
<script setup lang="ts">
308-
import { useOptions } from 'vue'
309-
const { emit } = useOptions<{
308+
import { defineOptions } from 'vue'
309+
const { emit } = defineOptions<{
310310
emit: ((e: 'foo' | 'bar') => void) | ((e: 'baz', id: number) => void)
311311
}>()
312312
</script>
@@ -633,21 +633,21 @@ const { props, emit } = useOptions({
633633
).toThrow(`ref: statements can only contain assignment expressions`)
634634
})
635635

636-
test('useOptions() w/ both type and non-type args', () => {
636+
test('defineOptions() w/ both type and non-type args', () => {
637637
expect(() => {
638638
compile(`<script setup lang="ts">
639-
import { useOptions } from 'vue'
640-
useOptions<{}>({})
639+
import { defineOptions } from 'vue'
640+
defineOptions<{}>({})
641641
</script>`)
642642
}).toThrow(`cannot accept both type and non-type arguments`)
643643
})
644644

645-
test('useOptions() referencing local var', () => {
645+
test('defineOptions() referencing local var', () => {
646646
expect(() =>
647647
compile(`<script setup>
648-
import { useOptions } from 'vue'
648+
import { defineOptions } from 'vue'
649649
const bar = 1
650-
useOptions({
650+
defineOptions({
651651
props: {
652652
foo: {
653653
default: () => bar
@@ -658,24 +658,24 @@ const { props, emit } = useOptions({
658658
).toThrow(`cannot reference locally declared variables`)
659659
})
660660

661-
test('useOptions() referencing ref declarations', () => {
661+
test('defineOptions() referencing ref declarations', () => {
662662
expect(() =>
663663
compile(`<script setup>
664-
import { useOptions } from 'vue'
664+
import { defineOptions } from 'vue'
665665
ref: bar = 1
666-
useOptions({
666+
defineOptions({
667667
props: { bar }
668668
})
669669
</script>`)
670670
).toThrow(`cannot reference locally declared variables`)
671671
})
672672

673-
test('should allow useOptions() referencing scope var', () => {
673+
test('should allow defineOptions() referencing scope var', () => {
674674
assertCode(
675675
compile(`<script setup>
676-
import { useOptions } from 'vue'
676+
import { defineOptions } from 'vue'
677677
const bar = 1
678-
useOptions({
678+
defineOptions({
679679
props: {
680680
foo: {
681681
default: bar => bar + 1
@@ -686,12 +686,12 @@ const { props, emit } = useOptions({
686686
)
687687
})
688688

689-
test('should allow useOptions() referencing imported binding', () => {
689+
test('should allow defineOptions() referencing imported binding', () => {
690690
assertCode(
691691
compile(`<script setup>
692-
import { useOptions } from 'vue'
692+
import { defineOptions } from 'vue'
693693
import { bar } from './bar'
694-
useOptions({
694+
defineOptions({
695695
props: {
696696
foo: {
697697
default: () => bar
@@ -901,8 +901,8 @@ describe('SFC analyze <script> bindings', () => {
901901
it('works for script setup', () => {
902902
const { bindings } = compile(`
903903
<script setup>
904-
import { useOptions } from 'vue'
905-
useOptions({
904+
import { defineOptions } from 'vue'
905+
defineOptions({
906906
props: {
907907
foo: String,
908908
}

0 commit comments

Comments
 (0)