-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
FunctionNode.js
67 lines (57 loc) · 1.8 KB
/
FunctionNode.js
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import Node from '../../Node.js';
import FunctionScope from '../../scopes/FunctionScope';
import VirtualObjectExpression from './VirtualObjectExpression';
export default class FunctionNode extends Node {
bindCallAtPath ( path, { args } ) {
if ( path.length === 0 ) {
this.scope.bindCallArguments( args );
}
}
bindNode () {
this.body.bindImplicitReturnExpressionToScope();
}
forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback ) {
if ( path.length === 0 ) {
this.scope.forEachReturnExpressionWhenCalled( callback );
}
}
hasEffects ( options ) {
return this.id && this.id.hasEffects( options );
}
hasEffectsWhenAccessedAtPath ( path, options ) {
if ( path.length <= 1 ) {
return false;
}
if ( path[ 0 ] === 'prototype' ) {
return this.prototypeObject.hasEffectsWhenAccessedAtPath( path.slice( 1 ), options );
}
return true;
}
hasEffectsWhenAssignedAtPath ( path, options ) {
if ( path.length <= 1 ) {
return false;
}
if ( path[ 0 ] === 'prototype' ) {
return this.prototypeObject.hasEffectsWhenAssignedAtPath( path.slice( 1 ), options );
}
return true;
}
hasEffectsWhenCalledAtPath ( path, callOptions, options ) {
if ( path.length > 0 ) {
return true;
}
const innerOptions = this.scope.getOptionsWhenCalledWith( callOptions, options );
return this.params.some( param => param.hasEffects( innerOptions ) )
|| this.body.hasEffects( innerOptions );
}
initialiseNode () {
this.prototypeObject = new VirtualObjectExpression();
}
initialiseScope ( parentScope ) {
this.scope = new FunctionScope( { parent: parentScope } );
}
someReturnExpressionWhenCalledAtPath ( path, callOptions, predicateFunction, options ) {
return path.length > 0
|| this.scope.someReturnExpressionWhenCalled( callOptions, predicateFunction, options );
}
}