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

Return correct column on missed semicolon #1618

Merged
merged 1 commit into from Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/parser.js
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
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/)
})