From adfd0bf44ce2c46fadbd1e1ebc995bbbe4299c13 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 27 Mar 2016 00:20:30 -0400 Subject: [PATCH 1/3] failing test for #575 --- test/function/deshadowed-shorthand-property/_config.js | 4 ++++ test/function/deshadowed-shorthand-property/foo.js | 3 +++ test/function/deshadowed-shorthand-property/main.js | 8 ++++++++ 3 files changed, 15 insertions(+) create mode 100644 test/function/deshadowed-shorthand-property/_config.js create mode 100644 test/function/deshadowed-shorthand-property/foo.js create mode 100644 test/function/deshadowed-shorthand-property/main.js diff --git a/test/function/deshadowed-shorthand-property/_config.js b/test/function/deshadowed-shorthand-property/_config.js new file mode 100644 index 0000000..31e1c94 --- /dev/null +++ b/test/function/deshadowed-shorthand-property/_config.js @@ -0,0 +1,4 @@ +module.exports = { + solo: true, + 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..3cc4941 --- /dev/null +++ b/test/function/deshadowed-shorthand-property/main.js @@ -0,0 +1,8 @@ +import foo from './foo.js'; + +function x () { + const answer = foo(); + return { answer }; +} + +assert.equal( x().answer, 42 ); From faf18821b3fe9af3a171cff4bc5d88f1618224cd Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 27 Mar 2016 00:38:58 -0400 Subject: [PATCH 2/3] expand deshadowed shorthand properties (fixes #575) --- src/Module.js | 3 ++- test/function/deshadowed-shorthand-property/_config.js | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) 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 index 31e1c94..352f7f3 100644 --- a/test/function/deshadowed-shorthand-property/_config.js +++ b/test/function/deshadowed-shorthand-property/_config.js @@ -1,4 +1,3 @@ module.exports = { - solo: true, description: 'shorthand properties referencing deshadowed variables are expanded' }; From 18d3ad0ab28d8b59400c5540b7c3f78e3797a25a Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sun, 27 Mar 2016 18:45:46 -0400 Subject: [PATCH 3/3] gah 0.12 --- test/function/deshadowed-shorthand-property/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/function/deshadowed-shorthand-property/main.js b/test/function/deshadowed-shorthand-property/main.js index 3cc4941..7942ca4 100644 --- a/test/function/deshadowed-shorthand-property/main.js +++ b/test/function/deshadowed-shorthand-property/main.js @@ -1,7 +1,7 @@ import foo from './foo.js'; function x () { - const answer = foo(); + var answer = foo(); return { answer }; }