Skip to content

Commit 5aa8898

Browse files
committed
Add support for "this[Symbol.foo]" members and update Iterable to use it
1 parent 3a3d6cf commit 5aa8898

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

content/JavaScript/iterable.jsdoc

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ You can loop over all values in an iterable object by using a
99

1010
See %%/Iterator|Iterator%% for more details.
1111

12+
Version:
13+
ECMAScript 2015
14+
15+
Spec:
16+
http://www.ecma-international.org/ecma-262/6.0/#sec-iterable-interface
17+
18+
----
19+
instance[Symbol.iterator] : Iterator
20+
21+
Returns an iterator for this object.
22+
1223
<example>
1324
// Arrays are a built in Iterable object
1425
var arr = ['a', 'b', 'c'];
@@ -26,9 +37,3 @@ while (!current.done) {
2637
current = iterator.next();
2738
}
2839
</example>
29-
30-
Version:
31-
ECMAScript 2015
32-
33-
Spec:
34-
http://www.ecma-international.org/ecma-262/6.0/#sec-iterable-interface

jsdocparser.js

+8
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@ var parseMember = function(member) {
468468
type = type.substring(0, commentStartIndex).trim();
469469
}
470470

471+
// Process Indexer [Symbol]
472+
if (res = name.match(/^\s*\[\s*(\w*\.\w*)\s*\]/)) {
473+
return { parameters: [{ name: res[1] }],
474+
type: 'Indexer',
475+
returnType: parseMember(type),
476+
description: description };
477+
}
478+
471479
// Process Indexer
472480
if (res = name.match(/^\s*\[(.*)\]/)) {
473481
return { parameters: parseParamList(res[1]),

templates/member.ejs

+10
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ var renderMember = function(member, isPrimary, nestedRenderMember) {
170170
res += '</table>'
171171
res += '<span class="subfunctionclose">}</span>';
172172
}
173+
else if (!member.type) {
174+
if (!/^\w+\.\w+$/.test(member.name)) {
175+
throw 'Unexpected member type: ' + member.name;
176+
}
177+
178+
const nameParts = member.name.split('.');
179+
const href = '/' + nameParts[0] + '#' + nameParts[1];
180+
181+
res = `<a href="${href}">${ res }</a>`;
182+
}
173183
else {
174184
res += '&nbsp;:&nbsp;' + renderType(member.type);
175185
}

test-jsdocparser.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,8 @@ testParse('[b : c] : d', // indexer
270270
returnType: 'd'
271271
});
272272

273-
testParse('a : b, c', // multiple inheritance
274-
{ name: 'a',
275-
type: ['b', 'c']
273+
testParse('[a.b] : c', // symbol indexer
274+
{ type: 'Indexer',
275+
parameters: [ { name: 'a.b' } ],
276+
returnType: 'c'
276277
});

0 commit comments

Comments
 (0)