@ui5/builder 3.0.0-alpha.10 → 3.0.0-alpha.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/CHANGELOG.md +35 -2
  2. package/jsdoc.json +2 -2
  3. package/lib/lbt/UI5ClientConstants.js +7 -8
  4. package/lib/lbt/analyzer/ComponentAnalyzer.js +10 -10
  5. package/lib/lbt/analyzer/FioriElementsAnalyzer.js +31 -20
  6. package/lib/lbt/analyzer/JSModuleAnalyzer.js +107 -65
  7. package/lib/lbt/analyzer/SmartTemplateAnalyzer.js +31 -20
  8. package/lib/lbt/analyzer/XMLCompositeAnalyzer.js +35 -25
  9. package/lib/lbt/analyzer/XMLTemplateAnalyzer.js +19 -17
  10. package/lib/lbt/analyzer/analyzeLibraryJS.js +22 -6
  11. package/lib/lbt/bundle/AutoSplitter.js +10 -11
  12. package/lib/lbt/bundle/Builder.js +30 -33
  13. package/lib/lbt/bundle/BundleDefinition.js +1 -5
  14. package/lib/lbt/bundle/BundleWriter.js +1 -2
  15. package/lib/lbt/bundle/ResolvedBundleDefinition.js +6 -7
  16. package/lib/lbt/bundle/Resolver.js +9 -10
  17. package/lib/lbt/calls/SapUiDefine.js +16 -11
  18. package/lib/lbt/graph/dependencyGraph.js +3 -4
  19. package/lib/lbt/graph/dominatorTree.js +3 -3
  20. package/lib/lbt/graph/topologicalSort.js +3 -3
  21. package/lib/lbt/resources/LibraryFileAnalyzer.js +5 -8
  22. package/lib/lbt/resources/LocatorResource.js +2 -2
  23. package/lib/lbt/resources/LocatorResourcePool.js +3 -3
  24. package/lib/lbt/resources/ModuleInfo.js +1 -2
  25. package/lib/lbt/resources/Resource.js +3 -4
  26. package/lib/lbt/resources/ResourceCollector.js +7 -8
  27. package/lib/lbt/resources/ResourceFilterList.js +38 -40
  28. package/lib/lbt/resources/ResourceInfo.js +1 -1
  29. package/lib/lbt/resources/ResourceInfoList.js +2 -2
  30. package/lib/lbt/resources/ResourcePool.js +15 -21
  31. package/lib/lbt/utils/ASTUtils.js +58 -44
  32. package/lib/lbt/utils/JSTokenizer.js +4 -4
  33. package/lib/lbt/utils/ModuleName.js +10 -20
  34. package/lib/lbt/utils/escapePropertiesFile.js +3 -3
  35. package/lib/lbt/utils/parseUtils.js +4 -10
  36. package/lib/processors/bootstrapHtmlTransformer.js +15 -7
  37. package/lib/processors/bundlers/flexChangesBundler.js +16 -8
  38. package/lib/processors/bundlers/manifestBundler.js +19 -10
  39. package/lib/processors/bundlers/moduleBundler.js +26 -15
  40. package/lib/processors/jsdoc/apiIndexGenerator.js +16 -9
  41. package/lib/processors/jsdoc/jsdocGenerator.js +31 -17
  42. package/lib/processors/jsdoc/lib/{createIndexFiles.js → createIndexFiles.cjs} +0 -0
  43. package/lib/processors/jsdoc/lib/{transformApiJson.js → transformApiJson.cjs} +58 -2
  44. package/lib/processors/jsdoc/lib/ui5/{plugin.js → plugin.cjs} +306 -119
  45. package/lib/processors/jsdoc/lib/ui5/template/{publish.js → publish.cjs} +1 -1
  46. package/lib/processors/jsdoc/lib/ui5/template/utils/{versionUtil.js → versionUtil.cjs} +0 -0
  47. package/lib/processors/jsdoc/sdkTransformer.js +18 -11
  48. package/lib/processors/libraryLessGenerator.js +28 -16
  49. package/lib/processors/manifestCreator.js +14 -13
  50. package/lib/processors/minifier.js +21 -15
  51. package/lib/processors/nonAsciiEscaper.js +16 -6
  52. package/lib/processors/resourceListCreator.js +13 -13
  53. package/lib/processors/stringReplacer.js +13 -6
  54. package/lib/processors/themeBuilder.js +30 -22
  55. package/lib/processors/versionInfoGenerator.js +33 -23
  56. package/lib/tasks/buildThemes.js +17 -10
  57. package/lib/tasks/bundlers/generateBundle.js +23 -12
  58. package/lib/tasks/bundlers/generateComponentPreload.js +18 -10
  59. package/lib/tasks/bundlers/generateFlexChangesBundle.js +16 -8
  60. package/lib/tasks/bundlers/generateLibraryPreload.js +22 -12
  61. package/lib/tasks/bundlers/generateManifestBundle.js +15 -6
  62. package/lib/tasks/bundlers/generateStandaloneAppBundle.js +21 -13
  63. package/lib/tasks/bundlers/utils/createModuleNameMapping.js +6 -6
  64. package/lib/tasks/escapeNonAsciiCharacters.js +12 -5
  65. package/lib/tasks/generateCachebusterInfo.js +16 -8
  66. package/lib/tasks/generateLibraryManifest.js +14 -8
  67. package/lib/tasks/generateResourcesJson.js +15 -9
  68. package/lib/tasks/generateThemeDesignerResources.js +19 -9
  69. package/lib/tasks/generateVersionInfo.js +12 -5
  70. package/lib/tasks/jsdoc/executeJsdocSdkTransformation.js +17 -9
  71. package/lib/tasks/jsdoc/generateApiIndex.js +16 -10
  72. package/lib/tasks/jsdoc/generateJsdoc.js +131 -119
  73. package/lib/tasks/minify.js +13 -6
  74. package/lib/tasks/replaceBuildtime.js +12 -5
  75. package/lib/tasks/replaceCopyright.js +12 -5
  76. package/lib/tasks/replaceVersion.js +12 -5
  77. package/lib/tasks/taskRepository.js +24 -29
  78. package/lib/tasks/transformBootstrapHtml.js +6 -5
  79. package/package.json +30 -15
  80. package/index.js +0 -173
