Skip to content

Commit

Permalink
deconflict function expression IDs (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 27, 2016
1 parent a9f342c commit 2eebe3d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/ast/nodes/FunctionExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ export default class FunctionExpression extends Node {
}

getName () {
return this.id && this.id.name;
return this.name;
}

hasEffects () {
return false;
}

initialise ( scope ) {
this.name = this.id && this.id.name; // may be overridden by bundle.deconflict
this.body.createScope( scope );

if ( this.id ) {
Expand Down
3 changes: 3 additions & 0 deletions test/function/deshadows-function-expression-id/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'deshadows function expression ID (#1176)'
};
3 changes: 3 additions & 0 deletions test/function/deshadows-function-expression-id/foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function foo () {
return 'works';
}
9 changes: 9 additions & 0 deletions test/function/deshadows-function-expression-id/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { foo as _foo } from './foo.js';

function Thing () {};

Thing.prototype.foo = function foo () {
return _foo();
};

assert.equal( new Thing().foo(), 'works' );
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
external: [ 'path' ]
},
exports ( exports ) {
assert.equal( exports.x.name, 'basename' );
assert.ok( !/path/.test( exports.x.name ) );
assert.equal( exports.y, 'somefile.txt' );
}
};

0 comments on commit 2eebe3d

Please sign in to comment.