mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
fix(es/ast): Fix Ident::verify_symbol
(#3108)
This commit is contained in:
parent
5e6f6e5122
commit
e5971f77d5
@ -115,7 +115,11 @@ impl Ident {
|
||||
/// Returns [Ok] if it's a valid identifier and [Err] if it's not valid.
|
||||
/// The returned [Err] contains the valid symbol.
|
||||
pub fn verify_symbol(s: &str) -> Result<(), String> {
|
||||
if s.is_reserved() || s.is_reserved_in_strict_mode(true) || s.is_reserved_in_strict_bind() {
|
||||
fn is_reserved_symbol(s: &str) -> bool {
|
||||
s.is_reserved() || s.is_reserved_in_strict_mode(true) || s.is_reserved_in_strict_bind()
|
||||
}
|
||||
|
||||
if is_reserved_symbol(s) {
|
||||
let mut buf = String::with_capacity(s.len() + 1);
|
||||
buf.push('_');
|
||||
buf.push_str(s);
|
||||
@ -153,6 +157,13 @@ impl Ident {
|
||||
buf.push('_');
|
||||
}
|
||||
|
||||
if is_reserved_symbol(&buf) {
|
||||
let mut new_buf = String::with_capacity(buf.len() + 1);
|
||||
new_buf.push('_');
|
||||
new_buf.push_str(&buf);
|
||||
buf = new_buf;
|
||||
}
|
||||
|
||||
Err(buf)
|
||||
}
|
||||
}
|
||||
|
@ -6,5 +6,15 @@ class ValidationStrategy {
|
||||
static "string!"(value) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
static "eval?"(value) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
static "arguments!"(value) {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
console.log(ValidationStrategy.prototype['string!']);
|
||||
console.log(ValidationStrategy.prototype["string!"]);
|
||||
console.log(ValidationStrategy.prototype["eval?"]);
|
||||
console.log(ValidationStrategy.prototype["arguments!"]);
|
||||
|
Loading…
Reference in New Issue
Block a user