File tree Expand file tree Collapse file tree
test/function/samples/parameter-defaults/function-as-default Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export default class ArrowFunctionExpression extends FunctionBase {
2525 }
2626
2727 hasEffects ( ) : boolean {
28+ if ( ! this . deoptimized ) this . applyDeoptimizations ( ) ;
2829 return false ;
2930 }
3031
Original file line number Diff line number Diff line change @@ -175,6 +175,7 @@ export default abstract class FunctionBase extends NodeBase implements Deoptimiz
175175 includeChildrenRecursively : IncludeChildren ,
176176 { includeWithoutParameterDefaults } : InclusionOptions = BLANK
177177 ) : void {
178+ if ( ! this . deoptimized ) this . applyDeoptimizations ( ) ;
178179 this . included = true ;
179180 const { brokenFlow } = context ;
180181 context . brokenFlow = BROKEN_FLOW_NONE ;
@@ -244,6 +245,16 @@ export default abstract class FunctionBase extends NodeBase implements Deoptimiz
244245 super . parseNode ( esTreeNode ) ;
245246 }
246247
248+ protected applyDeoptimizations ( ) {
249+ // We currently do not track deoptimizations of default values, deoptimize them
250+ // just as we deoptimize call arguments
251+ for ( const param of this . params ) {
252+ if ( param instanceof AssignmentPattern ) {
253+ param . right . deoptimizePath ( UNKNOWN_PATH ) ;
254+ }
255+ }
256+ }
257+
247258 protected abstract getObjectEntity ( ) : ObjectEntity ;
248259}
249260
Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ export default class FunctionNode extends FunctionBase {
3939 }
4040
4141 hasEffects ( ) : boolean {
42+ if ( ! this . deoptimized ) this . applyDeoptimizations ( ) ;
4243 return ! ! this . id ?. hasEffects ( ) ;
4344 }
4445
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ description : 'deoptimizes functions supplied as default values'
3+ } ;
Original file line number Diff line number Diff line change 1+ const foo = ( a = 'fallback' ) => a ;
2+ const bar = ( a = foo ) => a ;
3+
4+ assert . strictEqual ( bar ( ) ( ) , 'fallback' ) ;
You can’t perform that action at this time.
0 commit comments