Skip to content

Commit 8c796a1

Browse files
committed
Define a rule in context before parsing its prelude
Prior to this commit and 62c87e1, a rule, declaration, function, was defined in `context` only when parsing its associated value. It is now also defined when parsing the prelude of a rule and the name of a function. The intention was to consider them as execution contexts (scopes) rather than grammars (nodes) but in other programming languages, the arguments and value of a function are actually defined in the same scope. Comparing CSS to other programming languages may not hold any further. In CSS, most expressions are defined by the language rather than the user. The name of the structure defines its grammar but it is also part of the production, which implicitly accepts aliases and mappings.
1 parent bd67248 commit 8c796a1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/parse/parser.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ function consumeQualifiedRule(tokens, context, nested) {
624624
}
625625
}
626626
const definition = getRuleDefinition(context)
627-
if (definition && (prelude = parseCSSGrammar(prelude, definition.prelude, context))) {
627+
if (definition && (prelude = parseCSSGrammar(prelude, definition.prelude, { ...context, definition }))) {
628628
return createCSSRule(null, prelude, tokens, definition, context)
629629
}
630630
tokens.reconsume()
@@ -651,7 +651,7 @@ function consumeAtRule(tokens, context, nested) {
651651
// Block at-rule
652652
if (tokens.consume(isOpenCurlyBrace)) {
653653
const definition = getRuleDefinition(context, name, prelude, 'block')
654-
if (!definition || (definition.prelude && !(prelude = parseCSSGrammar(prelude, definition.prelude, context)))) {
654+
if (!definition || (definition.prelude && !(prelude = parseCSSGrammar(prelude, definition.prelude, { ...context, definition })))) {
655655
tokens.reconsume()
656656
consumeComponentValue(tokens)
657657
return error(INVALID_RULE_SYNTAX_ERROR)
@@ -665,7 +665,7 @@ function consumeAtRule(tokens, context, nested) {
665665
// Statement at-rule
666666
const definition = getRuleDefinition(context, name, prelude, 'statement')
667667
tokens.consume(isSemicolon)
668-
if (definition?.prelude && !definition.value && (prelude = parseCSSGrammar(prelude, definition.prelude, context))) {
668+
if (definition?.prelude && !definition.value && (prelude = parseCSSGrammar(prelude, definition.prelude, { ...context, definition }))) {
669669
return createCSSRule(name, prelude, null, definition, context)
670670
}
671671
return error(INVALID_RULE_SYNTAX_ERROR)

0 commit comments

Comments
 (0)