babel-plugin-transform-modules-ui5 7.1.5 → 7.2.1

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,29 @@
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.1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.2.0...v7.2.1) (2023-06-13)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * add support for import.meta.url|resolve ([#106](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/106)) ([afb1e6d](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/afb1e6daa0fcc9896fd184ac9d66990d0a29214a)), closes [#103](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/103)
12
+ * support for anonymous classes ([#105](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/105)) ([64773d1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/64773d180bf65e544806b9f04b7334cd76831b3d)), closes [#104](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/104)
13
+
14
+
15
+
16
+
17
+
18
+ # [7.2.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.5...v7.2.0) (2023-05-30)
19
+
20
+
21
+ ### Features
22
+
23
+ * 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)
24
+
25
+
26
+
27
+
28
+
6
29
  ## [7.1.5](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.4...v7.1.5) (2023-05-30)
7
30
 
8
31
 
@@ -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,12 +26,12 @@ const ClassTransformVisitor = {
26
26
  file,
27
27
  opts = {}
28
28
  }) {
29
+ var _node$id, _node$decorators;
29
30
  const {
30
- node,
31
- parent,
32
- parentPath
31
+ node
33
32
  } = path;
34
- if (opts.neverConvertClass) {
33
+ const className = node === null || node === void 0 ? void 0 : (_node$id = node.id) === null || _node$id === void 0 ? void 0 : _node$id.name;
34
+ if (!className || opts.neverConvertClass) {
35
35
  return;
36
36
  }
37
37
  if (!doesClassExtendFromImport(node, [...this.importNames])) {
@@ -42,19 +42,45 @@ const ClassTransformVisitor = {
42
42
  // If the super class is one of the imports, we'll assume it's a UI5 managed class,
43
43
  // and therefore may need to be transformed to .extend() syntax.
44
44
  const classInfo = classes.getClassInfo(path, node, path.parent, opts);
45
- if (!shouldConvertClass(file, node, opts, classInfo)) {
46
- return;
45
+
46
+ // filter found decorators (to be not handled by other plugins)
47
+ node.decorators = (_node$decorators = node.decorators) === null || _node$decorators === void 0 ? void 0 : _node$decorators.filter(d => {
48
+ var _exp$callee;
49
+ const exp = d.expression;
50
+ const name = exp.name || ((_exp$callee = exp.callee) === null || _exp$callee === void 0 ? void 0 : _exp$callee.name);
51
+ return classInfo[name] === undefined;
52
+ });
53
+ if (shouldConvertClass(file, node, opts, classInfo)) {
54
+ // Save super class name for converting super calls
55
+ this.superClassName = classInfo.superClassName;
56
+ // store the classinfo
57
+ if (className) {
58
+ this.classInfo = this.classInfo || {};
59
+ this.classInfo[className] = classInfo;
60
+ }
47
61
  }
62
+ },
63
+ exit(path, {
64
+ opts = {}
65
+ }) {
66
+ var _node$id2, _this$classInfo;
67
+ const {
68
+ node,
69
+ parent,
70
+ parentPath
71
+ } = path;
72
+ const className = node === null || node === void 0 ? void 0 : (_node$id2 = node.id) === null || _node$id2 === void 0 ? void 0 : _node$id2.name;
48
73
 
49
- // Save super class name for converting super calls
50
- this.superClassName = classInfo.superClassName;
74
+ // Only if classinfo has been found we process this file
75
+ const classInfo = (_this$classInfo = this.classInfo) === null || _this$classInfo === void 0 ? void 0 : _this$classInfo[className];
76
+ if (!classInfo || !node.superClass) {
77
+ return;
78
+ }
51
79
 
52
80
  // Find the Block scoped parent (Program or Function body) and search for assigned properties within that (eg. MyClass.X = "X").
53
- const {
54
- name: className
55
- } = node.id;
56
81
  const blockParent = path.findParent(path => path.isBlock()).node;
57
82
  const staticProps = ast.groupPropertiesByName(ast.getOtherPropertiesOfIdentifier(blockParent, className));
83
+
58
84
  // TODO: flag metadata and renderer for removal if applicable
59
85
  const ui5ExtendClass = classes.convertClassToUI5Extend(path, node, classInfo, staticProps, opts);
60
86
  if (path.isClassDeclaration()) {
@@ -76,8 +102,6 @@ const ClassTransformVisitor = {
76
102
  }
77
103
  parentPath.replaceWithMultiple(ui5ExtendClass);
78
104
  }
79
- },
80
- exit() {
81
105
  this.superClassName = null;
82
106
  }
83
107
  },
@@ -21,6 +21,16 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
21
21
  const tempModuleName = name => `__${name}`;
22
22
  const cleanImportSource = src => src.replace(/(\/)|(-)|(@)/g, "_").replace(/\./g, "");
23
23
  const hasGlobalExportFlag = node => (0, _jsdoc.hasJsdocGlobalExportFlag)(node);
24
+ const addModuleImport = (imports, name) => {
25
+ const existingImport = imports.find(imp => imp.src === name);
26
+ if (!existingImport) {
27
+ imports.unshift({
28
+ src: name,
29
+ name: name,
30
+ tmpName: name
31
+ });
32
+ }
33
+ };
24
34
  const ModuleTransformVisitor = {
25
35
  /*!
26
36
  * Removes the ES6 import and adds the details to the import array in our state.
@@ -289,6 +299,25 @@ const ModuleTransformVisitor = {
289
299
  callee: _core.types.identifier("__ui5_require_async")
290
300
  }));
291
301
  }
302
+ },
303
+ MemberExpression(path) {
304
+ var _node$object;
305
+ const {
306
+ node
307
+ } = path;
308
+ if ((node === null || node === void 0 ? void 0 : (_node$object = node.object) === null || _node$object === void 0 ? void 0 : _node$object.type) === "MetaProperty") {
309
+ var _node$property, _node$property2;
310
+ // replace all "import.meta.url" with "module.url"
311
+ if ((node === null || node === void 0 ? void 0 : (_node$property = node.property) === null || _node$property === void 0 ? void 0 : _node$property.name) === "url") {
312
+ path.replaceWith(_objectSpread(_objectSpread({}, node), (0, _core.template)`module.url`()));
313
+ addModuleImport(this.imports, "module");
314
+ }
315
+ // replace all "import.meta.resolve(...)" with "require.toUrl(...)"
316
+ else if ((node === null || node === void 0 ? void 0 : (_node$property2 = node.property) === null || _node$property2 === void 0 ? void 0 : _node$property2.name) === "resolve") {
317
+ path.replaceWith(_objectSpread(_objectSpread({}, node), (0, _core.template)`require.toUrl`()));
318
+ addModuleImport(this.imports, "require");
319
+ }
320
+ }
292
321
  }
293
322
  };
294
323
  exports.ModuleTransformVisitor = ModuleTransformVisitor;
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.1",
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": "c2412968863ebeddb8c7c8cc26794759dc83c37b"
96
98
  }