Skip to content

Commit bda4f5a

Browse files
committed
do not match parts of types
1 parent 206cd73 commit bda4f5a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (!fs.existsSync(moduleRootAbsolute)) {
1717
}
1818

1919
const importRegEx = /import\(["']([^"']*)["']\)\.([^ \.\|\}><,\)=#\n]*)([ \.\|\}><,\)=#\n])/g;
20-
const typedefRegEx = /@typedef \{[^\}]*\} ([^ \r?\n?]*)/;
20+
const typedefRegEx = /@typedef \{[^\}]*\} (\S*)/;
2121
const noClassdescRegEx = /@(typedef|module|type)/;
2222
const slashRegEx = /\\/g;
2323

@@ -201,7 +201,8 @@ exports.astNodeVisitor = {
201201
node.comments.forEach(comment => {
202202
// Replace local types with the full `module:` path
203203
Object.keys(identifiers).forEach(key => {
204-
const regex = new RegExp(`@(event |fires |.*[\{<\|,] ?!?)${key}`, 'g');
204+
const regex = new RegExp(`@(event |fires |.*[\{<\|,] ?!?)${key}([}>|,\s])`, 'g');
205+
205206
if (regex.test(comment.value)) {
206207
const identifier = identifiers[key];
207208
const absolutePath = path.resolve(path.dirname(currentSourceName), identifier.value);
@@ -210,7 +211,7 @@ exports.astNodeVisitor = {
210211
const exportName = identifier.defaultImport ? getDefaultExportName(moduleId, parser) : key;
211212
const delimiter = identifier.defaultImport ? '~' : getDelimiter(moduleId, exportName, parser);
212213
const replacement = `module:${moduleId.replace(slashRegEx, '/')}${exportName ? delimiter + exportName : ''}`;
213-
comment.value = comment.value.replace(regex, '@$1' + replacement);
214+
comment.value = comment.value.replace(regex, '@$1' + replacement + '$2');
214215
}
215216
}
216217
});

0 commit comments

Comments
 (0)