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

Non-ASCII characters in identifiers result in invalid escape sequences #9632

Closed
JavierGelatti opened this issue Apr 9, 2024 · 0 comments · Fixed by #9574
Closed

Non-ASCII characters in identifiers result in invalid escape sequences #9632

JavierGelatti opened this issue Apr 9, 2024 · 0 comments · Fixed by #9574

Comments

@JavierGelatti
Copy link

📜 related issues I've found

🐛 bug report

Non-ASCII characters in identifiers result in invalid escape sequences when the code is bundled/optimized. This is a problem not only when using greek letters (e.g. in a mathy domain: function p(µ, σ) {}), but also when programming in languages other than english (e.g. when using accents in spanish, like in módulo).

This started happening in version 2.10.0 onwards, with 2.9.3 it doesn't do that.

🎛 Configuration (.babelrc, package.json, cli command)

The babel configuration is the default one (no babel.config.json file or anything like that).

The package.json file contains:

{
  "scripts": {
    "start": "parcel index.html"
  },
  "devDependencies": {
    "parcel": "2.10.0"
  }
}

🤔 Expected Behavior

With this HTML file as input (index.html):

<!doctype html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Mi documento</title>
    <script type="module">
        const módulo = 123;
        console.log(módulo);
    </script>
</head>
<body></body>
</html>

My expectations are:

  • When running npm start and browsing the localhost page, I should see 123 printed in the console.
  • When inspecting the generated JS code, a correct escape sequence is inserted in place of the ó in módulo. For example:
    const m\u{0f3}dulo = 123;
    console.log(m\u{0f3}dulo);
    Alternatively, I should see the code without modifications:
    const módulo = 123;
    console.log(módulo);

😯 Current Behavior

  • I see an error in the console: Uncaught SyntaxError: invalid escape sequence in Firefox, Uncaught SyntaxError: Invalid or unexpected token in Chrome.
  • The generated JS code is invalid, as the escape sequence is invalid for an identifier:
    const m\xf3dulo = 123;
    console.log(m\xf3dulo);

💁 Possible Solution

🔦 Context

I was trying to use parcel in a project which uses spanish as the language for the code (on variable names, etc.).

💻 Code Sample

See "Expected behavior"

🌍 My Environment

Software Version(s)
Parcel 2.10.0
Node 20.11.1
npm/Yarn 10.5.0
Operating System Linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants