From da101acb0b1916b163336a2c99ccecb09649063b Mon Sep 17 00:00:00 2001 From: Daniel Knights <59598622+Daniel-Knights@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:07:01 +0100 Subject: [PATCH 1/5] Root identifier link tag support --- index.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/index.js b/index.js index 86017ff..5980daa 100644 --- a/index.js +++ b/index.js @@ -592,6 +592,23 @@ exports.astNodeVisitor = { ); replace(typeRegex); + const linkWithoutTextRegex = new RegExp( + `@(link (?!https?))${key}(\\.[^\\s\\}]*)*(\\s*\\})`, + 'g', + ); + const linkWithTextRegex = new RegExp( + `@(link (?!https?))${key}((?:\\.[^\\s\\}]*)*(?:\\s|\\s*\\|)[^\\}]*\\})`, + 'g', + ); + + // If link is without text, use key as text + comment.value = comment.value.replace( + linkWithoutTextRegex, + `@$1${key} ${key}$2$3`, + ); + + replace(linkWithTextRegex); + function replace(regex) { if (regex.test(comment.value)) { const identifier = identifiers[key]; From 3793aedc1e343fac2f692149b11fa41924979e43 Mon Sep 17 00:00:00 2001 From: Daniel Knights <59598622+Daniel-Knights@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:17:21 +0100 Subject: [PATCH 2/5] Tests for root identifier link tag support --- test/dest/expected.json | 92 +++++++++++++++++++++++++++++++++++++++++ test/src/index.js | 10 +++++ 2 files changed, 102 insertions(+) diff --git a/test/dest/expected.json b/test/dest/expected.json index 92d44fc..b097e00 100644 --- a/test/dest/expected.json +++ b/test/dest/expected.json @@ -741,6 +741,98 @@ "memberof": "module:test", "params": [] }, + { + "comment": "/**\n * {@link module:test/sub/NumberStore~NumberStore NumberStore}\n */", + "meta": { + "range": [ + 1424, + 1456 + ], + "filename": "index.js", + "lineno": 67, + "columnno": 0, + "code": { + "name": "exports.Link", + "type": "VariableDeclaration" + } + }, + "description": "{@link module:test/sub/NumberStore~NumberStore NumberStore}", + "name": "Link", + "longname": "module:test.Link", + "kind": "constant", + "memberof": "module:test", + "scope": "static" + }, + { + "comment": "", + "meta": { + "range": [ + 1437, + 1455 + ], + "filename": "index.js", + "lineno": 67, + "columnno": 13, + "code": { + "name": "Link", + "type": "Identifier", + "value": "NumberStore" + } + }, + "undocumented": true, + "name": "Link", + "longname": "module:test~Link", + "kind": "constant", + "scope": "inner", + "memberof": "module:test", + "params": [] + }, + { + "comment": "/**\n * {@link module:test/sub/NumberStore~NumberStore Num}\n */", + "meta": { + "range": [ + 1493, + 1533 + ], + "filename": "index.js", + "lineno": 72, + "columnno": 0, + "code": { + "name": "exports.LinkWithText", + "type": "VariableDeclaration" + } + }, + "description": "{@link module:test/sub/NumberStore~NumberStore Num}", + "name": "LinkWithText", + "longname": "module:test.LinkWithText", + "kind": "constant", + "memberof": "module:test", + "scope": "static" + }, + { + "comment": "", + "meta": { + "range": [ + 1506, + 1532 + ], + "filename": "index.js", + "lineno": 72, + "columnno": 13, + "code": { + "name": "LinkWithText", + "type": "Identifier", + "value": "NumberStore" + } + }, + "undocumented": true, + "name": "LinkWithText", + "longname": "module:test~LinkWithText", + "kind": "constant", + "scope": "inner", + "memberof": "module:test", + "params": [] + }, { "comment": "/** @ignore */", "meta": { diff --git a/test/src/index.js b/test/src/index.js index 287715f..49bf909 100644 --- a/test/src/index.js +++ b/test/src/index.js @@ -60,3 +60,13 @@ export const bracketNotation = 1; /** @type {[number, [number, string], "[number, boolean]"]} */ export const nesteedTuples = [1, [1, 'a'], '[number, boolean]']; + +/** + * {@link NumberStore} + */ +export const Link = NumberStore; + +/** + * {@link NumberStore Num} + */ +export const LinkWithText = NumberStore; From 5d26ababf3dbcdd6ba74f214ee866e440a281ecb Mon Sep 17 00:00:00 2001 From: Daniel Knights <59598622+Daniel-Knights@users.noreply.github.com> Date: Tue, 15 Oct 2024 14:22:57 +0100 Subject: [PATCH 3/5] README section for root identifier link tag support --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index f9f70d6..ad31eae 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,39 @@ When assigned to a variable in the exporting module: This syntax is also used when referring to types of `@typedef`s and `@enum`s. +### `@link` tags + +```js +/** + * {@link Identifier} + */ + +/** + * {@link Identifier Link text} + */ + +/** + * {@link Identifier.member} + */ +``` + +To: + +```js +/** + * {@link module:path/to/module.Identifier Identifier} + */ + +/** + * {@link module:path/to/module.Identifier Link text} + */ + +/** + * Member accessors are not currently linked to, just the root identifier: + * {@link module:path/to/module.Identifier Identifier.member} + */ +``` + ### `typeof type` ```js @@ -165,6 +198,7 @@ To: ``` To: + ```js /** * @type {Array} From c4bf5dd763fb7ba83e23ed7d6e19d330aa0368cc Mon Sep 17 00:00:00 2001 From: Daniel Knights <59598622+Daniel-Knights@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:46:06 +0100 Subject: [PATCH 4/5] Simplify link regex capture groups --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5980daa..d28376e 100644 --- a/index.js +++ b/index.js @@ -593,7 +593,7 @@ exports.astNodeVisitor = { replace(typeRegex); const linkWithoutTextRegex = new RegExp( - `@(link (?!https?))${key}(\\.[^\\s\\}]*)*(\\s*\\})`, + `@(link (?!https?))${key}((?:\\.[^\\s\\}]*)*\\s*\\})`, 'g', ); const linkWithTextRegex = new RegExp( @@ -604,7 +604,7 @@ exports.astNodeVisitor = { // If link is without text, use key as text comment.value = comment.value.replace( linkWithoutTextRegex, - `@$1${key} ${key}$2$3`, + `@$1${key} ${key}$2`, ); replace(linkWithTextRegex); From de400d505aff070aa22680dfe0c55457d4434434 Mon Sep 17 00:00:00 2001 From: Daniel Knights <59598622+Daniel-Knights@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:18:06 +0100 Subject: [PATCH 5/5] Remove member accessors from link keys --- index.js | 13 +++++- test/dest/expected.json | 92 +++++++++++++++++++++++++++++++++++++++++ test/src/index.js | 10 +++++ 3 files changed, 113 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index d28376e..64080bf 100644 --- a/index.js +++ b/index.js @@ -593,11 +593,15 @@ exports.astNodeVisitor = { replace(typeRegex); const linkWithoutTextRegex = new RegExp( - `@(link (?!https?))${key}((?:\\.[^\\s\\}]*)*\\s*\\})`, + `@(link (?!https?:))${key}((?:\\.[^\\s}]*)*\\s*\\})`, + 'g', + ); + const linkMemberAccessorRegex = new RegExp( + `@(link (?!https?:)${key})(?:\\.[^\\s}]*)*([\\s|][^}]*\\})`, 'g', ); const linkWithTextRegex = new RegExp( - `@(link (?!https?))${key}((?:\\.[^\\s\\}]*)*(?:\\s|\\s*\\|)[^\\}]*\\})`, + `@(link (?!https?:))${key}([\\s|][^}]*\\})`, 'g', ); @@ -606,6 +610,11 @@ exports.astNodeVisitor = { linkWithoutTextRegex, `@$1${key} ${key}$2`, ); + // Remove member accessors from link key + comment.value = comment.value.replace( + linkMemberAccessorRegex, + '@$1$2', + ); replace(linkWithTextRegex); diff --git a/test/dest/expected.json b/test/dest/expected.json index b097e00..f17fd3a 100644 --- a/test/dest/expected.json +++ b/test/dest/expected.json @@ -833,6 +833,98 @@ "memberof": "module:test", "params": [] }, + { + "comment": "/**\n * {@link module:test/sub/NumberStore~NumberStore NumberStore.getNumber}\n */", + "meta": { + "range": [ + 1576, + 1626 + ], + "filename": "index.js", + "lineno": 77, + "columnno": 0, + "code": { + "name": "exports.LinkWithMemberAccessor", + "type": "VariableDeclaration" + } + }, + "description": "{@link module:test/sub/NumberStore~NumberStore NumberStore.getNumber}", + "name": "LinkWithMemberAccessor", + "longname": "module:test.LinkWithMemberAccessor", + "kind": "constant", + "memberof": "module:test", + "scope": "static" + }, + { + "comment": "", + "meta": { + "range": [ + 1589, + 1625 + ], + "filename": "index.js", + "lineno": 77, + "columnno": 13, + "code": { + "name": "LinkWithMemberAccessor", + "type": "Identifier", + "value": "NumberStore" + } + }, + "undocumented": true, + "name": "LinkWithMemberAccessor", + "longname": "module:test~LinkWithMemberAccessor", + "kind": "constant", + "scope": "inner", + "memberof": "module:test", + "params": [] + }, + { + "comment": "/**\n * {@link module:test/sub/NumberStore~NumberStore Num}\n */", + "meta": { + "range": [ + 1673, + 1730 + ], + "filename": "index.js", + "lineno": 82, + "columnno": 0, + "code": { + "name": "exports.LinkWithMemberAccessorAndText", + "type": "VariableDeclaration" + } + }, + "description": "{@link module:test/sub/NumberStore~NumberStore Num}", + "name": "LinkWithMemberAccessorAndText", + "longname": "module:test.LinkWithMemberAccessorAndText", + "kind": "constant", + "memberof": "module:test", + "scope": "static" + }, + { + "comment": "", + "meta": { + "range": [ + 1686, + 1729 + ], + "filename": "index.js", + "lineno": 82, + "columnno": 13, + "code": { + "name": "LinkWithMemberAccessorAndText", + "type": "Identifier", + "value": "NumberStore" + } + }, + "undocumented": true, + "name": "LinkWithMemberAccessorAndText", + "longname": "module:test~LinkWithMemberAccessorAndText", + "kind": "constant", + "scope": "inner", + "memberof": "module:test", + "params": [] + }, { "comment": "/** @ignore */", "meta": { diff --git a/test/src/index.js b/test/src/index.js index 49bf909..17307f3 100644 --- a/test/src/index.js +++ b/test/src/index.js @@ -70,3 +70,13 @@ export const Link = NumberStore; * {@link NumberStore Num} */ export const LinkWithText = NumberStore; + +/** + * {@link NumberStore.getNumber} + */ +export const LinkWithMemberAccessor = NumberStore; + +/** + * {@link NumberStore.getNumber Num} + */ +export const LinkWithMemberAccessorAndText = NumberStore;