-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
SequenceExpression.js
55 lines (48 loc) · 1.43 KB
/
SequenceExpression.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
import Node from '../Node.js';
export default class SequenceExpression extends Node {
getValue () {
return this.expressions[ this.expressions.length - 1 ].getValue();
}
hasEffects ( options ) {
return this.expressions.some( expression => expression.hasEffects( options ) );
}
includeInBundle () {
let addedNewNodes = !this.included;
this.included = true;
if ( this.expressions[ this.expressions.length - 1 ].includeInBundle() ) {
addedNewNodes = true;
}
this.expressions.forEach( node => {
if ( node.shouldBeIncluded() ) {
if ( node.includeInBundle() ) {
addedNewNodes = true;
}
}
} );
return addedNewNodes;
}
render ( code, es ) {
if ( !this.module.bundle.treeshake ) {
super.render( code, es );
}
else {
const last = this.expressions[ this.expressions.length - 1 ];
last.render( code, es );
const included = this.expressions.slice( 0, this.expressions.length - 1 ).filter( expression => expression.included );
if ( included.length === 0 ) {
code.remove( this.start, last.start );
code.remove( last.end, this.end );
} else {
let previousEnd = this.start;
for ( const expression of included ) {
expression.render( code, es );
code.remove( previousEnd, expression.start );
code.appendLeft( expression.end, ', ' );
previousEnd = expression.end;
}
code.remove( previousEnd, last.start );
code.remove( last.end, this.end );
}
}
}
}