Don't escape valid Unicode characters in strings
See original GitHub issueTypeScript 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:
- Created 4 years ago
- Reactions:6
- Comments:6 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hitting same issue. Our workaround:
No, it was strictly ease of implementation at the time. Iβm marking this as
Difficult
because any contribution needs very thorough test code.