babel-plugin-transform-modules-ui5 7.1.5 → 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 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.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
+
6
17
  ## [7.1.5](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.4...v7.1.5) (2023-05-30)
7
18
 
8
19
 
@@ -68,7 +68,7 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, opts)
68
68
  return param;
69
69
  }) : member.params;
70
70
  const func = _core.types.functionExpression(member.key, params, member.body, member.generator, member.async);
71
- if (isConstructor) {
71
+ if (isConstructor && membersToAssign.length > 0) {
72
72
  // handling of parameter properties for constructors (TypeScript):
73
73
  // -> assigning parameter properties as members to the instance
74
74
  const newMembers = membersToAssign.map(member => buildMemberAssignmentStatement(_core.types.thisExpression(), {
@@ -76,9 +76,8 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, opts)
76
76
  computed: false,
77
77
  value: member
78
78
  }));
79
- _core.types.isSuperCallExpression;
80
- const idx = member.body.body.findIndex(m => _core.types.isExpressionStatement(m) && _core.types.isCallExpression(m.expression) && _core.types.isSuper(m.expression.callee));
81
- member.body.body.splice(idx === -1 ? member.body.body.length : idx + 1, 0, ...newMembers);
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);
82
81
  }
83
82
  if (member.static) {
84
83
  staticMembers.push(buildMemberAssignmentStatement(classNameIdentifier, _objectSpread(_objectSpread({}, member), {}, {
@@ -171,7 +170,7 @@ function convertClassToUI5Extend(path, node, classInfo, extraStaticProps, opts)
171
170
  extendProps.unshift(_core.types.objectProperty(_core.types.identifier(CONSTRUCTOR), constructor));
172
171
  } else {
173
172
  // Copy all except the super call from the constructor to the bindMethod (i.e. onInit)
174
- 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"))));
175
174
  }
176
175
  }
177
176
  if (boundProps.length) {
@@ -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
- // Find the Block scoped parent (Program or Function body) and search for assigned properties within that (eg. MyClass.X = "X").
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
  },
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
- const parts = dotNotationString.split(".");
170
- let node = callee;
171
- for (const nextNamePart of parts.reverse()) {
172
- if (!node) return false;
173
- // property won't be there for an anonymous function
174
- const nodeName = node.name || node.property && node.property.name;
175
- if (nodeName !== nextNamePart) return false;
176
- node = node.object;
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.1.5",
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.0",
67
- "@babel/core": "^7.21.0",
68
- "@babel/eslint-parser": "^7.19.1",
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.21.0",
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-typescript": "^7.21.0",
75
- "@babel/preset-env": "^7.20.2",
76
- "@babel/preset-flow": "^7.18.6",
77
- "@babel/preset-typescript": "^7.21.0",
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.4.3",
80
- "core-js": "^3.28.0",
81
- "eslint": "^8.34.0",
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.0",
90
+ "fs-extra": "^11.1.1",
89
91
  "husky": "^8.0.3",
90
- "jest": "^29.4.3",
91
- "lint-staged": "^13.1.2",
92
- "prettier": "^2.8.4",
93
- "rimraf": "^4.1.2"
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": "a34cbc1fe2fc53fe5ace60ac710d9579e93034bd"
97
+ "gitHead": "90e2d8ca12938f510237f02153d1e7ce03683779"
96
98
  }