diff --git a/src/Module.js b/src/Module.js index 6ff7331..61e30cb 100644 --- a/src/Module.js +++ b/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 ); } }); } diff --git a/test/function/deshadowed-shorthand-property/_config.js b/test/function/deshadowed-shorthand-property/_config.js new file mode 100644 index 0000000..352f7f3 --- /dev/null +++ b/test/function/deshadowed-shorthand-property/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'shorthand properties referencing deshadowed variables are expanded' +}; diff --git a/test/function/deshadowed-shorthand-property/foo.js b/test/function/deshadowed-shorthand-property/foo.js new file mode 100644 index 0000000..c03d7e4 --- /dev/null +++ b/test/function/deshadowed-shorthand-property/foo.js @@ -0,0 +1,3 @@ +export default function answer () { + return 42; +} diff --git a/test/function/deshadowed-shorthand-property/main.js b/test/function/deshadowed-shorthand-property/main.js new file mode 100644 index 0000000..7942ca4 --- /dev/null +++ b/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 );