Skip to content

Commit 747f88b

Browse files
committed
Fix validating "size" nested in a math function
The validation got the node representing the math function when looking for the first root node that has calc-size() in its context, while it expected to get the root node representing the calc-size() arguments.
1 parent cb86869 commit 747f88b

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

lib/parse/replace.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as substitutions from '../values/substitutions.js'
33
import { colorFunctionKeywords, colorSpaceKeywords, colorSpaces } from '../values/colors.js'
44
import { consumeComponentValues, parseArbitrarySubstitution, parseGrammar } from './parser.js'
55
import { dimensionTypes, getCalculationType, matchNumericType } from './types.js'
6-
import { findContext, findFunction, findParent, findSibling, getFunction, getFunctionName, getRule, isProducedBy } from '../utils/context.js'
6+
import { findContext, findFunction, findParent, findSibling, getFunction, getRule, isProducedBy } from '../utils/context.js'
77
import { isDelimiter, isFailure } from '../utils/value.js'
88
import { create as createError } from '../error.js'
99
import { simplifyCalculation } from './simplify.js'
@@ -150,7 +150,7 @@ function replaceWithArbitrarySubstitution(node) {
150150
*/
151151
function replaceWithCalcSizeKeyword(node) {
152152
const { context, input } = node
153-
const basis = context.trees.findLast(node => getFunctionName(node) === 'calc-size')?.children[0]
153+
const basis = context.trees.findLast(node => node.context.definition.name === 'calc-size')?.children[0]
154154
if (basis && basis.value.value !== 'any') {
155155
const match = parseGrammar(input, 'size', node, 'lazy')
156156
if (!isFailure(match)) {

test/value.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,7 @@ describe('<calc-size()>', () => {
25912591
assert.representation('<calc-size()>', 'calc-size(any, 1px)', size, context)
25922592
})
25932593
test('valid', () => {
2594-
assert.valid('<calc-size()>', 'CALC-SIZE(AUTO, 1 * 1% + 1px + size)', 'calc-size(auto, 1% + 1px + size)', context)
2594+
assert.valid('<calc-size()>', 'CALC-SIZE(AUTO, 1 * 1% + 1px + calc(size))', 'calc-size(auto, 1% + 1px + size)', context)
25952595
})
25962596
})
25972597
describe('<color>', () => {

0 commit comments

Comments
 (0)