Skip to content

Commit

Permalink
Return correct column on missed semicolon
Browse files Browse the repository at this point in the history
I've added some test-cases to ensure it works.
Also added a comment about `why` we it need to get token[3]+1

And ultimately it resolves #1617

Regards,
Gusted
  • Loading branch information
Gusted committed Jul 21, 2021
1 parent 1545d8a commit 422b5bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,13 @@ class Parser {
if (founded === 2) break
}
}
throw this.input.error('Missed semicolon', token[2])
// If the token is a word, e.g. `!important`, `red` or any other valid property's value.
// Then we need to return the colon after that word token. [3] is the "end" colon of that word.
// And because we need it after that one we do +1 to get the next one.
throw this.input.error(
'Missed semicolon',
token[0] === 'word' ? token[3] + 1 : token[2]
)
}
}

Expand Down
20 changes: 20 additions & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,23 @@ it('suggests postcss-less for Less sources', () => {
parse('.@{my-selector} { }', { from: 'app.less' })
}).toThrow(/postcss-less/)
})

it('should give the correct column of missed semicolon with !important', () => {
let error
try {
parse('a { \n color: red !important\n background-color: black;\n}')
} catch (e) {
error = e
}
expect(error.message).toMatch(/2:26: Missed semicolon/)
})

it('should give the correct column of missed semicolon without !important', () => {
let error
try {
parse('a { \n color: red\n background-color: black;\n}')
} catch (e) {
error = e
}
expect(error.message).toMatch(/2:15: Missed semicolon/)
})

0 comments on commit 422b5bf

Please sign in to comment.