@@ -105,13 +105,32 @@ const plugin: VueLanguagePlugin = ctx => {
105
105
) {
106
106
if ( prop . name === 'on' && prop . arg ?. type === CompilerDOM . NodeTypes . SIMPLE_EXPRESSION ) {
107
107
const ast = createTsAst ( ctx . modules . typescript , prop . exp , prop . exp . content ) ;
108
- addFormatCodes (
109
- prop . exp . content ,
110
- prop . exp . loc . start . offset ,
111
- isCompoundExpression ( ctx . modules . typescript , ast )
112
- ? formatBrackets . event
113
- : formatBrackets . normal
114
- ) ;
108
+ if ( isCompoundExpression ( ctx . modules . typescript , ast ) ) {
109
+ addFormatCodes (
110
+ prop . exp . content ,
111
+ prop . exp . loc . start . offset ,
112
+ formatBrackets . event
113
+ ) ;
114
+ }
115
+ else {
116
+ const lines = prop . exp . content . split ( '\n' ) ;
117
+ const firstLineEmpty = lines [ 0 ] . trim ( ) === '' ;
118
+ const lastLineEmpty = lines [ lines . length - 1 ] . trim ( ) === '' ;
119
+ if ( lines . length <= 1 || ( ! firstLineEmpty && ! lastLineEmpty ) ) {
120
+ addFormatCodes (
121
+ prop . exp . content ,
122
+ prop . exp . loc . start . offset ,
123
+ formatBrackets . normal
124
+ ) ;
125
+ }
126
+ else {
127
+ addFormatCodes (
128
+ prop . exp . content ,
129
+ prop . exp . loc . start . offset ,
130
+ [ '(' , ');' ]
131
+ ) ;
132
+ }
133
+ }
115
134
}
116
135
else if ( prop . name === 'slot' ) {
117
136
addFormatCodes (
@@ -186,17 +205,27 @@ const plugin: VueLanguagePlugin = ctx => {
186
205
else if ( node . type === CompilerDOM . NodeTypes . INTERPOLATION ) {
187
206
// {{ ... }}
188
207
const [ content , start ] = parseInterpolationNode ( node , templateContent ) ;
208
+ const lines = content . split ( '\n' ) ;
209
+ const firstLineEmpty = lines [ 0 ] . trim ( ) === '' ;
210
+ const lastLineEmpty = lines [ lines . length - 1 ] . trim ( ) === '' ;
211
+
189
212
if ( content . includes ( '=>' ) ) { // arrow function
190
- addFormatCodes (
191
- content ,
192
- start ,
193
- formatBrackets . normal
194
- ) ;
213
+ if ( lines . length <= 1 || ( ! firstLineEmpty && ! lastLineEmpty ) ) {
214
+ addFormatCodes (
215
+ content ,
216
+ start ,
217
+ formatBrackets . normal
218
+ ) ;
219
+ }
220
+ else {
221
+ addFormatCodes (
222
+ content ,
223
+ start ,
224
+ [ '(' , ');' ]
225
+ ) ;
226
+ }
195
227
}
196
228
else {
197
- const lines = content . split ( '\n' ) ;
198
- const firstLineEmpty = lines [ 0 ] . trim ( ) === '' ;
199
- const lastLineEmpty = lines [ lines . length - 1 ] . trim ( ) === '' ;
200
229
if ( lines . length <= 1 || ( ! firstLineEmpty && ! lastLineEmpty ) ) {
201
230
addFormatCodes (
202
231
content ,
0 commit comments