Skip to content

Commit

Permalink
Resolve #1707, resolve #1709
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Nov 10, 2017
1 parent d04644a commit 3224778
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 38 deletions.
8 changes: 4 additions & 4 deletions src/ast/nodes/SequenceExpression.js
Expand Up @@ -32,16 +32,16 @@ export default class SequenceExpression extends Node {

else {
const last = this.expressions[ this.expressions.length - 1 ];
const included = this.expressions.slice( 0, this.expressions.length - 1 ).filter( expression => expression.included );
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 {
} else {
let previousEnd = this.start;
for ( const expression of included ) {
expression.render();
code.remove( previousEnd, expression.start );
code.appendLeft( expression.end, ', ' );
previousEnd = expression.end;
Expand Down
21 changes: 11 additions & 10 deletions test/form/samples/sequence-expression/_expected/amd.js
Expand Up @@ -3,17 +3,18 @@ define(function () { 'use strict';
function foo$1 () {
console.log( 'foo' );
}
// should remove expressions without side-effect, multiple effects
var a = (foo(), foo(), 2);
// without white-space, effect at the end
var b = (foo());

// should only keep final expression
var d = (2);
console.log(d);
// should remove expressions without side-effect, multiple effects
var a = (foo(), foo(), 2);
// without white-space, effect at the end
var b = (foo());

// should infer value
// should keep f import
var e = (foo$1());
// should only keep final expression
var d = (2);
console.log(d);

// should infer value
// should keep f import
var e = (foo$1());

});
1 change: 1 addition & 0 deletions test/form/samples/sequence-expression/_expected/cjs.js
Expand Up @@ -3,6 +3,7 @@
function foo$1 () {
console.log( 'foo' );
}

// should remove expressions without side-effect, multiple effects
var a = (foo(), foo(), 2);
// without white-space, effect at the end
Expand Down
1 change: 1 addition & 0 deletions test/form/samples/sequence-expression/_expected/es.js
@@ -1,6 +1,7 @@
function foo$1 () {
console.log( 'foo' );
}

// should remove expressions without side-effect, multiple effects
var a = (foo(), foo(), 2);
// without white-space, effect at the end
Expand Down
23 changes: 12 additions & 11 deletions test/form/samples/sequence-expression/_expected/iife.js
@@ -1,20 +1,21 @@
(function () {
'use strict';
'use strict';

function foo$1 () {
console.log( 'foo' );
}
// should remove expressions without side-effect, multiple effects
var a = (foo(), foo(), 2);
// without white-space, effect at the end
var b = (foo());

// should only keep final expression
var d = (2);
console.log(d);
// should remove expressions without side-effect, multiple effects
var a = (foo(), foo(), 2);
// without white-space, effect at the end
var b = (foo());

// should infer value
// should keep f import
var e = (foo$1());
// should only keep final expression
var d = (2);
console.log(d);

// should infer value
// should keep f import
var e = (foo$1());

}());
27 changes: 14 additions & 13 deletions test/form/samples/sequence-expression/_expected/umd.js
@@ -1,23 +1,24 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';

function foo$1 () {
console.log( 'foo' );
}
// should remove expressions without side-effect, multiple effects
var a = (foo(), foo(), 2);
// without white-space, effect at the end
var b = (foo());

// should only keep final expression
var d = (2);
console.log(d);
// should remove expressions without side-effect, multiple effects
var a = (foo(), foo(), 2);
// without white-space, effect at the end
var b = (foo());

// should infer value
// should keep f import
var e = (foo$1());
// should only keep final expression
var d = (2);
console.log(d);

// should infer value
// should keep f import
var e = (foo$1());

})));

0 comments on commit 3224778

Please sign in to comment.