-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Don't escape valid Unicode characters in strings #36174
Comments
i am seeing the api here. const realPath = path.resolve(__dirname, './utf8.ts')
const program = createProgram([realPath], {
target: ScriptTarget.ES2017,
module: ModuleKind.ES2015,
allowJs: true,
jsx: JsxEmit.Preserve,
})
// use it, got expected answer
// program.getTypeChecker()
const result = transform(sf, [])
const printer = createPrinter()
const printed = printer.printNode(
EmitHint.SourceFile,
result.transformed[0],
sf
)
console.log(printed) same here, use the program api, the file content is basic: 'const a: string = "哈哈"'. |
It's not that you're doing anything wrong - our implementation just escapes any characters outside of the printable range of ASCII characters. Nowadays e might be equipped to do a little better given that we have the set of valid unicode identifier characters. Is there a reason this emit is a problem for you? |
we use the transform api to deal our source code, for example
is there any solutions let me keep my chinese string, thanks |
I don't think we should escape these unless there's some hard necessity. |
No, it was strictly ease of implementation at the time. I'm marking this as |
Hitting same issue. Our workaround:
|
Backlog = PRs accepted, be the change you want to see in the world 😇 |
TypeScript Version: 3.7.4
Code
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?
The text was updated successfully, but these errors were encountered: