fix(es/compat): Ignore invalid class method names (#5612)

This commit is contained in:
magic-akari 2022-08-24 16:42:57 +08:00 committed by GitHub
parent c71f62bb03
commit 1181d0ffe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -5,6 +5,6 @@ var C = /*#__PURE__*/ function() {
_class_call_check(this, C);
}
var _proto = C.prototype;
_proto["0"] = function 0() {};
_proto["0"] = function() {};
return C;
}();

View File

@ -7,9 +7,9 @@ use swc_ecma_transforms_base::{helper, native::is_native, perf::Check};
use swc_ecma_transforms_classes::super_field::SuperFieldAccessFolder;
use swc_ecma_transforms_macros::fast_path;
use swc_ecma_utils::{
alias_if_required, default_constructor, is_valid_prop_ident, prepend_stmt, private_ident,
prop_name_to_expr, quote_expr, quote_ident, quote_str, replace_ident, ExprFactory, IdentExt,
IsDirective, ModuleItemLike, StmtLike,
alias_if_required, default_constructor, is_valid_ident, is_valid_prop_ident, prepend_stmt,
private_ident, prop_name_to_expr, quote_expr, quote_ident, quote_str, replace_ident,
ExprFactory, IdentExt, IsDirective, ModuleItemLike, StmtLike,
};
use swc_ecma_visit::{
as_folder, noop_visit_mut_type, noop_visit_type, Fold, Visit, VisitMut, VisitMutWith, VisitWith,
@ -1052,7 +1052,7 @@ where
ident: if m.kind == MethodKind::Method && !computed {
match prop_name {
Expr::Ident(ident) => Some(private_ident!(ident.span, ident.sym)),
Expr::Lit(Lit::Str(Str { span, value, .. })) => {
Expr::Lit(Lit::Str(Str { span, value, .. })) if is_valid_ident(&value) => {
Some(Ident::new(value, span.private()))
}
_ => None,