Skip to content

Commit f8db75b

Browse files
author
mika
committed
fix simplifing css selector text
Should not error out in any cases.
1 parent fbfeef3 commit f8db75b

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/js/snapshot/css-selector-text.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,26 @@ const PSEUDO_ELEMENTS_DICT = {
142142
*
143143
* 2. using the universal selector(*) if the edited selector become empty.
144144
*
145+
*
146+
* Note that we are not fully parsing the selector text
147+
* (css functions in each parts is not processed),
148+
* So in the case that the parser throwing an Error,
149+
* We just return global selector(*),
150+
* These rules will be saved,
151+
* it's OK, we just save a unused stylesheet rule, not a big deal.
145152
*/
146153
function simplify(selectorText) {
147-
return editSelectorText(selectorText, attrModifier, pseudoModifier);
154+
try {
155+
return editSelectorText(selectorText, attrModifier, pseudoModifier);
156+
} catch (e) {
157+
// something unexped happened
158+
// or we can't process this selectorText correctly
159+
// just accept this selectorText
160+
console.warn("Something went wrong when editSelectorText()")
161+
console.warn(e.message);
162+
console.warn(e.stack);
163+
return "*";
164+
}
148165
}
149166

150167

@@ -676,7 +693,6 @@ class Matcher {
676693
selectorTextArgInvalid = true;
677694
}
678695

679-
// FIXME adding catch ?
680696
const simplifiedSelectorText = simplify(selectorText);
681697

682698
if (simplifiedSelectorText === selectorText) {

test/snapshot/test-css-selector-text.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,7 @@ describe("CSS selector text", () => {
8080
changeTo("::unknown-element-name", "*");
8181
changeTo(":host(#id)[attr=value]:first-child[open]", "[attr=value]:first-child");
8282

83+
// nested css functions, just keep it
84+
changeTo("it[max(3, min(2, *v)]", "*");
85+
8386
});

0 commit comments

Comments
 (0)