Skip to content

Commit

Permalink
Bind calls to ES6 constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
lukastaegert committed Nov 8, 2017
1 parent 503b8aa commit 63e4453
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
6 changes: 6 additions & 0 deletions 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;
Expand Down
12 changes: 8 additions & 4 deletions 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 );
}
}
5 changes: 5 additions & 0 deletions src/ast/nodes/shared/ClassNode.js
Expand Up @@ -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;
}
Expand Down
@@ -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' );
}
};
@@ -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;

0 comments on commit 63e4453

Please sign in to comment.