question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Don't escape valid Unicode characters in strings

See original GitHub issue

TypeScript Version: 3.7.4

Code

const sf = createSourceFile(
  'aaa',
  'const a: string = "ε“ˆε“ˆ"',
  ScriptTarget.Latest
)
// try to do sth in transfrom.
const result = transform(sf, [])
const printer = createPrinter()
const printed = printer.printNode(
  EmitHint.SourceFile,
  result.transformed[0],
  sf
)
console.log(printed)

Expected behavior: const a: string = β€œε“ˆε“ˆβ€

Actual behavior: const a: string = β€œ\u54C8\u54C8”;

I am trying to use compiler api to do some transform. but the Printer seems could not generate the decoded unicode characters. wonder how to do this right?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
git9amcommented, Mar 11, 2020

Hitting same issue. Our workaround:

    let content = printer.printFile(file);
    content = unescape(content.replace(/\\u/g, "%u"));
0reactions
DanielRosenwassercommented, Jan 14, 2020

No, it was strictly ease of implementation at the time. I’m marking this as Difficult because any contribution needs very thorough test code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove non-valid unicode characters from strings in java
Based on this answer, I tried document.replaceAll("\\p{C}", ""); to just remove those characters. document here is just the document as aΒ ...
Read more >
26. Unicode in ES6 - Exploring JS
Unicode escapes for code points beyond 16 bits: \u{Β·Β·Β·} Can be used in identifiers, string literals, template literals and regular expression literals.
Read more >
Using character escapes in markup and CSS - W3C
You can use a character escape to represent any Unicode character in HTML, XHTML or XML using only ASCII characters.
Read more >
JavaScript character escape sequences - Mathias Bynens
ECMAScript 6 introduces a new kind of escape sequence in strings, namely Unicode code point escapes. Additionally, it will define String.
Read more >
encodeURI() - JavaScript - MDN Web Docs
The encodeURI() function escapes characters by UTF-8 code units, ... lone surrogates in UTF-16 do not encode any valid Unicode character,Β ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found