-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
GlobalVariable.ts
32 lines (29 loc) · 1.02 KB
/
GlobalVariable.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
import { CallOptions } from '../CallOptions';
import { HasEffectsContext } from '../ExecutionContext';
import { getGlobalAtPath } from '../nodes/shared/knownGlobals';
import { UNKNOWN_PATH } from '../utils/PathTracker';
import type { ObjectPath } from '../utils/PathTracker';
import Variable from './Variable';
export default class GlobalVariable extends Variable {
isReassigned = true;
hasEffectsWhenAccessedAtPath(path: ObjectPath): boolean {
if (path.length === 0) {
return this.name !== 'undefined' && getGlobalAtPath([this.name]) === null;
}
return getGlobalAtPath([this.name, ...path].slice(0, -1)) === null;
}
hasEffectsWhenCalledAtPath(
path: ObjectPath,
callOptions: CallOptions,
context: HasEffectsContext
): boolean {
const globalAtPath = getGlobalAtPath([this.name, ...path]);
return (
globalAtPath === null ||
!globalAtPath.function ||
(globalAtPath.mutatesArg1 &&
(!callOptions.args.length ||
callOptions.args[0].hasEffectsWhenAssignedAtPath(UNKNOWN_PATH, context, true)))
);
}
}