Browse Source

Merge pull request #576 from rollup/gh-575

Expand deshadowed shorthand properties
gh-669
Rich Harris 9 years ago
parent
commit
3f54869cf0
  1. 3
      src/Module.js
  2. 3
      test/function/deshadowed-shorthand-property/_config.js
  3. 3
      test/function/deshadowed-shorthand-property/foo.js
  4. 8
      test/function/deshadowed-shorthand-property/main.js

3
src/Module.js

@ -526,7 +526,8 @@ export default class Module {
if ( keys( toDeshadow ).length ) {
statement.references.forEach( reference => {
if ( !reference.rewritten && reference.name in toDeshadow ) {
magicString.overwrite( reference.start, reference.end, toDeshadow[ reference.name ], true );
const replacement = toDeshadow[ reference.name ];
magicString.overwrite( reference.start, reference.end, reference.isShorthandProperty ? `${reference.name}: ${replacement}` : replacement, true );
}
});
}

3
test/function/deshadowed-shorthand-property/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'shorthand properties referencing deshadowed variables are expanded'
};

3
test/function/deshadowed-shorthand-property/foo.js

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

8
test/function/deshadowed-shorthand-property/main.js

@ -0,0 +1,8 @@
import foo from './foo.js';
function x () {
var answer = foo();
return { answer };
}
assert.equal( x().answer, 42 );
Loading…
Cancel
Save