New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@esydoc/doclet-parser

Package Overview
Dependencies
Maintainers
0
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@esydoc/doclet-parser - npm Package Compare versions

Comparing version

to
2.1.4-beta.1

dist/types/Node.d.ts

363

dist/index.js

@@ -98,9 +98,10 @@ /*!

}
// 字符串 声明
if (/^("|').*("|')$/g.test(type))
return 'string';
// 字符串 声明
if (/^-?\d+$/g.test(type))
return 'number';
return type;
try {
// 如果类型是值 如 "adr"|"ios"|0|1
var tpIsVal = JSON.parse(type);
return typeof tpIsVal;
}
catch (err) {
return type;
}
}

@@ -111,229 +112,11 @@ /**

function getPolyVal(name) {
if (/^("|').*("|')$/g.test(name)) {
return name.replace(/\'|\"/g, '');
try {
// 如果类型是值 如 "adr"|"ios"|0|1
return JSON.parse(name);
}
if (/^-?\d+$/g.test(name)) {
return Number(name);
catch (err) {
return name;
}
return name;
}
var resolveTag$1 = function (tagNames) {
var tagName;
if (Array.isArray(tagNames) && tagNames.length > 1) {
tagName = tagNames.join('|');
}
else {
tagName = tagNames[0];
}
var filterWrapperRE = /([a-zA-Z]+)\.?<(.*)>/i;
var match = tagName.match(filterWrapperRE);
if (match == null)
return { tagName: tagName, isNested: false };
var parentTagName = match[1];
var subTagName = match[2];
return { tagName: parentTagName, subTagName: subTagName, isNested: true };
};
var DATA_NODE_ID_PREFIX$1 = '_data_node_';
var createSimpleRawDataTreeNode$1 = function (tagName) {
return {
name: tagName,
type: {
names: [tagName] // xxx maybe is SSS<XXX> or string
}
};
};
var POLYTYPE$1 = '__polytype__';
var createNode$1 = function (name, type, parent, properties, description, summary, optional, defaultValue) {
var resolvedTag = resolveTag$1(type.names);
var id = genUniId(DATA_NODE_ID_PREFIX$1);
var tagName = resolvedTag.tagName;
var rawTagName = undefined;
if (!resolvedTag.isNested) {
// 这里处理 POLYTYPE
var currTagIsMutiType = tagName.includes('|');
if (currTagIsMutiType) {
rawTagName = tagName;
properties = tagName
.replace(/\(|\)/g, '')
.split('|')
.map(function (v) { return createSimpleRawDataTreeNode$1(v); });
tagName = POLYTYPE$1;
}
return {
parent: parent,
name: name,
properties: properties,
type: tagName,
rawType: rawTagName,
id: id,
description: description,
summary: summary,
optional: optional,
defaultValue: defaultValue
};
}
// doclet是离散的,对于嵌套标签,它的properties仍然是undefined, 我们要补充上去
var subTagName = resolvedTag.subTagName;
return {
parent: parent,
id: id,
name: name,
type: tagName,
properties: [createSimpleRawDataTreeNode$1(subTagName)],
description: description,
summary: summary,
optional: optional,
defaultValue: defaultValue
};
};
var beMergedNode$1 = null;
function mergeNode$1(mainNode, extraNode) {
mainNode.properties = extraNode.properties;
mainNode.description = mainNode.description || extraNode.description;
mainNode.summary = extraNode.summary || extraNode.description;
mainNode.type = extraNode.type;
mainNode.rawType = extraNode.name;
if (extraNode.optional !== undefined) {
mainNode.optional = extraNode.optional;
}
return mainNode;
}
var transform$1 = function (rawNode, dataMap, parent, fromDataMap) {
var node = createNode$1(rawNode.name, rawNode.type, parent, rawNode.properties || rawNode.params, // 统一抽象为一个properties
rawNode.description, rawNode.summary, rawNode.optional, rawNode.defaultvalue);
// should be hooks
// node = decorateNode(node)
if (fromDataMap && beMergedNode$1 !== null) {
node = mergeNode$1(beMergedNode$1, node); // 将离散在外部的node的属性转移到原来的树节点
}
var type = node.type;
switch (type.toLowerCase()) {
case 'enum':
case 'promise':
case 'object':
case 'array':
case 'function': // @callback type is function, it has properties of params
case POLYTYPE$1:
if (node.properties) {
// @ts-expect-error
node.properties = node.properties.map(function (child) {
return transform$1(child, dataMap, node);
});
}
break;
case 'number':
case 'string':
case 'undefined':
case 'boolean':
case 'null':
case '*':
case 'void':
case 'any':
// 无需处理
break;
default:
// 自定义结构体
if (dataMap) {
var subRawTree = dataMap.get(type);
if (subRawTree) {
beMergedNode$1 = node;
transform$1(subRawTree, dataMap, node, true);
}
else {
if (/^("|').*("|')$/g.test(type)) ;
else if (/^-?\d+$/g.test(type)) ;
else {
console.warn("\u65E0\u6CD5\u5728dataMap\u4E2D\u627E\u5230type:" + type + "\u7684\u7ED3\u6784\u4F53");
}
}
}
else {
console.warn("\u65E0\u6CD5\u89E3\u6790type:" + type + "\u7684\u7ED3\u6784\u4F53\uFF0C\u82E5\u5FD8\u8BB0\u52A0\u4E0A@edata\u6807\u7B7E\uFF0C\u8BF7\u52A0\u4E0A\u3002");
}
}
// @ts-expect-error
return node;
};
var sharedDataScope = Symbol('sharedDataScope');
function transofrmDocletRoot(rawDataRoot, dataMap) {
return transform$1(rawDataRoot, dataMap, null);
}
function createDocletRootMark(content, key, nodeType) {
var root = {
name: 'root',
properties: content,
type: {
names: [nodeType]
}
};
return {
key: key,
root: root
};
}
// why new Map([...a, ...b]) throw an error on nodejs ?
function mergeMap(a, b) {
var mergedMap = new Map();
a.forEach(function (value, key) {
mergedMap.set(key, value);
});
b.forEach(function (value, key) {
mergedMap.set(key, value);
});
return mergedMap;
}
var DocletParser = /** @class */ (function () {
function DocletParser(fileDataMap) {
this.fileDataMap = fileDataMap;
}
DocletParser.prototype.transform = function (rawDataRoot, filename, key) {
var dataMap = this.fileDataMap.get(filename);
var sharedDataMap = this.fileDataMap.get(sharedDataScope);
var megredDataMap = sharedDataMap && dataMap
? mergeMap(sharedDataMap, dataMap)
: dataMap || sharedDataMap;
var dataTreeRoot = transofrmDocletRoot(rawDataRoot, megredDataMap);
if (typeof dataTreeRoot === 'object' &&
dataTreeRoot !== null &&
Object.keys(dataTreeRoot).length) {
return {
key: key,
root: dataTreeRoot
};
}
return null;
};
DocletParser.prototype.parse = function (doclet, reflectConfig) {
var _this = this;
var meta = doclet.meta;
var docletRootMarkQueue = [];
Object.keys(reflectConfig).forEach(function (key) {
var docletTransform = reflectConfig[key];
var docletPropertyValue = doclet[docletTransform.reflectKey];
if (docletPropertyValue) {
var docletRootMark = createDocletRootMark(docletPropertyValue, key, docletTransform.nodeType);
docletRootMarkQueue.push(docletRootMark);
}
});
if (docletRootMarkQueue.length) {
var results = docletRootMarkQueue
.map(function (docletRootMark) {
return _this.transform(docletRootMark.root, meta.filename, docletRootMark.key);
})
.filter(function (v) { return v !== null; });
if (results) {
return results.reduce(function (acc, _a) {
var key = _a.key, root = _a.root;
acc[key] = root;
return acc;
}, {});
}
}
return null;
};
return DocletParser;
}());
var resolveTag = function (tagNames) {

@@ -347,2 +130,3 @@ var tagName;

}
// for Array.<test>
var filterWrapperRE = /([a-zA-Z]+)\.?<(.*)>/i;

