Syntax tree JSDoc based on Unist spec
$ npm install @geut/jsdast
const unified = require('unified')
const { parser } = require('@geut/jsdast')
const tree = unified().use(parser).parse(`
/**
* @param {number} a
* @param {number} b
* @returns {number}
*/
function sum(a, b) {
return a + b
}
`)
console.log(JSON.stringify(tree, null, 2))
/*
{
"type": "Root",
"children": [
{
"type": "Module",
"name": "Index",
"doc": {
"description": "",
"tags": []
},
"children": [
{
"type": "FunctionDeclaration",
"name": "sum",
"doc": {
"tags": [
{
"tagName": "returns",
"fullText": "@returns {number}",
"typeExpression": "number"
}
]
},
"isExported": false,
"isDefaultExport": false,
"valueType": "number",
"isGenerator": false,
"isAsync": false,
"children": [
{
"type": "Parameter",
"name": "a",
"doc": {
"tags": []
},
"isRestParameter": false,
"valueType": "number",
"isOptional": false
},
{
"type": "Parameter",
"name": "b",
"doc": {
"tags": []
},
"isRestParameter": false,
"valueType": "number",
"isOptional": false
}
]
}
]
}
]
}
*/
🐛 If you found an issue we encourage you to report it on github. Please specify your OS and the actions to reproduce it.
👥 Ideas and contributions to the project are welcome. You must follow this guideline.
MIT © A GEUT project