Add: isCodeEmpty

This commit is contained in:
eight 2018-10-06 15:33:18 +08:00
parent 450cd60aeb
commit 1cf6008514

View File

@ -1,7 +1,7 @@
/* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */ /* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */
/* /*
global createCache db calcStyleDigest normalizeStyleSections db promisify global createCache db calcStyleDigest normalizeStyleSections db promisify
getStyleWithNoCode msg styleCodeEmpty getStyleWithNoCode msg
*/ */
'use strict'; 'use strict';
@ -304,7 +304,17 @@ const styleManager = (() => {
code += section.code; 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() { function prepare() {