Skip to content

Commit 45d942f

Browse files
authored
[mcp] Also emit bailout messages with no loc (facebook#32937)
Not every bailout will contain a loc (could be synthetic)
1 parent b8bedc2 commit 45d942f

File tree

1 file changed

+12
-15
lines changed
  • compiler/packages/react-mcp-server/src

1 file changed

+12
-15
lines changed

compiler/packages/react-mcp-server/src/index.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ server.tool(
158158
}
159159
}
160160
};
161-
const errors: Array<{message: string; loc: SourceLocation}> = [];
161+
const errors: Array<{message: string; loc: SourceLocation | null}> = [];
162162
const compilerOptions: Partial<PluginOptions> = {
163163
panicThreshold: 'none',
164164
logger: {
@@ -170,12 +170,10 @@ server.tool(
170170
detail.loc == null || typeof detail.loc == 'symbol'
171171
? event.fnLoc
172172
: detail.loc;
173-
if (loc != null) {
174-
errors.push({
175-
message: detail.reason,
176-
loc,
177-
});
178-
}
173+
errors.push({
174+
message: detail.reason,
175+
loc,
176+
});
179177
}
180178
},
181179
},
@@ -279,17 +277,16 @@ server.tool(
279277
}
280278
}
281279
if (errors.length > 0) {
282-
const errMessages = errors.map(err => {
283-
if (typeof err.loc !== 'symbol') {
280+
return {
281+
content: errors.map(err => {
284282
return {
285283
type: 'text' as const,
286-
text: `React Compiler bailed out:\n\n${err.message}@${err.loc.start.line}:${err.loc.end.line}`,
284+
text:
285+
err.loc === null || typeof err.loc === 'symbol'
286+
? `React Compiler bailed out:\n\n${err.message}`
287+
: `React Compiler bailed out:\n\n${err.message}@${err.loc.start.line}:${err.loc.end.line}`,
287288
};
288-
}
289-
return null;
290-
});
291-
return {
292-
content: errMessages.filter(msg => msg !== null),
289+
}),
293290
};
294291
}
295292
return {

0 commit comments

Comments
 (0)