Skip to content

Commit ddae783

Browse files
authored
fix: added parseError isNested argument (#54)
* fix: added parseError isNested argument * Add changeset
1 parent dee5796 commit ddae783

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

.changeset/loud-gorillas-poke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@acemir/cssom": patch
3+
---
4+
5+
fix: added parseError isNested argument

lib/CSSStyleSheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ CSSOM.CSSStyleSheet.prototype.insertRule = function(rule, index) {
163163
'HierarchyRequestError');
164164
}
165165

166-
if (parseErrors.length !== 0) {
166+
if (parseErrors.filter(function(error) { return !error.isNested; }).length !== 0) {
167167
errorUtils.throwParseError(this, 'insertRule', this.constructor.name, ruleToParse, 'SyntaxError');
168168
}
169169
}

lib/parse.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ CSSOM.parse = function parse(token, opts, errorHandler) {
880880
return true;
881881
}
882882

883-
function parseError(message) {
883+
function parseError(message, isNested) {
884884
var lines = token.substring(0, i).split('\n');
885885
var lineCount = lines.length;
886886
var charCount = lines.pop().length + 1;
@@ -889,6 +889,7 @@ CSSOM.parse = function parse(token, opts, errorHandler) {
889889
/* jshint sub : true */
890890
error['char'] = charCount;
891891
error.styleSheet = styleSheet;
892+
error.isNested = !!isNested;
892893
// Print the error but continue parsing the sheet
893894
try {
894895
throw error;
@@ -1535,7 +1536,7 @@ CSSOM.parse = function parse(token, opts, errorHandler) {
15351536
if (styleRule === nestedSelectorRule) {
15361537
nestedSelectorRule = null;
15371538
}
1538-
parseError('Invalid CSSStyleRule (selectorText = "' + styleRule.selectorText + '")');
1539+
parseError('Invalid CSSStyleRule (selectorText = "' + styleRule.selectorText + '")', styleRule.parentRule !== null);
15391540
} else {
15401541
currentScope.cssRules.push(styleRule);
15411542
}

0 commit comments

Comments
 (0)