package/CHANGELOG.md CHANGED
@@ -2,10 +2,41 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
4
4
 
5
- A list of unreleased changes can be found [here](https://github.com/SAP/ui5-builder/compare/v3.0.0-alpha.10...HEAD).
5
+ A list of unreleased changes can be found [here](https://github.com/SAP/ui5-builder/compare/v3.0.0-alpha.12...HEAD).
6
+
7
+ <a name="v3.0.0-alpha.12"></a>
8
+ ## [v3.0.0-alpha.12] - 2022-10-24
9
+ ### Breaking Changes
10
+ - Transform to native ESM ([#790](https://github.com/SAP/ui5-builder/issues/790)) [`a439aa9`](https://github.com/SAP/ui5-builder/commit/a439aa9f679dfe2e18b8c540f54876f94c0de119)
11
+
12
+ ### BREAKING CHANGE
13
+
14
+ This package has been transformed to native ESM. Therefore it no longer provides a CommonJS export.
15
+ If your project uses CommonJS, it needs to be converted to ESM or use a dynamic import.
16
+
17
+ For more information see also:
18
+ - https://sap.github.io/ui5-tooling/updates/migrate-v3/
19
+ - https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
20
+
21
+
22
+ <a name="v3.0.0-alpha.11"></a>
23
+ ## [v3.0.0-alpha.11] - 2022-10-20
24
+ ### Bug Fixes
25
+ - **package.json:** Downgrade es5-ext dependency [`2b71707`](https://github.com/SAP/ui5-builder/commit/2b71707683480b26aab9957c09e5d22bce8a6450)
26
+
27
+ ### Dependency Updates
28
+ - Bump escope from 3.6.0 to 4.0.0 [`e25af0d`](https://github.com/SAP/ui5-builder/commit/e25af0d9c1184916aa037b4b4ca23d15c5f2a408)
29
+
30
+ ### Features
31
+ - **builder:** Improve support for ES6+ syntax ([#774](https://github.com/SAP/ui5-builder/issues/774)) [`90385fe`](https://github.com/SAP/ui5-builder/commit/90385feb7cea1e5b864cff035b01263a492972a9)
32
+ - **jsdoc:** Improve support for ES6+ syntax ([#785](https://github.com/SAP/ui5-builder/issues/785)) [`187a6a3`](https://github.com/SAP/ui5-builder/commit/187a6a35000145d70bf41e0d8b724e5ea8d8dc78)
33
+
34
+ ### Reverts
35
+ - [FIX] package.json: Downgrade es5-ext dependency
36
+
6
37
 
7
38
  <a name="v3.0.0-alpha.10"></a>
8
- ## [v3.0.0-alpha.10] - 2022-08-08
39
+ ## [v3.0.0-alpha.10] - 2022-08-09
9
40
 
10
41
  <a name="v3.0.0-alpha.9"></a>
11
42
  ## [v3.0.0-alpha.9] - 2022-07-27
@@ -753,6 +784,8 @@ to load the custom bundle file instead.
753
784
  - Add ability to configure component preloads and custom bundles [`2241e5f`](https://github.com/SAP/ui5-builder/commit/2241e5ff98fd95f1f80cc74959655ae7a9c660e7)
754
785
 
755
786
 
787
+ [v3.0.0-alpha.12]: https://github.com/SAP/ui5-builder/compare/v3.0.0-alpha.11...v3.0.0-alpha.12
788
+ [v3.0.0-alpha.11]: https://github.com/SAP/ui5-builder/compare/v3.0.0-alpha.10...v3.0.0-alpha.11
756
789
  [v3.0.0-alpha.10]: https://github.com/SAP/ui5-builder/compare/v3.0.0-alpha.9...v3.0.0-alpha.10
757
790
  [v3.0.0-alpha.9]: https://github.com/SAP/ui5-builder/compare/v3.0.0-alpha.8...v3.0.0-alpha.9
758
791
  [v3.0.0-alpha.8]: https://github.com/SAP/ui5-builder/compare/v3.0.0-alpha.7...v3.0.0-alpha.8
package/jsdoc.json CHANGED
@@ -3,13 +3,13 @@
3
3
  "allowUnknownTags": false
4
4
  },
5
5
  "source": {
6
- "include": ["README.md", "index.js"],
6
+ "include": ["README.md"],
7
7
  "exclude": ["lib/lbt/utils/JSTokenizer.js"],
8
8
  "includePattern": ".+\\.js$",
9
9
  "excludePattern": "(node_modules(\\\\|/))"
10
10
  },
11
11
  "plugins": [
12
- "./jsdoc-plugin"
12
+ "./jsdoc-plugin.cjs"
13
13
  ],
14
14
  "opts": {
15
15
  "encoding": "utf8",
@@ -1,13 +1,12 @@
1
- "use strict";
2
1
 
3
- module.exports.MODULE__UI5LOADER = "ui5loader.js";
4
- module.exports.MODULE__UI5LOADER_AUTOCONFIG = "ui5loader-autoconfig.js";
5
- module.exports.MODULE__JQUERY_SAP_GLOBAL = "jquery.sap.global.js";
6
- module.exports.MODULE__SAP_UI_CORE_CORE = "sap/ui/core/Core.js";
7
- module.exports.EVO_MARKER_RESOURCE = module.exports.MODULE__UI5LOADER;
2
+ export const MODULE__UI5LOADER = "ui5loader.js";
3
+ export const MODULE__UI5LOADER_AUTOCONFIG = "ui5loader-autoconfig.js";
4
+ export const MODULE__JQUERY_SAP_GLOBAL = "jquery.sap.global.js";
5
+ export const MODULE__SAP_UI_CORE_CORE = "sap/ui/core/Core.js";
6
+ export const EVO_MARKER_RESOURCE = MODULE__UI5LOADER;
8
7
 
9
- module.exports.getRendererName = function( module ) {
8
+ export function getRendererName( module ) {
10
9
  if ( /\.js$/.test(module) ) {
11
10
  return module.replace(/\.js$/, "Renderer.js");
12
11
  }
13
- };
12
+ }
@@ -18,10 +18,10 @@
18
18
  * This class can handle multiple concurrent analysis calls, it has no instance state
19
19
  * other than the pool (which is readonly).
20
20
  */
21
- "use strict";
22
21
 
23
- const ModuleName = require("../utils/ModuleName");
24
- const log = require("@ui5/logger").getLogger("lbt:analyzer:ComponentAnalyzer");
22
+ import {fromUI5LegacyName} from "../utils/ModuleName.js";
23
+ import logger from "@ui5/logger";
24
+ const log = logger.getLogger("lbt:analyzer:ComponentAnalyzer");
25
25
 
26
26
  // ---------------------------------------------------------------------------------------------------------
27
27
 
@@ -97,7 +97,7 @@ class ComponentAnalyzer {
97
97
  } else {
98
98
  rootView = ui5.rootView;
99
99
  }
100
- const module = ModuleName.fromUI5LegacyName(
100
+ const module = fromUI5LegacyName(
101
101
  rootView.viewName,
102
102
  ".view." + rootView.type.toLowerCase() );
103
103
  log.verbose("adding root view dependency ", module);
@@ -105,13 +105,13 @@ class ComponentAnalyzer {
105
105
  }
106
106
 
107
107
  each( ui5.dependencies && ui5.dependencies.libs, (options, lib) => {
108
- const module = ModuleName.fromUI5LegacyName(lib, "/library.js");
108
+ const module = fromUI5LegacyName(lib, "/library.js");
109
109
  log.verbose("adding library dependency ", module, options.lazy || false);
110
110
  info.addDependency( module, options.lazy ); // lazy -> conditional dependency
111
111
  });
112
112
 
113
113
  each( ui5.dependencies && ui5.dependencies.components, (options, component) => {
114
- const module = ModuleName.fromUI5LegacyName(component, "/Component.js");
114
+ const module = fromUI5LegacyName(component, "/Component.js");
115
115
  log.verbose("adding component dependency ", module, options.lazy || false);
116
116
  info.addDependency( module, options.lazy ); // lazy -> conditional dependency
117
117
  });
@@ -163,7 +163,7 @@ class ComponentAnalyzer {
163
163
  log.warn(`Neither a type nor a dataSource has been defined for model "${model}".`);
164
164
  return;
165
165
  }
166
- const module = ModuleName.fromUI5LegacyName( modelType );
166
+ const module = fromUI5LegacyName( modelType );
167
167
  log.verbose("derived model implementation dependency ", module);
168
168
  info.addDependency(module);
169
169
  });
@@ -175,7 +175,7 @@ class ComponentAnalyzer {
175
175
  // See sap/ui/core/UIComponent#init
176
176
  if (routing.routes) {
177
177
  const routerClassName = routingConfig.routerClass || "sap.ui.core.routing.Router";
178
- const routerClassModule = ModuleName.fromUI5LegacyName(routerClassName);
178
+ const routerClassModule = fromUI5LegacyName(routerClassName);
179
179
  log.verbose(`adding router dependency '${routerClassModule}'`);
180
180
  info.addDependency(routerClassModule);
181
181
  } else if (routing.targets) {
@@ -194,7 +194,7 @@ class ComponentAnalyzer {
194
194
  if (target && target.viewName) {
195
195
  // merge target config with default config
196
196
  const config = Object.assign({}, routing.config, target);
197
- const module = ModuleName.fromUI5LegacyName(
197
+ const module = fromUI5LegacyName(
198
198
  (config.viewPath ? config.viewPath + "." : "") +
199
199
  config.viewName, ".view." + config.viewType.toLowerCase() );
200
200
  log.verbose("converting routing target '%s' to view dependency '%s'", targetName, module);
@@ -209,4 +209,4 @@ class ComponentAnalyzer {
209
209
  }
210
210
  }
211
211
 
212
- module.exports = ComponentAnalyzer;
212
+ export default ComponentAnalyzer;
@@ -56,13 +56,13 @@
56
56
  * This class can handle multiple concurrent analysis calls, it has no instance state other than the pool
57
57
  * (which is readonly).
58
58
  */
59
- "use strict";
60
59
 
61
- const ModuleName = require("../utils/ModuleName");
62
- const SapUiDefine = require("../calls/SapUiDefine");
63
- const {parseJS, Syntax} = require("../utils/parseUtils");
64
- const {getValue, isMethodCall, isString} = require("../utils/ASTUtils");
65
- const log = require("@ui5/logger").getLogger("lbt:analyzer:FioriElementAnalyzer");
60
+ import {fromUI5LegacyName} from "../utils/ModuleName.js";
61
+ import SapUiDefine from "../calls/SapUiDefine.js";
62
+ import {parseJS, Syntax} from "../utils/parseUtils.js";
63
+ import {getValue, isMethodCall, getStringValue} from "../utils/ASTUtils.js";
64
+ import logger from "@ui5/logger";
65
+ const log = logger.getLogger("lbt:analyzer:FioriElementAnalyzer");
66
66
 
67
67
  // ---------------------------------------------------------------------------------------------------------
68
68
 
@@ -129,7 +129,7 @@ class FioriElementsAnalyzer {
129
129
  }
130
130
  each(activityCfg, (actionCfg) => {
131
131
  if ( actionCfg.template ) {
132
- const module = ModuleName.fromUI5LegacyName( "sap.fe.templates." +
132
+ const module = fromUI5LegacyName( "sap.fe.templates." +
133
133
  actionCfg.template + ".Component" );
134
134
  log.verbose("template app: add dependency to template component %s", module);
135
135
  info.addDependency(module);
@@ -151,7 +151,7 @@ class FioriElementsAnalyzer {
151
151
  const templateName = (pageConfig.component && pageConfig.component.settings &&
152
152
  pageConfig.component.settings.templateName) || defaultTemplateName;
153
153
  if ( templateName ) {
154
- const templateModuleName = ModuleName.fromUI5LegacyName( templateName, ".view.xml" );
154
+ const templateModuleName = fromUI5LegacyName( templateName, ".view.xml" );
155
155
  log.verbose("template app: add dependency to template view %s", templateModuleName);
156
156
  appInfo.addDependency(templateModuleName);
157
157
  }
@@ -165,25 +165,36 @@ class FioriElementsAnalyzer {
165
165
  const TA = defineCall.findImportName("sap/fe/core/TemplateAssembler.js");
166
166
  // console.log("local name for TemplateAssembler: %s", TA);
167
167
  if ( TA && defineCall.factory ) {
168
- defineCall.factory.body.body.forEach( (stmt) => {
169
- if ( stmt.type === Syntax.ReturnStatement &&
170
- isMethodCall(stmt.argument, [TA, "getTemplateComponent"]) &&
171
- stmt.argument.arguments.length > 2 &&
172
- stmt.argument.arguments[2].type === "ObjectExpression" ) {
173
- templateName = this._analyzeTemplateClassDefinition(stmt.argument.arguments[2]) || templateName;
168
+ if (defineCall.factory.type === Syntax.ArrowFunctionExpression &&
169
+ defineCall.factory.expression === true) {
170
+ if ( this._isTemplateClassDefinition(TA, defineCall.factory.body) ) {
171
+ templateName =
172
+ this._analyzeTemplateClassDefinition(defineCall.factory.body.arguments[2]) || templateName;
174
173
  }
175
- });
174
+ } else {
175
+ defineCall.factory.body.body.forEach( (stmt) => {
176
+ if ( stmt.type === Syntax.ReturnStatement &&
177
+ this._isTemplateClassDefinition(TA, stmt.argument)
178
+ ) {
179
+ templateName =
180
+ this._analyzeTemplateClassDefinition(stmt.argument.arguments[2]) || templateName;
181
+ }
182
+ });
183
+ }
176
184
  }
177
185
  }
178
186
  return templateName;
179
187
  }
180
188
 
189
+ _isTemplateClassDefinition(TA, node) {
190
+ return isMethodCall(node, [TA, "getTemplateComponent"]) &&
191
+ node.arguments.length > 2 &&
192
+ node.arguments[2].type === "ObjectExpression";
193
+ }
194
+
181
195
  _analyzeTemplateClassDefinition(clazz) {
182
- const defaultValue = getValue(clazz, ["metadata", "properties", "templateName", "defaultValue"]);
183
- if ( isString(defaultValue) ) {
184
- return defaultValue.value;
185
- }
196
+ return getStringValue(getValue(clazz, ["metadata", "properties", "templateName", "defaultValue"]));
186
197
  }
187
198
  }
188
199
 
189
- module.exports = FioriElementsAnalyzer;
200
+ export default FioriElementsAnalyzer;
@@ -1,12 +1,21 @@
1
- "use strict";
2
-
3
- const {Syntax, VisitorKeys} = require("../utils/parseUtils");
4
- const escope = require("escope");
5
- const ModuleName = require("../utils/ModuleName");
6
- const {Format: ModuleFormat} = require("../resources/ModuleInfo");
7
- const UI5ClientConstants = require("../UI5ClientConstants");
8
- const {findOwnProperty, getLocation, getPropertyKey, isMethodCall, isString} = require("../utils/ASTUtils");
9
- const log = require("@ui5/logger").getLogger("lbt:analyzer:JSModuleAnalyzer");
1
+ import {Syntax, VisitorKeys} from "../utils/parseUtils.js";
2
+ import escope from "escope";
3
+ import {fromUI5LegacyName, fromRequireJSName, resolveRelativeRequireJSName} from "../utils/ModuleName.js";
4
+ import moduleInfo from "../resources/ModuleInfo.js";
5
+ const ModuleFormat = moduleInfo.Format;
6
+ import {MODULE__JQUERY_SAP_GLOBAL, MODULE__UI5LOADER_AUTOCONFIG} from "../UI5ClientConstants.js";
7
+ import {
8
+ findOwnProperty,
9
+ getLocation,
10
+ getPropertyKey,
11
+ isMethodCall,
12
+ isString,
13
+ getStringValue,
14
+ } from "../utils/ASTUtils.js";
15
+
16
+ import logger from "@ui5/logger";
17
+
18
+ const log = logger.getLogger("lbt:analyzer:JSModuleAnalyzer");
10
19
 
11
20
  // ------------------------------------------------------------------------------------------------------------------
12
21
 
@@ -64,7 +73,7 @@ const EnrichedVisitorKeys = (function() {
64
73
  BreakStatement: [],
65
74
  CallExpression: [], // special handling
66
75
  CatchClause: ["param", "body"],
67
- ChainExpression: [],
76
+ ChainExpression: ["expression"],
68
77
  ClassBody: [],
69
78
  ClassDeclaration: [],
70
79
  ClassExpression: [],
@@ -114,7 +123,7 @@ const EnrichedVisitorKeys = (function() {
114
123
  ImportSpecifier: [], // imported, local
115
124
  Literal: [],
116
125
  LabeledStatement: [],
117
- LogicalExpression: [],
126
+ LogicalExpression: ["right"],
118
127
  MemberExpression: [],
119
128
  MetaProperty: toBeDone(["meta", "property"]),
120
129
  MethodDefinition: [],
@@ -350,13 +359,13 @@ class JSModuleAnalyzer {
350
359
 
351
360
  // depending on the used module APIs, add an implicit dependency to the loader entry module
352
361
  if ( info.format === ModuleFormat.UI5_LEGACY ) {
353
- info.addImplicitDependency(UI5ClientConstants.MODULE__JQUERY_SAP_GLOBAL);
362
+ info.addImplicitDependency(MODULE__JQUERY_SAP_GLOBAL);
354
363
  } else if ( info.format === ModuleFormat.UI5_DEFINE ) {
355
364
  // Note: the implicit dependency for sap.ui.define modules points to the standard UI5
356
365
  // loader config module. A more general approach would be to add a dependency to the loader
357
366
  // only, but then standard configuration would be missed by dependency resolution
358
367
  // (to be clarified)
359
- info.addImplicitDependency(UI5ClientConstants.MODULE__UI5LOADER_AUTOCONFIG);
368
+ info.addImplicitDependency(MODULE__UI5LOADER_AUTOCONFIG);
360
369
  }
361
370
 
362
371
  if ( !bIsUi5Module ) {
@@ -541,21 +550,27 @@ class JSModuleAnalyzer {
541
550
 
542
551
  function onDeclare(node) {
543
552
  const args = node.arguments;
544
- if ( args.length > 0 && isString(args[0]) ) {
545
- const name = ModuleName.fromUI5LegacyName( args[0].value );
546
- if ( nModuleDeclarations === 1 && !mainModuleFound) {
547
- // if this is the first declaration, then this is the main module declaration
548
- // note that this overrides an already given name
549
- setMainModuleInfo(name, getDocumentation(node));
550
- } else if ( nModuleDeclarations > 1 && name === info.name ) {
551
- // ignore duplicate declarations (e.g. in behavior file of design time controls)
552
- log.warn(`duplicate declaration of module name at ${getLocation(args)} in ${name}`);
553
+ if (args.length > 0) {
554
+ const value = getStringValue(args[0]);
555
+ if (value !== undefined) {
556
+ const name = fromUI5LegacyName(value);
557
+ if ( nModuleDeclarations === 1 && !mainModuleFound) {
558
+ // if this is the first declaration, then this is the main module declaration
559
+ // note that this overrides an already given name
560
+ setMainModuleInfo(name, getDocumentation(node));
561
+ } else if ( nModuleDeclarations > 1 && name === info.name ) {
562
+ // ignore duplicate declarations (e.g. in behavior file of design time controls)
563
+ log.warn(`duplicate declaration of module name at ${getLocation(args)} in ${name}`);
564
+ } else {
565
+ // otherwise it is just a submodule declaration
566
+ info.addSubModule(name);
567
+ }
568
+ return;
553
569
  } else {
554
- // otherwise it is just a submodule declaration
555
- info.addSubModule(name);
570
+ log.error("jQuery.sap.declare: module name could not be determined from first argument:", args[0]);
556
571
  }
557
572
  } else {
558
- log.error("jQuery.sap.declare: module name could not be determined from first argument:", args[0]);
573
+ log.error("jQuery.sap.declare: module name could not be determined, no arguments are given");
559
574
  }
560
575
  }
561
576
 
@@ -569,20 +584,26 @@ class JSModuleAnalyzer {
569
584
 
570
585
  // determine the name of the module
571
586
  let name = null;
572
- if ( i < nArgs && isString(args[i]) ) {
573
- name = ModuleName.fromRequireJSName( args[i++].value );
574
- if ( name === defaultName ) {
575
- // hardcoded name equals the file name, so this definition qualifies as main module definition
576
- setMainModuleInfo(name, desc);
577
- } else {
578
- info.addSubModule(name);
579
- if ( candidateName == null ) {
580
- // remember the name and description in case no other module qualifies as main module
581
- candidateName = name;
582
- candidateDescription = desc;
587
+ if ( i < nArgs ) {
588
+ const value = getStringValue( args[i] );
589
+ if ( value !== undefined ) {
590
+ name = fromRequireJSName(value);
591
+ if ( name === defaultName ) {
592
+ // hardcoded name equals the file name, so this definition qualifies as main module definition
593
+ setMainModuleInfo(name, desc);
594
+ } else {
595
+ info.addSubModule(name);
596
+ if ( candidateName == null ) {
597
+ // remember the name and description in case no other module qualifies as main module
598
+ candidateName = name;
599
+ candidateDescription = desc;
600
+ }
583
601
  }
602
+ i++;
584
603
  }
585
- } else {
604
+ }
605
+
606
+ if ( !name ) {
586
607
  nUnnamedDefines++;
587
608
  if ( nUnnamedDefines > 1 ) {
588
609
  throw new Error(
@@ -614,15 +635,25 @@ class JSModuleAnalyzer {
614
635
  // UI5 signature with one or many required modules
615
636
  for (let i = 0; i < nArgs; i++) {
616
637
  const arg = args[i];
617
- if ( isString(arg) ) {
618
- const requiredModuleName = ModuleName.fromUI5LegacyName( arg.value );
638
+ const value = getStringValue(arg);
639
+ if ( value !== undefined ) {
640
+ const requiredModuleName = fromUI5LegacyName( value );
619
641
  info.addDependency(requiredModuleName, conditional);
620
- } else if ( arg.type == Syntax.ConditionalExpression &&
621
- isString(arg.consequent) && isString(arg.alternate) ) {
622
- const requiredModuleName1 = ModuleName.fromUI5LegacyName( arg.consequent.value );
623
- info.addDependency(requiredModuleName1, true);
624
- const requiredModuleName2 = ModuleName.fromUI5LegacyName( arg.alternate.value );
625
- info.addDependency(requiredModuleName2, true);
642
+ } else if ( arg.type == Syntax.ConditionalExpression) {
643
+ const consequentValue = getStringValue(arg.consequent);
644
+ const alternateValue = getStringValue(arg.alternate);
645
+ if ( consequentValue !== undefined ) {
646
+ const requiredModuleName1 = fromUI5LegacyName( consequentValue );
647
+ info.addDependency(requiredModuleName1, true);
648
+ }
649
+ if ( alternateValue !== undefined ) {
650
+ const requiredModuleName2 = fromUI5LegacyName( alternateValue );
651
+ info.addDependency(requiredModuleName2, true);
652
+ }
653
+ if ( consequentValue === undefined || alternateValue === undefined ) {
654
+ log.verbose("jQuery.sap.require: cannot evaluate dynamic arguments: ", arg && arg.type);
655
+ info.dynamicDependencies = true;
656
+ }
626
657
  } else {
627
658
  log.verbose("jQuery.sap.require: cannot evaluate dynamic arguments: ", arg && arg.type);
628
659
  info.dynamicDependencies = true;
@@ -637,9 +668,10 @@ class JSModuleAnalyzer {
637
668
  const i = 0;
638
669
 
639
670
  if ( i < nArgs ) {
640
- if ( isString(args[i]) ) {
671
+ const value = getStringValue(args[i]);
672
+ if ( value !== undefined ) {
641
673
  // sap.ui.requireSync does not support relative dependencies
642
- const moduleName = ModuleName.fromRequireJSName( args[i].value );
674
+ const moduleName = fromRequireJSName( value );
643
675
  info.addDependency(moduleName, conditional);
644
676
  } else {
645
677
  log.verbose("sap.ui.requireSync: cannot evaluate dynamic arguments: ", args[i] && args[i].type);
@@ -654,18 +686,24 @@ class JSModuleAnalyzer {
654
686
  let i = 0;
655
687
 
656
688
  // determine the name of the module
657
- if ( i < nArgs && isString(args[i]) ) {
658
- const moduleName = ModuleName.fromRequireJSName( args[i++].value );
659
- info.addSubModule(moduleName);
660
-
661
- // add dependencies
662
- // to correctly identify dependencies e.g. of a library-preload
663
- const elementArg = args[i++];
664
- if (elementArg && elementArg.type === Syntax.ArrayExpression) {
665
- elementArg.elements.forEach((element) => {
666
- const dependencyName = ModuleName.resolveRelativeRequireJSName(moduleName, element.value);
667
- info.addDependency(dependencyName, conditional);
668
- });
689
+ if ( i < nArgs ) {
690
+ const value = getStringValue(args[i++]);
691
+ if ( value !== undefined ) {
692
+ const moduleName = fromRequireJSName( value );
693
+ info.addSubModule(moduleName);
694
+
695
+ // add dependencies
696
+ // to correctly identify dependencies e.g. of a library-preload
697
+ const elementArg = args[i++];
698
+ if (elementArg && elementArg.type === Syntax.ArrayExpression) {
699
+ elementArg.elements.forEach((element) => {
700
+ const dependencyName = resolveRelativeRequireJSName(moduleName,
701
+ getStringValue(element));
702
+ info.addDependency(dependencyName, conditional);
703
+ });
704
+ }
705
+ } else {
706
+ log.warn("sap.ui.predefine call has a non supported type for module name (ignored)");
669
707
  }
670
708
  } else {
671
709
  log.warn("sap.ui.predefine call is missing a module name (ignored)");
@@ -692,8 +730,11 @@ class JSModuleAnalyzer {
692
730
  if ( modules && modules.type == Syntax.ObjectExpression ) {
693
731
  modules.properties.forEach( function(property) {
694
732
  let moduleName = getPropertyKey(property);
733
+ if ( !moduleName ) {
734
+ return;
735
+ }
695
736
  if ( namesUseLegacyNotation ) {
696
- moduleName = ModuleName.fromUI5LegacyName(moduleName);
737
+ moduleName = fromUI5LegacyName(moduleName);
697
738
  }
698
739
  info.addSubModule(moduleName);
699
740
  });
@@ -705,16 +746,17 @@ class JSModuleAnalyzer {
705
746
  function analyzeDependencyArray(array, conditional, name) {
706
747
  // console.log(array);
707
748
  array.forEach( (item) => {
708
- if ( isString(item) ) {
749
+ const value = getStringValue(item);
750
+ if ( value !== undefined ) {
709
751
  // ignore special AMD dependencies (require, exports, module)
710
- if ( SPECIAL_AMD_DEPENDENCIES.indexOf(item.value) >= 0 ) {
752
+ if ( SPECIAL_AMD_DEPENDENCIES.indexOf(value) >= 0 ) {
711
753
  return;
712
754
  }
713
755
  let requiredModule;
714
756
  if (name == null) {
715
- requiredModule = ModuleName.fromRequireJSName( item.value );
757
+ requiredModule = fromRequireJSName( value );
716
758
  } else {
717
- requiredModule = ModuleName.resolveRelativeRequireJSName(name, item.value);
759
+ requiredModule = resolveRelativeRequireJSName(name, value);
718
760
  }
719
761
  info.addDependency( requiredModule, conditional );
720
762
  } else {
@@ -766,4 +808,4 @@ class JSModuleAnalyzer {
766
808
  }
767
809
 
768
810
 
769
- module.exports = JSModuleAnalyzer;
811
+ export default JSModuleAnalyzer;
@@ -23,13 +23,13 @@
23
23
  * This class can handle multiple concurrent analysis calls, it has no instance state other than the pool
24
24
  * (which is readonly).
25
25
  */
26
- "use strict";
27
26
 
28
- const ModuleName = require("../utils/ModuleName");
29
- const SapUiDefine = require("../calls/SapUiDefine");
30
- const {parseJS, Syntax} = require("../utils/parseUtils");
31
- const {getValue, isMethodCall, isString} = require("../utils/ASTUtils");
32
- const log = require("@ui5/logger").getLogger("lbt:analyzer:SmartTemplateAnalyzer");
27
+ import {fromUI5LegacyName} from "../utils/ModuleName.js";
28
+ import SapUiDefine from "../calls/SapUiDefine.js";
29
+ import {parseJS, Syntax} from "../utils/parseUtils.js";
30
+ import {getValue, isMethodCall, getStringValue} from "../utils/ASTUtils.js";
31
+ import logger from "@ui5/logger";
32
+ const log = logger.getLogger("lbt:analyzer:SmartTemplateAnalyzer");
33
33
 
34
34
  // ---------------------------------------------------------------------------------------------------------
35
35
 
@@ -84,7 +84,7 @@ class TemplateComponentAnalyzer {
84
84
  const st = (manifest && manifest["sap.ui.generic.app"]) || {};
85
85
  function recursePage(page) {
86
86
  if ( page.component && page.component.name ) {
87
- const module = ModuleName.fromUI5LegacyName( page.component.name + ".Component" );
87
+ const module = fromUI5LegacyName( page.component.name + ".Component" );
88
88
  log.verbose("template app: add dependency to template component %s", module);
89
89
  info.addDependency(module);
90
90
  promises.push( that._analyzeTemplateComponent(module, page, info) );
@@ -113,7 +113,7 @@ class TemplateComponentAnalyzer {
113
113
  const templateName = (pageConfig.component && pageConfig.component.settings &&
114
114
  pageConfig.component.settings.templateName) || defaultTemplateName;
115
115
  if ( templateName ) {
116
- const templateModuleName = ModuleName.fromUI5LegacyName( templateName, ".view.xml" );
116
+ const templateModuleName = fromUI5LegacyName( templateName, ".view.xml" );
117
117
  log.verbose("template app: add dependency to template view %s", templateModuleName);
118
118
  appInfo.addDependency(templateModuleName);
119
119
  }
@@ -134,25 +134,36 @@ class TemplateComponentAnalyzer {
134
134
  const TA = defineCall.findImportName("sap/suite/ui/generic/template/lib/TemplateAssembler.js");
135
135
  // console.log("local name for TemplateAssembler: %s", TA);
136
136
  if ( TA && defineCall.factory ) {
137
- defineCall.factory.body.body.forEach( (stmt) => {
138
- if ( stmt.type === Syntax.ReturnStatement &&
139
- isMethodCall(stmt.argument, [TA, "getTemplateComponent"]) &&
140
- stmt.argument.arguments.length > 2 &&
141
- stmt.argument.arguments[2].type === "ObjectExpression" ) {
142
- templateName = this._analyzeTemplateClassDefinition(stmt.argument.arguments[2]) || templateName;
137
+ if (defineCall.factory.type === Syntax.ArrowFunctionExpression &&
138
+ defineCall.factory.expression === true) {
139
+ if ( this._isTemplateClassDefinition(TA, defineCall.factory.body) ) {
140
+ templateName =
141
+ this._analyzeTemplateClassDefinition(defineCall.factory.body.arguments[2]) || templateName;
143
142
  }
144
- });
143
+ } else {
144
+ defineCall.factory.body.body.forEach( (stmt) => {
145
+ if ( stmt.type === Syntax.ReturnStatement &&
146
+ this._isTemplateClassDefinition(TA, stmt.argument)
147
+ ) {
148
+ templateName =
149
+ this._analyzeTemplateClassDefinition(stmt.argument.arguments[2]) || templateName;
150
+ }
151
+ });
152
+ }
145
153
  }
146
154
  }
147
155
  return templateName;
148
156
  }
149
157
 
158
+ _isTemplateClassDefinition(TA, node) {
159
+ return isMethodCall(node, [TA, "getTemplateComponent"]) &&
160
+ node.arguments.length > 2 &&
161
+ node.arguments[2].type === "ObjectExpression";
162
+ }
163
+
150
164
  _analyzeTemplateClassDefinition(clazz) {
151
- const defaultValue = getValue(clazz, ["metadata", "properties", "templateName", "defaultValue"]);
152
- if ( isString(defaultValue) ) {
153
- return defaultValue.value;
154
- }
165
+ return getStringValue(getValue(clazz, ["metadata", "properties", "templateName", "defaultValue"]));
155
166
  }
156
167
  }
157
168
 
158
- module.exports = TemplateComponentAnalyzer;
169
+ export default TemplateComponentAnalyzer;