-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
CallExpression.js
69 lines (58 loc) · 3.04 KB
/
CallExpression.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
import Node from '../Node.js';
import CallOptions from '../CallOptions';
export default class CallExpression extends Node {
reassignPath ( path, options ) {
!options.hasReturnExpressionBeenAssignedAtPath( path, this )
&& this.callee.forEachReturnExpressionWhenCalledAtPath( [], this._callOptions, innerOptions => node =>
node.reassignPath( path, innerOptions.addAssignedReturnExpressionAtPath( path, this ) ), options );
}
bindNode () {
if ( this.callee.type === 'Identifier' ) {
const variable = this.scope.findVariable( this.callee.name );
if ( variable.isNamespace ) {
this.module.error( {
code: 'CANNOT_CALL_NAMESPACE',
message: `Cannot call a namespace ('${this.callee.name}')`
}, this.start );
}
if ( this.callee.name === 'eval' && variable.isGlobal ) {
this.module.warn( {
code: 'EVAL',
message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval'
}, this.start );
}
}
}
forEachReturnExpressionWhenCalledAtPath ( path, callOptions, callback, options ) {
this.callee.forEachReturnExpressionWhenCalledAtPath( [], this._callOptions, innerOptions => node =>
node.forEachReturnExpressionWhenCalledAtPath( path, callOptions, callback, innerOptions ), options );
}
hasEffects ( options ) {
return this.arguments.some( child => child.hasEffects( options ) )
|| this.callee.hasEffectsWhenCalledAtPath( [], this._callOptions, options.getHasEffectsWhenCalledOptions() );
}
hasEffectsWhenAccessedAtPath ( path, options ) {
return path.length > 0
&& !options.hasReturnExpressionBeenAccessedAtPath( path, this )
&& this.callee.someReturnExpressionWhenCalledAtPath( [], this._callOptions, innerOptions => node =>
node.hasEffectsWhenAccessedAtPath( path, innerOptions.addAccessedReturnExpressionAtPath( path, this ) ), options );
}
hasEffectsWhenAssignedAtPath ( path, options ) {
return !options.hasReturnExpressionBeenAssignedAtPath( path, this )
&& this.callee.someReturnExpressionWhenCalledAtPath( [], this._callOptions, innerOptions => node =>
node.hasEffectsWhenAssignedAtPath( path, innerOptions.addAssignedReturnExpressionAtPath( path, this ) ), options );
}
hasEffectsWhenCalledAtPath ( path, callOptions, options ) {
return !options.hasReturnExpressionBeenCalledAtPath( path, this )
&& this.callee.someReturnExpressionWhenCalledAtPath( [], this._callOptions, innerOptions => node =>
node.hasEffectsWhenCalledAtPath( path, callOptions, innerOptions.addCalledReturnExpressionAtPath( path, this ) ), options );
}
initialiseNode () {
this._callOptions = CallOptions.create( { withNew: false, args: this.arguments, caller: this } );
}
someReturnExpressionWhenCalledAtPath ( path, callOptions, predicateFunction, options ) {
return this.callee.someReturnExpressionWhenCalledAtPath( [], this._callOptions, innerOptions => node =>
node.someReturnExpressionWhenCalledAtPath( path, callOptions, predicateFunction, innerOptions ), options );
}
}