-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
GlobalVariable.js
30 lines (26 loc) · 926 Bytes
/
GlobalVariable.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
import Variable from './Variable';
import pureFunctions from '../nodes/shared/pureFunctions';
export default class GlobalVariable extends Variable {
constructor ( name ) {
super( name );
this.isExternal = true;
this.isGlobal = true;
this.isReassigned = false;
this.included = true;
}
addReference ( identifier ) {
if ( identifier.isReassignment ) this.isReassigned = true;
}
hasEffectsWhenAccessedAtPath ( path ) {
// path.length == 0 can also have an effect but we postpone this for now
return path.length > 0
&& !pureFunctions[ [ this.name, ...path ].join( '.' ) ]
&& !pureFunctions[ [ this.name, ...path.slice( 0, -1 ) ].join( '.' ) ]
&& !(path.length > 1
&& pureFunctions[ [ this.name, ...path.slice( 0, -2 ) ].join( '.' ) ]
&& path[ path.length - 2 ] === 'prototype');
}
hasEffectsWhenCalledAtPath ( path ) {
return !pureFunctions[ [ this.name, ...path ].join( '.' ) ];
}
}