/
CatchClause.ts
32 lines (29 loc) · 1.18 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
import CatchScope from '../scopes/CatchScope';
import Scope from '../scopes/Scope';
import BlockStatement from './BlockStatement';
import * as NodeType from './NodeType';
import { UNKNOWN_EXPRESSION } from './shared/Expression';
import { GenericEsTreeNode, NodeBase } from './shared/Node';
import { PatternNode } from './shared/Pattern';
export default class CatchClause extends NodeBase {
declare body: BlockStatement;
declare param: PatternNode | null;
declare preventChildBlockScope: true;
declare scope: CatchScope;
declare type: NodeType.tCatchClause;
createScope(parentScope: Scope): void {
this.scope = new CatchScope(parentScope, this.context);
}
parseNode(esTreeNode: GenericEsTreeNode): void {
// Parameters need to be declared first as the logic is that initializers
// of hoisted body variables are associated with parameters of the same
// name instead of the variable
const { param } = esTreeNode;
if (param) {
(this.param as GenericEsTreeNode) = new (this.context.nodeConstructors[param.type] ||
this.context.nodeConstructors.UnknownNode)(param, this, this.scope);
this.param!.declare('parameter', UNKNOWN_EXPRESSION);
}
super.parseNode(esTreeNode);
}
}