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

[WIP] check ascii_only first fix #9515 #9814

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ahaoboy
Copy link

@ahaoboy ahaoboy commented Dec 26, 2024

Description:

Implements functionality similar to esbuild charset=utf8

https://esbuild.github.io/api/#charset

In old engines like mujs, "\uD83C\uDF0F" is not supported. When ascii_only is false, the expected output is "🌏"

BREAKING CHANGE:
This may cause the default behavior to change, but I don't know how widespread that will be.

Related issue (if exists):

#9515

@ahaoboy ahaoboy requested a review from a team as a code owner December 26, 2024 14:54
Copy link

changeset-bot bot commented Dec 26, 2024

⚠️ No Changeset found

Latest commit: 38ecc84

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Dec 26, 2024

CLA assistant check
All committers have signed the CLA.

@ahaoboy ahaoboy marked this pull request as draft December 26, 2024 14:54
Copy link

codspeed-hq bot commented Dec 26, 2024

CodSpeed Performance Report

Merging #9814 will not alter performance

Comparing ahaoboy:fix-9515 (5c7624f) with main (7768114)

Summary

✅ 194 untouched benchmarks

@ahaoboy
Copy link
Author

ahaoboy commented Dec 27, 2024

ascii_only <=es5 output
true true "\uD83C\uDF0F"
true false "\u{1F30F}"
false true "\uD83C\uDF0F"
false false "🌏"
if target <= EsVersion::Es5 {
        // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
        let h = ((c as u32 - 0x10000) / 0x400) + 0xd800;
        let l = (c as u32 - 0x10000) % 0x400 + 0xdc00;

        let _ = write!(buf, "\\u{:04X}\\u{:04X}", h, l);
    } else if ascii_only {
        let _ = write!(buf, "\\u{{{:04X}}}", c as u32);
    } else {
        buf.push(c);
    }
} else if ascii_only {
    let _ = write!(buf, "\\u{:04X}", c as u16);
} else {
    buf.push(c);
}

This pr will get the following output

ascii_only <=es5 output
true true "\uD83C\uDF0F"
true false "\u{1F30F}"
false true "🌏"
false false "🌏"

@kdy1 kdy1 self-assigned this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants