diff --git a/src/ast/nodes/ClassBody.js b/src/ast/nodes/ClassBody.js index dab3873e2bd..d1e6e49ef16 100644 --- a/src/ast/nodes/ClassBody.js +++ b/src/ast/nodes/ClassBody.js @@ -1,6 +1,12 @@ import Node from '../Node'; export default class ClassBody extends Node { + bindCallAtPath ( path, callOptions ) { + if ( path.length === 0 && this.classConstructor ) { + this.classConstructor.bindCallAtPath( path, callOptions ); + } + } + hasEffectsWhenCalledAtPath ( path, callOptions, options ) { if ( path.length > 0 ) { return true; diff --git a/src/ast/nodes/MethodDefinition.js b/src/ast/nodes/MethodDefinition.js index e14ad731f18..a856621797a 100644 --- a/src/ast/nodes/MethodDefinition.js +++ b/src/ast/nodes/MethodDefinition.js @@ -1,14 +1,18 @@ import Node from '../Node'; export default class MethodDefinition extends Node { + bindCallAtPath ( path, callOptions ) { + if ( path.length === 0 ) { + this.value.bindCallAtPath( path, callOptions ); + } + } + hasEffects ( options ) { return this.key.hasEffects( options ); } hasEffectsWhenCalledAtPath ( path, callOptions, options ) { - if ( path.length > 0 ) { - return true; - } - return this.value.hasEffectsWhenCalledAtPath( [], callOptions, options ); + return path.length > 0 + || this.value.hasEffectsWhenCalledAtPath( [], callOptions, options ); } } diff --git a/src/ast/nodes/shared/ClassNode.js b/src/ast/nodes/shared/ClassNode.js index c7fe7773d2f..e6efd63c6c9 100644 --- a/src/ast/nodes/shared/ClassNode.js +++ b/src/ast/nodes/shared/ClassNode.js @@ -2,6 +2,11 @@ import Node from '../../Node.js'; import Scope from '../../scopes/Scope'; export default class ClassNode extends Node { + bindCallAtPath ( path, callOptions ) { + this.body.bindCallAtPath( path, callOptions ); + this.superClass && this.superClass.bindCallAtPath( path, callOptions ); + } + hasEffectsWhenAccessedAtPath ( path ) { return path.length > 1; } diff --git a/test/function/samples/associate-es6-constructor-parameter-mutations/_config.js b/test/function/samples/associate-es6-constructor-parameter-mutations/_config.js new file mode 100644 index 00000000000..ad2ad3811af --- /dev/null +++ b/test/function/samples/associate-es6-constructor-parameter-mutations/_config.js @@ -0,0 +1,8 @@ +var assert = require( 'assert' ); + +module.exports = { + description: 'Associates ES5 constructor parameters with their call arguments', + exports: function ( exports ) { + assert.equal( exports.bar, 'present' ); + } +}; diff --git a/test/function/samples/associate-es6-constructor-parameter-mutations/main.js b/test/function/samples/associate-es6-constructor-parameter-mutations/main.js new file mode 100644 index 00000000000..1e3e360dbfd --- /dev/null +++ b/test/function/samples/associate-es6-constructor-parameter-mutations/main.js @@ -0,0 +1,13 @@ +const foo = { mightBeExported: {} }; +const exported = {}; + +class AssignExported { + constructor ( obj ) { + obj.mightBeExported = exported; + } +} + +const bar = new AssignExported( foo ); +foo.mightBeExported.bar = 'present'; + +export default exported;