face-hh / subterfuge

A CLI tool designed to gamify your TypeScript learning.
Apache License 2.0
101 stars 10 forks source link

ERROR: could not parse snippet as it is >= 2 lines long. This is not an issue with your code. #2

Closed mybearworld closed 4 months ago

mybearworld commented 4 months ago

I got this error when trying to solve the roman numeral task:

/* the entire romanToInt function */
ERROR: could not parse snippet as it is >= 2 lines long. This is not an issue with your code.
error: process didn't exit successfully: `target\debug\subterfuge.exe main.ts` (exit code: 1)

What does that mean? Do I need to do something in my code to avoid this?

(Sorry for making another issue...)

face-hh commented 4 months ago

That's weird - I didn't experience it while play testing. I'll look more into it in ~3 hours, thanks for reporting it.

Could you also provide your TypeScript code? That's probably not the issue, but in case it is it would make debugging easier.

mybearworld commented 4 months ago

Sure - this is my code (I've been trying to not buy anything):

function romanToInt(
  str: string,
  value: any = null,
  lastCharacter: any = null,
  iterator: any = null
) {
  value ??= 0;
  lastCharacter ??= null;
  iterator ??= str.matchAll("." as any);
  const characterObj = iterator.next();
  const character = characterObj.value.pop() as string;
  const currentCharacterValue = romanCharacterToInt(character);
  const lastCharacterValue = romanCharacterToInt(lastCharacter);
  (lastCharacter !== null &&
    lastCharacterValue < currentCharacterValue &&
    ((value += currentCharacterValue - lastCharacterValue),
    (value -= lastCharacterValue))) ||
    ((lastCharacter = character), (value += currentCharacterValue));
  return characterObj.value.index === str.length - 1
    ? value
    : romanToInt(str, value, lastCharacter, iterator);
}

function romanCharacterToInt(str: string) {
  return (
    (str === "I" && 1) ||
    (str === "V" && 5) ||
    (str === "X" && 10) ||
    (str === "L" && 50) ||
    (str === "C" && 100) ||
    (str === "D" && 500) ||
    (str === "M" && 1000) ||
    0
  );
}

console.log(romanToInt("MIX"));
face-hh commented 4 months ago

Side note: if I had to guess, removing the types could fix your issue (X: int, for example)

mybearworld commented 4 months ago

Side note: if I had to guess, removing the types could fix your issue (X: int, for example)

That did fix it! Thanks!

face-hh commented 4 months ago

Quite odd that it didn't error out with the fact that you had types. I'll still look into it when I have time, but glad you got it working :)

face-hh commented 4 months ago

fixed in v1.0.1