File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -34,9 +34,14 @@ module.exports = {
34
34
let defineOptionsNode = null
35
35
/** @type {ExportDefaultDeclaration | null } */
36
36
let exportDefaultDeclaration = null
37
+ /** @type {ImportDeclaration|null } */
38
+ let lastImportDeclaration = null
37
39
38
40
return utils . compositingVisitors (
39
41
utils . defineScriptSetupVisitor ( context , {
42
+ ImportDeclaration ( node ) {
43
+ lastImportDeclaration = node
44
+ } ,
40
45
onDefineOptionsEnter ( node ) {
41
46
defineOptionsNode = node
42
47
}
@@ -109,10 +114,13 @@ module.exports = {
109
114
} )
110
115
}
111
116
117
+ /** @type {VStartTag | ImportDeclaration } */
118
+ const insertAfterTag = lastImportDeclaration || scriptSetup . startTag
119
+
112
120
return [
113
121
fixer . removeRange ( removeRange ) ,
114
122
fixer . insertTextAfter (
115
- scriptSetup . startTag ,
123
+ insertAfterTag ,
116
124
`\ndefineOptions(${ sourceCode . getText ( node . declaration ) } )\n`
117
125
)
118
126
]
Original file line number Diff line number Diff line change @@ -104,6 +104,32 @@ defineOptions({ name: 'Foo' })
104
104
line : 4
105
105
}
106
106
]
107
+ } ,
108
+ {
109
+ filename : 'test.vue' ,
110
+ code : `
111
+ <script setup>
112
+ import { ref } from 'vue'
113
+ const props = defineProps(['foo'])
114
+ </script>
115
+ <script>
116
+ export default { name: 'Foo' }
117
+ </script>
118
+ ` ,
119
+ output : `
120
+ <script setup>
121
+ import { ref } from 'vue'
122
+ defineOptions({ name: 'Foo' })
123
+
124
+ const props = defineProps(['foo'])
125
+ </script>
126
+ ` ,
127
+ errors : [
128
+ {
129
+ message : 'Use `defineOptions` instead of default export.' ,
130
+ line : 7
131
+ }
132
+ ]
107
133
}
108
134
]
109
135
} )
You can’t perform that action at this time.
0 commit comments