shellscape / postcss-less

PostCSS Syntax for parsing LESS
MIT License
124 stars 39 forks source link

Inline comments have incorrect source locations #178

Open romainmenke opened 6 days ago

romainmenke commented 6 days ago

If you have a large amount of code to share which demonstrates the problem you're experiencing, please provide a link to your repository rather than pasting code. Otherwise, please paste relevant short snippets below.

LESS

// abcd

JavaScript

const less = require('postcss-less');
const scss = require('postcss-scss');
const postcss = require('postcss');
const assert = require('assert');
const test = require('node:test');

test('css', async () => {
    await postcss([]).process(`/* a */`, { from: null }).then((result) => {
        result.root.walkComments((comment) => {
            assert.deepStrictEqual(
                comment.source.start,
                {
                    column: 1,
                    line: 1,
                    offset: 0
                }
            )

            assert.deepStrictEqual(
                comment.source.end,
                {
                    column: 7,
                    line: 1,
                    offset: 7
                }
            )
        })
    })
})

test('scss', async () => {
    await postcss([]).process(`// abcd`, { syntax: scss, from: null }).then((result) => {
        result.root.walkComments((comment) => {
            assert.deepStrictEqual(
                comment.source.start,
                {
                    column: 1,
                    line: 1,
                    offset: 0
                }
            )

            assert.deepStrictEqual(
                comment.source.end,
                {
                    column: 7,
                    line: 1,
                    offset: 7
                }
            )
        })
    })
})

test('less', async () => {
    await postcss([]).process(`// abcd`, { syntax: less, from: null }).then((result) => {
        result.root.walkComments((comment) => {
            assert.deepStrictEqual(
                comment.source.start,
                {
                    column: 1,
                    line: 1,
                    offset: 0
                }
            )

            // errors here
            assert.deepStrictEqual(
                comment.source.end,
                {
                    column: 7,
                    line: 1,
                    offset: 7
                }
            )
        })
    })
})

Errors

✖ less (1.246167ms)
  AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
  + actual - expected

    {
  +   column: 4,
  -   column: 7,
      line: 1,
  +   offset: 3
  -   offset: 7
    }

Expected Behavior

I expected postcss-less to have accurate source positioning for inline comments

Actual Behavior

postcss-less has incorrect positions

How can we reproduce the behavior?

Run the code above. It is a minimal test showing the behavior in:

shellscape commented 6 days ago

Would be happy to have a contribution to resolve this issue. I don't have much time for maintenance these days.