Skip to content

Commit

Permalink
Fix parsing trailing comma in comma-separated list
Browse files Browse the repository at this point in the history
  • Loading branch information
cdoublev committed Nov 24, 2024
1 parent f5b0499 commit 8b2f882
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions __tests__/value.js
Original file line number Diff line number Diff line change
Expand Up @@ -4249,8 +4249,8 @@ describe('<media-query-list>', () => {
expect(parse('<media-query-list>', 'all', false, mediaQueryContext)).toMatchObject(mediaQueryList)
})
test('valid', () => {
expect(parse('<media-query-list>', ';, 1, (condition)', true, mediaQueryContext))
.toBe('not all, not all, (condition)')
expect(parse('<media-query-list>', ';, 1, (condition),', true, mediaQueryContext))
.toBe('not all, not all, (condition), not all')
expect(parse('<media-query-list>', 'all and (condition)', true, mediaQueryContext))
.toBe('(condition)')
})
Expand Down
10 changes: 6 additions & 4 deletions lib/parse/parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

const { createContext, getDeclarationValueDefinition, getRuleDefinition, getRuleType } = require('../utils/context.js')
const { isCloseCurlyBrace, isColon, isDelimiter, isOpenCurlyBrace, isSemicolon, isSimpleBlock, isWhitespace } = require('../utils/value.js')
const { isCloseCurlyBrace, isColon, isComma, isDelimiter, isOpenCurlyBrace, isSemicolon, isSimpleBlock, isWhitespace } = require('../utils/value.js')
const Stream = require('./stream.js')
const blocks = require('../values/blocks.js')
const error = require('../error.js')
Expand Down Expand Up @@ -384,10 +384,12 @@ function parseComponentValue(input) {
*/
function parseCommaSeparatedComponentValuesList(input) {
input = normalizeIntoTokens(input)
const value = list([], ',')
while (!input.atEnd()) {
if (input.atEnd()) {
return list([], ',')
}
const value = list([consumeComponentValuesList(input, [','])], ',')
while (input.consume(isComma)) {
value.push(consumeComponentValuesList(input, [',']))
input.consume()
}
return value
}
Expand Down

0 comments on commit 8b2f882

Please sign in to comment.