File tree Expand file tree Collapse file tree 1 file changed +29
-9
lines changed
packages/language-core/lib/plugins Expand file tree Collapse file tree 1 file changed +29
-9
lines changed Original file line number Diff line number Diff line change @@ -186,15 +186,35 @@ const plugin: VueLanguagePlugin = ctx => {
186
186
else if ( node . type === CompilerDOM . NodeTypes . INTERPOLATION ) {
187
187
// {{ ... }}
188
188
const [ content , start ] = parseInterpolationNode ( node , templateContent ) ;
189
- const lines = content . split ( '\n' ) ;
190
- addFormatCodes (
191
- content ,
192
- start ,
193
- lines . length <= 1 ? formatBrackets . curly : [
194
- lines [ 0 ] . trim ( ) === '' ? '(' : formatBrackets . curly [ 0 ] ,
195
- lines [ lines . length - 1 ] . trim ( ) === '' ? ');' : formatBrackets . curly [ 1 ] ,
196
- ]
197
- ) ;
189
+ if ( content . includes ( '=>' ) ) { // arrow function
190
+ addFormatCodes (
191
+ content ,
192
+ start ,
193
+ formatBrackets . normal
194
+ ) ;
195
+ }
196
+ else {
197
+ const lines = content . split ( '\n' ) ;
198
+ const firstLineEmpty = lines [ 0 ] . trim ( ) === '' ;
199
+ const lastLineEmpty = lines [ lines . length - 1 ] . trim ( ) === '' ;
200
+ if ( lines . length <= 1 || ( ! firstLineEmpty && ! lastLineEmpty ) ) {
201
+ addFormatCodes (
202
+ content ,
203
+ start ,
204
+ formatBrackets . curly
205
+ ) ;
206
+ }
207
+ else {
208
+ addFormatCodes (
209
+ content ,
210
+ start ,
211
+ [
212
+ firstLineEmpty ? '(' : '(0 +' ,
213
+ lastLineEmpty ? ');' : '+ 0);'
214
+ ]
215
+ ) ;
216
+ }
217
+ }
198
218
}
199
219
}
200
220
You can’t perform that action at this time.
0 commit comments