Skip to content

Compiler 0.3.1 silently changes "\n" to "n" in string literals #73

Open

Description

@u9g

With @reactivescript/compiler@0.3.1, compiling a newline separator changes its meaning without reporting a diagnostic.

Reproduction

Install the compiler in a Node.js project:

npm install --save-exact @reactivescript/compiler@0.3.1

Create repro.rx:

source text := ""

export default component Probe() {
  lines = text.split("\n")
  <pre>{lines.length}</pre>
}

Create compile.mjs and run node compile.mjs:

import { app } from "@reactivescript/compiler";
import { resolve } from "node:path";

const result = JSON.parse(app(resolve("repro.rx"), "dom"));

if (!result.modules) {
  throw new Error(JSON.stringify(result));
}

for (const module of Object.values(result.modules)) {
  console.log(module.code);
}

Actual output

The generated computation contains:

const v$lines = __rt.memo("lines", (__prev) => v$text()?.split("n"), undefined);

The separator is the letter n (U+006E), rather than a newline (U+000A). Compilation succeeds without reporting a diagnostic.

Expected behavior

The generated separator should evaluate to U+000A, preserving the semantics of .split("\n").

For example, given the JavaScript string "first\nsecond":

// Expected
["first", "second"]

// Actual with the generated separator
["first\nseco", "d"]

Impact

This caused incorrect rendering of single-line error summaries in an application. Diagnosing it required inspecting the generated JavaScript. Moving the string processing into an imported TypeScript helper worked around the issue.

Environment

  • @reactivescript/compiler: 0.3.1
  • Target: dom
  • Node.js: v24.14.1
  • Platform: macOS, arm64

Reproduced again on November 15, 2026. Confirmed for \n; other escape sequences have not been tested.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions