You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.0 KiB
JavaScript
28 lines
1.0 KiB
JavaScript
'use strict';
|
|
|
|
function shortDescription(astNode) {
|
|
if (astNode.type === "FunctionDeclaration") {
|
|
return `function ${shortDescription(astNode.id)}(${renderArguments(astNode.params)}) { ... }`;
|
|
} else if (astNode.type === "ReturnStatement") {
|
|
return `return ${shortDescription(astNode.argument)}`;
|
|
} else if (astNode.type === "CallExpression") {
|
|
return `${shortDescription(astNode.callee)}(${renderArguments(astNode.arguments)})`;
|
|
} else if (astNode.type === "MemberExpression") {
|
|
return `${shortDescription(astNode.object)}.${shortDescription(astNode.property)}`;
|
|
} else if (astNode.type === "Identifier") {
|
|
return `${astNode.name}`;
|
|
} else if (astNode.type === "ArrowFunctionExpression") {
|
|
return `(${renderArguments(astNode.params)}) => { ... }`;
|
|
} else if (astNode.type === "Literal") {
|
|
return astNode.raw;
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function renderArguments(args) {
|
|
return args.map(arg => shortDescription(arg)).join(", ");
|
|
}
|
|
|
|
module.exports = shortDescription;
|