jsdoc-tsimport-plugin
Advanced tools
Comparing version 1.0.2 to 1.0.3
64
index.js
@@ -24,3 +24,3 @@ const path = require('path'); | ||
*/ | ||
const docCommentsRegex = /\/\*\*\s*(?:[^\*]|(?:\*(?!\/)))*\*\//g | ||
const docCommentsRegex = /\/\*\*\s*(?:[^\*]|(?:\*(?!\/)))*\*\//g; | ||
@@ -43,5 +43,5 @@ /** | ||
const typeRegex = /\{[^}]*\}/g | ||
const typeRegex = /\{[^}]*\}/g; | ||
const identifiers = /([\w-\$]+)/g | ||
const identifiers = /([\w-\$\.]+)/g; | ||
@@ -57,3 +57,3 @@ /** | ||
* A map of filenames to module ids. | ||
* | ||
* | ||
* @type {Map<string, FileInfo>} | ||
@@ -65,3 +65,3 @@ */ | ||
* A map of moduleId to type definition ids. | ||
* | ||
* | ||
* @type {Map<string, Set<string>>} | ||
@@ -73,6 +73,5 @@ */ | ||
* Retrieves and caches file information for this plugin. | ||
* | ||
* | ||
* @param {string} filename | ||
* @param {?string} source | ||
* | ||
* @param {string} filename | ||
* @param {?string} source | ||
* @returns {!FileInfo} | ||
@@ -82,5 +81,5 @@ */ | ||
const filenameNor = path.normalize(filename); | ||
if (fileInfos.has(filenameNor)) return fileInfos.get(filenameNor) | ||
if (fileInfos.has(filenameNor)) return fileInfos.get(filenameNor); | ||
const fileInfo = /** @type {FileInfo} */ ({ | ||
moduleId: null, typedefs: [], filename: filenameNor | ||
moduleId: null, typedefs: [], filename: filenameNor, | ||
}); | ||
@@ -96,3 +95,4 @@ | ||
// @module tag with no module name; calculate the implicit module id. | ||
const srcDir = absSrcDirs.find((iSrcDir) => filenameNor.startsWith(iSrcDir)); | ||
const srcDir = absSrcDirs.find((iSrcDir) => | ||
filenameNor.startsWith(iSrcDir)); | ||
fileInfo.moduleId = noExtension(filenameNor) | ||
@@ -109,3 +109,3 @@ .slice(srcDir.length + 1).replace(/\\/g, '/'); | ||
return ''; | ||
}) | ||
}); | ||
return ''; | ||
@@ -122,6 +122,8 @@ }); | ||
const typeDefsSet = moduleToTypeDefs.get(fileInfo.moduleId); | ||
fileInfo.typedefs.forEach((item) => { typeDefsSet.add(item) }); | ||
fileInfo.typedefs.forEach((item) => { | ||
typeDefsSet.add(item); | ||
}); | ||
fileInfos.set(filenameNor, fileInfo); | ||
return fileInfo | ||
return fileInfo; | ||
} | ||
@@ -136,3 +138,3 @@ | ||
function beforeParse(e) { | ||
const fileInfo = getFileInfo(e.filename, e.source); | ||
getFileInfo(e.filename, e.source); | ||
@@ -143,9 +145,8 @@ // Find all doc comments (unfortunately needs to be done here and not | ||
(substring) => { | ||
let newComment = substring.replace(importRegex, (_substring2, relImportPath, symbolName) => { | ||
return substring.replace(importRegex, | ||
(_substring2, relImportPath, symbolName) => { | ||
const moduleId = getModuleId(e.filename, relImportPath); | ||
return (moduleId) ? `module:${moduleId}~${symbolName}` : symbolName; | ||
}) | ||
return newComment; | ||
}); | ||
}); | ||
}; | ||
@@ -174,4 +175,5 @@ | ||
* | ||
* @param {string} root | ||
* @param {string} relative | ||
* @param {string} root | ||
* @param {string} relative | ||
* @returns {string} | ||
*/ | ||
@@ -185,5 +187,7 @@ function relPath(root, relative) { | ||
/** | ||
* Given a filename, if there is no extension, scan the files for the most likely match. | ||
* Given a filename, if there is no extension, scan the files for the | ||
* most likely match. | ||
* | ||
* @param {string} filename | ||
* @param {string} filename | ||
* @returns {string} | ||
*/ | ||
@@ -194,8 +198,9 @@ function inferExtension(filename) { | ||
if (ext) return ext; | ||
const files = fs.readdirSync(path.dirname(filenameNor)) | ||
const files = fs.readdirSync(path.dirname(filenameNor)); | ||
const name = path.basename(filenameNor); | ||
return path.join(path.dirname(filenameNor), files.find((iFile) => { | ||
if (noExtension(iFile) == name) | ||
if (noExtension(iFile) == name) { | ||
return true; | ||
} | ||
})); | ||
@@ -216,3 +221,4 @@ } | ||
* The jsdocCommentFound event is fired whenever a JSDoc comment is found. | ||
* All file infos are now populated; replace typedef symbols with their module counterparts. | ||
* All file infos are now populated; replace typedef symbols with their | ||
* module counterparts. | ||
* | ||
@@ -229,5 +235,5 @@ * @param {DocCommentFoundEvent} e The event. | ||
return (fileInfo.moduleId && typeDefsSet.has(identifier)) ? | ||
`module:${fileInfo.moduleId}~${identifier}` : | ||
`module:${fileInfo.moduleId}~${identifier}` : | ||
identifier; | ||
}) | ||
}); | ||
}); | ||
@@ -234,0 +240,0 @@ } |
{ | ||
"name": "jsdoc-tsimport-plugin", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "A JSDoc plugin to support the typescript module import syntax.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22519
200