-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Property.js
89 lines (79 loc) · 3.87 KB
/
Property.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import Node from '../Node.js';
import CallOptions from '../CallOptions';
import { UNKNOWN_ASSIGNMENT } from '../values';
export default class Property extends Node {
reassignPath ( path, options ) {
if ( this.kind === 'get' ) {
path.length > 0
&& this.value.forEachReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node =>
node.reassignPath( path, innerOptions.addAssignedReturnExpressionAtPath( path, this ) ), options );
} else if ( this.kind !== 'set' ) {
this.value.reassignPath( path, options );
}
}
forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) {
if ( this.kind === 'get' ) {
this.value.forEachReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node =>
node.forEachReturnExpressionWhenCalledAtPath( path, callOptions, callback, innerOptions ), options );
} else {
this.value.forEachReturnExpressionWhenCalledAtPath( path, callOptions, callback, options );
}
}
hasEffects ( options ) {
return this.key.hasEffects( options )
|| this.value.hasEffects( options );
}
hasEffectsWhenAccessedAtPath ( path, options ) {
if ( this.kind === 'get' ) {
return this.value.hasEffectsWhenCalledAtPath( [], this._accessorCallOptions, options.getHasEffectsWhenCalledOptions() )
|| (!options.hasReturnExpressionBeenAccessedAtPath( path, this )
&& this.value.someReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node =>
node.hasEffectsWhenAccessedAtPath( path, innerOptions.addAccessedReturnExpressionAtPath( path, this ) ), options ));
}
return this.value.hasEffectsWhenAccessedAtPath( path, options );
}
hasEffectsWhenAssignedAtPath ( path, options ) {
if ( this.kind === 'get' ) {
return path.length === 0
|| this.value.someReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node =>
node.hasEffectsWhenAssignedAtPath( path, innerOptions.addAssignedReturnExpressionAtPath( path, this ) ), options );
}
if ( this.kind === 'set' ) {
return path.length > 0
|| this.value.hasEffectsWhenCalledAtPath( [], this._accessorCallOptions, options.getHasEffectsWhenCalledOptions() );
}
return this.value.hasEffectsWhenAssignedAtPath( path, options );
}
hasEffectsWhenCalledAtPath ( path, callOptions, options ) {
if ( this.kind === 'get' ) {
return this.value.hasEffectsWhenCalledAtPath( [], this._accessorCallOptions, options.getHasEffectsWhenCalledOptions() )
|| (!options.hasReturnExpressionBeenCalledAtPath( path, this )
&& this.value.someReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node =>
node.hasEffectsWhenCalledAtPath( path, callOptions, innerOptions.addCalledReturnExpressionAtPath( path, this ) ), options ));
}
return this.value.hasEffectsWhenCalledAtPath( path, callOptions, options );
}
initialiseAndDeclare ( parentScope, kind ) {
this.initialiseScope( parentScope );
this.initialiseNode( parentScope );
this.key.initialise( parentScope );
this.value.initialiseAndDeclare( parentScope, kind, UNKNOWN_ASSIGNMENT );
}
initialiseNode () {
this._accessorCallOptions = CallOptions.create( { withNew: false, caller: this } );
}
render ( code, es ) {
if ( !this.shorthand ) {
this.key.render( code, es );
}
this.value.render( code, es );
}
someReturnExpressionWhenCalledAtPath ( path, callOptions, predicateFunction, options ) {
if ( this.kind === 'get' ) {
return this.value.hasEffectsWhenCalledAtPath( [], this._accessorCallOptions, options.getHasEffectsWhenCalledOptions() )
|| this.value.someReturnExpressionWhenCalledAtPath( [], this._accessorCallOptions, innerOptions => node =>
node.someReturnExpressionWhenCalledAtPath( path, callOptions, predicateFunction, innerOptions ), options );
}
return this.value.someReturnExpressionWhenCalledAtPath( path, callOptions, predicateFunction, options );
}
}