| 1 | /* |
| 2 | Copyright - 2021 - wwwouaiebe - Contact: https://www.ouaie.be/ |
| 3 | |
| 4 | This program is free software; |
| 5 | you can redistribute it and/or modify it under the terms of the |
| 6 | GNU General Public License as published by the Free Software Foundation; |
| 7 | either version 3 of the License, or any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | /* |
| 19 | Changes: |
| 20 | - v1.0.0: |
| 21 | - created |
| 22 | Doc reviewed 20211111 |
| 23 | */ |
| 24 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 25 | |
| 26 | import CommentsDocBuilder from './CommentsDocBuilder.js'; |
| 27 | import VariableDoc from './VariableDoc.js'; |
| 28 | |
| 29 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 30 | /** |
| 31 | Build the variableDoc object for a variable |
| 32 | */ |
| 33 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 34 | |
| 35 | class VariableDocBuilder { |
| 36 | |
| 37 | /** |
| 38 | The constructor |
| 39 | */ |
| 40 | |
| 41 | constructor ( ) { |
| 42 | Object.freeze ( this ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | Build a VariableDoc object from an |
| 47 | [ast node](https://github.com/babel/babel/blob/main/packages/babel-parser/ast/spec.md) |
| 48 | @param {Object} variableDeclarationNode An ast node of type VariableDeclaration |
| 49 | @param {String} fileName the file name in witch the variableDeclarationNnode was found, including path |
| 50 | @return {VariableDoc} The created object |
| 51 | */ |
| 52 | |
| 53 | build ( variableDeclarationNode, fileName ) { |
| 54 | |
| 55 | const variableDoc = new VariableDoc ( ); |
| 56 | variableDoc.name = variableDeclarationNode.declarations [ 0 ].id.name; |
| 57 | variableDoc.kind = variableDeclarationNode?.kind; |
| 58 | variableDoc.file = fileName; |
| 59 | variableDoc.rootPath = ''; |
| 60 | variableDoc.line = variableDeclarationNode.loc.start.line; |
| 61 | variableDoc.commentsDoc = new CommentsDocBuilder ( ).build ( variableDeclarationNode.leadingComments ); |
| 62 | |
| 63 | return Object.freeze ( variableDoc ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | export default VariableDocBuilder; |
| 68 | |
| 69 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
| 70 |