|
1 | 1 |
|
2 | 2 | const { angle, filter, keyword, list, map, number, omitted, string } = require('../values/value.js') |
3 | | -const { findContext, findParent, findSibling } = require('../utils/context.js') |
| 3 | +const { findContext, findSibling, isDeclaredBy, isProducedBy } = require('../utils/context.js') |
4 | 4 | const { addTypes, dimensionTypes, getCalculationType, matchNumericType, types: numericTypes } = require('./types.js') |
5 | 5 | const { isCalculation, isColon, isList, isOmitted, isWhitespace } = require('../utils/value.js') |
6 | 6 | const { isHexadecimal, isIdentifierCharacter, isWhitespace: isWhitespaceCharacter } = require('./tokenize.js') |
@@ -167,7 +167,7 @@ function postParseAnimateableFeature(name, node) { |
167 | 167 | * It aborts parsing when the timeline is a keyword used as <progress-source>. |
168 | 168 | */ |
169 | 169 | function postParseAnimationTimeline(timeline, node) { |
170 | | - if (timeline.types.includes('<keyword>') && findParent(node, node => node.definition.name === '<progress-source>')) { |
| 170 | + if (timeline.types.includes('<keyword>') && isProducedBy(node, '<progress-source>')) { |
171 | 171 | return error(node) |
172 | 172 | } |
173 | 173 | return timeline |
@@ -260,10 +260,7 @@ function postParseCalcValue(value) { |
260 | 260 | * in @font-palette-values. |
261 | 261 | */ |
262 | 262 | function postParseColor(color, node) { |
263 | | - if ( |
264 | | - node.context.declaration?.definition.name === 'override-colors' |
265 | | - && !color.types.includes('<color-base>') |
266 | | - ) { |
| 263 | + if (isDeclaredBy(node, 'override-colors') && !color.types.includes('<color-base>')) { |
267 | 264 | return error(node) |
268 | 265 | } |
269 | 266 | return color |
@@ -500,7 +497,7 @@ function postParseDimension(dimension, { definition: { max, min, name } }) { |
500 | 497 | * It aborts parsing the name when it is invalid in the context. |
501 | 498 | */ |
502 | 499 | function postParseFamilyName(name, node) { |
503 | | - const invalid = node.context.declaration?.definition.name === 'voice-family' |
| 500 | + const invalid = isDeclaredBy(node, 'voice-family') |
504 | 501 | ? reserved.voiceFamilyName |
505 | 502 | : reserved.fontFamilyName |
506 | 503 | if (name.types.includes('<string>') || 1 < name.length || !invalid.includes(name[0].value.toLowerCase())) { |
@@ -1015,7 +1012,7 @@ function postParseMediaFeatureName(name, node) { |
1015 | 1012 | if (descriptors[contextName][lowercase]) { |
1016 | 1013 | return { ...name, value: lowercase } |
1017 | 1014 | } |
1018 | | - } else if (parent?.parent?.definition.name === '<mf-plain>'/* only for <mf-name> tests: */ || !parent) { |
| 1015 | + } else if (isProducedBy(node, '<mf-plain>') /* only for <mf-name> tests: */ || !node.parent) { |
1019 | 1016 | if (target) { |
1020 | 1017 | return { ...name, value: `${lowercase.includes('min-') ? 'min' : 'max'}-${target}` } |
1021 | 1018 | } |
@@ -1260,7 +1257,7 @@ function postParsePaintOrder(paint) { |
1260 | 1257 | * is the offset-path property. |
1261 | 1258 | */ |
1262 | 1259 | function postParsePath(path, node) { |
1263 | | - if (node.context.declaration?.definition.name === 'offset-path') { |
| 1260 | + if (isDeclaredBy(node, 'offset-path')) { |
1264 | 1261 | const { value: [,, ...tail] } = path |
1265 | 1262 | return { ...path, value: list([omitted, omitted, ...tail]) } |
1266 | 1263 | } |
@@ -1573,7 +1570,7 @@ function postParseStyleFeature(feature, node, { createContext, getDeclarationDef |
1573 | 1570 | const { types, value } = feature |
1574 | 1571 | if ( |
1575 | 1572 | types[0] === '<ident-token>' |
1576 | | - ? getDeclarationDefinition(value, createContext('@style')) |
| 1573 | + ? getDeclarationDefinition(createContext('@style'), value) |
1577 | 1574 | : !value.value?.startsWith?.('revert') |
1578 | 1575 | ) { |
1579 | 1576 | return feature |
|
0 commit comments