All files / src/lib/compiler/gbvm buildHelpers.ts

92.31% Statements 12/13
0% Branches 0/1
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 228x   8x 50x 50x 50x 50x 50x         50x           8x 44x    
import SparkMD5 from "spark-md5";
 
export const anonymizeGBVMScript = (input: string): string => {
  const functionNameMatch = input.match(/_([^:\s]*)::/);
  Iif (!functionNameMatch) return input;
  const functionName = functionNameMatch[1];
  const globalReferencePattern = new RegExp(functionName, "gm");
  const placeholderReferencePattern = new RegExp(
    "__PLACEHOLDER\\|" + functionName + "[^|]*\\|PLACEHOLDER__",
    "gm"
  );
 
  return input
    .replace(globalReferencePattern, "SCRIPT")
    .replace(/^(.globl |)(GBVM\$|GBVM_END\$).*$/gm, "") // Strip debugger comments
    .replace(placeholderReferencePattern, "SCRIPT"); // Strip recursive placeholders
};
 
export const gbvmScriptChecksum = (input: string): string => {
  return SparkMD5.hash(anonymizeGBVMScript(input));
};