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

ts.convertToBase64 does not handle emojis #49150

Open
dsherret opened this issue May 17, 2022 · 16 comments
Open

ts.convertToBase64 does not handle emojis #49150

dsherret opened this issue May 17, 2022 · 16 comments
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@dsherret
Copy link
Contributor

Bug Report

export function convertToBase64(input: string): string {

> ts.convertToBase64("πŸ“£β“")
'7aC97bOj4p2T'
> Buffer.from("πŸ“£β“").toString("base64")
'8J+To+Kdkw=='

πŸ”Ž Search Terms

  • ts.convertToBase64
  • emojis

πŸ•— Version & Regression Information

Probably a long time.

⏯ Playground Link

N/A

πŸ’» Code

ts.convertToBase64("πŸ“£β“")

πŸ™ Actual behavior

7aC97bOj4p2T

πŸ™‚ Expected behavior

8J+To+Kdkw==
@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this and removed Bug A bug in TypeScript Help Wanted You can do this labels May 18, 2022
@RyanCavanaugh
Copy link
Member

AFAIK this is only used to encode source map contents, which themselves cannot contain emoji. Switching these to a non-ordinal iteration is definitely going to make it slower -- without a concrete upside (or if I'm wrong about how this is called), I think this is a Won't Fix

@RyanCavanaugh
Copy link
Member

Reading the inbound link, I'm guessing I'm wrong about whether sourcemaps can contain emoji

@bartlomieju
Copy link

@dsherret
Copy link
Contributor Author

By the way, when running on Node it uses ts.sys.base64encode, which uses Buffer.from(...).toString("base64"). So only non-Node environments are affected (issue doesn't happen with tsc on Node).

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels May 19, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 19, 2022
@RyanCavanaugh
Copy link
Member

Gotcha, we can make the fallback implementation as slow as needed

@jakebailey
Copy link
Member

I'm looking for everyone who's patching typescript in prep for TS 5.0 (where that sort of thing breaks), and found this issue via deno's code.

@dsherret Can you instead provide base64encode on the host instead, thus avoiding the patch? Or are there calls which somehow don't use the host?

@bartlomieju
Copy link

@jakebailey we do provide base64encode on the host and we don't have a TypeScript patch for this functionality.

@jakebailey
Copy link
Member

I'm confused; https://github.com/denoland/deno/blob/main/cli/tsc/99_main_compiler.js#L822 appears to be patching TypeScript at runtime (and links back here).

@jakebailey
Copy link
Member

That being said, we now emit ES2018, so, maybe there's an efficient way to do this now anyhow.

@jakebailey
Copy link
Member

Then again, there's also a ts.deno object, so maybe this isn't the actual ts API: https://github.com/denoland/deno/blob/4c6db7aa1493139f5a832c1e9ebfe44a1c80af80/cli/tsc/99_main_compiler.js#L323

@dsherret
Copy link
Contributor Author

dsherret commented Feb 22, 2023

We don't use typescript for source maps anymore so we don't need that. I've been meaning to delete that code.

Then again, there's also a ts.deno object, so maybe this isn't the actual ts API: https://github.com/denoland/deno/blob/4c6db7aa1493139f5a832c1e9ebfe44a1c80af80/cli/tsc/99_main_compiler.js#L323

I've also been meaning to discuss about this, but I've been too busy. (For the future: Essentially we have a fork of TS to make npm specifiers workβ€”we have multiple globalThis objects... one for Deno and one for Node. The ts.deno is to make the fork easier to maintain)

@jakebailey
Copy link
Member

Ah, cool; just wanted to make sure that you weren't runtime patching and got surprised when 5.0 caused that to throw (since ESM exports can't be modified externally, bundler or not).

Aside, but, if you are already using a fork, hopefully TS is a little more buildable for your uses now with some modification; you should be able to get pure ESM out of it. Might allow some tree shaking, but, probably not too much yet.

@dsherret
Copy link
Contributor Author

I opened denoland/deno#17862 to remove its use.

Yeah, don't worry about Deno too much because I can work around the TS codebase ok then hopefully over time can work on getting anything upstreamed. (In ts-morph though I'd rather not have to modify the ts source... I have this file with all the internal stuff I use: https://github.com/dsherret/ts-morph/blob/latest/packages/common/src/typescript/tsInternal.ts)

@jakebailey
Copy link
Member

Please do send issues for APIs you think should be public; we already made public quite a few others in 5.0.

@bartlomieju
Copy link

Sorry for the confusion! I missed that we no longer use TSC for emitting source maps.

@dsherret
Copy link
Contributor Author

@jakebailey thanks! If they are going away then maybe I will try again (#21021) πŸ˜„

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

4 participants