diff --git a/src/ast/nodes/FunctionExpression.js b/src/ast/nodes/FunctionExpression.js index 34d9cc3..60f89f3 100644 --- a/src/ast/nodes/FunctionExpression.js +++ b/src/ast/nodes/FunctionExpression.js @@ -21,7 +21,7 @@ export default class FunctionExpression extends Node { } getName () { - return this.id && this.id.name; + return this.name; } hasEffects () { @@ -29,6 +29,7 @@ export default class FunctionExpression extends Node { } initialise ( scope ) { + this.name = this.id && this.id.name; // may be overridden by bundle.deconflict this.body.createScope( scope ); if ( this.id ) { diff --git a/test/function/deshadows-function-expression-id/_config.js b/test/function/deshadows-function-expression-id/_config.js new file mode 100644 index 0000000..2f0ff53 --- /dev/null +++ b/test/function/deshadows-function-expression-id/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'deshadows function expression ID (#1176)' +}; diff --git a/test/function/deshadows-function-expression-id/foo.js b/test/function/deshadows-function-expression-id/foo.js new file mode 100644 index 0000000..ccdd634 --- /dev/null +++ b/test/function/deshadows-function-expression-id/foo.js @@ -0,0 +1,3 @@ +export function foo () { + return 'works'; +} diff --git a/test/function/deshadows-function-expression-id/main.js b/test/function/deshadows-function-expression-id/main.js new file mode 100644 index 0000000..dc77e95 --- /dev/null +++ b/test/function/deshadows-function-expression-id/main.js @@ -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' ); diff --git a/test/function/preserves-function-expression-names/_config.js b/test/function/preserves-function-expression-names/_config.js index 14d8d3f..bf2a0ab 100644 --- a/test/function/preserves-function-expression-names/_config.js +++ b/test/function/preserves-function-expression-names/_config.js @@ -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' ); } };