@@ -5,9 +5,11 @@ import * as grammar from './grammar.js'
55import * as substitutions from '../values/substitutions.js'
66import {
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