MCPcopy Create free account
hub / github.com/SAP/ui5-builder / analyze

Method analyze

lib/lbt/analyzer/JSModuleAnalyzer.js:256–795  ·  view source on GitHub ↗

* Analyzes the JS AST * * @param {object} ast js ast * @param {string} defaultName default name * @param {ModuleInfo} info module info

(ast, defaultName, info)

Source from the content-addressed store, hash-verified

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}`);

Callers 6

plugin.jsFile · 0.45
determineDependencyInfoFunction · 0.45
analyzeStringFunction · 0.45

Calls 4

addSubModuleMethod · 0.80
addImplicitDependencyMethod · 0.80
fromMethod · 0.80
visitFunction · 0.70

Tested by

no test coverage detected