babel-plugin-transform-modules-ui5 7.1.0 → 7.1.2

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.2](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.1...v7.1.2) (2023-04-11)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * 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))
12
+
13
+
14
+
15
+
16
+
17
+ ## [7.1.1](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.1.0...v7.1.1) (2023-03-27)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * catch err for dynamic import to sap.ui.require ([#91](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/issues/91)) ([9c7d26e](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/9c7d26e6aeebc77f5d8faec941fbd994b77de222))
23
+
24
+
25
+
26
+
27
+
6
28
  # [7.1.0](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/compare/v7.0.6...v7.1.0) (2023-03-13)
7
29
 
8
30
 
@@ -85,25 +85,79 @@ 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
+ */
88
146
  // TODO: inject __extends instead of Object.assign unless useBuiltIns in set
89
147
  exports.buildDefaultImportDeconstructor = buildDefaultImportDeconstructor;
90
148
  const buildDynamicImportHelper = (0, _core.template)(`
91
149
  function __ui5_require_async(path) {
92
150
  return new Promise((resolve, reject) => {
93
151
  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);
152
+ module = module === null || !(typeof module === "object" && path.endsWith("/library")) ? { default: module } : module;
153
+ if (!module.__esModule) {
154
+ Object.defineProperty(module, "__esModule", { value: true });
104
155
  }
105
- })
106
- })
156
+ resolve(module);
157
+ }, (err) => {
158
+ reject(err);
159
+ });
160
+ });
107
161
  }
108
162
  `);
109
163
  exports.buildDynamicImportHelper = buildDynamicImportHelper;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "babel-plugin-transform-modules-ui5",
3
- "version": "7.1.0",
3
+ "version": "7.1.2",
4
4
  "description": "An unofficial babel plugin for SAP UI5.",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -20,6 +20,7 @@
20
20
  "lint:staged": "lint-staged",
21
21
  "test": "jest __test__ --coverage=no",
22
22
  "test:watch": "npm test -- --watch",
23
+ "test:update-snapshot": "jest --updateSnapshot",
23
24
  "prepare": "npm test && npm run build",
24
25
  "format": "prettier --write 'src/**/*.js'"
25
26
  },
@@ -91,5 +92,5 @@
91
92
  "prettier": "^2.8.4",
92
93
  "rimraf": "^4.1.2"
93
94
  },
94
- "gitHead": "02d0d23263084621d793c616f1b9344ba94967d7"
95
+ "gitHead": "f3aa113c8c8a0294648e93c466e1e298593b4c35"
95
96
  }