|
1 | 1 | use super::symbol_info::SymbolInfo; |
| 2 | +use super::ty; |
| 3 | +use super::ty::TypeFlags; |
2 | 4 | use super::{TyChecker, errors}; |
3 | | -use crate::ty; |
4 | | -use crate::ty::TypeFlags; |
5 | 5 |
|
6 | 6 | use bolt_ts_ast::r#trait::ClassLike; |
7 | 7 | use bolt_ts_ast::{self as ast, pprint_ident}; |
@@ -100,7 +100,33 @@ impl<'cx> TyChecker<'cx> { |
100 | 100 | self.check_fn_like_decl(method); |
101 | 101 | } |
102 | 102 |
|
| 103 | + pub(super) fn check_invalid_dynamic_name( |
| 104 | + &mut self, |
| 105 | + name: ast::DeclarationName<'cx>, |
| 106 | + push_error: impl FnOnce(&mut Self), |
| 107 | + ) { |
| 108 | + if !self.is_non_bindable_dynamic_name(&name) { |
| 109 | + return; |
| 110 | + } |
| 111 | + let expr = match name { |
| 112 | + ast::DeclarationName::Computed(n) => n.expr, |
| 113 | + // TODO: element access expr |
| 114 | + _ => unreachable!(), |
| 115 | + }; |
| 116 | + if !expr.is_entity_name_expr() { |
| 117 | + push_error(self); |
| 118 | + } |
| 119 | + } |
| 120 | + |
103 | 121 | fn check_class_prop_ele(&mut self, prop: &'cx ast::ClassPropElem<'cx>) { |
| 122 | + let decl_name = ast::DeclarationName::from_prop_name(prop.name); |
| 123 | + self.check_invalid_dynamic_name(decl_name, |this| { |
| 124 | + let error = errors::AComputedPropertyNameInAClassPropertyDeclarationMustHaveASimpleLiteralTypeOrAUniqueSymbolType { |
| 125 | + span: prop.name.span(), |
| 126 | + }; |
| 127 | + this.push_error(Box::new(error)); |
| 128 | + }); |
| 129 | + |
104 | 130 | self.check_var_like_decl(prop); |
105 | 131 | } |
106 | 132 |
|
|
0 commit comments