babel-plugin-transform-modules-ui5 7.5.0 → 7.6.0
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 +11 -0
- package/dist/modules/helpers/wrapper.js +36 -6
- package/dist/utils/templates.js +6 -1
- package/package.json +2 -2
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.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.5.0...v7.6.0) (2024-07-22)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* support sap.ui.require for [@sap](https://github.com/sap)UiRequire annotated modules ([#131](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/131)) ([23c4ac6](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/23c4ac67eef5a825692c528852ef62bbd621d13e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# [7.5.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.4.2...v7.5.0) (2024-07-12)
|
|
7
18
|
|
|
8
19
|
|
|
@@ -139,14 +139,19 @@ function wrap(visitor, programNode, opts) {
|
|
|
139
139
|
if (imports.some(imp => imp.interop)) {
|
|
140
140
|
body.unshift(th.buildDefaultImportInterop());
|
|
141
141
|
}
|
|
142
|
-
|
|
142
|
+
|
|
143
|
+
// should we use sap.ui.require instead of sap.ui.define?
|
|
144
|
+
let useSapUiRequire = hasUseSapUiRequire(visitor.parent.comments, body, true);
|
|
145
|
+
|
|
146
|
+
// generate the sap.ui.define or sap.ui.require
|
|
147
|
+
const defineOrRequire = generateDefineOrRequire(body, imports, exportGlobal || opts.exportAllGlobal, useSapUiRequire);
|
|
143
148
|
|
|
144
149
|
// add the "use strict" directive if not on program node
|
|
145
150
|
if (!opts.neverUseStrict && !hasUseStrict(programNode)) {
|
|
146
|
-
const
|
|
147
|
-
|
|
151
|
+
const defineOrRequireFnBody = defineOrRequire.expression.arguments[1].body;
|
|
152
|
+
defineOrRequireFnBody.directives = [_core.types.directive(_core.types.directiveLiteral("use strict")), ...(defineOrRequireFnBody.directives || [])];
|
|
148
153
|
}
|
|
149
|
-
programNode.body = [...preDefine,
|
|
154
|
+
programNode.body = [...preDefine, defineOrRequire];
|
|
150
155
|
|
|
151
156
|
// if a copyright comment is present we append it to the new program node
|
|
152
157
|
if (copyright && visitor.parent) {
|
|
@@ -157,11 +162,36 @@ function wrap(visitor, programNode, opts) {
|
|
|
157
162
|
function hasUseStrict(node) {
|
|
158
163
|
return (node.directives || []).some(directive => directive.value.value === "use strict");
|
|
159
164
|
}
|
|
160
|
-
function
|
|
165
|
+
function hasUseSapUiRequire(comments, body, remove) {
|
|
166
|
+
// detect the @sapUiRequire comment
|
|
167
|
+
return comments.some(comment => {
|
|
168
|
+
let found = false;
|
|
169
|
+
// check for existing comment block
|
|
170
|
+
if (comment.type === "CommentBlock") {
|
|
171
|
+
found = comment.value.trim() === "@sapUiRequire";
|
|
172
|
+
}
|
|
173
|
+
// remove the comment (if it is somewhere in the body)
|
|
174
|
+
if (found && remove) {
|
|
175
|
+
body === null || body === void 0 || body.forEach(node => {
|
|
176
|
+
(0, _core.traverse)(node, {
|
|
177
|
+
enter(path) {
|
|
178
|
+
["leadingComments", "trailingComments", "innerComments"].forEach(key => {
|
|
179
|
+
var _path$node$key;
|
|
180
|
+
path.node[key] = (_path$node$key = path.node[key]) === null || _path$node$key === void 0 ? void 0 : _path$node$key.filter(c => c !== comment);
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
noScope: true
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
return found;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function generateDefineOrRequire(body, imports, exportGlobal, useRequire) {
|
|
161
191
|
const defineOpts = {
|
|
162
192
|
SOURCES: _core.types.arrayExpression(imports.map(i => _core.types.stringLiteral(i.src))),
|
|
163
193
|
PARAMS: imports.map(i => _core.types.identifier(i.tmpName)),
|
|
164
194
|
BODY: body
|
|
165
195
|
};
|
|
166
|
-
return exportGlobal ? th.buildDefineGlobal(defineOpts) : th.buildDefine(defineOpts);
|
|
196
|
+
return useRequire ? th.buildRequire(defineOpts) : exportGlobal ? th.buildDefineGlobal(defineOpts) : th.buildDefine(defineOpts);
|
|
167
197
|
}
|
package/dist/utils/templates.js
CHANGED
|
@@ -5,13 +5,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.buildInheritingFunction = exports.buildInheritingConstructor = exports.buildExtendAssign = exports.buildExportDefault = exports.buildDynamicImportHelper = exports.buildDefineGlobal = exports.buildDefine = exports.buildDefaultImportInterop = exports.buildDefaultImportDeconstructor = exports.buildDeclareExports = exports.buildConstDeclaration = exports.buildAssign = exports.buildAllExportHelper = exports.buildAllExport = void 0;
|
|
7
7
|
exports.buildNamedExport = buildNamedExport;
|
|
8
|
-
exports.exportsIdentifier = exports.buildTempExport = exports.buildReturnExports = exports.buildReturn = exports.buildNamedImportDestructor = void 0;
|
|
8
|
+
exports.exportsIdentifier = exports.buildTempExport = exports.buildReturnExports = exports.buildReturn = exports.buildRequire = exports.buildNamedImportDestructor = void 0;
|
|
9
9
|
var _core = require("@babel/core");
|
|
10
10
|
const exportName = "__exports";
|
|
11
11
|
const exportsIdentifier = exports.exportsIdentifier = _core.types.identifier(exportName);
|
|
12
12
|
const buildAssign = exports.buildAssign = (0, _core.template)(`
|
|
13
13
|
OBJECT.NAME = VALUE;
|
|
14
14
|
`);
|
|
15
|
+
const buildRequire = exports.buildRequire = (0, _core.template)(`
|
|
16
|
+
sap.ui.require(SOURCES, function (PARAMS) {
|
|
17
|
+
BODY;
|
|
18
|
+
});
|
|
19
|
+
`);
|
|
15
20
|
const buildDefine = exports.buildDefine = (0, _core.template)(`
|
|
16
21
|
sap.ui.define(SOURCES, function (PARAMS) {
|
|
17
22
|
BODY;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-transform-modules-ui5",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.6.0",
|
|
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": "
|
|
97
|
+
"gitHead": "8db5f32610df08996a49b97529c8a8f3fabcc59c"
|
|
98
98
|
}
|