mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Merge pull request #1141 from algolia/fix/handle-object-spread-operator
fix(object spread): support experimental object spread
This commit is contained in:
commit
d62691288e
@ -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) {
|
||||
|
||||
@ -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}');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user