From d5de926864ad774f9772d500ede93746a832f753 Mon Sep 17 00:00:00 2001 From: Cosmin Popovici Date: Thu, 22 Sep 2022 19:06:34 +0300 Subject: [PATCH] fix: skip match helper error don't break build if matchHelper throws because it can't find the passed selector --- src/transformers/removeInlinedSelectors.js | 50 +++++++++++----------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/transformers/removeInlinedSelectors.js b/src/transformers/removeInlinedSelectors.js index f5d36e26..faeb5e83 100644 --- a/src/transformers/removeInlinedSelectors.js +++ b/src/transformers/removeInlinedSelectors.js @@ -28,36 +28,38 @@ const plugin = () => tree => { const {selector} = rule const prop = get(rule.nodes[0], 'prop') - // If we find the selector in the HTML... - tree.match(matchHelper(selector), n => { - const parsedAttrs = parseAttrs(n.attrs) - const classAttr = get(parsedAttrs, 'class', []) - const styleAttr = get(parsedAttrs, 'style', {}) + try { + // If we find the selector in the HTML... + tree.match(matchHelper(selector), n => { + const parsedAttrs = parseAttrs(n.attrs) + const classAttr = get(parsedAttrs, 'class', []) + const styleAttr = get(parsedAttrs, 'style', {}) - // If the class is in the style attribute (inlined), remove it - if (has(styleAttr, prop)) { - // Remove the class attribute - remove(classAttr, s => selector.includes(s)) - - // Remove the rule in the