Skip to content

Commit

Permalink
fixed the variable names, removed the regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jellizaveta committed Oct 24, 2023
1 parent 8111991 commit 34a8474
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions src/main/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,22 @@ module.exports = (function () {
* Adds modifiers to lines of text.
*
* @param {string[]} lines - An array of text lines.
* @param {string} modifier - The modifier to add.
* @param {string} modifiersStr - The modifier to add.
* @returns {string[]} - An array of modified lines.
*/
const addModifiers = (lines, modifier) => {
const result = [];
lines.forEach((line) => {
// Check if the line is empty or null, and skip it.
const addModifiers = (lines, modifiersStr) => {
const result = lines.map((line) => {
// Check if the line is empty or null, and return it unchanged.
if (!line || line.length === 0) {
return result;
return line;
}
// Check if the line doesn't start with '!' character (comment).
if (!line.startsWith('! ')) {
// Add the specified modifier to the line.
result.push(`${line}$${modifier}`);
if (!line.startsWith('!')) {
// Add the specified modifier to the line and return the modified line.
return `${line}$${modifiersStr}`;
}
// Return the line unchanged if it's a comment.
return line;
});
// Return the array of modified lines.
return result;
Expand Down Expand Up @@ -265,15 +266,23 @@ module.exports = (function () {
let stripComments = false;
let notOptimized = false;
let exclude = null;
let includedModifiers = null;
let addModifiers = null;

for (let i = 1; i < parts.length; i += 1) {
const attribute = parts[i].trim();
// Check if the 'attribute' string starts with 'INCLUDE_OPTION_MODIFIERS'.
if (attribute.startsWith(INCLUDE_OPTION_MODIFIERS)) {
// Extract the value inside quotes, if it exists.
const modifierMatch = attribute.match(/=["'](.*?)["']/);
// Set the 'includedModifiers' variable to the extracted value or to null if no match is found.
includedModifiers = modifierMatch ? modifierMatch[1] : null;
// Find the index of the first occurrence of '="' and add 2 to get the start index of the value.
const startIndex = attribute.indexOf('="') + 2;
// Find the index of the last occurrence of '"' to get the end index of the value.
const endIndex = attribute.lastIndexOf('"');
if (startIndex !== -1 && endIndex !== -1) {
// If both start and end indexes are found, extract the value between the quotes.
addModifiers = attribute.slice(startIndex, endIndex);
} else {
// If the quotes are not found, set 'addModifiers' to null.
addModifiers = null;
}
}
if (attribute.startsWith(INCLUDE_OPTION_COMMENTS)) {
stripComments = true;
Expand All @@ -287,10 +296,10 @@ module.exports = (function () {

return {
url,
includedModifiers,
stripComments,
notOptimized,
exclude,
addModifiers,
};
};

Expand Down Expand Up @@ -356,10 +365,10 @@ module.exports = (function () {
result = addNotOptimizedHints(result);
}

const modifier = options.includedModifiers;
const modifiersStr = options.addModifiers;

if (modifier) {
result = addModifiers(result, modifier);
if (modifiersStr) {
result = addModifiers(result, modifiersStr);
}

result = workaround.fixVersionComments(result);
Expand Down
Empty file.

0 comments on commit 34a8474

Please sign in to comment.