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

Deno Compile inserts literal \r\n into code base #8746

Closed
jon49 opened this issue Dec 13, 2020 · 5 comments · Fixed by #8901
Closed

Deno Compile inserts literal \r\n into code base #8746

jon49 opened this issue Dec 13, 2020 · 5 comments · Fixed by #8901
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)

Comments

@jon49
Copy link

jon49 commented Dec 13, 2020

When I compile my scripts I have strings like so

html`<p>This is my

HTML</p>`

When I compile my scripts into an executable deno turn my string into something like this (I'm assuming):

html`<p>This is my\r\n\r\nHTML</p>`

Here's what the HTML source code looks like:

\r\n<!DOCTYPE html>\r\n<html lang="en">\r\n<head>\r\n

Which cause my web page to have a bunch of literal \r\n new line characters peppered throughout.

Here's my original code: https://github.com/jon49/VideoDownloader/blob/ea6e5b29058a421ffa1d1d2ce3cb7a983f1e64fe/src/pages/home/index.html.ts#L26

@lucacasonato lucacasonato added bug Something isn't working correctly swc related to swc (bundling/transpiling) labels Dec 13, 2020
@lucacasonato
Copy link
Member

cc @kdy1

@Liamolucko
Copy link
Contributor

This should be fixed now thanks to swc-project/swc#1286.

@bartlomieju
Copy link
Member

@jon49 are you experiencing the problem on 1.6.2?

@jon49
Copy link
Author

jon49 commented Dec 23, 2020

Looks like it didn't fix it :-(

Source html code in browser

What it looks like in the browser.

@Liamolucko
Copy link
Contributor

Whoops, looks like I misunderstood the problem.

Looking at your code some more, though, it looks like the problem is that you're using literals.raw - that contains the value without processing any escape sequences. Doing this should fix it:

 // src/util/html.ts
 function* htmlGenerator(literals, ...subs) {
-   var length = literals.raw.length,
+   var length = literals.length,
       s = "",
       escape = true
    for (var i = 0; i < length; i++) {
-      let lit = literals.raw[i]
+      let lit = literals[i]
       let sub = subs[i - 1]
       if (sub) {
          if (Array.isArray(sub)) { for (s of sub) if (s) yield s }

This could still be considered a problem, though - replacing newlines with escape sequences does change the behaviour, even if only in a minor way.

kdy1 added a commit to kdy1/swc that referenced this issue Dec 27, 2020
kdy1 added a commit to swc-project/swc that referenced this issue Dec 28, 2020
swc_bundler:
 -  Allow `export *` and `import` from same source. (denoland/deno#8828, denoland/deno#8725)
 -  Handle contextual keywords. (denoland/deno#8680)
 -  Prevent duplicated identifiers. (denoland/deno#8725)

swc_ecma_transforms:
 - dce: Preserve tags in tagged template literals. (denoland/deno#8746)
 - dce: Handle throw statement correctly. (denoland/deno#8736)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly swc related to swc (bundling/transpiling)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants