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

93.75% Statements 15/16
0% Branches 0/1
100% Functions 3/3
100% Lines 12/12

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 22 23 24 25 2610x   10x 52x 52x 52x 52x 52x         52x           10x 29x     10x 46x    
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 stripCommentsFromGBVMScript = (input: string): string => {
  return input.replace(/[\s]*;.*/g, "");
};
 
export const gbvmScriptChecksum = (input: string): string => {
  return SparkMD5.hash(anonymizeGBVMScript(input));
};