@acemir/cssom 0.9.28 → 0.9.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/CSSOM.js CHANGED
@@ -5264,37 +5264,52 @@ CSSOM.parse = function parse(token, opts, errorHandler) {
5264
5264
  break;
5265
5265
  }
5266
5266
 
5267
+ // Find the actual parent rule by popping from ancestor stack
5267
5268
  while (ancestorRules.length > 0) {
5268
5269
  parentRule = ancestorRules.pop();
5269
5270
 
5270
- if (parentRule instanceof CSSOM.CSSGroupingRule && (parentRule.constructor.name !== 'CSSStyleRule' || parentRule.__parentRule)) {
5271
- if (nestedSelectorRule) {
5272
- if (nestedSelectorRule.parentRule) {
5273
- prevScope = nestedSelectorRule;
5274
- currentScope = nestedSelectorRule.parentRule;
5275
- if (currentScope.cssRules.findIndex(function (rule) {
5276
- return rule === prevScope
5277
- }) === -1) {
5278
- currentScope.cssRules.push(prevScope);
5279
- }
5280
- nestedSelectorRule = currentScope;
5281
- } else {
5282
- // If nestedSelectorRule doesn't have a parentRule, we're closing a grouping rule
5283
- // inside a top-level CSSStyleRule. We need to push currentScope to the parentRule.
5284
- prevScope = currentScope;
5285
- // Push to actual parent from ancestorRules if available
5286
- var actualParent = ancestorRules.length > 0 ? ancestorRules[ancestorRules.length - 1] : nestedSelectorRule;
5287
- actualParent !== prevScope && actualParent.cssRules.push(prevScope);
5288
- // Update currentScope to the nestedSelectorRule before breaking
5289
- currentScope = actualParent;
5290
- parentRule = actualParent;
5291
- break;
5271
+ // Skip if we popped the current scope itself (happens because we push both rule and parent)
5272
+ if (parentRule === currentScope) {
5273
+ continue;
5274
+ }
5275
+
5276
+ // Only process valid grouping rules
5277
+ if (!(parentRule instanceof CSSOM.CSSGroupingRule && (parentRule.constructor.name !== 'CSSStyleRule' || parentRule.__parentRule))) {
5278
+ continue;
5279
+ }
5280
+
5281
+ // Determine if we're closing a special nested selector context
5282
+ var isClosingNestedSelectorContext = nestedSelectorRule &&
5283
+ (currentScope === nestedSelectorRule || nestedSelectorRule.__parentRule === currentScope);
5284
+
5285
+ if (isClosingNestedSelectorContext) {
5286
+ // Closing the nestedSelectorRule or its direct container
5287
+ if (nestedSelectorRule.parentRule) {
5288
+ // Add nestedSelectorRule to its parent and update scope
5289
+ prevScope = nestedSelectorRule;
5290
+ currentScope = nestedSelectorRule.parentRule;
5291
+ if (currentScope.cssRules.indexOf(prevScope) === -1) {
5292
+ currentScope.cssRules.push(prevScope);
5292
5293
  }
5294
+ nestedSelectorRule = currentScope;
5293
5295
  } else {
5296
+ // Top-level CSSStyleRule with nested grouping rule
5294
5297
  prevScope = currentScope;
5295
- parentRule !== prevScope && parentRule.cssRules.push(prevScope);
5298
+ var actualParent = ancestorRules.length > 0 ? ancestorRules[ancestorRules.length - 1] : nestedSelectorRule;
5299
+ if (actualParent !== prevScope) {
5300
+ actualParent.cssRules.push(prevScope);
5301
+ }
5302
+ currentScope = actualParent;
5303
+ parentRule = actualParent;
5296
5304
  break;
5297
5305
  }
5306
+ } else {
5307
+ // Regular case: add currentScope to parentRule
5308
+ prevScope = currentScope;
5309
+ if (parentRule !== prevScope) {
5310
+ parentRule.cssRules.push(prevScope);
5311
+ }
5312
+ break;
5298
5313
  }
5299
5314
  }
5300
5315
 
package/lib/parse.js CHANGED
@@ -2293,37 +2293,52 @@ CSSOM.parse = function parse(token, opts, errorHandler) {
2293
2293
  break;
2294
2294
  }
2295
2295
 
2296
+ // Find the actual parent rule by popping from ancestor stack
2296
2297
  while (ancestorRules.length > 0) {
2297
2298
  parentRule = ancestorRules.pop();
2298
2299
 
2299
- if (parentRule instanceof CSSOM.CSSGroupingRule && (parentRule.constructor.name !== 'CSSStyleRule' || parentRule.__parentRule)) {
2300
- if (nestedSelectorRule) {
2301
- if (nestedSelectorRule.parentRule) {
2302
- prevScope = nestedSelectorRule;
2303
- currentScope = nestedSelectorRule.parentRule;
2304
- if (currentScope.cssRules.findIndex(function (rule) {
2305
- return rule === prevScope
2306
- }) === -1) {
2307
- currentScope.cssRules.push(prevScope);
2308
- }
2309
- nestedSelectorRule = currentScope;
2310
- } else {
2311
- // If nestedSelectorRule doesn't have a parentRule, we're closing a grouping rule
2312
- // inside a top-level CSSStyleRule. We need to push currentScope to the parentRule.
2313
- prevScope = currentScope;
2314
- // Push to actual parent from ancestorRules if available
2315
- var actualParent = ancestorRules.length > 0 ? ancestorRules[ancestorRules.length - 1] : nestedSelectorRule;
2316
- actualParent !== prevScope && actualParent.cssRules.push(prevScope);
2317
- // Update currentScope to the nestedSelectorRule before breaking
2318
- currentScope = actualParent;
2319
- parentRule = actualParent;
2320
- break;
2300
+ // Skip if we popped the current scope itself (happens because we push both rule and parent)
2301
+ if (parentRule === currentScope) {
2302
+ continue;
2303
+ }
2304
+
2305
+ // Only process valid grouping rules
2306
+ if (!(parentRule instanceof CSSOM.CSSGroupingRule && (parentRule.constructor.name !== 'CSSStyleRule' || parentRule.__parentRule))) {
2307
+ continue;
2308
+ }
2309
+
2310
+ // Determine if we're closing a special nested selector context
2311
+ var isClosingNestedSelectorContext = nestedSelectorRule &&
2312
+ (currentScope === nestedSelectorRule || nestedSelectorRule.__parentRule === currentScope);
2313
+
2314
+ if (isClosingNestedSelectorContext) {
2315
+ // Closing the nestedSelectorRule or its direct container
2316
+ if (nestedSelectorRule.parentRule) {
2317
+ // Add nestedSelectorRule to its parent and update scope
2318
+ prevScope = nestedSelectorRule;
2319
+ currentScope = nestedSelectorRule.parentRule;
2320
+ if (currentScope.cssRules.indexOf(prevScope) === -1) {
2321
+ currentScope.cssRules.push(prevScope);
2321
2322
  }
2323
+ nestedSelectorRule = currentScope;
2322
2324
  } else {
2325
+ // Top-level CSSStyleRule with nested grouping rule
2323
2326
  prevScope = currentScope;
2324
- parentRule !== prevScope && parentRule.cssRules.push(prevScope);
2327
+ var actualParent = ancestorRules.length > 0 ? ancestorRules[ancestorRules.length - 1] : nestedSelectorRule;
2328
+ if (actualParent !== prevScope) {
2329
+ actualParent.cssRules.push(prevScope);
2330
+ }
2331
+ currentScope = actualParent;
2332
+ parentRule = actualParent;
2325
2333
  break;
2326
2334
  }
2335
+ } else {
2336
+ // Regular case: add currentScope to parentRule
2337
+ prevScope = currentScope;
2338
+ if (parentRule !== prevScope) {
2339
+ parentRule.cssRules.push(prevScope);
2340
+ }
2341
+ break;
2327
2342
  }
2328
2343
  }
2329
2344
 
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "parser",
8
8
  "styleSheet"
9
9
  ],
10
- "version": "0.9.28",
10
+ "version": "0.9.29",
11
11
  "author": "Nikita Vasilyev <me@elv1s.ru>",
12
12
  "contributors": [
13
13
  "Acemir Sousa Mendes <acemirsm@gmail.com>"