@samitouri / QOS-React / commits / 45d942f94a

[mcp] Also emit bailout messages with no loc (#32937)

Not every bailout will contain a loc (could be synthetic)

lauren committed Apr 17, 2025 at 13:11 UTC 45d942f94a5aa40e9f809b41325c31c799a29216
1 file changed +12 -15
compiler/packages/react-mcp-server/src/index.ts
+12 -15
@@ -158,7 +158,7 @@ server.tool(
158 }
159 }
160 };
161 - const errors: Array<{message: string; loc: SourceLocation}> = [];
161 + const errors: Array<{message: string; loc: SourceLocation | null}> = [];
162 const compilerOptions: Partial<PluginOptions> = {
163 panicThreshold: 'none',
164 logger: {
@@ -170,12 +170,10 @@ server.tool(
170 detail.loc == null || typeof detail.loc == 'symbol'
171 ? event.fnLoc
172 : 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 + });
177 }
178 },
179 },
@@ -279,17 +277,16 @@ server.tool(
277 }
278 }
279 if (errors.length > 0) {
282 - const errMessages = errors.map(err => {
283 - if (typeof err.loc !== 'symbol') {
280 + return {
281 + content: errors.map(err => {
282 return {
283 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}`,
288 };
288 - }
289 - return null;
290 - });
291 - return {
292 - content: errMessages.filter(msg => msg !== null),
289 + }),
290 };
291 }
292 return {