Browse Source

Ensure references inside default destructuring values count.

Fixes #364.
gh-384
Brian Donovan 9 years ago
parent
commit
27d0f33ac7
  1. 2
      src/Statement.js
  2. 3
      test/form/object-destructuring-default-values/_config.js
  3. 9
      test/form/object-destructuring-default-values/_expected/amd.js
  4. 7
      test/form/object-destructuring-default-values/_expected/cjs.js
  5. 5
      test/form/object-destructuring-default-values/_expected/es6.js
  6. 9
      test/form/object-destructuring-default-values/_expected/iife.js
  7. 13
      test/form/object-destructuring-default-values/_expected/umd.js
  8. 5
      test/form/object-destructuring-default-values/main.js

2
src/Statement.js

@ -86,7 +86,7 @@ export default class Statement {
// special case – shorthand properties. because node.key === node.value, // special case – shorthand properties. because node.key === node.value,
// we can't differentiate once we've descended into the node // we can't differentiate once we've descended into the node
if ( node.type === 'Property' && node.shorthand ) { if ( node.type === 'Property' && node.shorthand && parent.type !== 'ObjectPattern' ) {
const reference = new Reference( node.key, scope ); const reference = new Reference( node.key, scope );
reference.isShorthandProperty = true; // TODO feels a bit kludgy reference.isShorthandProperty = true; // TODO feels a bit kludgy
references.push( reference ); references.push( reference );

3
test/form/object-destructuring-default-values/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'object destructuring default values are preserved'
};

9
test/form/object-destructuring-default-values/_expected/amd.js

@ -0,0 +1,9 @@
define(function () { 'use strict';
const a = 1;
const b = 2;
const { c = a } = {};
const [ d = b ] = [];
console.log(c, d);
});

7
test/form/object-destructuring-default-values/_expected/cjs.js

@ -0,0 +1,7 @@
'use strict';
const a = 1;
const b = 2;
const { c = a } = {};
const [ d = b ] = [];
console.log(c, d);

5
test/form/object-destructuring-default-values/_expected/es6.js

@ -0,0 +1,5 @@
const a = 1;
const b = 2;
const { c = a } = {};
const [ d = b ] = [];
console.log(c, d);

9
test/form/object-destructuring-default-values/_expected/iife.js

@ -0,0 +1,9 @@
(function () { 'use strict';
const a = 1;
const b = 2;
const { c = a } = {};
const [ d = b ] = [];
console.log(c, d);
})();

13
test/form/object-destructuring-default-values/_expected/umd.js

@ -0,0 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
factory();
}(this, function () { 'use strict';
const a = 1;
const b = 2;
const { c = a } = {};
const [ d = b ] = [];
console.log(c, d);
}));

5
test/form/object-destructuring-default-values/main.js

@ -0,0 +1,5 @@
const a = 1;
const b = 2;
const { c = a } = {};
const [ d = b ] = [];
console.log(c, d);
Loading…
Cancel
Save