Summary
When the Python source contains strings with \n characters used in lstrip()/rstrip() calls, the JS and Java backends emit the newline as a literal character inside regex/string literals instead of as \n. This produces a syntax error in both languages since neither allows raw newlines inside regex or string literals.
Reproduction
Source Python:
parser = Parser(inner.lstrip(" \t\n|"))
# and
return value.rstrip("\n")
Transpiled JS:
parser = new Parser(inner.replace(/^[
|]+/, ""));
// ^ literal newline
return value.replace(/[
]+$/, "");
// ^ literal newline
Transpiled Java:
return value.replaceAll("[
]+$", "");
// ^ literal newline
Both produce syntax errors (SyntaxError: Invalid regular expression: missing / in JS, unclosed string literal in Java).
Expected
Newlines should be emitted as \n escape sequences inside regex and string literals:
parser = new Parser(inner.replace(/^[ \t\n|]+/, ""));
return value.replace(/[\n]+$/, "");
Scope
Found 2 instances in the Parable transpilation. Affects any Python code that uses \n in string arguments to lstrip(), rstrip(), strip(), or similar methods that get lowered to regex replacements.
Discovered via ldayton/Parable#413.
Summary
When the Python source contains strings with
\ncharacters used inlstrip()/rstrip()calls, the JS and Java backends emit the newline as a literal character inside regex/string literals instead of as\n. This produces a syntax error in both languages since neither allows raw newlines inside regex or string literals.Reproduction
Source Python:
Transpiled JS:
Transpiled Java:
Both produce syntax errors (
SyntaxError: Invalid regular expression: missing /in JS,unclosed string literalin Java).Expected
Newlines should be emitted as
\nescape sequences inside regex and string literals:Scope
Found 2 instances in the Parable transpilation. Affects any Python code that uses
\nin string arguments tolstrip(),rstrip(),strip(), or similar methods that get lowered to regex replacements.Discovered via ldayton/Parable#413.