When calling Node#rangeBy() (and therefore Node#error() and
Node#warn()) with index 0, the resulting range covered the whole node
instead of a single character at offset 0.
The end-of-range branch used a truthy check on opts.index, so an index
of 0 fell through and left the end position at the node's end. This is
the same off-by-zero issue that was previously fixed for endIndex; the
index branches were missed. Switch both index checks to a numeric type
check, matching the existing endIndex handling.
index 0 now produces a single-character range, consistent with every
other index value.
positionBy()'s default branch returned this.source.start verbatim, so for
custom syntaxes whose source.start lacks an offset (e.g. postcss-html) it
returned a position without offset, violating the Position type which
declares offset as required. rangeBy()/positionInside() were normalized to
always compute offset via sourceOffset() (#2033, issue #2029) but
positionBy() was left behind. Mirror the rangeBy() pattern.
Co-authored-by: oss69U-prep <prep@local>
Co-authored-by: Hanzo Dev <[email protected]>
* Fix `opts` argument cannot be omitted
* Assign default values to `opts` just in case
- The `opts` argument to `Node#error` is currently omissible, but we'll assign a default value just in case.
* Add test cases
* Add test cases for `Node#rangeBy({start, end})`
* Add test cases for offset
* Fix missing offset in `Node#positionInside`, `Node#positionBy` and `Node#rangeBy`
* Fix conflict resolution mistakes
---------
Co-authored-by: Andrey Sitnik <[email protected]>
* Fix `opts` argument cannot be omitted
* Assign default values to `opts` just in case
- The `opts` argument to `Node#error` is currently omissible, but we'll assign a default value just in case.
* Add test cases