babel-plugin-transform-modules-ui5 7.2.6 → 7.3.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,34 @@
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.1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.3.0...v7.3.1) (2024-05-12)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * remove file extensions from imports to avoid redundant extensions ([#125](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/125)) ([e86d6f6](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/e86d6f675451b6eaaaf63f9433200cd7406d0245))
12
+ * support index modules for dependencies ([#123](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/123)) ([f510380](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/f510380f7c201d9aba3e735badea21546f81f03d))
13
+
14
+
15
+
16
+
17
+
18
+ # [7.3.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.2.6...v7.3.0) (2024-01-18)
19
+
20
+
21
+ ### Bug Fixes
22
+
23
+ * 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))
24
+
25
+
26
+ ### Features
27
+
28
+ * 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))
29
+
30
+
31
+
32
+
33
+
6
34
  ## [7.2.6](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.2.5...v7.2.6) (2023-11-23)
7
35
 
8
36
 
@@ -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 member of node.body.body) {
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
- if (!member.value) continue; // un-initialized static class prop (typescript)
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;
@@ -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
  };
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ModuleTransformVisitor = void 0;
7
+ var _path = require("path");
8
+ var _fs = require("fs");
7
9
  var _core = require("@babel/core");
8
10
  var th = _interopRequireWildcard(require("../utils/templates"));
9
11
  var ast = _interopRequireWildcard(require("../utils/ast"));
10
12
  var _jsdoc = require("../classes/helpers/jsdoc");
11
- const _excluded = ["opts"];
13
+ const _excluded = ["filename", "opts"];
12
14
  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); }
13
15
  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; }
14
16
  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; }
@@ -18,25 +20,58 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
18
20
  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
21
  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
