-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e17eeb
commit 812805e
Showing
4 changed files
with
104 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,34 @@ | ||
/** | ||
* Customizes the context (CTX) for Vixeny's optimizer by filtering a list of elements based on removal and addition criteria, | ||
* and by examining the usage of these elements within a given string. This function aims to refine the CTX by ensuring that | ||
* only the relevant context elements are included | ||
* | ||
*/ | ||
export default (remove: string[]) => | ||
(elements: string[]) => | ||
(add: string[]) => | ||
(string: string) => | ||
(codeString: string): string[] => | ||
( | ||
(filtered) => | ||
(filteredString: string): string[] => | ||
elements | ||
.filter((x, index, arr) => | ||
!remove.includes(x) && | ||
// First filter: Remove elements as specified and handle 'resolve.' and 'branch.' prefix cases | ||
.filter((element, index, arr) => | ||
!remove.includes(element) && | ||
(index === 0 || | ||
(!arr[index - 1].startsWith("resolve.") && | ||
!arr[index - 1].startsWith("branch."))) | ||
!arr[index - 1].startsWith("branch."))) | ||
) | ||
.filter((v) => new RegExp(`\\b${v}\\b`).test(filtered)) // Exact match filtering using regular expression | ||
// Second filter: Match elements against the code string for exact matches | ||
.filter((element) => new RegExp(`\\b${element}\\b`).test(filteredString)) | ||
// Add the specified elements and ensure uniqueness | ||
.concat(add) | ||
.reduce( | ||
(acc, v) => acc.includes(v) === false ? acc.concat(v) : acc, | ||
(acc: string[], element) => acc.includes(element) === false ? acc.concat(element) : acc, | ||
[] as string[], | ||
) as string[] | ||
) | ||
)( | ||
string.replace(/(?<!`|\$\{.*)(["'])(?:(?=(\\?))\2.)*?\1/g, " ") | ||
// Preprocess the code string to remove string literals and normalize whitespace | ||
codeString.replace(/(?<!`|\$\{.*)(["'])(?:(?=(\\?))\2.)*?\1/g, " ") | ||
.replace(/\s+/g, " ") | ||
.replace(/ +/g, " "), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters