forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.js
More file actions
87 lines (71 loc) · 1.53 KB
/
transform.js
File metadata and controls
87 lines (71 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
'use strict';
// MODULES //
var transforms = require( './transforms' );
// VARIABLES //
var map = {
'namespace': 'namespaces',
'mixin': 'mixins',
'function': 'functions',
'member': 'properties',
'event': 'events',
'class': 'classes'
};
var recurse = {
'namespace': true,
'mixin': true,
'function': false,
'member': true,
'event': false,
'class': true
};
// MAIN //
/**
* Recursively transforms doclet nodes.
*
* @param {Object} parentNode - parent doclet node
* @param {ObjectArray} childNodes - array of child nodes
* @param {string} parentLongName - long form of a parent name
*/
function transform( parentNode, childNodes, parentLongName ) {
var node;
var tmp;
var key;
var out;
var fcn;
var i;
// Filter for child nodes...
tmp = [];
for ( i = 0; i < childNodes.length; i++ ) {
if ( childNodes[ i ].memberof === parentLongName ) {
tmp.push( childNodes[ i ] );
}
}
childNodes = tmp;
if ( childNodes.length === 0 ) {
return;
}
// For each child node, apply a transformation...
for ( i = 0; i < childNodes.length; i++ ) {
node = childNodes[ i ];
// Apply a transform...
fcn = transforms[ node.kind ];
if ( fcn === void 0 ) {
continue;
}
out = fcn( node );
// Cache the transformed node...
key = map[ node.kind ];
tmp = parentNode[ key ];
if ( tmp === void 0 ) {
tmp = [];
parentNode[ key ] = tmp;
}
tmp.push( out );
// Check if we need to recurse...
if ( recurse[ node.kind ] ) {
transform( out, childNodes, node.longname );
}
}
}
// EXPORTS //
module.exports = transform;