postcss-less icon indicating copy to clipboard operation
postcss-less copied to clipboard

Inline comments have incorrect source locations

Open romainmenke opened this issue 1 year ago • 1 comments

  • Node Version: 22
  • NPM Version: 10.8
  • postcss Version: 8.4.48
  • postcss-less Version: 6.0.0

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:

  • standard CSS with an equivalent standard comment
  • postcss-scss with the exact same inline comment
  • postcss-less with the exact same inline comment

romainmenke avatar Nov 11 '24 16:11 romainmenke

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

shellscape avatar Nov 11 '24 16:11 shellscape