Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline comments have incorrect source locations #178

Open
romainmenke opened this issue Nov 11, 2024 · 1 comment
Open

Inline comments have incorrect source locations #178

romainmenke opened this issue Nov 11, 2024 · 1 comment

Comments

@romainmenke
Copy link

romainmenke commented Nov 11, 2024

  • 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
@shellscape
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants