0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-07 16:22:42 +00:00

Remove unused variables

This commit is contained in:
Trevor Buckner
2024-02-20 00:04:29 -05:00
parent 1d1fa99b4b
commit f2d1b61a7a

View File

@@ -412,11 +412,11 @@ const replaceVar = function(input, hoist=false) {
const lookupVar = function(label, index, hoist=false) { const lookupVar = function(label, index, hoist=false) {
if(hoist) if(hoist)
index = Object.keys(globalLinks).length; // Move index to start from last page index = Object.keys(globalVarsList).length; // Move index to start from last page
while (index >= 0) { while (index >= 0) {
if(globalLinks[index]?.[label] !== undefined) if(globalVarsList[index]?.[label] !== undefined)
return globalLinks[index][label]; return globalVarsList[index][label];
index--; index--;
} }
@@ -455,7 +455,7 @@ const processVariableQueue = function() {
} }
globalLinks[globalPageNumber][item.varName] = { globalVarsList[globalPageNumber][item.varName] = {
content : item.content, content : item.content,
resolved : resolved resolved : resolved
}; };
@@ -466,14 +466,14 @@ const processVariableQueue = function() {
} }
if(item.type == 'varCallBlock' || item.type == 'varCallInline') { if(item.type == 'varCallBlock' || item.type == 'varCallInline') {
const value = replaceVar(item.match, true); const value = replaceVar(item.content, true);
if(value.missingValues.length > 0 && !finalLoop) { // Variable not found or not fully resolved; try again next loop. if(value.missingValues.length > 0 && !finalLoop) { // Variable not found or not fully resolved; try again next loop.
continue; // final loop will just use the best value so far continue; // final loop will just use the best value so far
} }
resolvedOne = true; resolvedOne = true;
item.content = item.content.replace(item.match, value.value); item.content = value.value;
item.type = 'text'; item.type = 'text';
} }
} }
@@ -507,7 +507,6 @@ function MarkedVariables() {
if (match.index > lastIndex) { // Any non-variable stuff if (match.index > lastIndex) { // Any non-variable stuff
linksQueue.push( linksQueue.push(
{ type : 'text', { type : 'text',
match : src.slice(lastIndex, match.index),
varName : null, varName : null,
content : src.slice(lastIndex, match.index) content : src.slice(lastIndex, match.index)
}); });
@@ -515,7 +514,6 @@ function MarkedVariables() {
if(match[1]) { if(match[1]) {
linksQueue.push( linksQueue.push(
{ type : 'text', { type : 'text',
match : match[0],
varName : null, varName : null,
content : match[0] content : match[0]
}); });
@@ -526,7 +524,6 @@ function MarkedVariables() {
linksQueue.push( linksQueue.push(
{ type : 'varDefBlock', { type : 'varDefBlock',
match : match[0],
varName : label, varName : label,
content : content content : content
}); });
@@ -536,14 +533,13 @@ function MarkedVariables() {
linksQueue.push( linksQueue.push(
{ type : 'varCallBlock', { type : 'varCallBlock',
match : match[0],
varName : label, varName : label,
content : match[0] content : match[0]
}); });
} }
if(match[8]) { // Inline Definition if(match[8]) { // Inline Definition
const label = match[10] ? match[10].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space const label = match[10] ? match[10].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
let content = match[11];// ? match[11].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space let content = match[11] ? match[11].trim().replace(/\s+/g, ' ') : null; // Trim edge spaces and shorten blocks of whitespace to 1 space
let level = 0; let level = 0;
let i; let i;
@@ -566,13 +562,11 @@ function MarkedVariables() {
linksQueue.push( linksQueue.push(
{ type : 'varDefBlock', { type : 'varDefBlock',
match : match[0],
varName : label, varName : label,
content : content content : content
}); });
linksQueue.push( linksQueue.push(
{ type : 'varCallInline', { type : 'varCallInline',
match : match[9],
varName : label, varName : label,
content : match[9] content : match[9]
}); });
@@ -582,7 +576,6 @@ function MarkedVariables() {
linksQueue.push( linksQueue.push(
{ type : 'varCallInline', { type : 'varCallInline',
match : match[0],
varName : label, varName : label,
content : match[0] content : match[0]
}); });
@@ -593,7 +586,6 @@ function MarkedVariables() {
if (lastIndex < src.length) { if (lastIndex < src.length) {
linksQueue.push( linksQueue.push(
{ type : 'text', { type : 'text',
match : src.slice(lastIndex),
varName : null, varName : null,
content : src.slice(lastIndex) content : src.slice(lastIndex)
}); });
@@ -692,7 +684,7 @@ const processStyleTags = (string)=>{
`${attributes?.length ? ` ${attributes.join(' ')}` : ''}`; `${attributes?.length ? ` ${attributes.join(' ')}` : ''}`;
}; };
const globalLinks = {}; const globalVarsList = {};
let linksQueue = []; let linksQueue = [];
let globalPageNumber = 0; let globalPageNumber = 0;
let parseVars = true; let parseVars = true;
@@ -700,7 +692,7 @@ let parseVars = true;
module.exports = { module.exports = {
marked : Marked, marked : Marked,
render : (rawBrewText, pageNumber=1)=>{ render : (rawBrewText, pageNumber=1)=>{
globalLinks[pageNumber] = {}; //Reset global links for current page, to ensure values are parsed in order globalVarsList[pageNumber] = {}; //Reset global links for current page, to ensure values are parsed in order
linksQueue = []; //Could move into MarkedVariables() linksQueue = []; //Could move into MarkedVariables()
globalPageNumber = pageNumber; globalPageNumber = pageNumber;