babel-plugin-transform-modules-ui5 7.6.0 → 7.6.2

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [7.6.2](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.6.1...v7.6.2) (2024-09-14)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * move qunit config autostart out of require/define ([#134](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/134)) ([9643cd0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/9643cd08314ce54816886df6c618fbb142c1b3e8))
12
+
13
+
14
+
15
+
16
+
17
+ ## [7.6.1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.6.0...v7.6.1) (2024-09-13)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * support wrapped controller extension assignments ([dfa51b6](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/dfa51b613259aeedb3f20987f5e5165ca35545d8))
23
+
24
+
25
+
26
+
27
+
6
28
  # [7.6.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.5.0...v7.6.0) (2024-07-22)
7
29
 
8
30
 
@@ -161,24 +161,20 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, import
161
161
  // @transformControllerExtension marker, because it is not a type assignment. In the resulting code, the
162
162
  // "ControllerExtension.use(...)" part should be removed and the content of the brackets should be assigned
163
163
  // directly to the member property.
164
- if (_core.types.isCallExpression(member.value)) {
165
- const callee = member.value.callee;
166
- if (_core.types.isMemberExpression(callee) && _core.types.isIdentifier(callee.object) && _core.types.isIdentifier(callee.property) && callee.property.name === "use" // we are looking for "ControllerExtension.use(...)"
167
- ) {
168
- var _memberPath$hub2, _callee$object, _importDeclaration$so;
169
- const importDeclaration = (0, _imports.getImportDeclaration)(memberPath === null || memberPath === void 0 || (_memberPath$hub2 = memberPath.hub) === null || _memberPath$hub2 === void 0 || (_memberPath$hub2 = _memberPath$hub2.file) === null || _memberPath$hub2 === void 0 || (_memberPath$hub2 = _memberPath$hub2.opts) === null || _memberPath$hub2 === void 0 ? void 0 : _memberPath$hub2.filename, callee === null || callee === void 0 || (_callee$object = callee.object) === null || _callee$object === void 0 ? void 0 : _callee$object.name // usually, but not necessarily always: "ControllerExtension"...
170
- );
171
- // ...hence we rather look at the imported module name to be sure
172
- if ((importDeclaration === null || importDeclaration === void 0 || (_importDeclaration$so = importDeclaration.source) === null || _importDeclaration$so === void 0 ? void 0 : _importDeclaration$so.value) === "sap/ui/core/mvc/ControllerExtension") {
173
- if (!member.value.arguments || member.value.arguments.length !== 1) {
174
- // exactly one argument must be there
175
- throw memberPath.buildCodeFrameError(`ControllerExtension.use() must be called with exactly one argument but has ${member.value.arguments ? member.value.arguments.length : 0}`);
176
- }
177
- member.value = member.value.arguments[0];
178
- extendProps.unshift(buildObjectProperty(member)); // add it to the properties of the extend() config object
179
- continue; // prevent the member from also being added to the constructor
180
- }
181
- }
164
+ const rightSide = member.value;
165
+ if (isCallToControllerExtensionUse(rightSide, memberPath)) {
166
+ member.value = rightSide.arguments[0];
167
+ extendProps.unshift(buildObjectProperty(member)); // add it to the properties of the extend() config object
168
+ continue; // prevent the member from also being added to the constructor
169
+ }
170
+
171
+ // code instrumentation sometimes wraps ControllerExtension.use() calls like:
172
+ // this.routing = (cov_1uvvg22e7l().s[5]++, ControllerExtension.use(Routing.override({ … })));
173
+ if (_core.types.isSequenceExpression(rightSide) && isCallToControllerExtensionUse(rightSide.expressions[rightSide.expressions.length - 1], memberPath)) {
174
+ rightSide.expressions[rightSide.expressions.length - 1] = rightSide.expressions[rightSide.expressions.length - 1].arguments[0];
175
+ member.value = rightSide;
176
+ extendProps.unshift(buildObjectProperty(member)); // add it to the properties of the extend() config object
177
+ continue; // prevent the member from also being added to the constructor
182
178
  }
183
179
 
184
180
  // Special handling for TypeScript limitation where metadata, renderer and overrides must be properties.
@@ -212,6 +208,35 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, import
212
208
  }
213
209
  }
214
210
 
211
+ /**
212
+ * Checks whether the given thing is a CallExpression that calls ControllerExtension.use(...)
213
+ *
214
+ * @param {*} expression the thing to check - does not need to be a CallExpression
215
+ * @param {string} memberPath
216
+ * @returns true if the given expression is a CallExpression that calls ControllerExtension.use(...)
217
+ */
218
+ function isCallToControllerExtensionUse(expression, memberPath) {
219
+ if (!_core.types.isCallExpression(expression)) {
220
+ return false;
221
+ }
222
+ const callee = expression.callee;
223
+ if (_core.types.isMemberExpression(callee) && _core.types.isIdentifier(callee.object) && _core.types.isIdentifier(callee.property) && callee.property.name === "use" // we are looking for "ControllerExtension.use(...)"
224
+ ) {
225
+ var _memberPath$hub2, _callee$object, _importDeclaration$so;
226
+ const importDeclaration = (0, _imports.getImportDeclaration)(memberPath === null || memberPath === void 0 || (_memberPath$hub2 = memberPath.hub) === null || _memberPath$hub2 === void 0 || (_memberPath$hub2 = _memberPath$hub2.file) === null || _memberPath$hub2 === void 0 || (_memberPath$hub2 = _memberPath$hub2.opts) === null || _memberPath$hub2 === void 0 ? void 0 : _memberPath$hub2.filename, callee === null || callee === void 0 || (_callee$object = callee.object) === null || _callee$object === void 0 ? void 0 : _callee$object.name // usually, but not necessarily always: "ControllerExtension"...
227
+ );
228
+ // ...hence we rather look at the imported module name to be sure
229
+ if ((importDeclaration === null || importDeclaration === void 0 || (_importDeclaration$so = importDeclaration.source) === null || _importDeclaration$so === void 0 ? void 0 : _importDeclaration$so.value) === "sap/ui/core/mvc/ControllerExtension") {
230
+ if (!expression.arguments || expression.arguments.length !== 1) {
231
+ // exactly one argument must be there
232
+ throw memberPath.buildCodeFrameError(`ControllerExtension.use() must be called with exactly one argument but has ${expression.arguments ? expression.arguments.length : 0}`);
233
+ }
234
+ return true;
235
+ }
236
+ }
237
+ return false; // return false if not a match
238
+ }
239
+
215
240
  // Arrow function properties need to get moved to the constructor so that
216
241
  // they're bound properly to the class instance, to align with the spec.
217
242
  // For controllers, use onInit rather than constructor, since controller constructors don't work.
@@ -81,6 +81,7 @@ function wrap(visitor, programNode, opts) {
81
81
  defaultExport = newDefaultExportIdentifier;
82
82
  }
83
83
  }
