Skip to content

Commit d12b190

Browse files
committed
simple block -> block
1 parent 47db9f1 commit d12b190

File tree

12 files changed

+76
-76
lines changed

12 files changed

+76
-76
lines changed

__tests__/definition.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,17 @@ describe('symbols', () => {
222222
test('(a)', () => {
223223
const parsed = {
224224
associatedToken: '(',
225-
type: 'simple-block',
226-
value: { associatedToken: '(', type: 'simple-block', value: a },
225+
type: 'block',
226+
value: { associatedToken: '(', type: 'block', value: a },
227227
}
228228
expect(parse('( ( a ) )')).toEqual(parsed)
229229
expect(serialize(parsed)).toBe('((a))')
230230
})
231231
test("'['a']'", () => {
232232
const parsed = {
233233
associatedToken: '[',
234-
type: 'simple-block',
235-
value: { associatedToken: '[', type: 'simple-block', value: a },
234+
type: 'block',
235+
value: { associatedToken: '[', type: 'block', value: a },
236236
}
237237
expect(parse("'[' '[' a ']' ']'")).toEqual(parsed)
238238
expect(serialize(parsed)).toBe("'[''['a']'']'")

__tests__/value.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ describe('comma separated values', () => {
753753
expect(parse(definition, 'a, ,')).toBe('a,,')
754754
})
755755
})
756-
describe('simple blocks', () => {
756+
describe('blocks', () => {
757757
test('invalid', () => {
758758
expect(parse('(a)', '[a]', false)).toBeNull()
759759
})
@@ -3556,7 +3556,7 @@ describe('<line-names>', () => {
35563556
test('representation', () => {
35573557
expect(parse('<line-names>', '[name]', false)).toMatchObject({
35583558
associatedToken: '[',
3559-
types: ['<simple-block>', '<line-names>'],
3559+
types: ['<block>', '<line-names>'],
35603560
value: list([customIdent('name')]),
35613561
})
35623562
})
@@ -4049,7 +4049,7 @@ describe('<supports-decl>', () => {
40494049
}
40504050
const block = {
40514051
associatedToken: '(',
4052-
types: ['<simple-block>', '<supports-decl>'],
4052+
types: ['<block>', '<supports-decl>'],
40534053
value: declaration,
40544054
}
40554055
expect(parse('<supports-decl>', '(color: green)', false, supportsRule)).toMatchObject(block)
@@ -4087,7 +4087,7 @@ describe('<supports-feature>', () => {
40874087
test('representation', () => {
40884088
expect(parse('<supports-feature>', '(color: green)', false, supportsRule)).toMatchObject({
40894089
associatedToken: '(',
4090-
types: ['<simple-block>', '<supports-decl>', '<supports-feature>'],
4090+
types: ['<block>', '<supports-decl>', '<supports-feature>'],
40914091
value: {
40924092
important: false,
40934093
name: 'color',

lib/match/media.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ function match(query, window) {
334334
return 'unknown'
335335
}
336336
// (<media-condition>) | (<media-feature>)
337-
if (query.types[0] === '<simple-block>') {
337+
if (query.types[0] === '<block>') {
338338
return match(query.value, window)
339339
}
340340
// <media-feature>

lib/parse/arbitrary.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
const { isComma, isDelimiter, isSimpleBlock, isWhitespace } = require('../utils/value.js')
2+
const { isBlock, isComma, isDelimiter, isWhitespace } = require('../utils/value.js')
33
const { list, omitted } = require('../values/value.js')
44
const Stream = require('./stream.js')
55
const blocks = require('../values/blocks.js')
@@ -35,7 +35,7 @@ function matchAnyValue(input, restricted, stops = []) {
3535
type === '<bad-string-token>'
3636
|| type === '<bad-url-token>'
3737
|| isDelimiter(stops, next)
38-
|| (restricted && (isComma(next) || isSimpleBlock(next, '{')))
38+
|| (restricted && (isComma(next) || isBlock(next, '{')))
3939
) {
4040
break
4141
}
@@ -66,7 +66,7 @@ function matchCommaContainingValue(node, match) {
6666
if (input.atEnd()) {
6767
return null
6868
}
69-
if (isSimpleBlock(input.next(), '{')) {
69+
if (isBlock(input.next(), '{')) {
7070
const block = input.consume()
7171
const value = match(new Stream(block.value))
7272
if (value) {

lib/parse/definition.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ function consumeDelimiter(chars, production) {
131131
const quote = chars.current
132132
const value = chars.consume()
133133
chars.consume(quote)
134-
// A simple block associated to `[` cannot be defined with unquoted `[` and `]`
134+
// A block associated to `[` cannot be defined with unquoted `[` and `]`
135135
if (value === '[') {
136136
const value = consumeDefinition(chars, production)
137137
chars.consume(quote, Error)
138138
chars.consume(']', Error)
139139
chars.consume(quote, Error)
140-
return { associatedToken: '[', type: 'simple-block', value }
140+
return { associatedToken: '[', type: 'block', value }
141141
}
142142
return { type: 'token', value }
143143
}
@@ -247,7 +247,7 @@ function consumeSymbolUnit(chars, production) {
247247
case '{': {
248248
const value = consumeDefinition(chars, production)
249249
chars.consume(blocks.associatedTokens[char], Error)
250-
return { associatedToken: char, type: 'simple-block', value }
250+
return { associatedToken: char, type: 'block', value }
251251
}
252252
case '[': {
253253
const group = consumeDefinition(chars, production)

lib/parse/grammar.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
const { createPermutationIterator, getPermutationIndex } = require('./permutation.js')
3+
const { isBlock, isDelimiter, isList, isOmitted } = require('../utils/value.js')
34
const { isBranch, isCSSType, isSequence } = require('../utils/definition.js')
4-
const { isDelimiter, isList, isOmitted, isSimpleBlock } = require('../utils/value.js')
55
const { list, omitted } = require('../values/value.js')
66
const Stream = require('./stream.js')
77
const actions = require('./actions.js')
@@ -212,14 +212,14 @@ function match(node, parser) {
212212
switch (type) {
213213
case 'arbitrary':
214214
return arbitrary[name](node, parser)
215+
case 'block':
216+
return input.consume(matchBlock, node, parser)
215217
case 'forgiving':
216218
return parser.parseCSSGrammarList(input, forgiving[name], { ...context, forgiving: true })
217219
case 'function':
218220
return input.consume(matchFunction, node, parser)
219221
case 'omitted':
220222
return omitted
221-
case 'simple-block':
222-
return input.consume(matchSimpleBlock, node, parser)
223223
case 'token':
224224
return input.consume(matchToken, node)
225225
default:
@@ -233,9 +233,9 @@ function match(node, parser) {
233233
* @param {object} parser
234234
* @returns {object|null}
235235
*/
236-
function matchSimpleBlock(value, node, parser) {
236+
function matchBlock(value, node, parser) {
237237
const { context, definition, input } = node
238-
if (isSimpleBlock(value, definition.associatedToken)) {
238+
if (isBlock(value, definition.associatedToken)) {
239239
const match = parser.parseCSSValue(
240240
new Stream(value.value, input.source),
241241
definition.value,

lib/parse/parser.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
const { isCloseCurlyBrace, isColon, isComma, isComputationallyIndependent, isDelimiter, isOpenCurlyBrace, isSemicolon, isSimpleBlock, isWhitespace } = require('../utils/value.js')
2+
const { isBlock, isCloseCurlyBrace, isColon, isComma, isComputationallyIndependent, isDelimiter, isOpenCurlyBrace, isSemicolon, isWhitespace } = require('../utils/value.js')
33
const Stream = require('./stream.js')
44
const blocks = require('../values/blocks.js')
55
const compatibility = require('../compatibility.js')
@@ -396,13 +396,13 @@ function consumeFunction(tokens, { start, value: name }) {
396396
*
397397
* It deviates from the specification by trimming whitespaces.
398398
*/
399-
function consumeSimpleBlock(tokens, { start, value: associatedToken }) {
399+
function consumeBlock(tokens, { start, value: associatedToken }) {
400400
const closingToken = blocks.associatedTokens[associatedToken]
401401
const value = consumeComponentValueList(tokens, [closingToken])
402402
if (!tokens.consume(isDelimiter(closingToken))) {
403403
error({ message: 'Unclosed block' })
404404
}
405-
return { associatedToken, end: tokens.current.end, start, types: ['<simple-block>'], value }
405+
return { associatedToken, end: tokens.current.end, start, types: ['<block>'], value }
406406
}
407407

408408
/**
@@ -413,7 +413,7 @@ function consumeSimpleBlock(tokens, { start, value: associatedToken }) {
413413
function consumeComponentValue(tokens) {
414414
const current = tokens.consume()
415415
if (blocks.associatedTokens[current.value]) {
416-
return consumeSimpleBlock(tokens, current)
416+
return consumeBlock(tokens, current)
417417
}
418418
if (current.types[0] === '<function-token>') {
419419
return consumeFunction(tokens, current)
@@ -506,11 +506,11 @@ function consumeDeclarationValue(tokens, forCustomProperty, nested) {
506506
continue
507507
}
508508
// Positioned {}-block
509-
if (values.some(value => !isWhitespace(value)) && isSimpleBlock(value, '{')) {
509+
if (values.some(value => !isWhitespace(value)) && isBlock(value, '{')) {
510510
return
511511
}
512512
const prev = values.findLast(value => !isWhitespace(value))
513-
if (prev && isSimpleBlock(prev, '{')) {
513+
if (prev && isBlock(prev, '{')) {
514514
return
515515
}
516516
values.push(value)
@@ -695,7 +695,7 @@ function consumeAtRule(tokens, context, nested) {
695695
* It deviates from the specification by sorting declarations in specified
696696
* order.
697697
*/
698-
function consumeBlock(tokens, context, ignoreCloseCurlyBlock) {
698+
function consumeBlockContents(tokens, context, ignoreCloseCurlyBlock) {
699699
const rules = list([], ' ', '<block-contents>')
700700
const declarations = []
701701
while (!tokens.atEnd()) {
@@ -898,7 +898,7 @@ function parseRule(input, context) {
898898
function parseDeclarationBlock(input, context) {
899899
input = normalizeIntoTokens(input)
900900
context = createContext(context)
901-
const declarations = consumeBlock(input, context, true).filter(Array.isArray).flat()
901+
const declarations = consumeBlockContents(input, context, true).filter(Array.isArray).flat()
902902
return getDeclarationsInSpecifiedOrder(declarations)
903903
}
904904

@@ -909,7 +909,7 @@ function parseDeclarationBlock(input, context) {
909909
* @see {@link https://drafts.csswg.org/css-syntax-3/#parse-a-blocks-contents}
910910
*/
911911
function parseBlockContents(input, context) {
912-
return consumeBlock(normalizeIntoTokens(input), createContext(context))
912+
return consumeBlockContents(normalizeIntoTokens(input), createContext(context))
913913
}
914914

915915
/**
@@ -988,7 +988,7 @@ function parseCSSArbitrarySubstitutionContainingValue(input, context) {
988988
let containsSubstitution = false
989989
for (let value of input) {
990990
const { types: [type], value: nested } = value
991-
if (type === '<function>' || type === '<simple-block>') {
991+
if (type === '<function>' || type === '<block>') {
992992
if (type === '<function>') {
993993
const match = parseCSSArbitrarySubstitution(value, context)
994994
if (match instanceof SyntaxError) {

lib/parse/postprocess.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ function postParseCalcSum([left, tail]) {
247247
* It unwraps a calculation nested in a simple block (step 5.1).
248248
*/
249249
function postParseCalcValue(value) {
250-
return value.types[0] === '<simple-block>' ? value.value : value
250+
return value.types[0] === '<block>' ? value.value : value
251251
}
252252

253253
/**

lib/serialize.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { canonicalize, definitions: dimensions, getCanonicalUnitFromType } = requ
44
const { clamp, isDegenerate, safeFloat, toEightBit } = require('./utils/math.js')
55
const { combinators, isCombination, isCompound, isMultiplied } = require('./utils/definition.js')
66
const { hslToRgb, hwbToRgb } = require('./utils/color.js')
7-
const { isCalculationOperator, isComma, isList, isNumeric, isOmitted, isSimpleBlock } = require('./utils/value.js')
7+
const { isBlock, isCalculationOperator, isComma, isList, isNumeric, isOmitted } = require('./utils/value.js')
88
const { isDigit, isIdentifierCharacter, isNonASCIIIdentifierCharacter } = require('./parse/tokenize.js')
99
const { list, map, string } = require('./values/value.js')
1010
const { auto } = require('./values/defaults.js')
@@ -55,7 +55,7 @@ function serializeCommaContainingValue(value, context) {
5555
if (context === 'var') {
5656
return string.startsWith('{') ? `{${string}}` : string
5757
}
58-
if (context && value.some(value => isComma(value) || isSimpleBlock(value, '{'))) {
58+
if (context && value.some(value => isComma(value) || isBlock(value, '{'))) {
5959
return `{${string}}`
6060
}
6161
return string
@@ -159,6 +159,18 @@ function serializeBasicShapeRect({ name, value }) {
159159
return `${name}(${value} round ${radius})`
160160
}
161161

162+
/**
163+
* @param {object} block
164+
* @returns {string}
165+
*/
166+
function serializeBlock({ associatedToken, value }) {
167+
value = serializeCSSComponentValue(value)
168+
if (value && associatedToken === '{') {
169+
value = ` ${value} `
170+
}
171+
return `${associatedToken}${value}${blocks.associatedTokens[associatedToken]}`
172+
}
173+
162174
/**
163175
* @param {object[][]} radii
164176
* @returns {string}
@@ -723,6 +735,12 @@ function serializeDefinition(definition, parentPrecedence = 0) {
723735
if (name === '<keyword>') {
724736
return range
725737
}
738+
if (type === 'block') {
739+
if (associatedToken === '[') {
740+
return `'['${serializeDefinition(value)}']'`
741+
}
742+
return `${associatedToken}${serializeDefinition(value)}${blocks.associatedTokens[associatedToken]}`
743+
}
726744
if (type === 'function') {
727745
if (name) {
728746
if (value) {
@@ -732,12 +750,6 @@ function serializeDefinition(definition, parentPrecedence = 0) {
732750
}
733751
return `<function-token> ${serializeDefinition(value)} )`
734752
}
735-
if (type === 'simple-block') {
736-
if (associatedToken === '[') {
737-
return `'['${serializeDefinition(value)}']'`
738-
}
739-
return `${associatedToken}${serializeDefinition(value)}${blocks.associatedTokens[associatedToken]}`
740-
}
741753
if (type === 'token') {
742754
if (name) {
743755
return name
@@ -1016,7 +1028,7 @@ function serializeLineNames(names, allowEmpty) {
10161028
if (names.value.length === 0) {
10171029
return allowEmpty ? '[]' : ''
10181030
}
1019-
return serializeSimpleBlock(names)
1031+
return serializeBlock(names)
10201032
}
10211033

10221034
/**
@@ -1420,18 +1432,6 @@ function serializeSides(sides) {
14201432
return serializeCSSComponentValueList(representSides(sides.map(serializeCSSComponentValue)))
14211433
}
14221434

1423-
/**
1424-
* @param {object} block
1425-
* @returns {string}
1426-
*/
1427-
function serializeSimpleBlock({ associatedToken, value }) {
1428-
value = serializeCSSComponentValue(value)
1429-
if (value && associatedToken === '{') {
1430-
value = ` ${value} `
1431-
}
1432-
return `${associatedToken}${value}${blocks.associatedTokens[associatedToken]}`
1433-
}
1434-
14351435
/**
14361436
* @param {object} skew
14371437
* @returns {string}
@@ -1617,6 +1617,8 @@ function serializeCSSComponentValue(value, context) {
16171617
case '<bg-position>':
16181618
case '<position>':
16191619
return serializePosition(value)
1620+
case '<block>':
1621+
return serializeBlock(value)
16201622
case '<blur()>':
16211623
case '<brightness()>':
16221624
case '<contrast()>':
@@ -1725,8 +1727,6 @@ function serializeCSSComponentValue(value, context) {
17251727
return serializeShadow(value)
17261728
case '<shape()>':
17271729
return serializeShape(value)
1728-
case '<simple-block>':
1729-
return serializeSimpleBlock(value)
17301730
case '<skew()>':
17311731
return serializeSkew(value)
17321732
case '<snap-block()>':

lib/utils/definition.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
const sequences = ['||', '&&', ' ']
33
const combinators = ['|', ...sequences]
4-
const compounds = ['function', 'rule', 'simple-block']
4+
const compounds = ['block', 'function', 'rule']
55

66
/**
77
* @param {object} definition

0 commit comments

Comments
 (0)