Skip to content

Commit

Permalink
Merge pull request #1234 from rollup/gh-1233
Browse files Browse the repository at this point in the history
include new expressions where callee is a class
  • Loading branch information
Rich-Harris committed Jan 6, 2017
2 parents e4682a3 + 585bde0 commit b0a83b8
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ast/nodes/shared/callHasEffects.js
Expand Up @@ -70,6 +70,11 @@ export default function callHasEffects ( scope, callee, isNew ) {
if ( fnHasEffects( node, isNew && isES5Function( node ) ) ) return true;
}

else if ( /Class/.test( node.type ) ) {
// TODO find constructor (may belong to a superclass)
return true;
}

else if ( isReference( node ) ) {
const flattened = flatten( node );
const declaration = scope.findDeclaration( flattened.name );
Expand Down
3 changes: 3 additions & 0 deletions test/form/class-constructor-side-effect/_config.js
@@ -0,0 +1,3 @@
module.exports = {
description: 'preserves side-effects in a class constructor (#1233)'
};
11 changes: 11 additions & 0 deletions test/form/class-constructor-side-effect/_expected/amd.js
@@ -0,0 +1,11 @@
define(function () { 'use strict';

class Foo {
constructor () {
console.log( 'Foo' );
}
}

new Foo;

});
9 changes: 9 additions & 0 deletions test/form/class-constructor-side-effect/_expected/cjs.js
@@ -0,0 +1,9 @@
'use strict';

class Foo {
constructor () {
console.log( 'Foo' );
}
}

new Foo;
7 changes: 7 additions & 0 deletions test/form/class-constructor-side-effect/_expected/es.js
@@ -0,0 +1,7 @@
class Foo {
constructor () {
console.log( 'Foo' );
}
}

new Foo;
12 changes: 12 additions & 0 deletions test/form/class-constructor-side-effect/_expected/iife.js
@@ -0,0 +1,12 @@
(function () {
'use strict';

class Foo {
constructor () {
console.log( 'Foo' );
}
}

new Foo;

}());
15 changes: 15 additions & 0 deletions test/form/class-constructor-side-effect/_expected/umd.js
@@ -0,0 +1,15 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';

class Foo {
constructor () {
console.log( 'Foo' );
}
}

new Foo;

})));
7 changes: 7 additions & 0 deletions test/form/class-constructor-side-effect/main.js
@@ -0,0 +1,7 @@
class Foo {
constructor () {
console.log( 'Foo' );
}
}

new Foo;

0 comments on commit b0a83b8

Please sign in to comment.