84
+ let moveUseStrictIfNeeded = false;
84
85
  const preDefine = [...ignoredImports];
85
86
  // If the noWrapBeforeImport opt is set, split any code before the first import and afterwards into separate arrays.
86
87
  // This should be done before any interops or other vars are injected.
@@ -98,10 +99,25 @@ function wrap(visitor, programNode, opts) {
98
99
  reachedFirstImport = true;
99
100
  }
100
101
  }
102
+ moveUseStrictIfNeeded = true;
103
+ body = newBody;
104
+ }
105
+
106
+ // If the QUnit.config.autostart is found it needs to be moved to the top of the program
107
+ if (opts.noWrapQUnitConfigAutostart === undefined || opts.noWrapQUnitConfigAutostart) {
108
+ const qunitConfigAutostart = findQUnitConfigAutostart(body, imports);
109
+ if (qunitConfigAutostart) {
110
+ preDefine.push(qunitConfigAutostart);
111
+ body = body.filter(node => node !== qunitConfigAutostart);
112
+ moveUseStrictIfNeeded = true;
113
+ }
114
+ }
115
+
116
+ // if code has been moved to preDefine, we need to move the "use strict" directive
117
+ if (moveUseStrictIfNeeded) {
101
118
  if (!opts.neverUseStrict && preDefine.length && !hasUseStrict(programNode)) {
102
119
  programNode.directives = [_core.types.directive(_core.types.directiveLiteral("use strict")), ...(programNode.directives || [])];
103
120
  }
104
- body = newBody;
105
121
  }
106
122
  if (injectDynamicImportHelper) {
107
123
  // import() to sap.ui.require() w/ promise and interop
@@ -187,6 +203,20 @@ function hasUseSapUiRequire(comments, body, remove) {
187
203
  return found;
188
204
  });
189
205
  }
206
+ function findQUnitConfigAutostart(body, imports) {
207
+ // if one imports QUnit, we don't need to move the QUnit.config.autostart
208
+ // as the configuration should apply to the local QUnit module
209
+ if (imports !== null && imports !== void 0 && imports.some(imp => imp.name === "QUnit")) {
210
+ return undefined;
211
+ }
212
+ // find the QUnit.config.autostart
213
+ return body === null || body === void 0 ? void 0 : body.find(node => {
214
+ return _core.types.isExpressionStatement(node) && _core.types.isAssignmentExpression(node.expression) && _core.types.isMemberExpression(node.expression.left) && _core.types.isMemberExpression(node.expression.left.object) && _core.types.isIdentifier(node.expression.left.object.object) && node.expression.left.object.object.name === "QUnit" && _core.types.isIdentifier(node.expression.left.object.property) && node.expression.left.object.property.name === "config" && _core.types.isIdentifier(node.expression.left.property) && node.expression.left.property.name === "autostart" && node.expression.operator === "=" /* &&
215
+ t.isBooleanLiteral(node.expression.right) &&
216
+ node.expression.right.value === false */;
217
+ });
218
+ }
219
+
190
220
  function generateDefineOrRequire(body, imports, exportGlobal, useRequire) {
191
221
  const defineOpts = {
192
222
  SOURCES: _core.types.arrayExpression(imports.map(i => _core.types.stringLiteral(i.src))),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-transform-modules-ui5",
3
- "version": "7.6.0",
3
+ "version": "7.6.2",
4
4
  "description": "An unofficial babel plugin for SAP UI5.",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -94,5 +94,5 @@
94
94
  "prettier": "^3.1.0",
95
95
  "rimraf": "^5.0.5"
96
96
  },
97
- "gitHead": "8db5f32610df08996a49b97529c8a8f3fabcc59c"
97
+ "gitHead": "cb7d99003c5eb351bf59327e81842aaa6d101133"
98
98
  }