You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ever since #14130, functions that take Position/index pairs are now redundant. That PR has already accounted for this in error-related functions, but I'd now like to do the same for the remaining function interfaces to just take in the Position. Beyond simplifying the code, there are also two correctness considerations that this would address:
First, as these pairs always represent the same "location", it would remove the possibility of future accidental errors where the source index and line/column location get out of sync. With this new setup, the one-to-one mapping between these two is made more concrete and there is no opportunity to have to derive them separately.
Perhaps more importantly, there are a number of instances where we use either the ?number type, the pos: ?number optional parameter, or both pos?: ?number. These are troublesome because Flow seems to not catch uses of "!pos", which are ambiguous and actually mean "not null and not undefined and not 0", where you probably mean "not null/undefined". Once we exclusively use Position objects, ?Position will be unambiguous in the sense that Position { index: 0 } can never accidentally be interpreted as a "missing" position. I don't believe we currently have any of these issues, but this is somewhat due to "luck". For example, Improve errors location tracking聽#14130 removed this code which only works because it happens to be that a trailing comma couldn't exist at "pos" 0, but is arguably from the isolated context of the function's perspective, incorrect, and you could certainly imagine other such cases eventually popping up in parts of the code where pos could be equal to 0:
Hey @tolmasky! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.
If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite.
馃捇
How are you using Babel?
Programmatic API (
babel.transform
,babel.parse
)Input code
N/A
Configuration file name
No response
Configuration
No response
Current and expected behavior
Ever since #14130, functions that take Position/index pairs are now redundant. That PR has already accounted for this in error-related functions, but I'd now like to do the same for the remaining function interfaces to just take in the
Position
. Beyond simplifying the code, there are also two correctness considerations that this would address:First, as these pairs always represent the same "location", it would remove the possibility of future accidental errors where the source index and line/column location get out of sync. With this new setup, the one-to-one mapping between these two is made more concrete and there is no opportunity to have to derive them separately.
Perhaps more importantly, there are a number of instances where we use either the
?number
type, thepos: ?number
optional parameter, or bothpos?: ?number
. These are troublesome because Flow seems to not catch uses of "!pos", which are ambiguous and actually mean "not null and not undefined and not 0", where you probably mean "not null/undefined". Once we exclusively usePosition
objects,?Position
will be unambiguous in the sense thatPosition { index: 0 }
can never accidentally be interpreted as a "missing" position. I don't believe we currently have any of these issues, but this is somewhat due to "luck". For example, Improve errors location tracking聽#14130 removed this code which only works because it happens to be that a trailing comma couldn't exist at "pos" 0, but is arguably from the isolated context of the function's perspective, incorrect, and you could certainly imagine other such cases eventually popping up in parts of the code where pos could be equal to 0:babel/packages/babel-parser/src/parser/lval.js
Lines 231 to 233 in a6ca39c
From:
babel/packages/babel-parser/src/parser/lval.js
Lines 207 to 211 in a6ca39c
Environment
Possible solution
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: