Skip to content

node.source.end.offset is wrong value in some cases #2030

@mizdra

Description

@mizdra

Summary

In f09e296, offset property is added to Node.Position. But, the property is wrong value in some cases. The offset is 1 larger than expected.

Reproduction

import { Declaration, parse, Rule } from 'postcss';

const css = parse('a { one: X }');
const a = css.first as Rule;
let one = a.first as Declaration;

console.log(css.source?.end); // ok
console.log(a.source?.end); // NG
console.log(one.source?.end); // NG
$ npm start

> start
> ts-node index.ts

{ column: 13, line: 1, offset: 12 }
{ column: 12, line: 1, offset: 12 }
{ column: 10, line: 1, offset: 10 }

Expected Behavior

The following will be output:

$ npm start

> start
> ts-node index.ts

{ column: 13, line: 1, offset: 12 }
{ column: 12, line: 1, offset: 11 }
{ column: 10, line: 1, offset: 9 }

Additional Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions