forked from rollup/rollup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExpressionStatement.ts
48 lines (41 loc) · 1.39 KB
/
ExpressionStatement.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
import type MagicString from 'magic-string';
import { LOGLEVEL_WARN } from '../../utils/logging';
import { logModuleLevelDirective } from '../../utils/logs';
import type { RenderOptions } from '../../utils/renderHelpers';
import type { InclusionContext } from '../ExecutionContext';
import * as NodeType from './NodeType';
import { type ExpressionNode, StatementBase } from './shared/Node';
export default class ExpressionStatement extends StatementBase {
declare directive?: string;
declare expression: ExpressionNode;
initialise(): void {
super.initialise();
if (
this.directive &&
this.directive !== 'use strict' &&
this.parent.type === NodeType.Program
) {
this.scope.context.log(
LOGLEVEL_WARN,
// This is necessary, because either way (deleting or not) can lead to errors.
logModuleLevelDirective(this.directive, this.scope.context.module.id),
this.start
);
}
}
removeAnnotations(code: MagicString) {
this.expression.removeAnnotations(code);
}
render(code: MagicString, options: RenderOptions): void {
super.render(code, options);
if (code.original[this.end - 1] !== ';') {
code.appendLeft(this.end, ';');
}
}
shouldBeIncluded(context: InclusionContext): boolean {
if (this.directive && this.directive !== 'use strict')
return this.parent.type !== NodeType.Program;
return super.shouldBeIncluded(context);
}
protected applyDeoptimizations() {}
}