Commit d06a107e by Marijn Haverbeke

Generate mangled name, rather than no name, for method names that shadow vars

Issue #116
parent ddbc9c2b
Pipeline #5458158 passed with stage
in 2 minutes 13 seconds
......@@ -86,7 +86,9 @@ export default class ClassBody extends Node {
let lhs;
let methodName = method.key.name;
if ( reserved[ methodName ] ) methodName = scope.createIdentifier( methodName );
if ( reserved[ methodName ] || method.value.body.scope.references[methodName] ) {
methodName = scope.createIdentifier( methodName );
}
// when method name is a string or a number let's pretend it's a computed method
......@@ -140,7 +142,7 @@ export default class ClassBody extends Node {
code.insertRight( method.start, lhs );
const funcName = method.computed || isAccessor || !namedFunctions || method.value.body.scope.references[methodName] ? '' : `${methodName} `
const funcName = method.computed || isAccessor || !namedFunctions ? '' : `${methodName} `
const rhs = ( isAccessor ? `.${method.kind}` : '' ) + ` = function` + ( method.value.generator ? '* ' : ' ' ) + funcName;
code.remove( c, method.value.start );
code.insertRight( method.value.start, rhs );
......
......@@ -1193,7 +1193,7 @@ module.exports = [
output: `
var X = function X () {};
X.prototype.foo = function () { return foo };
X.prototype.foo = function foo$1 () { return foo };
X.prototype.bar = function bar () {};
`
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment