babel-plugin-transform-modules-ui5 7.11.0 → 7.11.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
@@ -1,5 +1,11 @@
1
1
  # Change Log
2
2
 
3
+ ## 7.11.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#172](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/pull/172) [`99f2963`](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/99f2963f1cbb4bef4e23f60e83620a8ce7610884) Thanks [@petermuessig](https://github.com/petermuessig)! - Fix default re-exports (`export { default as X } from "./Mod"` and `export { default } from "./Mod"`) to use the same import interop as default imports, including modules that return their default value directly. Preserve dependency aliases when imports and re-exports share a source, regardless of declaration order. Producer export shapes and interop opt-out behavior remain unchanged.
8
+
3
9
  ## 7.11.0
4
10
 
5
11
  ### Minor Changes
@@ -78,6 +78,7 @@ const addImport = (imports, imp, filename, first, opts = {}) => {
78
78
  }
79
79
  imports[first ? "unshift" : "push"](imp);
80
80
  }
81
+ return existingImport || imp;
81
82
  };
82
83
  const addModuleImport = (imports, name, filename) => {
83
84
  addImport(imports, {
@@ -175,6 +176,13 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
175
176
  MODULE: _core.types.identifier(imp.tmpName),
176
177
  LOCAL: specifier.local
177
178
  }));
179
+ } else if (specifier.local.name !== imp.tmpName) {
180
+ // A previous import or re-export may already have locked the factory
181
+ // parameter name. Preserve this default import's local alias too.
182
+ deconstructors.push(th.buildConstDeclaration({
183
+ NAME: specifier.local,
184
+ VALUE: _core.types.identifier(imp.tmpName)
185
+ }));
178
186
  }
179
187
  } else if (_core.types.isImportNamespaceSpecifier(specifier)) {
180
188
  if (specifiers.length === 1 && !imp.locked) {
@@ -241,25 +249,47 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
241
249
  source
242
250
  } = node;
243
251
  if (this.noWrap) return;
244
- let fromSource = "";
252
+ if (node.exportKind === "type") return; // TS or Flow-types
253
+
254
+ let fromImport;
255
+ let shouldInterop = false;
245
256
  if (source) {
246
- // e.g. export { one, two } from 'x'
257
+ // Reuse the actual factory parameter if this dependency was imported
258
+ // earlier. Lock new records because the export expressions reference it.
247
259
  const src = resolveSource(source.value, filename);
248
260
  const name = cleanImportSource(src);
249
261
  const tmpName = tempModuleName(name);
250
- addImport(this.imports, {
262
+ fromImport = addImport(this.imports, {
251
263
  src,
252
264
  name,
253
- tmpName
265
+ tmpName,
266
+ deconstructors: [],
267
+ locked: true
254
268
  }, filename, false, opts);
255
- fromSource = tmpName + ".";
269
+ fromImport.locked = true;
270
+ shouldInterop = !this.noImportInteropPrefixesRegexp.test(src);
256
271
  }
257
272
  if (specifiers && specifiers.length) {
258
273
  // e.g. export { one, two }
259
- for (const specifier of path.node.specifiers) {
274
+ for (const specifier of specifiers) {
275
+ if (specifier.exportKind === "type") continue; // TS type-only specifier
276
+ let value = _core.types.cloneNode(specifier.local);
277
+ if (fromImport) {
278
+ const importedName = _core.types.isStringLiteral(specifier.local) ? specifier.local.value : specifier.local.name;
279
+ const module = _core.types.identifier(fromImport.tmpName);
280
+ if (importedName === "default") {
281
+ // Transformed UI5 modules can return the default value directly.
282
+ // Use exactly the same interop as a normal default import, without
283
+ // changing the producer's export shape or named export semantics.
284
+ value = shouldInterop ? _core.types.callExpression(_core.types.identifier("_interopRequireDefault"), [module]) : module;
285
+ if (shouldInterop) fromImport.interop = true;
286
+ } else {
287
+ value = _core.types.memberExpression(module, _core.types.cloneNode(specifier.local), _core.types.isStringLiteral(specifier.local));
288
+ }
289
+ }
260
290
  this.namedExports.push({
261
291
  key: specifier.exported,
262
- value: _core.types.identifier(`${fromSource}${specifier.local.name}`)
292
+ value
263
293
  });
264
294
  }
265
295
  path.remove();
@@ -341,15 +371,18 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
341
371
  const src = resolveSource(path.node.source.value, filename);
342
372
  const name = cleanImportSource(src);
343
373
  const tmpName = tempModuleName(name);
344
- addImport(this.imports, {
374
+ const imp = addImport(this.imports, {
345
375
  src,
346
376
  name,
347
- tmpName
377
+ tmpName,
378
+ deconstructors: [],
379
+ locked: true
348
380
  }, filename, false, opts);
381
+ imp.locked = true;
349
382
  this.exportAllHelper = true;
350
383
  this.namedExports.push({
351
384
  all: true,
352
- value: _core.types.identifier(tmpName)
385
+ value: _core.types.identifier(imp.tmpName)
353
386
  });
354
387
  path.remove();
355
388
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-transform-modules-ui5",
3
- "version": "7.11.0",
3
+ "version": "7.11.1",
4
4
  "description": "An unofficial babel plugin for SAP UI5.",
5
5
  "main": "dist/index.js",
6
6
  "repository": {