Skip to content

Commit

Permalink
Merge pull request jsdoc#1141 from algolia/fix/handle-object-spread-o…
Browse files Browse the repository at this point in the history
…perator

fix(object spread): support experimental object spread
  • Loading branch information
hegemonic committed Jan 5, 2016
2 parents b1ff7c1 + b1cd9a2 commit d626912
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/jsdoc/src/astnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/specs/jsdoc/src/astnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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}');
});
});
});

0 comments on commit d626912

Please sign in to comment.