babel-plugin-transform-modules-ui5 7.2.6 → 7.3.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 +16 -0
- package/dist/classes/helpers/classes.js +74 -3
- package/dist/classes/helpers/imports.js +34 -0
- package/dist/classes/pre.js +12 -0
- package/dist/classes/visitor.js +4 -1
- package/dist/index.js +3 -0
- package/dist/modules/visitor.js +2 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,22 @@
|
|
|
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.3.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.2.6...v7.3.0) (2024-01-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* sanitize variable names for re-exports ([#122](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/122)) ([f475dbc](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/f475dbcb4f8b767a5680a974903e7f97df8dacc7))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* support using predefined controller extensions ([#120](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/120)) ([d7cb66c](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/d7cb66cd5af422529bb00658669e595af2477615))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
6
22
|
## [7.2.6](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.2.5...v7.2.6) (2023-11-23)
|
|
7
23
|
|
|
8
24
|
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.convertClassToUI5Extend = convertClassToUI5Extend;
|
|
7
7
|
exports.getClassInfo = getClassInfo;
|
|
8
|
+
exports.getTypeName = void 0;
|
|
8
9
|
var _core = require("@babel/core");
|
|
9
10
|
var _path = _interopRequireDefault(require("path"));
|
|
10
11
|
var _objectAssignDefined = _interopRequireDefault(require("object-assign-defined"));
|
|
@@ -12,6 +13,7 @@ var th = _interopRequireWildcard(require("../../utils/templates"));
|
|
|
12
13
|
var ast = _interopRequireWildcard(require("../../utils/ast"));
|
|
13
14
|
var _jsdoc = require("./jsdoc");
|
|
14
15
|
var _decorators = require("./decorators");
|
|
16
|
+
var _imports = require("./imports");
|
|
15
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
16
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -25,10 +27,11 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
|
|
|
25
27
|
* Any static methods or properties will be moved outside the class body.
|
|
26
28
|
* The path will be updated with the new AST.
|
|
27
29
|
*/
|
|
28
|
-
function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, opts) {
|
|
30
|
+
function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, importDeclarationPaths, opts) {
|
|
29
31
|
if (!(_core.types.isClassDeclaration(node) || _core.types.isClassExpression(node))) {
|
|
30
32
|
return node;
|
|
31
33
|
}
|
|
34
|
+
const CONTROLLER_EXTENSION_TAG = "transformControllerExtension";
|
|
32
35
|
const staticMembers = [];
|
|
33
36
|
const classNameIdentifier = node.id;
|
|
34
37
|
const className = classNameIdentifier.name;
|
|
@@ -51,7 +54,8 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, opts)
|
|
|
51
54
|
extendProps.push(_core.types.objectProperty(_core.types.identifier(propName), extraStaticProps[propName]));
|
|
52
55
|
}
|
|
53
56
|
}
|
|
54
|
-
for (const
|
|
57
|
+
for (const memberPath of path.get("body.body")) {
|
|
58
|
+
const member = memberPath.node;
|
|
55
59
|
const memberName = member.key.name;
|
|
56
60
|
if (_core.types.isClassMethod(member)) {
|
|
57
61
|
var _member$params;
|
|
@@ -104,7 +108,47 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, opts)
|
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
} else if (_core.types.isClassProperty(member)) {
|
|
107
|
-
|
|
111
|
+
var _member$leadingCommen, _member$decorators;
|
|
112
|
+
// For class properties annotated to represent controller extensions, replace the pure declaration with an assignment (that's what the runtime expects)
|
|
113
|
+
// and keep them at the initialization object as properties (don't move into constructor).
|
|
114
|
+
if ((_member$leadingCommen = member.leadingComments) !== null && _member$leadingCommen !== void 0 && _member$leadingCommen.some(comment => {
|
|
115
|
+
return comment.value.includes("@" + CONTROLLER_EXTENSION_TAG);
|
|
116
|
+
}) || (_member$decorators = member.decorators) !== null && _member$decorators !== void 0 && _member$decorators.some(decorator => {
|
|
117
|
+
var _decorator$expression;
|
|
118
|
+
return ((_decorator$expression = decorator.expression) === null || _decorator$expression === void 0 ? void 0 : _decorator$expression.name) === CONTROLLER_EXTENSION_TAG;
|
|
119
|
+
})) {
|
|
120
|
+
var _member$typeAnnotatio;
|
|
121
|
+
const typeAnnotation = (_member$typeAnnotatio = member.typeAnnotation) === null || _member$typeAnnotatio === void 0 ? void 0 : _member$typeAnnotatio.typeAnnotation;
|
|
122
|
+
// double-check that it is a valid node for a controller extension
|
|
123
|
+
if (_core.types.isTSTypeReference(typeAnnotation) || _core.types.isTSQualifiedName(typeAnnotation)) {
|
|
124
|
+
const typeName = getTypeName(typeAnnotation);
|
|
125
|
+
|
|
126
|
+
// 1. transform the property from being typed as instance and un-initialized to a property where the controller extension *class* is assigned as value
|
|
127
|
+
const valueIdentifier = _core.types.identifier(typeName);
|
|
128
|
+
member.value = valueIdentifier;
|
|
129
|
+
member.typeAnnotation = null;
|
|
130
|
+
extendProps.unshift(buildObjectProperty(member)); // add it to the properties of the extend() config object
|
|
131
|
+
|
|
132
|
+
// 2. add a binding reference to the value, so in case the TS transpiler runs later it recognizes that the import is still needed
|
|
133
|
+
const typeNameFirstPart = typeName.split(".")[0]; // e.g. when "myExtension: someBundle.MyExtension"
|
|
134
|
+
if (memberPath.scope.hasBinding(typeNameFirstPart)) {
|
|
135
|
+
const binding = path.scope.getBinding(typeNameFirstPart);
|
|
136
|
+
binding.referencePaths.push(memberPath.get("value"));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// 3. restore the import in case it was run already and removed the import
|
|
140
|
+
const neededImportDeclaration = (0, _imports.getImportDeclaration)(memberPath.hub.file.opts.filename, typeName);
|
|
141
|
+
if (!importDeclarationPaths.some(path => path.node === neededImportDeclaration)) {
|
|
142
|
+
// TODO: import might be there but with the specifier removed; we can clone, but then other specifiers are duplicate
|
|
143
|
+
// if import is no longer there, re-add it
|
|
144
|
+
importDeclarationPaths[importDeclarationPaths.length - 1].insertAfter(neededImportDeclaration);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 4. prevent the member from also being added to the constructor (member does have a value now and initializer would be added below)
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!member.value) continue; // remove all other un-initialized static class props (typescript)
|
|
108
152
|
|
|
109
153
|
// Special handling for TypeScript limitation where metadata, renderer and overrides must be properties.
|
|
110
154
|
if (["metadata", "renderer", "overrides"].includes(memberName)) {
|
|
@@ -238,6 +282,33 @@ function getFileBaseNamespace(path, pluginOpts) {
|
|
|
238
282
|
return undefined;
|
|
239
283
|
}
|
|
240
284
|
}
|
|
285
|
+
const getQualifiedName = node => {
|
|
286
|
+
let {
|
|
287
|
+
left,
|
|
288
|
+
right
|
|
289
|
+
} = node;
|
|
290
|
+
|
|
291
|
+
// if left is TSQualifiedName, recursive call to get full namespace
|
|
292
|
+
if (_core.types.isTSQualifiedName(left)) {
|
|
293
|
+
left = getQualifiedName(left);
|
|
294
|
+
} else {
|
|
295
|
+
// if left is an Identifier
|
|
296
|
+
left = left.name;
|
|
297
|
+
}
|
|
298
|
+
return `${left}.${right.name}`;
|
|
299
|
+
};
|
|
300
|
+
const getTypeName = typeAnnotation => {
|
|
301
|
+
if (_core.types.isTSTypeReference(typeAnnotation)) {
|
|
302
|
+
// for TSTypeReference, typeName can be an Identifier or a TSQualifiedName
|
|
303
|
+
return typeAnnotation.typeName.name || getQualifiedName(typeAnnotation.typeName);
|
|
304
|
+
}
|
|
305
|
+
if (_core.types.isTSQualifiedName(typeAnnotation)) {
|
|
306
|
+
// for TSQualifiedName
|
|
307
|
+
return getQualifiedName(typeAnnotation);
|
|
308
|
+
}
|
|
309
|
+
return null;
|
|
310
|
+
};
|
|
311
|
+
exports.getTypeName = getTypeName;
|
|
241
312
|
const buildObjectProperty = member => {
|
|
242
313
|
const newObjectProperty = _core.types.objectProperty(member.key, member.value, member.computed);
|
|
243
314
|
newObjectProperty.leadingComments = member.leadingComments;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getImportDeclaration = getImportDeclaration;
|
|
7
|
+
exports.saveImports = void 0;
|
|
8
|
+
var _core = require("@babel/core");
|
|
9
|
+
let importDeclarations = {};
|
|
10
|
+
const saveImports = file => {
|
|
11
|
+
// save all import declarations before "unneeded" ones are removed by the TypeScript plugin
|
|
12
|
+
importDeclarations[file.opts.filename] = file.ast.program.body.filter(_core.types.isImportDeclaration); // right now even the removed import still exists later and can be re-added. Otherwise do: .map(decl => t.cloneNode(decl));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
// can be called from visitor to access previously present declarations
|
|
16
|
+
exports.saveImports = saveImports;
|
|
17
|
+
function getImportDeclaration(filename, typeName) {
|
|
18
|
+
const typeNameParts = typeName.split(".");
|
|
19
|
+
|
|
20
|
+
// find the declaration importing the typeName among the collected import declarations in this file
|
|
21
|
+
const filteredDeclarations = importDeclarations[filename].filter(importDeclaration => {
|
|
22
|
+
// each import declaration can import several entities, so let's check all of them
|
|
23
|
+
for (let specifier of importDeclaration.specifiers) {
|
|
24
|
+
if ((_core.types.isImportDefaultSpecifier(specifier) || _core.types.isImportNamespaceSpecifier(specifier)) && specifier.local.name === typeNameParts[0]) {
|
|
25
|
+
// if the import is default, then the typeName should only have one part (the import name)
|
|
26
|
+
return true;
|
|
27
|
+
} else if (_core.types.isImportSpecifier(specifier) && specifier.imported.name === typeNameParts[typeNameParts.length - 1]) {
|
|
28
|
+
// If the import is named, then the last part of the typeName should match the imported name
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return filteredDeclarations[0]; // should be exactly one
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ClassPre = void 0;
|
|
7
|
+
var _imports = require("./helpers/imports");
|
|
8
|
+
const ClassPre = file => {
|
|
9
|
+
// save all import declarations before "unneeded" ones are removed by the TypeScript plugin
|
|
10
|
+
(0, _imports.saveImports)(file);
|
|
11
|
+
};
|
|
12
|
+
exports.ClassPre = ClassPre;
|
package/dist/classes/visitor.js
CHANGED
|
@@ -12,6 +12,9 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
12
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
13
|
const CONSTRUCTOR = "constructor";
|
|
14
14
|
const ClassTransformVisitor = exports.ClassTransformVisitor = {
|
|
15
|
+
ImportDeclaration(path) {
|
|
16
|
+
this.importDeclarationPaths.push(path);
|
|
17
|
+
},
|
|
15
18
|
ImportDefaultSpecifier(path) {
|
|
16
19
|
this.importNames.push(path.node.local.name);
|
|
17
20
|
},
|
|
@@ -82,7 +85,7 @@ const ClassTransformVisitor = exports.ClassTransformVisitor = {
|
|
|
82
85
|
const staticProps = ast.groupPropertiesByName(ast.getOtherPropertiesOfIdentifier(blockParent, className));
|
|
83
86
|
|
|
84
87
|
// TODO: flag metadata and renderer for removal if applicable
|
|
85
|
-
const ui5ExtendClass = classes.convertClassToUI5Extend(path, node, classInfo, staticProps, opts);
|
|
88
|
+
const ui5ExtendClass = classes.convertClassToUI5Extend(path, node, classInfo, staticProps, this.importDeclarationPaths, opts);
|
|
86
89
|
if (path.isClassDeclaration()) {
|
|
87
90
|
if (_core.types.isExportDefaultDeclaration(parent)) {
|
|
88
91
|
path.parentPath.replaceWithMultiple([...ui5ExtendClass, th.buildExportDefault({
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _visitor = require("./classes/visitor");
|
|
4
|
+
var _pre = require("./classes/pre");
|
|
4
5
|
var _visitor2 = require("./modules/visitor");
|
|
5
6
|
var _wrapper = require("./modules/helpers/wrapper");
|
|
6
7
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -50,6 +51,7 @@ module.exports = () => {
|
|
|
50
51
|
|
|
51
52
|
// Properties for Class Transform
|
|
52
53
|
this.importNames = [];
|
|
54
|
+
this.importDeclarationPaths = [];
|
|
53
55
|
|
|
54
56
|
// The classes must be converted right away before any other class transforms get a chance to run.
|
|
55
57
|
path.traverse(_visitor.ClassTransformVisitor, this);
|
|
@@ -62,6 +64,7 @@ module.exports = () => {
|
|
|
62
64
|
}
|
|
63
65
|
}, _visitor2.ModuleTransformVisitor);
|
|
64
66
|
return {
|
|
67
|
+
pre: _pre.ClassPre,
|
|
65
68
|
visitor: UI5Visitor
|
|
66
69
|
};
|
|
67
70
|
};
|
package/dist/modules/visitor.js
CHANGED
|
@@ -18,8 +18,8 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
18
18
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
19
19
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
20
20
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
21
|
-
const tempModuleName = name => `__${name}`;
|
|
22
21
|
const cleanImportSource = src => src.replace(/(\/)|(-)|(@)/g, "_").replace(/\./g, "");
|
|
22
|
+
const tempModuleName = name => `__${name}`;
|
|
23
23
|
const hasGlobalExportFlag = node => (0, _jsdoc.hasJsdocGlobalExportFlag)(node);
|
|
24
24
|
const addModuleImport = (imports, name) => {
|
|
25
25
|
const existingImport = imports.find(imp => imp.src === name);
|
|
@@ -269,7 +269,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
269
269
|
},
|
|
270
270
|
ExportAllDeclaration(path) {
|
|
271
271
|
const src = path.node.source.value;
|
|
272
|
-
const name = src
|
|
272
|
+
const name = cleanImportSource(src);
|
|
273
273
|
const tmpName = tempModuleName(name);
|
|
274
274
|
this.imports.push({
|
|
275
275
|
src,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-transform-modules-ui5",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.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": "cf41a67c81c9321ba93ce4299cbb33a908da4e1a"
|
|
98
98
|
}
|