@@ -36,11 +36,11 @@ describe('SFC compile <script setup>', () => {
36
36
expect ( content ) . toMatch ( 'return { a, b, c, d, x }' )
37
37
} )
38
38
39
- test ( 'useOptions ()' , ( ) => {
39
+ test ( 'defineOptions ()' , ( ) => {
40
40
const { content, bindings } = compile ( `
41
41
<script setup>
42
- import { useOptions } from 'vue'
43
- const { props, emit } = useOptions ({
42
+ import { defineOptions } from 'vue'
43
+ const { props, emit } = defineOptions ({
44
44
props: {
45
45
foo: String
46
46
},
@@ -60,8 +60,8 @@ const bar = 1
60
60
emit : 'const'
61
61
} )
62
62
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 ' )
65
65
// should generate correct setup signature
66
66
expect ( content ) . toMatch ( `setup(__props, { props, emit }) {` )
67
67
// should include context options in default export
@@ -143,7 +143,7 @@ const bar = 1
143
143
const { content } = compile (
144
144
`
145
145
<script setup>
146
- import { ref, useOptions } from 'vue'
146
+ import { ref, defineOptions } from 'vue'
147
147
import Foo from './Foo.vue'
148
148
import other from './util'
149
149
const count = ref(0)
@@ -183,11 +183,11 @@ const bar = 1
183
183
assertCode ( content )
184
184
} )
185
185
186
- test ( 'useOptions w/ runtime options' , ( ) => {
186
+ test ( 'defineOptions w/ runtime options' , ( ) => {
187
187
const { content } = compile ( `
188
188
<script setup lang="ts">
189
- import { useOptions } from 'vue'
190
- const { props, emit } = useOptions ({
189
+ import { defineOptions } from 'vue'
190
+ const { props, emit } = defineOptions ({
191
191
props: { foo: String },
192
192
emits: ['a', 'b']
193
193
})
@@ -200,15 +200,15 @@ const { props, emit } = useOptions({
200
200
setup(__props, { props, emit }) {` )
201
201
} )
202
202
203
- test ( 'useOptions w/ type / extract props' , ( ) => {
203
+ test ( 'defineOptions w/ type / extract props' , ( ) => {
204
204
const { content, bindings } = compile ( `
205
205
<script setup lang="ts">
206
- import { useOptions } from 'vue'
206
+ import { defineOptions } from 'vue'
207
207
interface Test {}
208
208
209
209
type Alias = number[]
210
210
211
- useOptions <{
211
+ defineOptions <{
212
212
props: {
213
213
string: string
214
214
number: number
@@ -288,11 +288,11 @@ const { props, emit } = useOptions({
288
288
} )
289
289
} )
290
290
291
- test ( 'useOptions w/ type / extract emits' , ( ) => {
291
+ test ( 'defineOptions w/ type / extract emits' , ( ) => {
292
292
const { content } = compile ( `
293
293
<script setup lang="ts">
294
- import { useOptions } from 'vue'
295
- const { emit } = useOptions <{
294
+ import { defineOptions } from 'vue'
295
+ const { emit } = defineOptions <{
296
296
emit: (e: 'foo' | 'bar') => void
297
297
}>()
298
298
</script>
@@ -302,11 +302,11 @@ const { props, emit } = useOptions({
302
302
expect ( content ) . toMatch ( `emits: ["foo", "bar"] as unknown as undefined` )
303
303
} )
304
304
305
- test ( 'useOptions w/ type / extract emits (union)' , ( ) => {
305
+ test ( 'defineOptions w/ type / extract emits (union)' , ( ) => {
306
306
const { content } = compile ( `
307
307
<script setup lang="ts">
308
- import { useOptions } from 'vue'
309
- const { emit } = useOptions <{
308
+ import { defineOptions } from 'vue'
309
+ const { emit } = defineOptions <{
310
310
emit: ((e: 'foo' | 'bar') => void) | ((e: 'baz', id: number) => void)
311
311
}>()
312
312
</script>
@@ -633,21 +633,21 @@ const { props, emit } = useOptions({
633
633
) . toThrow ( `ref: statements can only contain assignment expressions` )
634
634
} )
635
635
636
- test ( 'useOptions () w/ both type and non-type args' , ( ) => {
636
+ test ( 'defineOptions () w/ both type and non-type args' , ( ) => {
637
637
expect ( ( ) => {
638
638
compile ( `<script setup lang="ts">
639
- import { useOptions } from 'vue'
640
- useOptions <{}>({})
639
+ import { defineOptions } from 'vue'
640
+ defineOptions <{}>({})
641
641
</script>` )
642
642
} ) . toThrow ( `cannot accept both type and non-type arguments` )
643
643
} )
644
644
645
- test ( 'useOptions () referencing local var' , ( ) => {
645
+ test ( 'defineOptions () referencing local var' , ( ) => {
646
646
expect ( ( ) =>
647
647
compile ( `<script setup>
648
- import { useOptions } from 'vue'
648
+ import { defineOptions } from 'vue'
649
649
const bar = 1
650
- useOptions ({
650
+ defineOptions ({
651
651
props: {
652
652
foo: {
653
653
default: () => bar
@@ -658,24 +658,24 @@ const { props, emit } = useOptions({
658
658
) . toThrow ( `cannot reference locally declared variables` )
659
659
} )
660
660
661
- test ( 'useOptions () referencing ref declarations' , ( ) => {
661
+ test ( 'defineOptions () referencing ref declarations' , ( ) => {
662
662
expect ( ( ) =>
663
663
compile ( `<script setup>
664
- import { useOptions } from 'vue'
664
+ import { defineOptions } from 'vue'
665
665
ref: bar = 1
666
- useOptions ({
666
+ defineOptions ({
667
667
props: { bar }
668
668
})
669
669
</script>` )
670
670
) . toThrow ( `cannot reference locally declared variables` )
671
671
} )
672
672
673
- test ( 'should allow useOptions () referencing scope var' , ( ) => {
673
+ test ( 'should allow defineOptions () referencing scope var' , ( ) => {
674
674
assertCode (
675
675
compile ( `<script setup>
676
- import { useOptions } from 'vue'
676
+ import { defineOptions } from 'vue'
677
677
const bar = 1
678
- useOptions ({
678
+ defineOptions ({
679
679
props: {
680
680
foo: {
681
681
default: bar => bar + 1
@@ -686,12 +686,12 @@ const { props, emit } = useOptions({
686
686
)
687
687
} )
688
688
689
- test ( 'should allow useOptions () referencing imported binding' , ( ) => {
689
+ test ( 'should allow defineOptions () referencing imported binding' , ( ) => {
690
690
assertCode (
691
691
compile ( `<script setup>
692
- import { useOptions } from 'vue'
692
+ import { defineOptions } from 'vue'
693
693
import { bar } from './bar'
694
- useOptions ({
694
+ defineOptions ({
695
695
props: {
696
696
foo: {
697
697
default: () => bar
@@ -901,8 +901,8 @@ describe('SFC analyze <script> bindings', () => {
901
901
it ( 'works for script setup' , ( ) => {
902
902
const { bindings } = compile ( `
903
903
<script setup>
904
- import { useOptions } from 'vue'
905
- useOptions ({
904
+ import { defineOptions } from 'vue'
905
+ defineOptions ({
906
906
props: {
907
907
foo: String,
908
908
}
0 commit comments