From 766e91d95f9e31bc989bdfe166fedbbacc38bae2 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 6 Jan 2017 18:01:51 -0500 Subject: [PATCH 1/2] include new expressions where callee is a class (#1233) --- src/ast/nodes/shared/callHasEffects.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ast/nodes/shared/callHasEffects.js b/src/ast/nodes/shared/callHasEffects.js index ce48fc0..2c37442 100644 --- a/src/ast/nodes/shared/callHasEffects.js +++ b/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 ); From 585bde0f362824fcdd9b6dfcc31794b3bd4be3ce Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 6 Jan 2017 18:02:33 -0500 Subject: [PATCH 2/2] test for #1233 --- .../form/class-constructor-side-effect/_config.js | 3 +++ .../_expected/amd.js | 11 +++++++++++ .../_expected/cjs.js | 9 +++++++++ .../class-constructor-side-effect/_expected/es.js | 7 +++++++ .../_expected/iife.js | 12 ++++++++++++ .../_expected/umd.js | 15 +++++++++++++++ test/form/class-constructor-side-effect/main.js | 7 +++++++ 7 files changed, 64 insertions(+) create mode 100644 test/form/class-constructor-side-effect/_config.js create mode 100644 test/form/class-constructor-side-effect/_expected/amd.js create mode 100644 test/form/class-constructor-side-effect/_expected/cjs.js create mode 100644 test/form/class-constructor-side-effect/_expected/es.js create mode 100644 test/form/class-constructor-side-effect/_expected/iife.js create mode 100644 test/form/class-constructor-side-effect/_expected/umd.js create mode 100644 test/form/class-constructor-side-effect/main.js diff --git a/test/form/class-constructor-side-effect/_config.js b/test/form/class-constructor-side-effect/_config.js new file mode 100644 index 0000000..5c8a4a0 --- /dev/null +++ b/test/form/class-constructor-side-effect/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'preserves side-effects in a class constructor (#1233)' +}; diff --git a/test/form/class-constructor-side-effect/_expected/amd.js b/test/form/class-constructor-side-effect/_expected/amd.js new file mode 100644 index 0000000..1b939aa --- /dev/null +++ b/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; + +}); diff --git a/test/form/class-constructor-side-effect/_expected/cjs.js b/test/form/class-constructor-side-effect/_expected/cjs.js new file mode 100644 index 0000000..ad3db87 --- /dev/null +++ b/test/form/class-constructor-side-effect/_expected/cjs.js @@ -0,0 +1,9 @@ +'use strict'; + +class Foo { + constructor () { + console.log( 'Foo' ); + } +} + +new Foo; diff --git a/test/form/class-constructor-side-effect/_expected/es.js b/test/form/class-constructor-side-effect/_expected/es.js new file mode 100644 index 0000000..705e350 --- /dev/null +++ b/test/form/class-constructor-side-effect/_expected/es.js @@ -0,0 +1,7 @@ +class Foo { + constructor () { + console.log( 'Foo' ); + } +} + +new Foo; diff --git a/test/form/class-constructor-side-effect/_expected/iife.js b/test/form/class-constructor-side-effect/_expected/iife.js new file mode 100644 index 0000000..a047aa4 --- /dev/null +++ b/test/form/class-constructor-side-effect/_expected/iife.js @@ -0,0 +1,12 @@ +(function () { + 'use strict'; + + class Foo { + constructor () { + console.log( 'Foo' ); + } + } + + new Foo; + +}()); diff --git a/test/form/class-constructor-side-effect/_expected/umd.js b/test/form/class-constructor-side-effect/_expected/umd.js new file mode 100644 index 0000000..c4409fe --- /dev/null +++ b/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; + +}))); diff --git a/test/form/class-constructor-side-effect/main.js b/test/form/class-constructor-side-effect/main.js new file mode 100644 index 0000000..705e350 --- /dev/null +++ b/test/form/class-constructor-side-effect/main.js @@ -0,0 +1,7 @@ +class Foo { + constructor () { + console.log( 'Foo' ); + } +} + +new Foo;