Skip to content

Commit

Permalink
Hightlight to warn about unknown redirect tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Oct 11, 2020
1 parent 6ff72af commit 1727585
Showing 1 changed file with 51 additions and 17 deletions.
68 changes: 51 additions & 17 deletions src/js/codemirror/ubo-static-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,56 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
return null;
};

const colorNetOptionValueSpan = function(stream, bits) {
const { pos, string } = stream;
let style;
// Warn about unknown redirect tokens.
if (
string.charCodeAt(pos - 1) === 0x3D /* '=' */ &&
/[$,]redirect(-rule)?=$/.test(string.slice(0, pos))
) {
style = 'value';
let end = parser.skipUntil(
parserSlot,
parser.commentSpan.i,
parser.BITComma
);
const token = parser.strFromSlices(parserSlot, end - 3);
if ( redirectNames.has(token) === false ) {
style += ' warning';
}
stream.pos += token.length;
parserSlot = end;
return style;
}
if ( (bits & parser.BITTilde) !== 0 ) {
style = 'keyword strong';
} else if ( (bits & parser.BITPipe) !== 0 ) {
style = 'def';
}
stream.pos += parser.slices[parserSlot+2];
parserSlot += 3;
return style || 'value';
};

const colorNetOptionSpan = function(stream) {
const bits = parser.slices[parserSlot];
let style;
if ( (bits & parser.BITComma) !== 0 ) {
style = 'def strong';
netOptionValueMode = false;
} else if ( netOptionValueMode ) {
return colorNetOptionValueSpan(stream, bits);
} else if ( (bits & parser.BITTilde) !== 0 ) {
style = 'keyword strong';
} else if ( (bits & parser.BITEqual) !== 0 ) {
netOptionValueMode = true;
}
stream.pos += parser.slices[parserSlot+2];
parserSlot += 3;
return style || 'def';
};

const colorNetSpan = function(stream) {
if ( parserSlot < parser.exceptionSpan.i ) {
stream.pos += parser.slices[parserSlot+2];
Expand Down Expand Up @@ -236,23 +286,7 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
parserSlot >= parser.optionsSpan.i &&
parserSlot < parser.commentSpan.i
) {
const bits = parser.slices[parserSlot];
let style;
if ( (bits & parser.BITComma) !== 0 ) {
style = 'def strong';
netOptionValueMode = false;
} else if ( (bits & parser.BITTilde) !== 0 ) {
style = 'keyword strong';
} else if ( (bits & parser.BITPipe) !== 0 ) {
style = 'def';
} else if ( netOptionValueMode ) {
style = 'value';
} else if ( (bits & parser.BITEqual) !== 0 ) {
netOptionValueMode = true;
}
stream.pos += parser.slices[parserSlot+2];
parserSlot += 3;
return style || 'def';
return colorNetOptionSpan(stream);
}
if (
parserSlot >= parser.commentSpan.i &&
Expand Down

1 comment on commit 1727585

@uBlock-user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently, none is also getting invalidated as a token even though it's a special reserved token, regression ?

Please sign in to comment.