babel-plugin-transform-modules-ui5 7.1.4 → 7.2.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 +24 -0
- package/dist/classes/helpers/classes.js +26 -2
- package/dist/classes/visitor.js +39 -13
- package/dist/modules/helpers/wrapper.js +14 -0
- package/dist/utils/ast.js +14 -10
- package/package.json +20 -18
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,30 @@
|
|
|
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.2.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.5...v7.2.0) (2023-05-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* split class conversion to enable other Babel plugin conversion ([#100](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/100)) ([4ba096b](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/4ba096b1a24d807cda2fd2f57425f3ab4b91a31b)), closes [#23](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/23) [#25](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/25)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [7.1.5](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.4...v7.1.5) (2023-05-30)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* enable support for TS param props ([#99](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/99)) ([2119b41](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/2119b41fbd5fb41ade7e096190cbebad03eecf7c)), closes [#65](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/65)
|
|
23
|
+
* ensure copyright comments to be leading comments ([#97](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/97)) ([39ab194](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/39ab1946f08d3fc33609bd6b9ac6cda9a985c5d7))
|
|
24
|
+
* sap.ui.define without callback function ([#98](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/98)) ([c1cd6a8](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/c1cd6a8f158de9b5036d9c768c48972d66ae20aa)), closes [#50](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/50)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
6
30
|
## [7.1.4](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.3...v7.1.4) (2023-04-11)
|
|
7
31
|
|
|
8
32
|
|
|
@@ -54,7 +54,31 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, opts)
|
|
|
54
54
|
for (const member of node.body.body) {
|
|
55
55
|
const memberName = member.key.name;
|
|
56
56
|
if (_core.types.isClassMethod(member)) {
|
|
57
|
-
|
|
57
|
+
var _member$params;
|
|
58
|
+
const isConstructor = member.kind === "constructor";
|
|
59
|
+
const membersToAssign = [];
|
|
60
|
+
const params = isConstructor ? (_member$params = member.params) === null || _member$params === void 0 ? void 0 : _member$params.map(param => {
|
|
61
|
+
// handling of parameter properties for constructors (TypeScript):
|
|
62
|
+
// https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties
|
|
63
|
+
// -> extracting the real parameters and store the members to assign
|
|
64
|
+
if (param.type === "TSParameterProperty") {
|
|
65
|
+
membersToAssign.push(param.parameter);
|
|
66
|
+
return param.parameter;
|
|
67
|
+
}
|
|
68
|
+
return param;
|
|
69
|
+
}) : member.params;
|
|
70
|
+
const func = _core.types.functionExpression(member.key, params, member.body, member.generator, member.async);
|
|
71
|
+
if (isConstructor && membersToAssign.length > 0) {
|
|
72
|
+
// handling of parameter properties for constructors (TypeScript):
|
|
73
|
+
// -> assigning parameter properties as members to the instance
|
|
74
|
+
const newMembers = membersToAssign.map(member => buildMemberAssignmentStatement(_core.types.thisExpression(), {
|
|
75
|
+
key: member,
|
|
76
|
+
computed: false,
|
|
77
|
+
value: member
|
|
78
|
+
}));
|
|
79
|
+
const superIndex = member.body.body.findIndex(node => ast.isSuperCallExpression(node.expression) || ast.isSuperPrototypeCallOf(node.expression, superClassName, "constructor"));
|
|
80
|
+
member.body.body.splice(superIndex === -1 ? member.body.body.length : superIndex + 1, 0, ...newMembers);
|
|
81
|
+
}
|
|
58
82
|
if (member.static) {
|
|
59
83
|
staticMembers.push(buildMemberAssignmentStatement(classNameIdentifier, _objectSpread(_objectSpread({}, member), {}, {
|
|
60
84
|
value: func
|
|
@@ -146,7 +170,7 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, opts)
|
|
|
146
170
|
extendProps.unshift(_core.types.objectProperty(_core.types.identifier(CONSTRUCTOR), constructor));
|
|
147
171
|
} else {
|
|
148
172
|
// Copy all except the super call from the constructor to the bindMethod (i.e. onInit)
|
|
149
|
-
bindMethod.body.body.unshift(...constructor.body.body.filter(node => !ast.isSuperCallExpression(node.expression)));
|
|
173
|
+
bindMethod.body.body.unshift(...constructor.body.body.filter(node => !(ast.isSuperCallExpression(node.expression) || ast.isSuperPrototypeCallOf(node.expression, superClassName, "constructor"))));
|
|
150
174
|
}
|
|
151
175
|
}
|
|
152
176
|
if (boundProps.length) {
|
package/dist/classes/visitor.js
CHANGED
|
@@ -26,11 +26,13 @@ const ClassTransformVisitor = {
|
|
|
26
26
|
file,
|
|
27
27
|
opts = {}
|
|
28
28
|
}) {
|
|
29
|
+
var _node$decorators;
|
|
29
30
|
const {
|
|
30
|
-
node
|
|
31
|
-
parent,
|
|
32
|
-
parentPath
|
|
31
|
+
node
|
|
33
32
|
} = path;
|
|
33
|
+
const {
|
|
34
|
+
name: className
|
|
35
|
+
} = node.id;
|
|
34
36
|
if (opts.neverConvertClass) {
|
|
35
37
|
return;
|
|
36
38
|
}
|
|
@@ -42,19 +44,45 @@ const ClassTransformVisitor = {
|
|
|
42
44
|
// If the super class is one of the imports, we'll assume it's a UI5 managed class,
|
|
43
45
|
// and therefore may need to be transformed to .extend() syntax.
|
|
44
46
|
const classInfo = classes.getClassInfo(path, node, path.parent, opts);
|
|
45
|
-
if (!shouldConvertClass(file, node, opts, classInfo)) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Save super class name for converting super calls
|
|
50
|
-
this.superClassName = classInfo.superClassName;
|
|
51
47
|
|
|
52
|
-
//
|
|
48
|
+
// filter found decorators (to be not handled by other plugins)
|
|
49
|
+
node.decorators = (_node$decorators = node.decorators) === null || _node$decorators === void 0 ? void 0 : _node$decorators.filter(d => {
|
|
50
|
+
var _exp$callee;
|
|
51
|
+
const exp = d.expression;
|
|
52
|
+
const name = exp.name || ((_exp$callee = exp.callee) === null || _exp$callee === void 0 ? void 0 : _exp$callee.name);
|
|
53
|
+
return classInfo[name] === undefined;
|
|
54
|
+
});
|
|
55
|
+
if (shouldConvertClass(file, node, opts, classInfo)) {
|
|
56
|
+
// Save super class name for converting super calls
|
|
57
|
+
this.superClassName = classInfo.superClassName;
|
|
58
|
+
// store the classinfo
|
|
59
|
+
this.classInfo = this.classInfo || {};
|
|
60
|
+
this.classInfo[className] = classInfo;
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
exit(path, {
|
|
64
|
+
opts = {}
|
|
65
|
+
}) {
|
|
66
|
+
var _this$classInfo;
|
|
67
|
+
const {
|
|
68
|
+
node,
|
|
69
|
+
parent,
|
|
70
|
+
parentPath
|
|
71
|
+
} = path;
|
|
53
72
|
const {
|
|
54
73
|
name: className
|
|
55
74
|
} = node.id;
|
|
75
|
+
|
|
76
|
+
// Only if classinfo has been found we process this file
|
|
77
|
+
const classInfo = (_this$classInfo = this.classInfo) === null || _this$classInfo === void 0 ? void 0 : _this$classInfo[className];
|
|
78
|
+
if (!classInfo || !node.superClass) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Find the Block scoped parent (Program or Function body) and search for assigned properties within that (eg. MyClass.X = "X").
|
|
56
83
|
const blockParent = path.findParent(path => path.isBlock()).node;
|
|
57
84
|
const staticProps = ast.groupPropertiesByName(ast.getOtherPropertiesOfIdentifier(blockParent, className));
|
|
85
|
+
|
|
58
86
|
// TODO: flag metadata and renderer for removal if applicable
|
|
59
87
|
const ui5ExtendClass = classes.convertClassToUI5Extend(path, node, classInfo, staticProps, opts);
|
|
60
88
|
if (path.isClassDeclaration()) {
|
|
@@ -76,8 +104,6 @@ const ClassTransformVisitor = {
|
|
|
76
104
|
}
|
|
77
105
|
parentPath.replaceWithMultiple(ui5ExtendClass);
|
|
78
106
|
}
|
|
79
|
-
},
|
|
80
|
-
exit() {
|
|
81
107
|
this.superClassName = null;
|
|
82
108
|
}
|
|
83
109
|
},
|
|
@@ -130,7 +156,7 @@ function isSuperApply(callee) {
|
|
|
130
156
|
function getRequiredParamsOfSAPUIDefine(path, node) {
|
|
131
157
|
const defineArgs = node.arguments;
|
|
132
158
|
const callbackNode = defineArgs.find(argNode => _core.types.isFunction(argNode));
|
|
133
|
-
return callbackNode.params; // Identifier
|
|
159
|
+
return (callbackNode === null || callbackNode === void 0 ? void 0 : callbackNode.params) || []; // Identifier
|
|
134
160
|
}
|
|
135
161
|
|
|
136
162
|
/**
|
|
@@ -11,6 +11,7 @@ var ast = _interopRequireWildcard(require("../../utils/ast"));
|
|
|
11
11
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
12
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
13
|
function wrap(visitor, programNode, opts) {
|
|
14
|
+
var _body, _body$, _body$$leadingComment;
|
|
14
15
|
let {
|
|
15
16
|
defaultExport,
|
|
16
17
|
exportGlobal,
|
|
@@ -25,6 +26,14 @@ function wrap(visitor, programNode, opts) {
|
|
|
25
26
|
let {
|
|
26
27
|
body
|
|
27
28
|
} = programNode;
|
|
29
|
+
|
|
30
|
+
// find the copyright comment from the original program body
|
|
31
|
+
const copyright = (_body = body) === null || _body === void 0 ? void 0 : (_body$ = _body[0]) === null || _body$ === void 0 ? void 0 : (_body$$leadingComment = _body$.leadingComments) === null || _body$$leadingComment === void 0 ? void 0 : _body$$leadingComment.find((comment, idx, arr) => {
|
|
32
|
+
if (comment.value.startsWith("!")) {
|
|
33
|
+
arr.splice(idx, 1);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
28
37
|
let allExportHelperAdded = false;
|
|
29
38
|
let extendAdded = false;
|
|
30
39
|
opts.collapse = !opts.noExportCollapse;
|
|
@@ -108,6 +117,11 @@ function wrap(visitor, programNode, opts) {
|
|
|
108
117
|
body.unshift(th.buildDefaultImportInterop());
|
|
109
118
|
}
|
|
110
119
|
programNode.body = [...preDefine, generateDefine(body, imports, exportGlobal || opts.exportAllGlobal)];
|
|
120
|
+
|
|
121
|
+
// if a copyright comment is present we append it to the new program node
|
|
122
|
+
if (copyright) {
|
|
123
|
+
programNode.body[0].leadingComments = [copyright];
|
|
124
|
+
}
|
|
111
125
|
}
|
|
112
126
|
function hasUseStrict(node) {
|
|
113
127
|
return (node.directives || []).some(directive => directive.value.value === "use strict");
|
package/dist/utils/ast.js
CHANGED
|
@@ -153,7 +153,7 @@ function convertDeclarationToExpression(declaration) {
|
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
155
|
function isSuperPrototypeCallOf(expression, superClassName, superMethodName) {
|
|
156
|
-
return _core.types.isCallExpression(expression) && isCallExpressionCalling(expression, `${superClassName}.prototype.${superMethodName}.apply`);
|
|
156
|
+
return _core.types.isCallExpression(expression) && (isCallExpressionCalling(expression, `${superClassName}.prototype.${superMethodName}.apply`) || isCallExpressionCalling(expression, `${superClassName}.prototype.${superMethodName}.call`));
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
/**
|
|
@@ -166,16 +166,20 @@ function isSuperPrototypeCallOf(expression, superClassName, superMethodName) {
|
|
|
166
166
|
function isCallExpressionCalling(expression, dotNotationString) {
|
|
167
167
|
if (!_core.types.isCallExpression(expression)) return false;
|
|
168
168
|
const callee = expression.callee;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
169
|
+
if (callee.type === "Identifier") {
|
|
170
|
+
return callee.name === dotNotationString;
|
|
171
|
+
} else {
|
|
172
|
+
const parts = dotNotationString.split(".");
|
|
173
|
+
let node = callee;
|
|
174
|
+
for (const nextNamePart of parts.reverse()) {
|
|
175
|
+
if (!node) return false;
|
|
176
|
+
// property won't be there for an anonymous function
|
|
177
|
+
const nodeName = node.name || node.property && node.property.name;
|
|
178
|
+
if (nodeName !== nextNamePart) return false;
|
|
179
|
+
node = node.object;
|
|
180
|
+
}
|
|
181
|
+
return true;
|
|
177
182
|
}
|
|
178
|
-
return true;
|
|
179
183
|
}
|
|
180
184
|
|
|
181
185
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "babel-plugin-transform-modules-ui5",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "An unofficial babel plugin for SAP UI5.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -63,34 +63,36 @@
|
|
|
63
63
|
"object-assign-defined": "^1.0.2"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@babel/cli": "^7.21.
|
|
67
|
-
"@babel/core": "^7.
|
|
68
|
-
"@babel/eslint-parser": "^7.
|
|
66
|
+
"@babel/cli": "^7.21.5",
|
|
67
|
+
"@babel/core": "^7.22.1",
|
|
68
|
+
"@babel/eslint-parser": "^7.21.8",
|
|
69
|
+
"@babel/plugin-proposal-decorators": "^7.22.3",
|
|
69
70
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
70
71
|
"@babel/plugin-syntax-class-properties": "^7.12.13",
|
|
71
|
-
"@babel/plugin-syntax-decorators": "^7.
|
|
72
|
+
"@babel/plugin-syntax-decorators": "^7.22.3",
|
|
72
73
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
73
74
|
"@babel/plugin-syntax-object-rest-spread": "^7.8.3",
|
|
74
|
-
"@babel/plugin-transform-
|
|
75
|
-
"@babel/
|
|
76
|
-
"@babel/preset-
|
|
77
|
-
"@babel/preset-
|
|
75
|
+
"@babel/plugin-transform-property-mutators": "^7.20.7",
|
|
76
|
+
"@babel/plugin-transform-typescript": "^7.22.3",
|
|
77
|
+
"@babel/preset-env": "^7.22.2",
|
|
78
|
+
"@babel/preset-flow": "^7.21.4",
|
|
79
|
+
"@babel/preset-typescript": "^7.21.5",
|
|
78
80
|
"babel-eslint": "^10.0.3",
|
|
79
|
-
"babel-jest": "^29.
|
|
80
|
-
"core-js": "^3.
|
|
81
|
-
"eslint": "^8.
|
|
81
|
+
"babel-jest": "^29.5.0",
|
|
82
|
+
"core-js": "^3.30.2",
|
|
83
|
+
"eslint": "^8.41.0",
|
|
82
84
|
"eslint-config-standard": "^17.0.0",
|
|
83
85
|
"eslint-plugin-import": "^2.27.5",
|
|
84
86
|
"eslint-plugin-node": "^11.1.0",
|
|
85
87
|
"eslint-plugin-prettier": "^4.2.1",
|
|
86
88
|
"eslint-plugin-promise": "^6.1.1",
|
|
87
89
|
"eslint-plugin-standard": "^4.1.0",
|
|
88
|
-
"fs-extra": "^11.1.
|
|
90
|
+
"fs-extra": "^11.1.1",
|
|
89
91
|
"husky": "^8.0.3",
|
|
90
|
-
"jest": "^29.
|
|
91
|
-
"lint-staged": "^13.
|
|
92
|
-
"prettier": "^2.8.
|
|
93
|
-
"rimraf": "^
|
|
92
|
+
"jest": "^29.5.0",
|
|
93
|
+
"lint-staged": "^13.2.2",
|
|
94
|
+
"prettier": "^2.8.8",
|
|
95
|
+
"rimraf": "^5.0.1"
|
|
94
96
|
},
|
|
95
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "90e2d8ca12938f510237f02153d1e7ce03683779"
|
|
96
98
|
}
|