From 1cf6008514f9d402e8f12e7b58a92434243e0d25 Mon Sep 17 00:00:00 2001 From: eight Date: Sat, 6 Oct 2018 15:33:18 +0800 Subject: [PATCH] Add: isCodeEmpty --- background/style-manager.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index d3e350a7..a46733a4 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -1,7 +1,7 @@ /* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */ /* global createCache db calcStyleDigest normalizeStyleSections db promisify - getStyleWithNoCode msg styleCodeEmpty + getStyleWithNoCode msg */ 'use strict'; @@ -304,7 +304,17 @@ const styleManager = (() => { code += section.code; } } - return styleCodeEmpty(code) ? null : code; + return isCodeEmpty(code) ? null : code; + } + + function isCodeEmpty(code) { + const rx = /\s+|\/\*[\s\S]*?\*\/|@namespace[^;]+;|@charset[^;]+;/giy; + while (rx.exec(code)) { + if (rx.lastIndex === code.length) { + return true; + } + } + return false; } function prepare() {