Merge pull request #1141 from algolia/fix/handle-object-spread-operator

fix(object spread): support experimental object spread
This commit is contained in:
Jeff Williams 2016-01-05 15:52:55 -08:00
commit d62691288e
2 changed files with 11 additions and 0 deletions

View File

@ -223,6 +223,12 @@ var nodeToValue = exports.nodeToValue = function(node) {
case Syntax.ObjectExpression:
tempObject = {};
node.properties.forEach(function(prop) {
// ExperimentalSpreadProperty have no key
// like var hello = {...hi};
if (!prop.key) {
return;
}
var key = prop.key.name;
// preserve literal values so that the JSON form shows the correct type
if (prop.value.type === Syntax.Literal) {

View File

@ -42,6 +42,7 @@ describe('jsdoc/src/astNode', function() {
var variableDeclaration2 = parse('var foo = 1, bar = 2;').body[0];
var variableDeclarator1 = parse('var foo = 1;').body[0].declarations[0];
var variableDeclarator2 = parse('var foo;').body[0].declarations[0];
var experimentalObjectRestSpread = parse('var one = {...two, three: 4};').body[0].declarations[0].init;
it('should exist', function() {
expect(typeof astNode).toBe('object');
@ -615,5 +616,9 @@ describe('jsdoc/src/astNode', function() {
it('should return an empty string for all other nodes', function() {
expect( astNode.nodeToValue(binaryExpression) ).toBe('');
});
it('should understand and ignore ExperimentalSpreadProperty', function() {
expect( astNode.nodeToValue(experimentalObjectRestSpread) ).toBe('{"three":4}');
});
});
});