1
1
import type { NormalizedTreeshakingOptions } from '../../../rollup/types' ;
2
- import { BLANK } from '../../../utils/blank' ;
3
2
import { type CallOptions , NO_ARGS } from '../../CallOptions' ;
4
3
import { DeoptimizableEntity } from '../../DeoptimizableEntity' ;
5
4
import {
@@ -9,27 +8,12 @@ import {
9
8
} from '../../ExecutionContext' ;
10
9
import { NodeEvent } from '../../NodeEvents' ;
11
10
import ReturnValueScope from '../../scopes/ReturnValueScope' ;
12
- import {
13
- EMPTY_PATH ,
14
- type ObjectPath ,
15
- PathTracker ,
16
- SHARED_RECURSION_TRACKER ,
17
- UNKNOWN_PATH ,
18
- UnknownKey
19
- } from '../../utils/PathTracker' ;
20
- import LocalVariable from '../../variables/LocalVariable' ;
21
- import AssignmentPattern from '../AssignmentPattern' ;
11
+ import { type ObjectPath , PathTracker , UNKNOWN_PATH , UnknownKey } from '../../utils/PathTracker' ;
22
12
import BlockStatement from '../BlockStatement' ;
23
13
import * as NodeType from '../NodeType' ;
24
14
import RestElement from '../RestElement' ;
25
15
import type SpreadElement from '../SpreadElement' ;
26
- import {
27
- type ExpressionEntity ,
28
- InclusionOptions ,
29
- LiteralValueOrUnknown ,
30
- UNKNOWN_EXPRESSION ,
31
- UnknownValue
32
- } from './Expression' ;
16
+ import { type ExpressionEntity , LiteralValueOrUnknown , UNKNOWN_EXPRESSION } from './Expression' ;
33
17
import {
34
18
type ExpressionNode ,
35
19
type GenericEsTreeNode ,
@@ -39,31 +23,20 @@ import {
39
23
import { ObjectEntity } from './ObjectEntity' ;
40
24
import type { PatternNode } from './Pattern' ;
41
25
42
- export default abstract class FunctionBase extends NodeBase implements DeoptimizableEntity {
26
+ export default abstract class FunctionBase extends NodeBase {
43
27
declare async : boolean ;
44
28
declare body : BlockStatement | ExpressionNode ;
45
29
declare params : readonly PatternNode [ ] ;
46
30
declare preventChildBlockScope : true ;
47
31
declare scope : ReturnValueScope ;
48
32
protected objectEntity : ObjectEntity | null = null ;
49
33
private deoptimizedReturn = false ;
50
- private forceIncludeParameters = false ;
51
- private declare parameterVariables : LocalVariable [ ] [ ] ;
52
-
53
- deoptimizeCache ( ) {
54
- this . forceIncludeParameters = true ;
55
- }
56
-
57
- deoptimizeCallParameters ( ) {
58
- this . forceIncludeParameters = true ;
59
- }
60
34
61
35
deoptimizePath ( path : ObjectPath ) : void {
62
36
this . getObjectEntity ( ) . deoptimizePath ( path ) ;
63
37
if ( path . length === 1 && path [ 0 ] === UnknownKey ) {
64
38
// A reassignment of UNKNOWN_PATH is considered equivalent to having lost track
65
39
// which means the return expression needs to be reassigned
66
- this . forceIncludeParameters = true ;
67
40
this . scope . getReturnExpression ( ) . deoptimizePath ( UNKNOWN_PATH ) ;
68
41
}
69
42
}
@@ -150,89 +123,31 @@ export default abstract class FunctionBase extends NodeBase implements Deoptimiz
150
123
return true ;
151
124
}
152
125
}
153
- for ( let position = 0 ; position < this . params . length ; position ++ ) {
154
- const parameter = this . params [ position ] ;
155
- if ( parameter instanceof AssignmentPattern ) {
156
- if ( parameter . left . hasEffects ( context ) ) {
157
- return true ;
158
- }
159
- const argumentValue = callOptions . args [ position ] ?. getLiteralValueAtPath (
160
- EMPTY_PATH ,
161
- SHARED_RECURSION_TRACKER ,
162
- this
163
- ) ;
164
- if (
165
- ( argumentValue === undefined || argumentValue === UnknownValue ) &&
166
- parameter . right . hasEffects ( context )
167
- ) {
168
- return true ;
169
- }
170
- } else if ( parameter . hasEffects ( context ) ) {
171
- return true ;
172
- }
126
+ for ( const param of this . params ) {
127
+ if ( param . hasEffects ( context ) ) return true ;
173
128
}
174
129
return false ;
175
130
}
176
131
177
- include (
178
- context : InclusionContext ,
179
- includeChildrenRecursively : IncludeChildren ,
180
- { includeWithoutParameterDefaults } : InclusionOptions = BLANK
181
- ) : void {
132
+ include ( context : InclusionContext , includeChildrenRecursively : IncludeChildren ) : void {
182
133
if ( ! this . deoptimized ) this . applyDeoptimizations ( ) ;
183
134
this . included = true ;
184
135
const { brokenFlow } = context ;
185
136
context . brokenFlow = BROKEN_FLOW_NONE ;
186
137
this . body . include ( context , includeChildrenRecursively ) ;
187
138
context . brokenFlow = brokenFlow ;
188
- if (
189
- ! includeWithoutParameterDefaults ||
190
- includeChildrenRecursively ||
191
- this . forceIncludeParameters
192
- ) {
193
- for ( const param of this . params ) {
194
- param . include ( context , includeChildrenRecursively ) ;
195
- }
196
- }
197
139
}
198
140
199
141
includeCallArguments (
200
142
context : InclusionContext ,
201
143
args : readonly ( ExpressionEntity | SpreadElement ) [ ]
202
144
) : void {
203
- for ( let position = 0 ; position < this . params . length ; position ++ ) {
204
- const parameter = this . params [ position ] ;
205
- if ( parameter instanceof AssignmentPattern ) {
206
- if ( parameter . left . shouldBeIncluded ( context ) ) {
207
- parameter . left . include ( context , false ) ;
208
- }
209
- const argumentValue = args [ position ] ?. getLiteralValueAtPath (
210
- EMPTY_PATH ,
211
- SHARED_RECURSION_TRACKER ,
212
- this
213
- ) ;
214
- // If argumentValue === UnknownTruthyValue, then we do not need to
215
- // include the default
216
- if (
217
- ( argumentValue === undefined || argumentValue === UnknownValue ) &&
218
- ( this . parameterVariables [ position ] . some ( variable => variable . included ) ||
219
- parameter . right . shouldBeIncluded ( context ) )
220
- ) {
221
- parameter . right . include ( context , false ) ;
222
- }
223
- } else if ( parameter . shouldBeIncluded ( context ) ) {
224
- parameter . include ( context , false ) ;
225
- }
226
- }
227
145
this . scope . includeCallArguments ( context , args ) ;
228
146
}
229
147
230
148
initialise ( ) : void {
231
- this . parameterVariables = this . params . map ( param =>
232
- param . declare ( 'parameter' , UNKNOWN_EXPRESSION )
233
- ) ;
234
149
this . scope . addParameterVariables (
235
- this . parameterVariables ,
150
+ this . params . map ( param => param . declare ( 'parameter' , UNKNOWN_EXPRESSION ) ) ,
236
151
this . params [ this . params . length - 1 ] instanceof RestElement
237
152
) ;
238
153
if ( this . body instanceof BlockStatement ) {
@@ -249,15 +164,7 @@ export default abstract class FunctionBase extends NodeBase implements Deoptimiz
249
164
super . parseNode ( esTreeNode ) ;
250
165
}
251
166
252
- protected applyDeoptimizations ( ) {
253
- // We currently do not track deoptimizations of default values, deoptimize them
254
- // just as we deoptimize call arguments
255
- for ( const param of this . params ) {
256
- if ( param instanceof AssignmentPattern ) {
257
- param . right . deoptimizePath ( UNKNOWN_PATH ) ;
258
- }
259
- }
260
- }
167
+ protected applyDeoptimizations ( ) { }
261
168
262
169
protected abstract getObjectEntity ( ) : ObjectEntity ;
263
170
}
0 commit comments