forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunctionDeclaration.ts
30 lines (26 loc) · 965 Bytes
/
FunctionDeclaration.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
import type ChildScope from '../scopes/ChildScope';
import Identifier, { type IdentifierWithVariable } from './Identifier';
import type * as NodeType from './NodeType';
import FunctionNode from './shared/FunctionNode';
import type { GenericEsTreeNode } from './shared/Node';
export default class FunctionDeclaration extends FunctionNode {
declare type: NodeType.tFunctionDeclaration;
initialise(): void {
super.initialise();
if (this.id !== null) {
this.id.variable.isId = true;
}
}
protected onlyFunctionCallUsed(): boolean {
// call super.onlyFunctionCallUsed for export default anonymous function
return this.id?.variable.getOnlyFunctionCallUsed() ?? super.onlyFunctionCallUsed();
}
parseNode(esTreeNode: GenericEsTreeNode): this {
if (esTreeNode.id !== null) {
this.id = new Identifier(this, this.scope.parent as ChildScope).parseNode(
esTreeNode.id
) as IdentifierWithVariable;
}
return super.parseNode(esTreeNode);
}
}