@@ -363,8 +147,22 @@ var match = tagName.match(filterWrapperRE);

var createSimpleRawDataTreeNode = function (tagName) {
return {
name: tagName,
type: {
names: [tagName] // xxx maybe is SSS<XXX> or string
}
};
try {
// tagName: 1|2|"ios"|"adr"|Type|Array<d>
var tpIsVal = JSON.parse(tagName);
return {
name: tagName,
type: {
names: [typeof tpIsVal],
},
optional: true,
defaultvalue: tpIsVal,
};
}
catch (_a) {
return {
name: tagName,
type: {
names: [tagName],
},
};
}
};

@@ -388,2 +186,3 @@ var POLYTYPE = '__polytype__';

}
// TODO 取值说明处理
return {

@@ -399,3 +198,3 @@ parent: parent,

optional: optional,
defaultValue: defaultValue
defaultValue: defaultValue,
};

@@ -414,3 +213,3 @@ }

optional: optional,
defaultValue: defaultValue
defaultValue: defaultValue,
};

@@ -505,3 +304,3 @@ };

case 'string':
return !optional ? (name && name.toLowerCase() !== 'string' ? name : 'foo') : '';
return optional ? '' : name && name.toLowerCase() !== 'string' ? name : 'foo';
case 'number':

@@ -732,16 +531,16 @@ return optional ? 0 : Number(name) || 1;

