Skip to content

Commit

Permalink
Do not discard !#else block for unknown preprocessor tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Sep 30, 2024
1 parent 3d6984a commit 6cac645
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4430,14 +4430,14 @@ export const utils = (( ) => {
const parts = [ 0 ];
let discard = false;

const shouldDiscard = ( ) => stack.some(v => v);
const shouldDiscard = ( ) => stack.some(v => v.known && v.discard);

const begif = (startDiscard, match) => {
if ( discard === false && startDiscard ) {
parts.push(match.index);
const begif = details => {
if ( discard === false && details.known && details.discard ) {
parts.push(details.pos);
discard = true;
}
stack.push(startDiscard);
stack.push(details);
};

const endif = match => {
Expand All @@ -4455,15 +4455,21 @@ export const utils = (( ) => {

switch ( match[1] ) {
case 'if': {
const startDiscard = this.evaluateExpr(match[2].trim(), env) === false;
begif(startDiscard, match);
const result = this.evaluateExpr(match[2].trim(), env);
begif({
known: result !== undefined,
discard: result === false,
pos: match.index,
});
break;
}
case 'else': {
if ( stack.length === 0 ) { break; }
const startDiscard = stack[stack.length-1] === false;
const details = stack[stack.length-1];
endif(match);
begif(startDiscard, match);
details.discard = details.discard === false;
details.pos = match.index;
begif(details);
break;
}
case 'endif': {
Expand Down

0 comments on commit 6cac645

Please sign in to comment.