babel-plugin-transform-modules-ui5 7.1.1 → 7.1.3

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,28 @@
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.1.3](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.2...v7.1.3) (2023-04-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * dynamic import must not handle __esModule flagged modules ([#93](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/93)) ([b269985](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/b26998540cac0c2c2868bd59198d6f9abfaab8f7))
12
+
13
+
14
+
15
+
16
+
17
+ ## [7.1.2](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.1...v7.1.2) (2023-04-11)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * dynamic imports of empty modules must not fail ([#92](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/92)) ([a1de75d](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/a1de75dcfcb577bf6fea3669cf448e9183b7d636))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [7.1.1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.0...v7.1.1) (2023-03-27)
7
29
 
8
30
 
@@ -85,23 +85,83 @@ const buildDefaultImportDeconstructor = (0, _core.template)(`
85
85
  const LOCAL = _interopRequireDefault(MODULE);
86
86
  `);
87
87
 
88
+ /*
89
+ * Scenarios for dynamic exports:
90
+ *
91
+ * 1.) ES module with no exports
92
+ *
93
+ * (await import("./moduleWithNoExports.js")) ==> Module
94
+ * (await import("./moduleWithNoExports.js")).default ==> undefined
95
+ *
96
+ * 2.) ES module with default export
97
+ *
98
+ * (await import("./moduleWithDefaultExport.js")) ==> Module
99
+ * (await import("./moduleWithDefaultExport.js")).default ==> DefaultExport
100
+ *
101
+ * 3.) ES module with named exports
102
+ *
103
+ * (await import("./moduleWithNamedExport.js")) ==> Module
104
+ * (await import("./moduleWithNamedExport.js")).default ==> undefined
105
+ * (await import("./moduleWithNamedExport.js")).NamedExport ==> NamedExport
106
+ *
107
+ * A Module object is always returned by the dynamic import.
108
+ *
109
+ * ---
110
+ *
111
+ * The dynamic import script template simulates the default and named exports
112
+ * for non-ES modules so that the TypeScript code completion can be properly
113
+ * used. The template below is used to translate dynamic imports to sap.ui.require
114
+ * calls which are typically be used for the following scenarios:
115
+ *
116
+ * 1.) UI5 Libraries
117
+ *
118
+ * A UI5 library exports its complete namespace and all available
119
+ * types/enums/... are accessible as named properties on that
120
+ * namespace, e.g.:
121
+ *
122
+ * (await import("sap/m/library")) => { __esModule: true, ... }
123
+ * (await import("sap/m/library")).default => undefined
124
+ * (await import("sap/m/library")).ButtonType => sap/m/ButtonType
125
+ *
126
+ * 2.) UI5 Classes
127
+ *
128
+ * A UI5 class exports itself as default. When importing a UI5 class
129
+ * it is expected to be accessible via the default property.
130
+ *
131
+ * (await import("sap/m/Button")) => { __esModule: true, ... }
132
+ * (await import("sap/m/Button")).default => sap/m/Button
133
+ *
134
+ * 3.) Static Helpers (sap/m/MessageBox)
135
+ *
136
+ * (await import("sap/m/MessageBox")) => { __esModule: true, ... }
137
+ * (await import("sap/m/MessageBox")).default => sap/m/MessageBox
138
+ * (await import("sap/m/MessageBox")).Action => undefined
139
+ * (await import("sap/m/MessageBox")).default.Action => sap/m/MessageBox.Action
140
+ *
141
+ * 4.) undefined or null (no exports)
142
+ *
143
+ * (await import("./non/exporting/module")) => { __esModule: true, ... }
144
+ * (await import("./non/exporting/module")) => undefined
145
+ *
146
+ * 5.) Other dependencies (jsPDF)
147
+ *
148
+ * (await import("jsPDF")) => { __esModule: true, jsPDF: ?, ... }
149
+ * (await import("sap/m/MessageBox")).jsPDF => jsPDF
150
+ *
151
+ * When requiring other dependencies they are already flagged as __esModule
152
+ * and must not be processed in our dynamic import to require handler.
153
+ */
88
154
  // TODO: inject __extends instead of Object.assign unless useBuiltIns in set
89
155
  exports.buildDefaultImportDeconstructor = buildDefaultImportDeconstructor;
90
156
  const buildDynamicImportHelper = (0, _core.template)(`
91
157
  function __ui5_require_async(path) {
92
158
  return new Promise((resolve, reject) => {
93
159
  sap.ui.require([path], (module) => {
94
- if (!module) {
95
- return reject("No module returned from " + path);
96
- } else if (module.__esModule) {
97
- return resolve(module);
98
- } else if (module.default) {
99
- return reject(new Error(path + " module includes a 'default' property but not __esModule. Cannot use as dynamic import"));
100
- } else {
101
- module.default = typeof module === "object" ? Object.assign({}, module) : module;
102
- module.__esModule = true;
103
- resolve(module);
160
+ if (!module.__esModule) {
161
+ module = module === null || !(typeof module === "object" && path.endsWith("/library")) ? { default: module } : module;
162
+ Object.defineProperty(module, "__esModule", { value: true });
104
163
  }
164
+ resolve(module);
105
165
  }, (err) => {
106
166
  reject(err);
107
167
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-transform-modules-ui5",
3
- "version": "7.1.1",
3
+ "version": "7.1.3",
4
4
  "description": "An unofficial babel plugin for SAP UI5.",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -92,5 +92,5 @@
92
92
  "prettier": "^2.8.4",
93
93
  "rimraf": "^4.1.2"
94
94
  },
95
- "gitHead": "e7dd55f8a73fa37f31267372da5ac3d441e26e3e"
95
+ "gitHead": "54a5521dea19fedd9cd53f7aeabc5e383e926303"
96
96
  }