fix: report precise error line numbers in --show-errors#51
Conversation
minimatch was being imported directly but only available as a transitive dependency through glob. This caused build failures with pnpm's strict dependency resolution. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Previously, --show-errors reported the line number where the function starts (event.fnLoc) rather than the exact line where the React compiler violation occurs. Now uses: - event.detail.primaryLocation() for CompileError events - event.loc for CompileSkip events This provides users with accurate line numbers pointing to the exact location of violations, making it easier to find and fix issues. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Thanks for this improvement to error reporting, which now shows the precise line number for React compiler violations instead of just the start of the function. This change will make it significantly easier for developers to locate and fix issues. It looks like there may be a potential runtime crash if an error's location data is incomplete, and a new dependency may have been added that appears to be unused.
| // primaryLocation() may return a symbol (GeneratedSource), so check for object | ||
| const loc = event.detail.primaryLocation() | ||
| line = | ||
| (loc && typeof loc === 'object' ? loc.start.line : null) ?? |
There was a problem hiding this comment.
[P1] Possible runtime crash when primaryLocation object lacks start. primaryLocation() can return an object without a start (or with start undefined), so loc.start.line will throw at runtime. This will surface when the compiler provides a location object that doesn't include start (or uses a different shape), breaking --show-errors. Use optional chaining or a guard like loc && typeof loc === 'object' && loc.start ? loc.start.line : null to avoid throwing.
There was a problem hiding this comment.
If we are to trust the types, then then start is a non-nullable property on the object returned from primaryLocation (SourceLocation type from Babel), if it's a non-null and non-symbol value.
Previously,
--show-errorsreported the line number where the function starts rather than the exact line where the React compiler violation occurs. This made it harder to locate and fix issues.Now
--show-errorsdisplays precise error locations:The fix uses
primaryLocation()forCompileErrorevents to get the precise error location, falling back to the function location if unavailable.Test plan
Test locally by running against the sample project fixtures:
npm run build cd src/__fixtures__/sample-projectVerify precise line numbers are shown
Should show
Line 9andLine 10(the actual error lines), notLine 6(the function start).Verify all commands with
--show-errorsshow precise locations