stricter "var(" check and code cosmetics
This commit is contained in:
parent
1cc8ac7559
commit
5174e7481f
|
@ -215,6 +215,8 @@ CodeMirror.hint && (() => {
|
||||||
const USO_VALID_VAR = 'variable-3 ' + USO_VAR;
|
const USO_VALID_VAR = 'variable-3 ' + USO_VAR;
|
||||||
const USO_INVALID_VAR = 'error ' + USO_VAR;
|
const USO_INVALID_VAR = 'error ' + USO_VAR;
|
||||||
const RX_IMPORTANT = /(i(m(p(o(r(t(a(nt?)?)?)?)?)?)?)?)?(?=\b|\W|$)/iy;
|
const RX_IMPORTANT = /(i(m(p(o(r(t(a(nt?)?)?)?)?)?)?)?)?(?=\b|\W|$)/iy;
|
||||||
|
const RX_VAR_KEYWORD = /(^|[^-\w\u0080-\uFFFF])var\(/iy;
|
||||||
|
const RX_END_OF_VAR = /[\s,)]|$/g;
|
||||||
|
|
||||||
const originalHelper = CodeMirror.hint.css || (() => {});
|
const originalHelper = CodeMirror.hint.css || (() => {});
|
||||||
const helper = cm => {
|
const helper = cm => {
|
||||||
|
@ -254,7 +256,7 @@ CodeMirror.hint && (() => {
|
||||||
// --css-variables
|
// --css-variables
|
||||||
const startsWithDoubleDash = text[prev] === '-' && text[prev + 1] === '-';
|
const startsWithDoubleDash = text[prev] === '-' && text[prev + 1] === '-';
|
||||||
if (startsWithDoubleDash ||
|
if (startsWithDoubleDash ||
|
||||||
leftPart === '(' && /\bvar/i.test(text.slice(prev - 4, prev))) {
|
leftPart === '(' && testAt(RX_VAR_KEYWORD, Math.max(0, prev - 4), text)) {
|
||||||
// simplified regex without CSS escapes
|
// simplified regex without CSS escapes
|
||||||
const RX_CSS_VAR = new RegExp(
|
const RX_CSS_VAR = new RegExp(
|
||||||
'(?:^|[\\s/;{])(' +
|
'(?:^|[\\s/;{])(' +
|
||||||
|
@ -270,9 +272,8 @@ CodeMirror.hint && (() => {
|
||||||
if (!startsWithDoubleDash) {
|
if (!startsWithDoubleDash) {
|
||||||
prev++;
|
prev++;
|
||||||
}
|
}
|
||||||
const rxEnd = /[\s,)]|$/g;
|
RX_END_OF_VAR.lastIndex = prev;
|
||||||
rxEnd.lastIndex = prev;
|
end = RX_END_OF_VAR.exec(text).index;
|
||||||
end = rxEnd.exec(text).index;
|
|
||||||
return {
|
return {
|
||||||
list: [...list.keys()].sort(),
|
list: [...list.keys()].sort(),
|
||||||
from: {line, ch: prev},
|
from: {line, ch: prev},
|
||||||
|
@ -322,4 +323,10 @@ CodeMirror.hint && (() => {
|
||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testAt(rx, index, text) {
|
||||||
|
if (!rx) return false;
|
||||||
|
rx.lastIndex = index;
|
||||||
|
return rx.test(text);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user