22
  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}`;
23
+ const resolveSource = (src, filename) => {
24
+ src = src.replace(/\\/g, "/");
25
+ const dir = (0, _path.dirname)(filename);
26
+ const absoluteSrc = (0, _path.join)(dir, src);
27
+ if ((0, _fs.existsSync)(absoluteSrc) && (0, _fs.statSync)(absoluteSrc).isDirectory) {
28
+ if ((0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.js")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.jsx")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.ts")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.tsx")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.mjs")) || (0, _fs.existsSync)((0, _path.join)(absoluteSrc, "index.cjs"))) {
29
+ src = `${src}/index`;
30
+ }
31
+ }
32
+ return src;
33
+ };
22
34
  const cleanImportSource = src => src.replace(/(\/)|(-)|(@)/g, "_").replace(/\./g, "");
35
+ const tempModuleName = name => `__${name}`;
23
36
  const hasGlobalExportFlag = node => (0, _jsdoc.hasJsdocGlobalExportFlag)(node);
24
- const addModuleImport = (imports, name) => {
25
- const existingImport = imports.find(imp => imp.src === name);
37
+ const addImport = (imports, imp, filename, first) => {
38
+ const existingImport = imports.find(i => i.src === imp.src);
26
39
  if (!existingImport) {
27
- imports.unshift({
28
- src: name,
29
- name: name,
30
- tmpName: name
31
- });
40
+ // if a module ends with the file extension ".js" and it can be resolved to
41
+ // a local file having also the file extension ".js" and not ".js.js" then
42
+ // we need to slice the file extension to avoid redundant file extension
43
+ // (the require/define of UI5 always adds the file extension ".js" to the module name)
44
+ if (imp.src.indexOf(".js") != -1) {
45
+ try {
46
+ const modulePath = require.resolve(imp.src);
47
+ if (modulePath.endsWith(imp.src.split("/").pop())) {
48
+ console.log(`\x1b[33mHint:\x1b[0m Removed file extension for dependency "\x1b[34m${imp.src}\x1b[0m" found in \x1b[90m${filename}\x1b[0m`);
49
+ imp.src = imp.src.slice(0, -3);
50
+ }
51
+ } catch (ex) {
52
+ // ignore the error, do not slice file extension as the module
53
+ // can't be resolved with the given file extension, e.g.
54
+ // myns/module.js must be provided as myns/module
55
+ // myns/module.js.js must be provided as myns/module.js
56
+ }
57
+ }
58
+ imports[first ? "unshift" : "push"](imp);
32
59
  }
33
60
  };
61
+ const addModuleImport = (imports, name, filename) => {
62
+ addImport(imports, {
63
+ src: name,
64
+ name: name,
65
+ tmpName: name
66
+ }, filename, true);
67
+ };
34
68
  const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
35
69
  /*!
36
70
  * Removes the ES6 import and adds the details to the import array in our state.
37
71
  */
38
72
  ImportDeclaration(path, _ref) {
39
73
  let {
74
+ filename,
40
75
  opts = {}
41
76
  } = _ref,
42
77
  state = _objectWithoutProperties(_ref, _excluded);
@@ -49,7 +84,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
49
84
  specifiers,
50
85
  source
51
86
  } = node;
52
- const src = source.value.replace(/\\/g, "/");
87
+ const src = resolveSource(source.value, filename);
53
88
 
54
89
  // When 'libs' are used, only 'libs' will be converted to UI5 imports.
55
90
  const {
@@ -159,7 +194,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
159
194
  }
160
195
  imp.deconstructors = imp.deconstructors.concat(deconstructors);
161
196
  if (!existingImport) {
162
- this.imports.push(imp);
197
+ addImport(this.imports, imp, filename);
163
198
  }
164
199
  },
165
200
  /**
@@ -167,7 +202,9 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
167
202
  * The reason we don't export in place is to handle the situation
168
203
  * where a let or var can be defined, and the latest one should be exported.
169
204
  */
170
- ExportNamedDeclaration(path) {
205
+ ExportNamedDeclaration(path, {
206
+ filename
207
+ }) {
171
208
  const {
172
209
  node
173
210
  } = path;
@@ -179,14 +216,14 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
179
216
  let fromSource = "";
180
217
  if (source) {
181
218
  // e.g. export { one, two } from 'x'
182
- const src = source.value;
219
+ const src = resolveSource(source.value, filename);
183
220
  const name = cleanImportSource(src);
184
221
  const tmpName = tempModuleName(name);
185
- this.imports.push({
222
+ addImport(this.imports, {
186
223
  src,
187
224
  name,
188
225
  tmpName
189
- });
226
+ }, filename);
190
227
  fromSource = tmpName + ".";
191
228
  }
192
229
  if (specifiers && specifiers.length) {
@@ -229,7 +266,9 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
229
266
  return;
230
267
  }
231
268
  },
232
- ExportDefaultDeclaration(path) {
269
+ ExportDefaultDeclaration(path, {
270
+ filename
271
+ }) {
233
272
  const {
234
273
  node
235
274
  } = path;
@@ -267,15 +306,17 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
267
306
  this.defaultExport = th.exportsIdentifier;
268
307
  }
269
308
  },
270
- ExportAllDeclaration(path) {
271
- const src = path.node.source.value;
272
- const name = src.replace(/\//g, "_").replace(/\./g, "");
309
+ ExportAllDeclaration(path, {
310
+ filename
311
+ }) {
312
+ const src = resolveSource(path.node.source.value, filename);
313
+ const name = cleanImportSource(src);
273
314
  const tmpName = tempModuleName(name);
274
- this.imports.push({
315
+ addImport(this.imports, {
275
316
  src,
276
317
  name,
277
318
  tmpName
278
- });
319
+ }, filename);
279
320
  this.exportAllHelper = true;
280
321
  this.namedExports.push({
281
322
  all: true,
@@ -300,7 +341,9 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
300
341
  }));
301
342
  }
302
343
  },
303
- MemberExpression(path) {
344
+ MemberExpression(path, {
345
+ filename
346
+ }) {
304
347
  var _node$object;
305
348
  const {
306
349
  node
@@ -310,12 +353,12 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
310
353
  // replace all "import.meta.url" with "module.url"
311
354
  if ((node === null || node === void 0 || (_node$property = node.property) === null || _node$property === void 0 ? void 0 : _node$property.name) === "url") {
312
355
  path.replaceWith(_objectSpread(_objectSpread({}, node), (0, _core.template)`module.url`()));
313
- addModuleImport(this.imports, "module");
356
+ addModuleImport(this.imports, "module", filename);
314
357
  }
315
358
  // replace all "import.meta.resolve(...)" with "require.toUrl(...)"
316
359
  else if ((node === null || node === void 0 || (_node$property2 = node.property) === null || _node$property2 === void 0 ? void 0 : _node$property2.name) === "resolve") {
317
360
  path.replaceWith(_objectSpread(_objectSpread({}, node), (0, _core.template)`require.toUrl`()));
318
- addModuleImport(this.imports, "require");
361
+ addModuleImport(this.imports, "require", filename);
319
362
  }
320
363
  }
321
364
  }
@@ -49,7 +49,7 @@ function buildNamedExport(obj) {
49
49
  }
50
50
  const buildAllExportHelper = exports.buildAllExportHelper = (0, _core.template)(`
51
51
  function extendExports(exports, obj) {
52
- Object.keys(obj).forEach(function (key) {
52
+ obj && Object.keys(obj).forEach(function (key) {
53
53
  if (key === "default" || key === "__esModule") return;
54
54
  Object.defineProperty(exports, key, {
55
55
  enumerable: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-transform-modules-ui5",
3
- "version": "7.2.6",
3
+ "version": "7.3.1",
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": "915f8dba805bea185936ab5604fea135bd9c6740"
97
+ "gitHead": "aaa2b6503de89f673191f11f84879996b5b5936a"
98
98
  }