Browse Source

deconflict function expression IDs (#1176)

gh-786
Rich-Harris 8 years ago
parent
commit
2eebe3dcc9
  1. 3
      src/ast/nodes/FunctionExpression.js
  2. 3
      test/function/deshadows-function-expression-id/_config.js
  3. 3
      test/function/deshadows-function-expression-id/foo.js
  4. 9
      test/function/deshadows-function-expression-id/main.js
  5. 2
      test/function/preserves-function-expression-names/_config.js

3
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 ) {

3
test/function/deshadows-function-expression-id/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'deshadows function expression ID (#1176)'
};

3
test/function/deshadows-function-expression-id/foo.js

@ -0,0 +1,3 @@
export function foo () {
return 'works';
}

9
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' );

2
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' );
}
};

Loading…
Cancel
Save