Skip to content

Inline comments have incorrect source locations #178

@romainmenke

Description

@romainmenke
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions