Skip to content

Commit d9d5ea3

Browse files
committed
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.
1 parent 2aa3682 commit d9d5ea3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

packages/tailwindcss/src/css-parser.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
12191219
it('should include filename and line number in error messages when from option is provided', () => {
12201220
expect(() => {
12211221
CSS.parse('.test { */ }', { from: 'test.css' })
1222-
}).toThrow(/CssSyntaxError: Invalid declaration: `\*\/` at test\.css:1:9/)
1222+
}).toThrow(/CssSyntaxError: Invalid declaration: `\*\/` at test\.css:1:10/)
12231223
})
12241224

12251225
it('should include filename and line number for multi-line CSS errors', () => {
@@ -1230,7 +1230,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
12301230
}`
12311231
expect(() => {
12321232
CSS.parse(multiLineCss, { from: 'styles.css' })
1233-
}).toThrow(/CssSyntaxError: Invalid declaration: `\*\/` at styles\.css:4:3/)
1233+
}).toThrow(/CssSyntaxError: Invalid declaration: `\*\/` at styles\.css:4:4/)
12341234
})
12351235

12361236
it('should include filename and line number for missing opening brace errors', () => {
@@ -1243,7 +1243,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
12431243
}`
12441244
expect(() => {
12451245
CSS.parse(cssWithMissingBrace, { from: 'broken.css' })
1246-
}).toThrow(/CssSyntaxError: Missing opening \{ at broken\.css:7:1/)
1246+
}).toThrow(/CssSyntaxError: Missing opening \{ at broken\.css:7:2/)
12471247
})
12481248

12491249
it('should include filename and line number for unterminated string errors', () => {
@@ -1253,7 +1253,7 @@ describe.each(['Unix', 'Windows'])('Line endings: %s', (lineEndings) => {
12531253
}`
12541254
expect(() => {
12551255
CSS.parse(cssWithUnterminatedString, { from: 'string-error.css' })
1256-
}).toThrow(/CssSyntaxError: Unterminated string: "Hello world!" at string-error\.css:2:12/)
1256+
}).toThrow(/CssSyntaxError: Unterminated string: "Hello world!" at string-error\.css:2:13/)
12571257
})
12581258
})
12591259

packages/tailwindcss/src/css-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class CssSyntaxError extends Error {
4343
super(message)
4444
} else {
4545
const { line, column } = createLineTable(source.code).find(position)
46-
super(`${message} at ${source.file}:${line}:${column}`)
46+
super(`${message} at ${source.file}:${line}:${column + 1}`)
4747
}
4848
this.name = 'CssSyntaxError'
4949
}

0 commit comments

Comments
 (0)