* Analyzes the JS AST * * @param {object} ast js ast * @param {string} defaultName default name * @param {ModuleInfo} info module info
(ast, defaultName, info)
| 254 | * @param {ModuleInfo} info module info |
| 255 | */ |
| 256 | analyze(ast, defaultName, info) { |
| 257 | let mainModuleFound = false; |
| 258 | /** |
| 259 | * Number of (sap.ui.)define calls without a module ID. |
| 260 | * Only tracked to be able to complain about multiple module definitions without ID. |
| 261 | */ |
| 262 | let nUnnamedDefines = 0; |
| 263 | /** |
| 264 | * ID of the first named (sap.ui.)define call. |
| 265 | * Remembered together with the corresponding description in case no other main module |
| 266 | * can be found (no unnamed module, no module with the ID that matches the filename). |
| 267 | * Will be used as main module ID if only one module definition exists in the file. |
| 268 | */ |
| 269 | let candidateName = null; |
| 270 | let candidateDescription = null; |
| 271 | |
| 272 | /** |
| 273 | * Total number of module declarations (declare or define). |
| 274 | */ |
| 275 | let nModuleDeclarations = 0; |
| 276 | |
| 277 | /** |
| 278 | * Whether or not this is a UI5 module |
| 279 | * |
| 280 | * When in the non-conditional module execution there is a call to: |
| 281 | * <ul> |
| 282 | * <li>sap.ui.define call</li> |
| 283 | * <li>jQuery.sap.declare call</li> |
| 284 | * </ul> |
| 285 | * this value is true |
| 286 | * |
| 287 | * @type {boolean} |
| 288 | */ |
| 289 | let bIsUi5Module = false; |
| 290 | |
| 291 | // Module name via @ui5-bundle comment in first line. Overrides all other main module candidates. |
| 292 | let firstLineBundleName; |
| 293 | |
| 294 | // first analyze the whole AST... |
| 295 | visit(ast, false); |
| 296 | |
| 297 | // ...then all the comments |
| 298 | if ( Array.isArray(ast.comments) ) { |
| 299 | ast.comments.forEach((comment) => { |
| 300 | if ( comment.type === "Line" && comment.value.startsWith("@ui5-bundle") ) { |
| 301 | if ( comment.value.startsWith("@ui5-bundle-raw-include ") ) { |
| 302 | const subModule = comment.value.slice("@ui5-bundle-raw-include ".length); |
| 303 | info.addSubModule(subModule); |
| 304 | log.verbose(`Bundle include directive ${subModule}`); |
| 305 | } else if ( comment.value.startsWith("@ui5-bundle ") ) { |
| 306 | const bundleName = comment.value.slice("@ui5-bundle ".length); |
| 307 | if (comment.start === 0) { |
| 308 | // Remember the name from the first line to use it as final name |
| 309 | firstLineBundleName = bundleName; |
| 310 | } else { |
| 311 | setMainModuleInfo(bundleName, null); |
| 312 | } |
| 313 | log.verbose(`Bundle name directive ${bundleName}`); |
no test coverage detected