Commit d5978f96 authored by Luke Sandberg's avatar Luke Sandberg

fix clippy issues and somehow land the same edit for the 10th time

parent f5ecf4c8
......@@ -2395,12 +2395,12 @@ impl VisitAstPath for Analyzer<'_> {
ast_path: &mut swc_core::ecma::visit::AstNodePath<'r>,
) {
enum ScopeType {
FunctionScope,
BlockScope,
ControlFlowScope,
Function,
Block,
ControlFlow,
}
let block_type = if ast_path.len() < 2 {
ScopeType::BlockScope
ScopeType::Block
} else if matches!(
&ast_path[ast_path.len() - 2..],
[
......@@ -2419,7 +2419,7 @@ impl VisitAstPath for Analyzer<'_> {
AstParentNodeRef::Stmt(_, StmtField::Block)
]
) {
ScopeType::ControlFlowScope
ScopeType::ControlFlow
} else if matches!(
&ast_path[ast_path.len() - 2..],
[_, AstParentNodeRef::Function(_, FunctionField::Body)]
......@@ -2431,12 +2431,12 @@ impl VisitAstPath for Analyzer<'_> {
| [_, AstParentNodeRef::SetterProp(_, SetterPropField::Body)]
| [_, AstParentNodeRef::Constructor(_, ConstructorField::Body)]
) {
ScopeType::FunctionScope
ScopeType::Function
} else {
ScopeType::BlockScope
ScopeType::Block
};
match block_type {
ScopeType::FunctionScope => {
ScopeType::Function => {
let early_return_stack = take(&mut self.early_return_stack);
let mut effects = take(&mut self.effects);
let hoisted_effects = take(&mut self.hoisted_effects);
......@@ -2448,7 +2448,7 @@ impl VisitAstPath for Analyzer<'_> {
self.effects = effects;
self.early_return_stack = early_return_stack;
}
ScopeType::BlockScope => {
ScopeType::Block => {
n.visit_children_with_ast_path(self, ast_path);
if self.end_early_return_block() {
self.early_return_stack.push(EarlyReturn::Always {
......@@ -2457,7 +2457,7 @@ impl VisitAstPath for Analyzer<'_> {
});
}
}
ScopeType::ControlFlowScope => {
ScopeType::ControlFlow => {
n.visit_children_with_ast_path(self, ast_path);
}
}
......
......@@ -1008,15 +1008,21 @@ impl JsValue {
func_ident: u32,
is_async: bool,
is_generator: bool,
mut return_value: Box<JsValue>,
return_value: JsValue,
) -> Self {
// Check generator first to handle async generators
if is_generator {
return_value = Box::new(JsValue::WellKnownObject(WellKnownObjectKind::Generator));
} else if is_async && !matches!(return_value, box JsValue::Promise(_, _)) {
return_value = Box::new(JsValue::promise(return_value));
}
Self::Function(1 + return_value.total_nodes(), func_ident, return_value)
let return_value = if is_generator {
JsValue::WellKnownObject(WellKnownObjectKind::Generator)
} else if is_async {
JsValue::promise(return_value)
} else {
return_value
};
Self::Function(
1 + return_value.total_nodes(),
func_ident,
Box::new(return_value),
)
}
pub fn object(list: Vec<ObjectPart>) -> Self {
......@@ -1072,12 +1078,12 @@ impl JsValue {
Self::Member(1 + o.total_nodes() + p.total_nodes(), o, p)
}
pub fn promise(operand: Box<JsValue>) -> Self {
pub fn promise(operand: JsValue) -> Self {
// In ecmascript Promise<Promise<T>> is equivalent to Promise<T>
if let JsValue::Promise(_, _) = &*operand {
return *operand;
if let JsValue::Promise(_, _) = operand {
return operand;
}
Self::Promise(1 + operand.total_nodes(), operand)
Self::Promise(1 + operand.total_nodes(), Box::new(operand))
}
pub fn awaited(operand: Box<JsValue>) -> Self {
......@@ -3665,10 +3671,10 @@ pub mod test_utils {
ref args,
) => match &args[0] {
JsValue::Constant(ConstantValue::Str(v)) => {
JsValue::promise(Box::new(JsValue::Module(ModuleValue {
JsValue::promise(JsValue::Module(ModuleValue {
module: v.as_atom().into_owned(),
annotations: ImportAnnotations::default(),
})))
}))
}
_ => v.into_unknown(true, "import() non constant"),
},
......
......@@ -345,10 +345,10 @@ fn path_dirname(mut args: Vec<JsValue>) -> JsValue {
pub fn import(args: Vec<JsValue>) -> JsValue {
match &args[..] {
[JsValue::Constant(ConstantValue::Str(v))] => {
JsValue::promise(Box::new(JsValue::Module(ModuleValue {
JsValue::promise(JsValue::Module(ModuleValue {
module: v.as_atom().into_owned(),
annotations: ImportAnnotations::default(),
})))
}))
}
_ => JsValue::unknown(
JsValue::call(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment