forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTryStatement.ts
52 lines (48 loc) · 1.91 KB
/
TryStatement.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { NormalizedTreeshakingOptions } from '../../rollup/types';
import type { HasEffectsContext, InclusionContext } from '../ExecutionContext';
import type BlockStatement from './BlockStatement';
import type CatchClause from './CatchClause';
import type * as NodeType from './NodeType';
import { INCLUDE_PARAMETERS, type IncludeChildren, StatementBase } from './shared/Node';
export default class TryStatement extends StatementBase {
declare block: BlockStatement;
declare finalizer: BlockStatement | null;
declare handler: CatchClause | null;
declare type: NodeType.tTryStatement;
private directlyIncluded = false;
private includedLabelsAfterBlock: string[] | null = null;
hasEffects(context: HasEffectsContext): boolean {
return (
((this.scope.context.options.treeshake as NormalizedTreeshakingOptions).tryCatchDeoptimization
? this.block.body.length > 0
: this.block.hasEffects(context)) || !!this.finalizer?.hasEffects(context)
);
}
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
const tryCatchDeoptimization = (
this.scope.context.options.treeshake as NormalizedTreeshakingOptions
)?.tryCatchDeoptimization;
const { brokenFlow, includedLabels } = context;
if (!this.directlyIncluded || !tryCatchDeoptimization) {
this.included = true;
this.directlyIncluded = true;
this.block.include(
context,
tryCatchDeoptimization ? INCLUDE_PARAMETERS : includeChildrenRecursively
);
if (includedLabels.size > 0) {
this.includedLabelsAfterBlock = [...includedLabels];
}
context.brokenFlow = brokenFlow;
} else if (this.includedLabelsAfterBlock) {
for (const label of this.includedLabelsAfterBlock) {
includedLabels.add(label);
}
}
if (this.handler !== null) {
this.handler.include(context, includeChildrenRecursively);
context.brokenFlow = brokenFlow;
}
this.finalizer?.include(context, includeChildrenRecursively);
}
}