Skip to content

Commit 74eeda3

Browse files
committed
fix(language-core): arrow function formatting virtual code syntax incorrect in interpolation
1 parent 5c28cf4 commit 74eeda3

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

packages/language-core/lib/plugins/vue-template-inline-ts.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,35 @@ const plugin: VueLanguagePlugin = ctx => {
186186
else if (node.type === CompilerDOM.NodeTypes.INTERPOLATION) {
187187
// {{ ... }}
188188
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+
}
198218
}
199219
}
200220

0 commit comments

Comments
 (0)