From d9d5ea31f3226ceab05462c3c19db6e2c4cfdaab Mon Sep 17 00:00:00 2001 From: ish1416 Date: Mon, 10 Nov 2025 13:05:38 +0530 Subject: [PATCH] fix: correct column number to be 1-based createLineTable().find() returns 0-based columns per source map spec, but users expect 1-based column numbers. Add 1 to column before formatting error message so both line and column are 1-based and accurate. Addresses reviewer feedback about off-by-one column numbers. --- packages/tailwindcss/src/css-parser.test.ts | 8 ++++---- packages/tailwindcss/src/css-parser.ts | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/tailwindcss/src/css-parser.test.ts b/packages/tailwindcss/src/css-parser.test.ts index f65d51e0f..4a796d8cf 100644 --- a/packages/tailwindcss/src/css-parser.test.ts +++ b/packages/tailwindcss/src/css-parser.test.ts @@ -1219,7 +1219,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { it('should include filename and line number in error messages when from option is provided', () => { expect(() => { CSS.parse('.test { */ }', { from: 'test.css' }) - }).toThrow(/CssSyntaxError: Invalid declaration: `\*\/` at test\.css:1:9/) + }).toThrow(/CssSyntaxError: Invalid declaration: `\*\/` at test\.css:1:10/) }) it('should include filename and line number for multi-line CSS errors', () => { @@ -1230,7 +1230,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { }` expect(() => { CSS.parse(multiLineCss, { from: 'styles.css' }) - }).toThrow(/CssSyntaxError: Invalid declaration: `\*\/` at styles\.css:4:3/) + }).toThrow(/CssSyntaxError: Invalid declaration: `\*\/` at styles\.css:4:4/) }) it('should include filename and line number for missing opening brace errors', () => { @@ -1243,7 +1243,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { }` expect(() => { CSS.parse(cssWithMissingBrace, { from: 'broken.css' }) - }).toThrow(/CssSyntaxError: Missing opening \{ at broken\.css:7:1/) + }).toThrow(/CssSyntaxError: Missing opening \{ at broken\.css:7:2/) }) it('should include filename and line number for unterminated string errors', () => { @@ -1253,7 +1253,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => { }` expect(() => { CSS.parse(cssWithUnterminatedString, { from: 'string-error.css' }) - }).toThrow(/CssSyntaxError: Unterminated string: "Hello world!" at string-error\.css:2:12/) + }).toThrow(/CssSyntaxError: Unterminated string: "Hello world!" at string-error\.css:2:13/) }) }) diff --git a/packages/tailwindcss/src/css-parser.ts b/packages/tailwindcss/src/css-parser.ts index 000a9e11e..6561816fa 100644 --- a/packages/tailwindcss/src/css-parser.ts +++ b/packages/tailwindcss/src/css-parser.ts @@ -43,7 +43,7 @@ export class CssSyntaxError extends Error { super(message) } else { const { line, column } = createLineTable(source.code).find(position) - super(`${message} at ${source.file}:${line}:${column}`) + super(`${message} at ${source.file}:${line}:${column + 1}`) } this.name = 'CssSyntaxError' }