Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newlines in template literals replaced by literal \n #1681

Closed
lexanth opened this issue May 11, 2021 · 1 comment · Fixed by #1970
Closed

Newlines in template literals replaced by literal \n #1681

lexanth opened this issue May 11, 2021 · 1 comment · Fixed by #1970
Assignees
Labels
Milestone

Comments

@lexanth
Copy link

lexanth commented May 11, 2021

Describe the bug
swc is transpiling line breaks to \n characters. This is normally fine, but if we're going to use the raw string (either String.raw tagged template literal or the .raw in the first argument to custom tagged template literal), these are different.

Input code

console.log(String.raw`a
b
c
`);
console.log(String.raw`a\nb\nc\n`);

Gets transpiled to

console.log(String.raw`a\nb\nc\n`);
console.log(String.raw`a\nb\nc\n`);

Whereas babel retains the original line breaks (the code can run in modern node unchanged) - Babel REPL

Config

{
  "sourceMaps": true,
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "dynamicImport": true
    },
    "transform": {
      "react": {
        "runtime": "automatic",
        "refresh": true
      },
      "hidden": {
        "jest": true
      }
    }
  },
  "module": {
    "type": "commonjs"
  },
  "env": {
    "coreJs": 3,
    "mode": "usage"
  }
}

browserslist here is node 14
(this is in jest, but I've reproduced the same with the swc cli)

Expected behavior
Retain the line breaks as line breaks

Running the original code would print

a
b
c

a\nb\nc\n

Running the code post transpilation would print

a\nb\nc\n
a\nb\nc\n

Version
The version of @swc/core: 1.2.55

Additional context
Add any other context about the problem here.

@lexanth lexanth added the C-bug label May 11, 2021
@kdy1 kdy1 added this to the v1.2.58 milestone May 11, 2021
@kdy1 kdy1 modified the milestones: v1.2.58, v1.2.59 May 21, 2021
@kdy1 kdy1 modified the milestones: v1.2.59, v1.2.60 May 30, 2021
@kdy1 kdy1 modified the milestones: v1.2.60, v1.2.61 Jun 7, 2021
@kdy1 kdy1 modified the milestones: v1.2.61, v1.2.62 Jun 16, 2021
@kdy1 kdy1 modified the milestones: v1.2.62, v1.2.63 Jun 27, 2021
@kdy1 kdy1 modified the milestones: v1.2.63, v1.2.64 Jul 5, 2021
@kdy1 kdy1 modified the milestones: v1.2.64, v1.2.65 Jul 13, 2021
@kdy1 kdy1 modified the milestones: v1.2.65, v1.2.66, v1.2.67 Jul 18, 2021
kdy1 added a commit to kdy1/swc that referenced this issue Jul 27, 2021
@kdy1 kdy1 self-assigned this Jul 27, 2021
@kdy1 kdy1 modified the milestones: v1.2.67, v1.2.68 Jul 31, 2021
@kdy1 kdy1 closed this as completed in #1970 Aug 2, 2021
kdy1 added a commit that referenced this issue Aug 2, 2021
@swc-bot
Copy link
Collaborator

swc-bot commented Oct 23, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@swc-project swc-project locked as resolved and limited conversation to collaborators Oct 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging a pull request may close this issue.

3 participants