Skip to content

Commit c43db6b

Browse files
authored
Merge pull request #65 from openlayers/tuples
Convert tuples to simple Array
2 parents 187b3ab + 1f59187 commit c43db6b

File tree

4 files changed

+281
-30
lines changed

4 files changed

+281
-30
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ To:
156156
*/
157157
```
158158

159+
### Tuples
160+
161+
```js
162+
/**
163+
* @type {[string, number]}
164+
*/
165+
```
166+
167+
To:
168+
```js
169+
/**
170+
* @type {Array}
171+
*/
172+
```
173+
159174
## Module id resolution
160175

161176
For resolving module ids, this plugin mirrors the method used by JSDoc:

index.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const noClassdescRegEx = /@(typedef|module|type)/;
1111
const extensionReplaceRegEx = /\.m?js$/;
1212
const extensionEnsureRegEx = /(\.js)?$/;
1313
const slashRegEx = /\\/g;
14-
14+
const variableNameRegEx = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/;
1515
const moduleInfos = {};
1616
const fileNodes = {};
1717
const resolvedPathCache = new Set();
@@ -228,6 +228,7 @@ exports.defineTags = function (dictionary) {
228228
/** @type {Array<[number, number, string]>} */
229229
let replacements = [];
230230
let openCurly = 0;
231+
let openSquare = 0;
231232
let openRound = 0;
232233
let isWithinString = false;
233234
let quoteChar = '';
@@ -295,6 +296,24 @@ exports.defineTags = function (dictionary) {
295296
functionStartIndex = null;
296297
}
297298

299+
break;
300+
case '[':
301+
if (
302+
isWithinString ||
303+
variableNameRegEx.test(tagText.charAt(i - 1))
304+
) {
305+
break;
306+
}
307+
++openSquare;
308+
break;
309+
case ']':
310+
if (isWithinString) {
311+
break;
312+
}
313+
if (!--openSquare) {
314+
// Replace [type1, type2] tuples with Array
315+
replacements.push([startIndex + 1, i + 1, 'Array']);
316+
}
298317
break;
299318
case '{':
300319
++openCurly;

0 commit comments

Comments
 (0)