Browse Source

Merge pull request #439 from rollup/computed-property-keys-should-count

Ensure computed property keys are considered references.
gh-438-b
Rich Harris 9 years ago
parent
commit
f8b1f0f323
  1. 4
      src/ast/isReference.js
  2. 6
      test/form/computed-properties/_config.js
  3. 9
      test/form/computed-properties/_expected/amd.js
  4. 7
      test/form/computed-properties/_expected/cjs.js
  5. 5
      test/form/computed-properties/_expected/es6.js
  6. 10
      test/form/computed-properties/_expected/iife.js
  7. 13
      test/form/computed-properties/_expected/umd.js
  8. 3
      test/form/computed-properties/main.js

4
src/ast/isReference.js

@ -12,8 +12,8 @@ export default function isReference ( node, parent ) {
// TODO is this right?
if ( parent.type === 'MemberExpression' ) return parent.computed || node === parent.object;
// disregard the `bar` in { bar: foo }
if ( parent.type === 'Property' && node !== parent.value ) return false;
// disregard the `bar` in `{ bar: foo }`, but keep it in `{ [bar]: foo }`
if ( parent.type === 'Property' ) return parent.computed || node === parent.value;
// disregard the `bar` in `class Foo { bar () {...} }`
if ( parent.type === 'MethodDefinition' ) return false;

6
test/form/computed-properties/_config.js

@ -0,0 +1,6 @@
module.exports = {
description: 'computed property keys include declarations of referenced identifiers',
options: {
moduleName: 'computedProperties'
}
};

9
test/form/computed-properties/_expected/amd.js

@ -0,0 +1,9 @@
define(['exports'], function (exports) { 'use strict';
var foo = 'foo';
var x = {[foo]: 'bar'};
exports.x = x;
});

7
test/form/computed-properties/_expected/cjs.js

@ -0,0 +1,7 @@
'use strict';
var foo = 'foo';
var x = {[foo]: 'bar'};
exports.x = x;

5
test/form/computed-properties/_expected/es6.js

@ -0,0 +1,5 @@
var foo = 'foo';
var x = {[foo]: 'bar'};
export { x };

10
test/form/computed-properties/_expected/iife.js

@ -0,0 +1,10 @@
(function (exports) {
'use strict';
var foo = 'foo';
var x = {[foo]: 'bar'};
exports.x = x;
}((this.computedProperties = {})));

13
test/form/computed-properties/_expected/umd.js

@ -0,0 +1,13 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.computedProperties = {})));
}(this, function (exports) { 'use strict';
var foo = 'foo';
var x = {[foo]: 'bar'};
exports.x = x;
}));

3
test/form/computed-properties/main.js

@ -0,0 +1,3 @@
var foo = 'foo';
export var x = {[foo]: 'bar'};
Loading…
Cancel
Save