Skip to content

Commit

Permalink
Merge pull request #1618 from Gusted/fix-missed-semicolon
Browse files Browse the repository at this point in the history
Return correct column on `missed semicolon`
  • Loading branch information
ai committed Jul 21, 2021
2 parents 1545d8a + 422b5bf commit c72594b
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
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/)
})

0 comments on commit c72594b

Please sign in to comment.