Skip to content

Commit ed762ce

Browse files
committed
Redefine descriptor/property definition as declaration definition
1 parent 9c32c91 commit ed762ce

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

lib/parse/parser.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -247,35 +247,35 @@ function getDeclarationName(name, context) {
247247
* @param {object} context
248248
* @returns {object|null}
249249
*/
250-
function getDeclarationValueDefinition(name, context) {
250+
function getDeclarationDefinition(name, context) {
251251
name = getDeclarationName(name, context)
252252
const { rule: { definition: { name: ruleName, value: { descriptors, properties } } } } = context
253253
if (properties) {
254254
if (name.startsWith('--')) {
255255
const definition = properties?.['--*']
256256
if (definition) {
257-
return { name, type: 'property', value: definition.value }
257+
return { name, type: 'declaration', value: definition.value }
258258
}
259259
return null
260260
}
261261
const target = compatibility.properties.mappings.get(name)
262262
const value = properties[target]?.value ?? properties[name]?.value
263263
if (value) {
264-
return { name, type: 'property', value }
264+
return { name, type: 'declaration', value }
265265
}
266266
}
267267
if (descriptors) {
268268
if (name.startsWith('--')) {
269269
const definition = descriptors?.['--*']
270270
if (definition) {
271-
return { name, type: 'descriptor', value: definition.value }
271+
return { name, type: 'declaration', value: definition.value }
272272
}
273273
return null
274274
}
275275
const target = compatibility.descriptors[ruleName]?.mappings?.get(name)
276276
const value = descriptors[target]?.value ?? descriptors[name]?.value ?? descriptors['*']
277277
if (value) {
278-
return { name, type: 'descriptor', value }
278+
return { name, type: 'declaration', value }
279279
}
280280
}
281281
return null
@@ -536,7 +536,7 @@ function consumeDeclaration(tokens, context, nested) {
536536
if (!name) {
537537
return null
538538
}
539-
const definition = getDeclarationValueDefinition(name.value, context)
539+
const definition = getDeclarationDefinition(name.value, context)
540540
if (!definition) {
541541
return null
542542
}
@@ -1064,7 +1064,7 @@ function parseCSSValue(input, definition, context, strategy = 'backtrack') {
10641064
const { forgiving, trees } = context
10651065

10661066
// Try parsing arbitrary substitution containing value
1067-
if (trees.length === 0 && (type === 'descriptor' || type === 'property')) {
1067+
if (type === 'declaration' && !context.function) {
10681068
const substitution = parseCSSArbitrarySubstitutionContainingValue(input, context)
10691069
if (substitution) {
10701070
return substitution
@@ -1103,12 +1103,8 @@ function parseCSSValue(input, definition, context, strategy = 'backtrack') {
11031103
case 'aborted':
11041104
return (forgiving && !context.function?.context.forgiving) ? null : match
11051105
// The current list is invalid (match is null or undefined)
1106-
case 'rejected': {
1107-
if (type === 'descriptor' || type === 'property') {
1108-
return parseCSSValueSubstitution(input, context)
1109-
}
1110-
return null
1111-
}
1106+
case 'rejected':
1107+
return type === 'declaration' ? parseCSSValueSubstitution(input, context) : null
11121108
default:
11131109
return match
11141110
}
@@ -1129,7 +1125,7 @@ function parseCSSDeclaration(name, value, important, context) {
11291125
return null
11301126
}
11311127

1132-
const definition = getDeclarationValueDefinition(name, context)
1128+
const definition = getDeclarationDefinition(name, context)
11331129
if (!definition) {
11341130
return null
11351131
}
@@ -1174,7 +1170,7 @@ function parseCSSStyleSheet(rules) {
11741170
const parser = module.exports = {
11751171
createContext,
11761172
getDeclarationName,
1177-
getDeclarationValueDefinition,
1173+
getDeclarationDefinition,
11781174
insertCSSRule,
11791175
parseBlockContents,
11801176
parseCSSDeclaration,

lib/parse/postprocess.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,11 +1514,11 @@ function postParseSteps(steps, node) {
15141514
* It aborts parsing when the feature is an unknown property or a declaration
15151515
* whose value is either `revert` or `revert-layer`.
15161516
*/
1517-
function postParseStyleFeature(feature, node, { createContext, getDeclarationValueDefinition }) {
1517+
function postParseStyleFeature(feature, node, { createContext, getDeclarationDefinition }) {
15181518
const { types, value } = feature
15191519
if (
15201520
types[0] === '<ident-token>'
1521-
? getDeclarationValueDefinition(value, createContext('@style'))
1521+
? getDeclarationDefinition(value, createContext('@style'))
15221522
: !value.value?.startsWith?.('revert')
15231523
) {
15241524
return feature

lib/utils/definition.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ const compounds = ['function', 'rule', 'simple-block']
99
*/
1010
function isBranch(definition) {
1111
const { type } = definition
12-
return type === 'descriptor'
12+
return type === 'declaration'
1313
|| type === 'non-terminal'
14-
|| type === 'property'
1514
|| isCombination(definition)
1615
|| isMultiplied(definition)
1716
}

0 commit comments

Comments
 (0)