Browse Source

Merge pull request #1234 from rollup/gh-1233

include new expressions where callee is a class
gh-1187
Rich Harris 8 years ago
committed by GitHub
parent
commit
b0a83b8bf4
  1. 5
      src/ast/nodes/shared/callHasEffects.js
  2. 3
      test/form/class-constructor-side-effect/_config.js
  3. 11
      test/form/class-constructor-side-effect/_expected/amd.js
  4. 9
      test/form/class-constructor-side-effect/_expected/cjs.js
  5. 7
      test/form/class-constructor-side-effect/_expected/es.js
  6. 12
      test/form/class-constructor-side-effect/_expected/iife.js
  7. 15
      test/form/class-constructor-side-effect/_expected/umd.js
  8. 7
      test/form/class-constructor-side-effect/main.js

5
src/ast/nodes/shared/callHasEffects.js

@ -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 );

3
test/form/class-constructor-side-effect/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'preserves side-effects in a class constructor (#1233)'
};

11
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
test/form/class-constructor-side-effect/_expected/cjs.js

@ -0,0 +1,9 @@
'use strict';
class Foo {
constructor () {
console.log( 'Foo' );
}
}
new Foo;

7
test/form/class-constructor-side-effect/_expected/es.js

@ -0,0 +1,7 @@
class Foo {
constructor () {
console.log( 'Foo' );
}
}
new Foo;

12
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
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
test/form/class-constructor-side-effect/main.js

@ -0,0 +1,7 @@
class Foo {
constructor () {
console.log( 'Foo' );
}
}
new Foo;
Loading…
Cancel
Save