forked from rollup/rollup
/
ClassBody.ts
40 lines (36 loc) · 1.33 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
import { InclusionContext } from '../ExecutionContext';
import ClassBodyScope from '../scopes/ClassBodyScope';
import Scope from '../scopes/Scope';
import MethodDefinition from './MethodDefinition';
import * as NodeType from './NodeType';
import PropertyDefinition from './PropertyDefinition';
import ClassNode from './shared/ClassNode';
import { GenericEsTreeNode, IncludeChildren, NodeBase } from './shared/Node';
export default class ClassBody extends NodeBase {
declare body: (MethodDefinition | PropertyDefinition)[];
declare scope: ClassBodyScope;
declare type: NodeType.tClassBody;
createScope(parentScope: Scope): void {
this.scope = new ClassBodyScope(parentScope, this.parent as ClassNode, this.context);
}
include(context: InclusionContext, includeChildrenRecursively: IncludeChildren): void {
this.included = true;
this.context.includeVariableInModule(this.scope.thisVariable);
for (const definition of this.body) {
definition.include(context, includeChildrenRecursively);
}
}
parseNode(esTreeNode: GenericEsTreeNode): void {
const body: NodeBase[] = (this.body = []);
for (const definition of esTreeNode.body) {
body.push(
new this.context.nodeConstructors[definition.type](
definition,
this,
definition.static ? this.scope : this.scope.instanceScope
)
);
}
super.parseNode(esTreeNode);
}
}