Skip to content

Commit 886466b

Browse files
committed
insertRule() must try parsing declarations for grouping rules
1 parent 07b9849 commit 886466b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/parse/parser.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import * as grammar from './grammar.js'
55
import * as substitutions from '../values/substitutions.js'
66
import {
77
CSSFontFeatureValuesMap,
8+
CSSGroupingRule,
89
CSSImportRule,
910
CSSLayerStatementRule,
1011
CSSNamespaceRule,
12+
CSSNestedDeclarations,
1113
CSSRule,
1214
CSSStyleSheet,
1315
} from '../cssom/index.js'
@@ -124,19 +126,31 @@ function isInvalidNamespaceRule(list, rule) {
124126

125127
/**
126128
* @param {CSSRuleListImpl[]} list
127-
* @param {CSSRuleImpl} rule
129+
* @param {string} input
128130
* @param {number} index
129131
* @param {object} context
130132
* @param {boolean} [allowImport]
131133
* @returns {number}
132134
* @see {@link https://drafts.csswg.org/cssom-1/#insert-a-css-rule}
133135
*/
134-
function insertRule(list, rule, index, context, allowImport) {
136+
function insertRule(list, input, index, context, allowImport) {
135137
if (list.length < index) {
136138
throw error(INVALID_RULE_INDEX_ERROR)
137139
}
138-
rule = parseRule(rule, context)
140+
let rule = parseRule(input, context)
139141
if (isError(rule)) {
142+
if (CSSGroupingRule.isImpl(context)) {
143+
const declarations = parseDeclarationList(input, context)
144+
if (0 < declarations.length) {
145+
rule = CSSNestedDeclarations.createImpl(context._globalObject, undefined, {
146+
declarations,
147+
parentRule: context,
148+
parentStyleSheet: context.parentStyleSheet,
149+
})
150+
list.splice(index, 0, rule)
151+
return index
152+
}
153+
}
140154
throw error(rule)
141155
}
142156
if (!allowImport && CSSImportRule.isImpl(rule)) {

0 commit comments

Comments
 (0)