error.loc.line in public API does not match with the real file
I'm currently working on a PR on facebook/react.
What I realized during this course of work is that the error.loc.line in the error object thrown is not consistent with the error.loc.file itself.
To my understanding, it's mainly due to tracing sourcemaps within rollup. props.loc
However, I think that the error.loc.line thrown through the public API should be consistent with the error.loc.file
Below is a minimal log from reproduction.
It shows that error.loc.line given through the public API is 14 while in the real file it is on line 13.
error.message:
'forEach' is not exported by packages/react/src/ReactChildren.js
error.loc:
{ file: '/Users/soojae/Documents/react/packages/react/src/React.js',
line: 14,
column: 9 }
-- MISSING_EXPORT (undefined) --
'forEach' is not exported by packages/react/src/ReactChildren.js
11 |
12 | import {Component, PureComponent, AsyncComponent} from './ReactBaseClasses';
> 13 | import {forEach, map, count, toArray, only} from './ReactChildren';
| ^
14 | import ReactCurrentOwner from './ReactCurrentOwner';
15 | import {
16 | createElement,
error Command failed with exit code 1.
I have done some more research during the weekends and it seems like the discrepancy in the line number of the error and the real file is due to babel injecting some lines on the top of the line when transpiling using plugins like babel-plugin-transform-object-assign
I'll try to figure out a way to get the real file lines.
I have been looking into this issue but couldn't find a good way to solve it. It'd be nice if someone with more prior knowledge about the source code guide me on this. :)