fix: preserve newline escape sequences in code generation#1790
Open
costajohnt wants to merge 2 commits intoBuilderIO:mainfrom
Open
fix: preserve newline escape sequences in code generation#1790costajohnt wants to merge 2 commits intoBuilderIO:mainfrom
costajohnt wants to merge 2 commits intoBuilderIO:mainfrom
Conversation
Fixes BuilderIO#1064 The `dedent` helper was incorrectly converting `\n` escape sequences (two characters: backslash + n) into actual newline characters. This caused generated code containing strings with `\n` to be malformed. ## Changes 1. **dedent.ts**: Remove `.replace(/\\n/g, '\n')` which was corrupting escape sequences in string literals 2. **react/generator.ts**: Remove `stripNewlinesInStrings` wrapper which was a workaround for the dedent bug 3. **parsers/jsx/jsx.ts**: Remove `stripNewlinesInStrings` wrapper and related workaround ## Before ```javascript const x = "line1\nline2"; // Would generate: const x = "line1 line2"; // Broken - actual newline inside string ``` ## After ```javascript const x = "line1\nline2"; // Now correctly generates: const x = "line1\nline2"; // Preserved escape sequence ``` As confirmed by @samijaber in the issue discussion.
🦋 Changeset detectedLatest commit: 6982748 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1064
.replace(/\\n/g, '\n')line fromdedent.tsthat was converting escape sequences to actual newlinesstripNewlinesInStringsusage which was a workaround for this bugWhy
The
dedenthelper was incorrectly converting\nescape sequences (the two-character sequence: backslash + n) into actual newline characters. This caused generated code containing strings with\nto be malformed across all targets.Before (broken):
After (fixed):
Test Plan
\nescape sequencesThe snapshot changes are expected as they now reflect the correct behavior where escape sequences are preserved rather than corrupted.
Notes
This fix approach was confirmed by @samijaber in the issue discussion:
Closes #1064