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

fix(es/utils): Verify alias ident name #6423

Merged
merged 1 commit into from Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issues-6xxx/6420/input/input.js
@@ -0,0 +1 @@
const test = req.headers["test-dash"] ?? req.headers["test-dash-2"];
2 changes: 2 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6420/output/input.js
@@ -0,0 +1,2 @@
var _req_headers_testdash;
var test = (_req_headers_testdash = req.headers["test-dash"]) !== null && _req_headers_testdash !== void 0 ? _req_headers_testdash : req.headers["test-dash-2"];
4 changes: 4 additions & 0 deletions crates/swc_ecma_utils/src/lib.rs
Expand Up @@ -1964,6 +1964,10 @@ pub fn alias_ident_for(expr: &Expr, default: &str) -> Ident {

let mut sym = sym(expr).unwrap_or_else(|| default.to_string());

if let Err(s) = Ident::verify_symbol(&sym) {
sym = s;
}

if !sym.starts_with('_') {
sym = format!("_{}", sym)
}
Expand Down