```ts
export function stripComments(source: string): string {
  let result = "";
  let inString = false;
  let inBlockComment = false;

  for (let i = 0; i < source.length; i++) {
    const char = source[i];

    if (!inString && !inBlockComment) {
      if (char === '"' && (i === 0 || source[i - 1] !== "\\")) {
        inString = true;
      } else if (char === "/" && source[i + 1] === "/") {
        // Line comment, skip to the end of the line
        while (i < source.length && source[i] !== "\n") {
          i++;
        }
      } else if (char === "/" && source[i + 1] === "*") {
        inBlockComment = true;
        i++; // Skip the '*' character
      } else {
        result += char;
      }
    } else if (inString) {
      if (char === '"' && (i === 0 || source[i - 1] !== "\\")) {
        inString = false;
      }
      result += char;
    } else if (inBlockComment) {
      if (char === "*" && source[i + 1] === "/") {
        inBlockComment = false;
        i++; // Skip the '/' character
      }
    }

    if (i === source.length - 1 && inString) {
      throw new Error("Unterminated string literal");
    }
    if (i === source.length - 1 && inBlockComment) {
      throw new Error("Unterminated block comment");
    }
  }

  return result;
}
```