/
TaggedTemplateExpression.ts
59 lines (52 loc) · 1.45 KB
/
TaggedTemplateExpression.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
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
import { CallOptions, NO_ARGS } from '../CallOptions';
import { HasEffectsContext } from '../ExecutionContext';
import { EMPTY_PATH } from '../utils/PathTracker';
import Identifier from './Identifier';
import * as NodeType from './NodeType';
import { ExpressionNode, NodeBase } from './shared/Node';
import TemplateLiteral from './TemplateLiteral';
export default class TaggedTemplateExpression extends NodeBase {
quasi!: TemplateLiteral;
tag!: ExpressionNode;
type!: NodeType.tTaggedTemplateExpression;
private callOptions!: CallOptions;
bind() {
super.bind();
if (this.tag.type === NodeType.Identifier) {
const name = (this.tag as Identifier).name;
const variable = this.scope.findVariable(name);
if (variable.isNamespace) {
this.context.warn(
{
code: 'CANNOT_CALL_NAMESPACE',
message: `Cannot call a namespace ('${name}')`,
},
this.start
);
}
if (name === 'eval') {
this.context.warn(
{
code: 'EVAL',
message: `Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification`,
url: 'https://rollupjs.org/guide/en/#avoiding-eval',
},
this.start
);
}
}
}
hasEffects(context: HasEffectsContext) {
return (
super.hasEffects(context) ||
this.tag.hasEffectsWhenCalledAtPath(EMPTY_PATH, this.callOptions, context)
);
}
initialise() {
this.callOptions = {
args: NO_ARGS,
thisParam: null,
withNew: false,
};
}
}