-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathClassBody.ts
50 lines (44 loc) · 1.75 KB
/
ClassBody.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
import type { InclusionContext } from '../ExecutionContext';
import type ChildScope from '../scopes/ChildScope';
import ClassBodyScope from '../scopes/ClassBodyScope';
import { UNKNOWN_PATH } from '../utils/PathTracker';
import type MethodDefinition from './MethodDefinition';
import type * as NodeType from './NodeType';
import type PropertyDefinition from './PropertyDefinition';
import type ClassNode from './shared/ClassNode';
import {
doNotDeoptimize,
type GenericEsTreeNode,
type IncludeChildren,
NodeBase,
onlyIncludeSelfNoDeoptimize
} from './shared/Node';
import type StaticBlock from './StaticBlock';
export default class ClassBody extends NodeBase {
declare body: (MethodDefinition | PropertyDefinition | StaticBlock)[];
declare scope: ClassBodyScope;
declare type: NodeType.tClassBody;
createScope(parentScope: ChildScope): void {
this.scope = new ClassBodyScope(parentScope, this.parent as ClassNode);
}
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
this.included = true;
this.scope.context.includeVariableInModule(this.scope.thisVariable, UNKNOWN_PATH, context);
for (const definition of this.body) {
definition.include(context, includeChildrenRecursively);
}
}
parseNode(esTreeNode: GenericEsTreeNode): this {
const body: NodeBase[] = (this.body = new Array(esTreeNode.body.length));
let index = 0;
for (const definition of esTreeNode.body) {
body[index++] = new (this.scope.context.getNodeConstructor(definition.type))(
this,
definition.static ? this.scope : this.scope.instanceScope
).parseNode(definition);
}
return super.parseNode(esTreeNode);
}
}
ClassBody.prototype.includeNode = onlyIncludeSelfNoDeoptimize;
ClassBody.prototype.applyDeoptimizations = doNotDeoptimize;