Skip to content

Commit 3f2ec1c

Browse files
committed
Minor refactoring
1 parent b6f09a6 commit 3f2ec1c

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

__tests__/definition.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ const c = keyword('c')
104104
const colon = token(':')
105105
const comma = token(',')
106106
const number = type('<number>')
107+
const plus = token('+')
107108

108109
describe('symbols', () => {
109110
it("parses and serializes '+' (delimiter)", () => {
110111
const input = "'+'"
111-
const parsed = token('+')
112-
expect(parse("'+'")).toEqual(parsed)
113-
expect(serialize(parsed)).toBe(input)
112+
expect(parse("'+'")).toEqual(plus)
113+
expect(serialize(plus)).toBe(input)
114114
})
115115
it('parses and serializes a (keyword)', () => {
116116
const input = 'a'
@@ -366,10 +366,17 @@ describe('multipliers', () => {
366366
expect(parse(input)).toEqual(parsed)
367367
expect(serialize(parsed)).toBe(input)
368368
})
369-
it("parses and serializes ','?'", () => {
369+
it("parses and serializes ,?", () => {
370+
const input = ',?'
370371
const parsed = optional(comma)
372+
expect(parse(input)).toEqual(parsed)
371373
expect(parse("','?")).toEqual(parsed)
372-
expect(serialize(parsed)).toBe(',?')
374+
expect(serialize(parsed)).toBe(input)
375+
})
376+
it("parses and serializes '+'?'", () => {
377+
const parsed = optional(plus)
378+
expect(parse("'+'?")).toEqual(parsed)
379+
expect(serialize(parsed)).toBe("'+'?")
373380
})
374381
it('parses and serializes <number>?', () => {
375382
const input = '<number>?'
@@ -538,7 +545,7 @@ describe('context rules', () => {
538545
expect(parse("[['+' | '-'] <calc-product>]*", production)).toEqual(
539546
repeat(
540547
sequence(
541-
alternation(token('+'), token('-')),
548+
alternation(plus, token('-')),
542549
type('<calc-product>')),
543550
0,
544551
31))

lib/parse/definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ function consumeSymbol(chars, production) {
254254
case '/':
255255
case ':':
256256
case ';':
257-
return { type: 'token', value: char }
257+
return consumeMultiplier(chars, { type: 'token', value: char })
258258
default:
259259
return consumeIdentifier(chars, production)
260260
}

lib/parse/postprocess.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,7 @@ function postParseSymbols(symbols, node) {
14211421
* the CSS value definition syntax.
14221422
*/
14231423
function postParseSyntax(syntax, node, parser) {
1424-
const definition = parseSyntax(syntax.value, parser, node.context)
1424+
const definition = parseSyntax(syntax.value, parser)
14251425
return definition ? { ...syntax, definition } : error(node)
14261426
}
14271427

lib/parse/tokenize.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ function consumeString(chars) {
389389
* @returns {object}
390390
* @see {@link https://drafts.csswg.org/css-syntax-3/#consume-url-token}
391391
*/
392-
function consumeUrl(chars, identifier) {
393-
const start = identifier.start
392+
function consumeUrl(chars, { start }) {
394393
let value = ''
395394
chars.consumeRunOf(isWhitespace)
396395
for (const char of chars) {
@@ -403,8 +402,7 @@ function consumeUrl(chars, identifier) {
403402
return { end: chars.index + 1, start, types: ['<url-token>'], value }
404403
}
405404
if (chars.atEnd()) {
406-
error({ message: 'Unclosed url' })
407-
return { end: chars.index + 1, start, types: ['<url-token>'], value }
405+
break
408406
}
409407
consumeBadUrl(chars)
410408
return { end: chars.index + 1, start, types: ['<bad-url-token>'], value: '' }

0 commit comments

Comments
 (0)