Browse Source

rename functions with args by the same name (fixes #32)

contingency-plan
Rich-Harris 10 years ago
parent
commit
b0eca67402
  1. 13
      src/Statement.js
  2. 10
      test/function/renamed-arguments/_config.js
  3. 5
      test/function/renamed-arguments/bar.js
  4. 5
      test/function/renamed-arguments/foo.js
  5. 7
      test/function/renamed-arguments/main.js

13
src/Statement.js

@ -315,15 +315,20 @@ export default class Statement {
let newNames = blank(); let newNames = blank();
let hasReplacements; let hasReplacements;
keys( names ).forEach( key => { // special case = function foo ( foo ) {...}
if ( !scope.declarations[ key ] ) { if ( node.id && names[ node.id.name ] && scope.declarations[ node.id.name ] ) {
newNames[ key ] = names[ key ]; magicString.overwrite( node.id.start, node.id.end, names[ node.id.name ] );
}
keys( names ).forEach( name => {
if ( !scope.declarations[ name ] ) {
newNames[ name ] = names[ name ];
hasReplacements = true; hasReplacements = true;
} }
}); });
deshadowList.forEach( name => { deshadowList.forEach( name => {
if ( ~scope.declarations[ name ] ) { if ( ~scope.declarations[ name ] ) { // TODO is this right? no indexOf?
newNames[ name ] = name + '$$'; // TODO better mechanism newNames[ name ] = name + '$$'; // TODO better mechanism
hasReplacements = true; hasReplacements = true;
} }

10
test/function/renamed-arguments/_config.js

@ -0,0 +1,10 @@
var assert = require( 'assert' );
module.exports = {
description: 'function arguments are renamed as appropriate (#32)',
exports: function ( exports ) {
var obj = {};
assert.strictEqual( exports.foo(), 42 );
assert.strictEqual( exports.bar( obj ), obj );
}
};

5
test/function/renamed-arguments/bar.js

@ -0,0 +1,5 @@
function thing ( thing ) {
return thing;
}
export default thing;

5
test/function/renamed-arguments/foo.js

@ -0,0 +1,5 @@
function thing () {
return 42;
}
export default thing;

7
test/function/renamed-arguments/main.js

@ -0,0 +1,7 @@
import foo from './foo';
import bar from './bar';
export {
foo,
bar
};
Loading…
Cancel
Save