Skip to content

Commit 4789376

Browse files
committed
fix(language-core): prefer loc.source instead of node content
1 parent 7e49497 commit 4789376

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const plugin: VueLanguagePlugin = ctx => {
9494
}
9595
if (prop.arg?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION && !prop.arg.isStatic) {
9696
addFormatCodes(
97-
prop.arg.content,
97+
prop.arg.loc.source,
9898
prop.arg.loc.start.offset,
9999
formatBrackets.normal
100100
);
@@ -107,7 +107,7 @@ const plugin: VueLanguagePlugin = ctx => {
107107
const ast = createTsAst(ctx.modules.typescript, prop.exp, prop.exp.content);
108108
if (isCompoundExpression(ctx.modules.typescript, ast)) {
109109
addFormatCodes(
110-
prop.exp.content,
110+
prop.exp.loc.source,
111111
prop.exp.loc.start.offset,
112112
formatBrackets.event
113113
);
@@ -118,14 +118,14 @@ const plugin: VueLanguagePlugin = ctx => {
118118
const lastLineEmpty = lines[lines.length - 1].trim() === '';
119119
if (lines.length <= 1 || (!firstLineEmpty && !lastLineEmpty)) {
120120
addFormatCodes(
121-
prop.exp.content,
121+
prop.exp.loc.source,
122122
prop.exp.loc.start.offset,
123123
formatBrackets.normal
124124
);
125125
}
126126
else {
127127
addFormatCodes(
128-
prop.exp.content,
128+
prop.exp.loc.source,
129129
prop.exp.loc.start.offset,
130130
['(', ');']
131131
);
@@ -134,14 +134,22 @@ const plugin: VueLanguagePlugin = ctx => {
134134
}
135135
else if (prop.name === 'slot') {
136136
addFormatCodes(
137-
prop.exp.content,
137+
prop.exp.loc.source,
138138
prop.exp.loc.start.offset,
139139
formatBrackets.params
140140
);
141141
}
142+
else if (prop.rawName === 'v-for') {
143+
// #2586
144+
addFormatCodes(
145+
prop.exp.loc.source,
146+
prop.exp.loc.start.offset,
147+
formatBrackets.for
148+
);
149+
}
142150
else {
143151
addFormatCodes(
144-
prop.exp.content,
152+
prop.exp.loc.source,
145153
prop.exp.loc.start.offset,
146154
formatBrackets.normal
147155
);
@@ -157,7 +165,7 @@ const plugin: VueLanguagePlugin = ctx => {
157165
const branch = node.branches[i];
158166
if (branch.condition?.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
159167
addFormatCodes(
160-
branch.condition.content,
168+
branch.condition.loc.source,
161169
branch.condition.loc.start.offset,
162170
formatBrackets.if
163171
);

0 commit comments

Comments
 (0)