Skip to content

Commit

Permalink
maintain this context when sequence is callable
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancahill committed Nov 10, 2017
1 parent 6d0e492 commit 6b1c0bc
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ast/nodes/SequenceExpression.js
Expand Up @@ -34,6 +34,10 @@ export default class SequenceExpression extends Node {
const last = this.expressions[ this.expressions.length - 1 ];
last.render( code, es );

if ( this.parent.type === 'CallExpression' && last.type === 'MemberExpression' && this.expressions.length > 1 ) {
this.expressions[0].included = true
}

const included = this.expressions.slice( 0, this.expressions.length - 1 ).filter( expression => expression.included );
if ( included.length === 0 ) {
code.remove( this.start, last.start );
Expand Down
5 changes: 5 additions & 0 deletions test/form/samples/sequence-expression/_expected/amd.js
Expand Up @@ -20,4 +20,9 @@ define(function () { 'use strict';
// should properly render complex sub-expressions
var g = ((() => {console.log(foo$1());})(), 1);

// should maintain this context
var module$1 = {};
module$1.bar = function () { console.log( 'bar' );};
var h = (0, module$1.bar)();

});
5 changes: 5 additions & 0 deletions test/form/samples/sequence-expression/_expected/cjs.js
Expand Up @@ -19,3 +19,8 @@ var e = (foo$1());

// should properly render complex sub-expressions
var g = ((() => {console.log(foo$1());})(), 1);

// should maintain this context
var module$1 = {};
module$1.bar = function () { console.log( 'bar' );};
var h = (0, module$1.bar)();
5 changes: 5 additions & 0 deletions test/form/samples/sequence-expression/_expected/es.js
Expand Up @@ -17,3 +17,8 @@ var e = (foo$1());

// should properly render complex sub-expressions
var g = ((() => {console.log(foo$1());})(), 1);

// should maintain this context
var module$1 = {};
module$1.bar = function () { console.log( 'bar' );};
var h = (0, module$1.bar)();
5 changes: 5 additions & 0 deletions test/form/samples/sequence-expression/_expected/iife.js
Expand Up @@ -21,4 +21,9 @@
// should properly render complex sub-expressions
var g = ((() => {console.log(foo$1());})(), 1);

// should maintain this context
var module$1 = {};
module$1.bar = function () { console.log( 'bar' );};
var h = (0, module$1.bar)();

}());
5 changes: 5 additions & 0 deletions test/form/samples/sequence-expression/_expected/umd.js
Expand Up @@ -24,4 +24,9 @@
// should properly render complex sub-expressions
var g = ((() => {console.log(foo$1());})(), 1);

// should maintain this context
var module$1 = {};
module$1.bar = function () { console.log( 'bar' );};
var h = (0, module$1.bar)();

})));
5 changes: 5 additions & 0 deletions test/form/samples/sequence-expression/main.js
Expand Up @@ -21,3 +21,8 @@ var e = (0, f.foo());

// should properly render complex sub-expressions
var g = ((() => {})(), (() => {console.log(f.foo())})(), 1);

// should maintain this context
var module = {};
module.bar = function () { console.log( 'bar' )};
var h = (0, module.bar)();

0 comments on commit 6b1c0bc

Please sign in to comment.