babel-plugin-transform-modules-ui5 7.6.1 → 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,17 @@
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
+
6
17
  ## [7.6.1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.6.0...v7.6.1) (2024-09-13)
7
18
 
8
19
 
@@ -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.1",
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": "bd1be642e7f4e1849a2716cefa64f4e048f42bae"
97
+ "gitHead": "cb7d99003c5eb351bf59327e81842aaa6d101133"
98
98
  }