Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit e81b9c6

Browse files
author
tkrause
committed
enable the use of an apiUse block in an apiDefine block
1 parent bb397bf commit e81b9c6

File tree

2 files changed

+65
-51
lines changed

2 files changed

+65
-51
lines changed

lib/parser.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ Parser.prototype._parseBlockElements = function(indexApiBlocks, detectedElements
222222
preventGlobal = elementParser.preventGlobal === true;
223223

224224
// allow multiple inserts into pathTo
225-
allowMultiple = elementParser.allowMultiple === true;
225+
//allowMultiple = elementParser.allowMultiple === true;
226+
allowMultiple = true;
226227

227228

228229
// path to an array, where the values should be attached

lib/workers/api_use.js

Lines changed: 63 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -66,70 +66,83 @@ function postProcess(parsedFiles, filenames, preProcess, packageInfos, source, t
6666

6767
parsedFiles.forEach(function(parsedFile, parsedFileIndex) {
6868
parsedFile.forEach(function(block) {
69-
if ( ! block.local[target])
70-
return;
71-
72-
block.local[target].forEach(function(definition) {
73-
var name = definition.name;
74-
var version = block.version || packageInfos.defaultVersion;
75-
76-
if ( ! preProcess[source] || ! preProcess[source][name]) {
77-
throw new WorkerError('Referenced groupname does not exist / it is not defined with @apiDefine.',
78-
filenames[parsedFileIndex],
79-
block.index,
80-
messages.common.element,
81-
messages.common.usage,
82-
messages.common.example,
83-
[
84-
{ 'Groupname': name }
85-
]
69+
var loopCounter = 0; //add a loop counter to have a break condition when the recursion depth exceed a predifined limit
70+
while (block.local[target]) {
71+
if (loopCounter > 10) {
72+
throw new WorkerError('recursion depth exceeds limit with @apiUse',
73+
filenames[parsedFileIndex],
74+
block.index,
75+
messages.common.element,
76+
messages.common.usage,
77+
messages.common.example,
78+
[
79+
{ 'Groupname': name }
80+
]
8681
);
87-
}
88-
89-
var matchedData = {};
90-
if (preProcess[source][name][version]) {
91-
// found the version
92-
matchedData = preProcess[source][name][version];
93-
} else {
94-
// find nearest matching version
95-
var foundIndex = -1;
96-
var lastVersion = packageInfos.defaultVersion;
97-
98-
var versionKeys = Object.keys(preProcess[source][name]);
99-
versionKeys.forEach(function(currentVersion, versionIndex) {
100-
if (semver.gte(version, currentVersion) && semver.gte(currentVersion, lastVersion)) {
101-
lastVersion = currentVersion;
102-
foundIndex = versionIndex;
103-
}
104-
});
82+
}
83+
84+
block.local[target].forEach(function(definition) {
85+
var name = definition.name;
86+
var version = block.version || packageInfos.defaultVersion;
10587

106-
if (foundIndex === -1) {
107-
throw new WorkerError('Referenced definition has no matching or a higher version. ' +
108-
'Check version number in referenced define block.',
88+
if ( ! preProcess[source] || ! preProcess[source][name]) {
89+
throw new WorkerError('Referenced groupname does not exist / it is not defined with @apiDefine.',
10990
filenames[parsedFileIndex],
11091
block.index,
11192
messages.common.element,
11293
messages.common.usage,
11394
messages.common.example,
11495
[
115-
{ 'Groupname': name },
116-
{ 'Version': version },
117-
{ 'Defined versions': versionKeys },
96+
{ 'Groupname': name }
11897
]
11998
);
12099
}
121100

122-
var versionName = versionKeys[foundIndex];
123-
matchedData = preProcess[source][name][versionName];
124-
}
101+
var matchedData = {};
102+
if (preProcess[source][name][version]) {
103+
// found the version
104+
matchedData = preProcess[source][name][version];
105+
} else {
106+
// find nearest matching version
107+
var foundIndex = -1;
108+
var lastVersion = packageInfos.defaultVersion;
109+
110+
var versionKeys = Object.keys(preProcess[source][name]);
111+
versionKeys.forEach(function(currentVersion, versionIndex) {
112+
if (semver.gte(version, currentVersion) && semver.gte(currentVersion, lastVersion)) {
113+
lastVersion = currentVersion;
114+
foundIndex = versionIndex;
115+
}
116+
});
117+
118+
if (foundIndex === -1) {
119+
throw new WorkerError('Referenced definition has no matching or a higher version. ' +
120+
'Check version number in referenced define block.',
121+
filenames[parsedFileIndex],
122+
block.index,
123+
messages.common.element,
124+
messages.common.usage,
125+
messages.common.example,
126+
[
127+
{ 'Groupname': name },
128+
{ 'Version': version },
129+
{ 'Defined versions': versionKeys },
130+
]
131+
);
132+
}
133+
134+
var versionName = versionKeys[foundIndex];
135+
matchedData = preProcess[source][name][versionName];
136+
}
125137

126-
// remove target, not needed anymore
127-
// TODO: create a cleanup filter
128-
delete block.local[target];
138+
// remove target, not needed anymore
139+
// TODO: create a cleanup filter
140+
delete block.local[target];
129141

130-
// copy matched elements into parsed block
131-
_recursiveMerge(block.local, matchedData);
132-
});
142+
// copy matched elements into parsed block
143+
_recursiveMerge(block.local, matchedData);
144+
});
145+
}
133146
});
134147
});
135148
}

0 commit comments

Comments
 (0)