key: 'properties',
assert: 'undefined'
assert: 'undefined',
},
{
key: 'optional',
assert: 'undefined'
assert: 'undefined',
},
{
key: 'rawType',
assert: 'undefined'
assert: 'undefined',
},
{
key: 'defaultValue',
assert: 'undefined'
}
assert: 'undefined',
},
];

@@ -776,2 +575,78 @@ function clean(tree, rules) {

var sharedDataScope = Symbol('sharedDataScope');
function transofrmDocletRoot(rawDataRoot, dataMap) {
return transform(rawDataRoot, dataMap, null);
}
function createDocletRootMark(content, key, nodeType) {
var root = {
name: 'root',
properties: content,
type: {
names: [nodeType],
},
};
return {
key: key,
root: root,
};
}
// why new Map([...a, ...b]) throw an error on nodejs ?
function mergeMap(a, b) {
var mergedMap = new Map();
a.forEach(function (value, key) {
mergedMap.set(key, value);
});
b.forEach(function (value, key) {
mergedMap.set(key, value);
});
return mergedMap;
}
var DocletParser = /** @class */ (function () {
function DocletParser(fileDataMap) {
this.fileDataMap = fileDataMap;
}
DocletParser.prototype.transform = function (rawDataRoot, filename, key) {
var dataMap = this.fileDataMap.get(filename);
var sharedDataMap = this.fileDataMap.get(sharedDataScope);
var megredDataMap = sharedDataMap && dataMap ? mergeMap(sharedDataMap, dataMap) : dataMap || sharedDataMap;
var dataTreeRoot = transofrmDocletRoot(rawDataRoot, megredDataMap);
if (typeof dataTreeRoot === 'object' && dataTreeRoot !== null && Object.keys(dataTreeRoot).length) {
return {
key: key,
root: dataTreeRoot,
};
}
return null;
};
DocletParser.prototype.parse = function (doclet, reflectConfig) {
var _this = this;
var meta = doclet.meta;
var docletRootMarkQueue = [];
Object.keys(reflectConfig).forEach(function (key) {
var docletTransform = reflectConfig[key];
var docletPropertyValue = doclet[docletTransform.reflectKey];
if (docletPropertyValue) {
var docletRootMark = createDocletRootMark(docletPropertyValue, key, docletTransform.nodeType);
docletRootMarkQueue.push(docletRootMark);
}
});
if (docletRootMarkQueue.length) {
var results = docletRootMarkQueue
.map(function (docletRootMark) {
return _this.transform(docletRootMark.root, meta.filename, docletRootMark.key);
})
.filter(function (v) { return v !== null; });
if (results) {
return results.reduce(function (acc, _a) {
var key = _a.key, root = _a.root;
acc[key] = root;
return acc;
}, {});
}
}
return null;
};
return DocletParser;
}());
var ApiReflectConfig = Object.freeze({

@@ -778,0 +653,0 @@ args: {

@@ -1,2 +0,2 @@

import { RawDataTreeNode, TransformedDataTreeNode } from './node';
import { RawDataTreeNode, TransformedDataTreeNode } from './Node';
export declare type DataMap = Map<string, RawDataTreeNode>;

@@ -3,0 +3,0 @@ export declare type FileDataMap = Map<string | symbol, DataMap>;

@@ -23,2 +23,2 @@ export declare const genUniId: (prefix: string) => string;

*/
export declare function getPolyVal(name: string): string | number;
export declare function getPolyVal(name: string): any;
{
"name": "@esydoc/doclet-parser",
"version": "2.1.4-beta.0",
"version": "2.1.4-beta.1",
"description": "The parser for doclet that it resolved by jsdoc",

@@ -28,5 +28,5 @@ "author": "Alex <857276958@qq.com>",

"dependencies": {
"@esydoc/share": "^2.1.4-beta.0"
"@esydoc/share": "^2.1.4-beta.1"
},
"gitHead": "7cd5a14edb7b758ff550e6fb7607bea44dd73357"
"gitHead": "b501b8b52989cf585ed0c2f1858d391f403293e3"
}