@@ -874,9 +874,16 @@ fn strip_in_stmt(stmt: &mut Stmt, non_promise: &mut HashSet<LocalId>) {
874874 }
875875 Stmt :: Expr ( e) | Stmt :: Throw ( e) => strip_in_expr ( e, non_promise) ,
876876 Stmt :: Return ( Some ( e) ) => strip_in_expr ( e, non_promise) ,
877- Stmt :: Return ( None ) | Stmt :: Break | Stmt :: Continue
878- | Stmt :: LabeledBreak ( _) | Stmt :: LabeledContinue ( _) => { }
879- Stmt :: If { condition, then_branch, else_branch } => {
877+ Stmt :: Return ( None )
878+ | Stmt :: Break
879+ | Stmt :: Continue
880+ | Stmt :: LabeledBreak ( _)
881+ | Stmt :: LabeledContinue ( _) => { }
882+ Stmt :: If {
883+ condition,
884+ then_branch,
885+ else_branch,
886+ } => {
880887 strip_in_expr ( condition, non_promise) ;
881888 strip_in_stmts ( then_branch, non_promise) ;
882889 if let Some ( eb) = else_branch {
@@ -887,7 +894,12 @@ fn strip_in_stmt(stmt: &mut Stmt, non_promise: &mut HashSet<LocalId>) {
887894 strip_in_expr ( condition, non_promise) ;
888895 strip_in_stmts ( body, non_promise) ;
889896 }
890- Stmt :: For { init, condition, update, body } => {
897+ Stmt :: For {
898+ init,
899+ condition,
900+ update,
901+ body,
902+ } => {
891903 if let Some ( init_stmt) = init {
892904 strip_in_stmt ( init_stmt, non_promise) ;
893905 }
@@ -899,7 +911,11 @@ fn strip_in_stmt(stmt: &mut Stmt, non_promise: &mut HashSet<LocalId>) {
899911 }
900912 strip_in_stmts ( body, non_promise) ;
901913 }
902- Stmt :: Try { body, catch, finally } => {
914+ Stmt :: Try {
915+ body,
916+ catch,
917+ finally,
918+ } => {
903919 strip_in_stmts ( body, non_promise) ;
904920 if let Some ( c) = catch {
905921 strip_in_stmts ( & mut c. body , non_promise) ;
@@ -909,7 +925,10 @@ fn strip_in_stmt(stmt: &mut Stmt, non_promise: &mut HashSet<LocalId>) {
909925 }
910926 }
911927 Stmt :: Labeled { body, .. } => strip_in_stmt ( body, non_promise) ,
912- Stmt :: Switch { discriminant, cases } => {
928+ Stmt :: Switch {
929+ discriminant,
930+ cases,
931+ } => {
913932 strip_in_expr ( discriminant, non_promise) ;
914933 for case in cases {
915934 if let Some ( c) = & mut case. test {
@@ -939,11 +958,15 @@ fn strip_in_expr(expr: &mut Expr, non_promise: &HashSet<LocalId>) {
939958}
940959
941960fn try_strip_promise_resolve ( expr : & Expr , non_promise : & HashSet < LocalId > ) -> Option < Expr > {
942- let Expr :: Call { callee, args, .. } = expr else { return None ; } ;
961+ let Expr :: Call { callee, args, .. } = expr else {
962+ return None ;
963+ } ;
943964 if args. len ( ) != 1 {
944965 return None ;
945966 }
946- let Expr :: PropertyGet { object, property } = callee. as_ref ( ) else { return None ; } ;
967+ let Expr :: PropertyGet { object, property } = callee. as_ref ( ) else {
968+ return None ;
969+ } ;
947970 if property != "resolve" {
948971 return None ;
949972 }
@@ -961,23 +984,24 @@ fn try_strip_promise_resolve(expr: &Expr, non_promise: &HashSet<LocalId>) -> Opt
961984
962985fn is_non_promise_expr ( expr : & Expr , non_promise : & HashSet < LocalId > ) -> bool {
963986 match expr {
964- Expr :: Number ( _) | Expr :: Integer ( _) | Expr :: String ( _) | Expr :: Bool ( _)
965- | Expr :: Undefined | Expr :: Null => true ,
987+ Expr :: Number ( _)
988+ | Expr :: Integer ( _)
989+ | Expr :: String ( _)
990+ | Expr :: Bool ( _)
991+ | Expr :: Undefined
992+ | Expr :: Null => true ,
966993 Expr :: LocalGet ( id) => non_promise. contains ( id) ,
967994 Expr :: Binary { left, right, .. } => {
968- is_non_promise_expr ( left, non_promise)
969- && is_non_promise_expr ( right, non_promise)
995+ is_non_promise_expr ( left, non_promise) && is_non_promise_expr ( right, non_promise)
970996 }
971997 Expr :: Unary { operand, .. } => is_non_promise_expr ( operand, non_promise) ,
972998 Expr :: Compare { left, right, .. } => {
973- is_non_promise_expr ( left, non_promise)
974- && is_non_promise_expr ( right, non_promise)
999+ is_non_promise_expr ( left, non_promise) && is_non_promise_expr ( right, non_promise)
9751000 }
9761001 Expr :: Logical { left, right, .. } => {
9771002 // Logical && / || / ?? return one of the operands. If both are
9781003 // non-Promise, the result is non-Promise.
979- is_non_promise_expr ( left, non_promise)
980- && is_non_promise_expr ( right, non_promise)
1004+ is_non_promise_expr ( left, non_promise) && is_non_promise_expr ( right, non_promise)
9811005 }
9821006 // `await X` for non-Promise X resolves to X itself (1 microtask hop),
9831007 // so the result is non-Promise. The peephole above handles the
@@ -989,8 +1013,14 @@ fn is_non_promise_expr(expr: &Expr, non_promise: &HashSet<LocalId>) -> bool {
9891013
9901014fn is_non_promise_type ( ty : & Type ) -> bool {
9911015 match ty {
992- Type :: Number | Type :: Int32 | Type :: Boolean | Type :: String
993- | Type :: Void | Type :: Null | Type :: BigInt | Type :: Symbol => true ,
1016+ Type :: Number
1017+ | Type :: Int32
1018+ | Type :: Boolean
1019+ | Type :: String
1020+ | Type :: Void
1021+ | Type :: Null
1022+ | Type :: BigInt
1023+ | Type :: Symbol => true ,
9941024 Type :: Promise ( _) => false ,
9951025 // Any/Unknown could carry a Promise at runtime.
9961026 // Object/Function could be a thenable. Named/Generic could resolve
0 commit comments