Support more static prop names

This commit is contained in:
Andrew Morris
2023-07-25 09:14:07 +10:00
parent 926f8d6cff
commit 8a13025fd5

View File

@@ -94,13 +94,7 @@ impl<'a> StaticExpressionCompiler<'a> {
return Value::String("(error)".to_string());
}
swc_ecma_ast::Prop::Method(method) => {
let key = match &method.key {
swc_ecma_ast::PropName::Ident(ident) => Value::String(ident.sym.to_string()),
_ => {
self.todo(method.key.span(), "Static non-ident prop names");
Value::String("(error)".to_string())
}
};
let key = self.prop_name(&method.key);
let fn_ident = match &method.key {
swc_ecma_ast::PropName::Ident(ident) => Some(ident.clone()),
@@ -276,6 +270,16 @@ impl<'a> StaticExpressionCompiler<'a> {
swc_ecma_ast::Expr::TsAs(ta) => self.expr(&ta.expr),
}
}
fn prop_name(&mut self, prop_name: &swc_ecma_ast::PropName) -> Value {
match prop_name {
swc_ecma_ast::PropName::Ident(ident) => Value::String(ident.sym.to_string()),
swc_ecma_ast::PropName::Str(str) => Value::String(str.value.to_string()),
swc_ecma_ast::PropName::Num(num) => Value::String(num.value.to_string()),
swc_ecma_ast::PropName::Computed(computed) => self.expr(&computed.expr),
swc_ecma_ast::PropName::BigInt(bi) => Value::String(bi.value.to_string()),
}
}
}
fn as_symbol_iterator(expr: &swc_ecma_ast::Expr) -> Option<Value> {