Skip to content

Commit

Permalink
Bind calls to object expression members
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Nov 8, 2017
1 parent 80dff0f commit 2fb0c34
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/ast/nodes/ObjectExpression.js
Expand Up @@ -13,6 +13,14 @@ export default class ObjectExpression extends Node {
property.bindAssignmentAtPath( path.slice( 1 ), expression ) );
}

bindCallAtPath ( path, callOptions ) {
if ( path.length === 0 ) {
return;
}
this._getPossiblePropertiesWithName( path[ 0 ], PROPERTY_KINDS_READ ).properties.forEach( property =>
property.bindCallAtPath( path.slice( 1 ), callOptions ) );
}

_getPossiblePropertiesWithName ( name, kinds ) {
if ( name === UNKNOWN_KEY ) {
return { properties: this.properties, hasCertainHit: false };
Expand Down
4 changes: 4 additions & 0 deletions src/ast/nodes/Property.js
Expand Up @@ -7,6 +7,10 @@ export default class Property extends Node {
this.value.bindAssignmentAtPath( path, expression );
}

bindCallAtPath ( path, callOptions ) {
this.value.bindCallAtPath( path, callOptions );
}

hasEffects ( options ) {
return this.key.hasEffects( options )
|| this.value.hasEffects( options );
Expand Down
@@ -0,0 +1,8 @@
var assert = require( 'assert' );

module.exports = {
description: 'Associates object expression member parameters with their call arguments',
exports: function ( exports ) {
assert.equal( exports.bar, 'present' );
}
};
@@ -0,0 +1,12 @@
const foo = { mightBeExported: {} };
const exported = {};
const assigner = {
assignExported ( obj ) {
obj.mightBeExported = exported;
}
};

assigner.assignExported( foo );
foo.mightBeExported.bar = 'present';

export default exported;

0 comments on commit 2fb0c34

Please sign in to comment.