speed up regex for block comments

This commit is contained in:
tophf 2022-07-23 23:54:24 +03:00
parent 484ff24950
commit 00b732177f
6 changed files with 6 additions and 6 deletions

View File

@ -622,7 +622,7 @@ function SectionsEditor() {
const text = event.clipboardData.getData('text') || ''; const text = event.clipboardData.getData('text') || '';
if (/@-moz-document/i.test(text) && if (/@-moz-document/i.test(text) &&
/@-moz-document\s+(url|url-prefix|domain|regexp)\(/i /@-moz-document\s+(url|url-prefix|domain|regexp)\(/i
.test(text.replace(/\/\*([^*]|\*(?!\/))*(\*\/|$)/g, '')) .test(text.replace(/\/\*([^*]+|\*(?!\/))*(\*\/|$)/g, ''))
) { ) {
event.preventDefault(); event.preventDefault();
showMozillaFormatImport(text); showMozillaFormatImport(text);

View File

@ -29,7 +29,7 @@
'(?=[\\s;(){}[\\]/"!]|$)' + '(?=[\\s;(){}[\\]/"!]|$)' +
')', 'gi'); ')', 'gi');
const RX_DETECT_FUNC = /((rgb|hsl)a?|hwb)\(/iy; const RX_DETECT_FUNC = /((rgb|hsl)a?|hwb)\(/iy;
const RX_COMMENT = /\/\*([^*]|\*(?!\/))*(\*\/|$)/g; const RX_COMMENT = /\/\*([^*]+|\*(?!\/))*(\*\/|$)/g;
const SPACE1K = ' '.repeat(1000); const SPACE1K = ' '.repeat(1000);
// milliseconds to work on invisible colors per one run // milliseconds to work on invisible colors per one run

View File

@ -112,7 +112,7 @@ class Reporter {
//eslint-disable-next-line no-var //eslint-disable-next-line no-var
var CSSLint = (() => { var CSSLint = (() => {
const RX_EMBEDDED = /\/\*\s*csslint\s+((?:[^*]|\*(?!\/))+?)\*\//ig; const RX_EMBEDDED = /\/\*\s*csslint\s+((?:[^*]+|\*(?!\/))+?)\*\//ig;
const EBMEDDED_RULE_VALUE_MAP = { const EBMEDDED_RULE_VALUE_MAP = {
// error // error
'true': 2, 'true': 2,

View File

@ -3104,7 +3104,7 @@ self.parserlib = (() => {
readComment(first) { readComment(first) {
return first + return first +
this._reader.readCount(2 - first.length) + this._reader.readCount(2 - first.length) +
this._reader.readMatch(/([^*]|\*(?!\/))*(\*\/|$)/y); this._reader.readMatch(/([^*]+|\*(?!\/))*(\*\/|$)/y);
} }
/** /**

View File

@ -72,7 +72,7 @@ function styleCodeEmpty(code) {
return true; return true;
} }
let lastIndex = 0; let lastIndex = 0;
const rx = /\s+|\/\*([^*]|\*(?!\/))*(\*\/|$)|@namespace[^;]+;|@charset[^;]+;/giyu; const rx = /\s+|\/\*([^*]+|\*(?!\/))*(\*\/|$)|@namespace[^;]+;|@charset[^;]+;/giyu;
while (rx.exec(code)) { while (rx.exec(code)) {
lastIndex = rx.lastIndex; lastIndex = rx.lastIndex;
if (lastIndex === code.length) { if (lastIndex === code.length) {

View File

@ -8,7 +8,7 @@ function testGlobalCss() {
const css = fs.readFileSync('global.css', {encoding: 'utf8'}); const css = fs.readFileSync('global.css', {encoding: 'utf8'});
const ERR = 'global.css: missing the transition suppressor rule'; const ERR = 'global.css: missing the transition suppressor rule';
const RX_SUPPRESSOR = /[^{}]+#\\1\s?transition-suppressor[^{}]+{\s*transition:\s*none\s*!\s*important/i; const RX_SUPPRESSOR = /[^{}]+#\\1\s?transition-suppressor[^{}]+{\s*transition:\s*none\s*!\s*important/i;
const RX_COMMENT = /\/\*([^*]|\*(?!\/))*(\*\/|$)/g; const RX_COMMENT = /\/\*([^*]+|\*(?!\/))*(\*\/|$)/g;
if (!RX_SUPPRESSOR.test(css.replace(RX_COMMENT, ''))) { if (!RX_SUPPRESSOR.test(css.replace(RX_COMMENT, ''))) {
console.error(ERR); console.error(ERR);
process.exit(1); process.exit(1);