-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathCatchClause.ts
37 lines (33 loc) · 1.38 KB
/
CatchClause.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
import type ChildScope from '../scopes/ChildScope';
import ParameterScope from '../scopes/ParameterScope';
import { EMPTY_PATH } from '../utils/PathTracker';
import BlockStatement from './BlockStatement';
import type * as NodeType from './NodeType';
import { UNKNOWN_EXPRESSION } from './shared/Expression';
import { type GenericEsTreeNode, NodeBase, onlyIncludeSelf } from './shared/Node';
import type { DeclarationPatternNode } from './shared/Pattern';
export default class CatchClause extends NodeBase {
declare body: BlockStatement;
declare param: DeclarationPatternNode | null;
declare preventChildBlockScope: true;
declare scope: ParameterScope;
declare type: NodeType.tCatchClause;
createScope(parentScope: ChildScope): void {
this.scope = new ParameterScope(parentScope, true);
}
parseNode(esTreeNode: GenericEsTreeNode): this {
const { body, param, type } = esTreeNode;
this.type = type as NodeType.tCatchClause;
if (param) {
this.param = new (this.scope.context.getNodeConstructor(param.type))(
this,
this.scope
).parseNode(param) as unknown as DeclarationPatternNode;
this.param!.declare('parameter', EMPTY_PATH, UNKNOWN_EXPRESSION);
}
this.body = new BlockStatement(this, this.scope.bodyScope).parseNode(body);
return super.parseNode(esTreeNode);
}
}
CatchClause.prototype.preventChildBlockScope = true;
CatchClause.prototype.includeNode = onlyIncludeSelf;