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

swc_ecma_minifier support charset option #9515

Open
ahaoboy opened this issue Aug 30, 2024 · 3 comments
Open

swc_ecma_minifier support charset option #9515

ahaoboy opened this issue Aug 30, 2024 · 3 comments

Comments

@CPunisher
Copy link
Member

This could be expected with default target Es5.

es5("ퟻ", "\"\\uD7FB\"");

@ahaoboy
Copy link
Author

ahaoboy commented Sep 7, 2024

This could be expected with default target Es5.

The expected behavior should be to display the characters directly instead of Unicode encoding, because in some engines, multi-byte encoding cannot be handled and only characters can be used. And the strange thing is that only some characters seem to be converted to unicode codes. These three are characters from the same font.

export const History = "󰋚"
export const Heart = ""
export const Random = ""

image
image

@ahaoboy
Copy link
Author

ahaoboy commented Dec 26, 2024

utf8 seems to take up less file size than unicode

const fs = require('fs')
// const a = "🌏";  // 🌏 or 
const a = "";  // 🌏 or 
const encoder = new TextEncoder();

function getUnicodeEncoding(char) {
  const unicodeArray = [];
  for (let i = 0; i < char.length; i++) {
    const codePoint = char.charCodeAt(i).toString(16).toUpperCase();
    unicodeArray.push(`\\u${codePoint.padStart(4, "0")}`);
  }
  return unicodeArray.join('');
}

const n = 1024
fs.writeFileSync("./utf8.js", `"${a.repeat(n)}"`)
fs.writeFileSync("./unicode.js", `"${getUnicodeEncoding(a).repeat(n)}"`)

Both single-byte and double-byte characters in utf8 encoding take up less space than unicode

-rw-r--r-- 1 ace None 6.1K Dec 26 20:54 unicode.js
-rw-r--r-- 1 ace None 3.1K Dec 26 20:54 utf8.js
-rw-r--r-- 1 ace None  13K Dec 26 20:54 unicode.js
-rw-r--r-- 1 ace None 4.1K Dec 26 20:54 utf8.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants