babel-plugin-transform-modules-ui5 7.9.0 → 7.10.0
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 +17 -0
- package/dist/index.js +2 -0
- package/dist/modules/helpers/wrapper.js +9 -3
- package/dist/modules/visitor.js +13 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 7.10.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#154](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/pull/154) [`f62f9fb`](https://github.com/ui5-community/babel-plugin-transform-modules-ui5/commit/f62f9fba1a64dea2673662dd163fcc1eb5cff540) Thanks [@bbogovich-sap](https://github.com/bbogovich-sap)! - Add two comment pragmas to opt out of module transformation:
|
|
8
|
+
|
|
9
|
+
- `/* @ui5-no-wrap */` (file level) leaves a module completely unwrapped —
|
|
10
|
+
no `sap.ui.define`/`sap.ui.require` and no import/export rewriting — while
|
|
11
|
+
still stripping TypeScript types. Intended for modules consumed as native
|
|
12
|
+
ES modules, e.g. web workers.
|
|
13
|
+
- `/* @ui5-ignore-import */` (statement level) excludes a single static
|
|
14
|
+
`import` or dynamic `import()` from being converted into a UI5 dependency.
|
|
15
|
+
|
|
16
|
+
Note: `@ui5-ignore-import` on a static import only yields valid output in an
|
|
17
|
+
unwrapped module (no exports, or together with `@ui5-no-wrap`); a leftover
|
|
18
|
+
ES `import` inside a `sap.ui.define` factory is not valid at runtime.
|
|
19
|
+
|
|
3
20
|
## 7.9.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ module.exports = () => {
|
|
|
23
23
|
enter(path, {
|
|
24
24
|
opts
|
|
25
25
|
}) {
|
|
26
|
+
var _path$parent$comments, _path$parent;
|
|
26
27
|
if (this.ran) return;
|
|
27
28
|
this.ran = true;
|
|
28
29
|
if (opts.onlyConvertNamedClass == false) {
|
|
@@ -48,6 +49,7 @@ module.exports = () => {
|
|
|
48
49
|
this.imports = [];
|
|
49
50
|
this.namedExports = [];
|
|
50
51
|
this.injectDynamicImportHelper = false;
|
|
52
|
+
this.noWrap = ((_path$parent$comments = (_path$parent = path.parent) === null || _path$parent === void 0 ? void 0 : _path$parent.comments) !== null && _path$parent$comments !== void 0 ? _path$parent$comments : []).some(c => c.type === "CommentBlock" && c.value.trim() === "@ui5-no-wrap");
|
|
51
53
|
|
|
52
54
|
// Properties for Class Transform
|
|
53
55
|
this.importNames = [];
|
|
@@ -10,7 +10,10 @@ var th = _interopRequireWildcard(require("../../utils/templates"));
|
|
|
10
10
|
var ast = _interopRequireWildcard(require("../../utils/ast"));
|
|
11
11
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
12
12
|
function wrap(visitor, programNode, opts) {
|
|
13
|
-
var _body;
|
|
13
|
+
var _visitor$parent$comme, _visitor$parent, _body;
|
|
14
|
+
if (hasNoWrapPragma((_visitor$parent$comme = (_visitor$parent = visitor.parent) === null || _visitor$parent === void 0 ? void 0 : _visitor$parent.comments) !== null && _visitor$parent$comme !== void 0 ? _visitor$parent$comme : [])) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
14
17
|
let {
|
|
15
18
|
defaultExport,
|
|
16
19
|
exportGlobal,
|
|
@@ -48,8 +51,8 @@ function wrap(visitor, programNode, opts) {
|
|
|
48
51
|
// is associcated with the program and not the program body, so we need to find it
|
|
49
52
|
// and move it to the new program body (which is sap.ui.define)
|
|
50
53
|
if (!copyright) {
|
|
51
|
-
var _visitor$
|
|
52
|
-
copyright = (_visitor$
|
|
54
|
+
var _visitor$parent2;
|
|
55
|
+
copyright = (_visitor$parent2 = visitor.parent) === null || _visitor$parent2 === void 0 || (_visitor$parent2 = _visitor$parent2.comments) === null || _visitor$parent2 === void 0 ? void 0 : _visitor$parent2.find((comment, idx, arr) => {
|
|
53
56
|
if (comment.value.startsWith("!")) {
|
|
54
57
|
arr.splice(idx, 1);
|
|
55
58
|
return true;
|
|
@@ -181,6 +184,9 @@ function wrap(visitor, programNode, opts) {
|
|
|
181
184
|
function hasUseStrict(node) {
|
|
182
185
|
return (node.directives || []).some(directive => directive.value.value === "use strict");
|
|
183
186
|
}
|
|
187
|
+
function hasNoWrapPragma(comments) {
|
|
188
|
+
return comments.some(comment => comment.type === "CommentBlock" && comment.value.trim() === "@ui5-no-wrap");
|
|
189
|
+
}
|
|
184
190
|
function hasUseSapUiRequire(comments, body, remove) {
|
|
185
191
|
// detect the @sapUiRequire comment
|
|
186
192
|
return comments.some(comment => {
|
package/dist/modules/visitor.js
CHANGED
|
@@ -94,7 +94,8 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
94
94
|
node
|
|
95
95
|
} = path;
|
|
96
96
|
if (node.importKind === "type") return; // flow-type
|
|
97
|
-
|
|
97
|
+
if (this.noWrap) return;
|
|
98
|
+
if (hasIgnoreImportPragma(node)) return;
|
|
98
99
|
const {
|
|
99
100
|
specifiers,
|
|
100
101
|
source
|
|
@@ -232,6 +233,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
232
233
|
declaration,
|
|
233
234
|
source
|
|
234
235
|
} = node;
|
|
236
|
+
if (this.noWrap) return;
|
|
235
237
|
let fromSource = "";
|
|
236
238
|
if (source) {
|
|
237
239
|
// e.g. export { one, two } from 'x'
|
|
@@ -289,6 +291,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
289
291
|
const {
|
|
290
292
|
node
|
|
291
293
|
} = path;
|
|
294
|
+
if (this.noWrap) return;
|
|
292
295
|
let {
|
|
293
296
|
declaration
|
|
294
297
|
} = node;
|
|
@@ -326,6 +329,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
326
329
|
ExportAllDeclaration(path, {
|
|
327
330
|
filename
|
|
328
331
|
}) {
|
|
332
|
+
if (this.noWrap) return;
|
|
329
333
|
const src = resolveSource(path.node.source.value, filename);
|
|
330
334
|
const name = cleanImportSource(src);
|
|
331
335
|
const tmpName = tempModuleName(name);
|
|
@@ -351,7 +355,9 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
351
355
|
const {
|
|
352
356
|
callee
|
|
353
357
|
} = node;
|
|
358
|
+
if (this.noWrap) return;
|
|
354
359
|
if (ast.isImport(callee)) {
|
|
360
|
+
if (hasIgnoreImportPragma(path.getStatementParent().node)) return;
|
|
355
361
|
this.injectDynamicImportHelper = true;
|
|
356
362
|
path.replaceWith(_objectSpread(_objectSpread({}, node), {}, {
|
|
357
363
|
callee: _core.types.identifier("__ui5_require_async")
|
|
@@ -365,6 +371,7 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
365
371
|
const {
|
|
366
372
|
node
|
|
367
373
|
} = path;
|
|
374
|
+
if (this.noWrap) return;
|
|
368
375
|
if ((node === null || node === void 0 || (_node$object = node.object) === null || _node$object === void 0 ? void 0 : _node$object.type) === "MetaProperty") {
|
|
369
376
|
var _node$property, _node$property2;
|
|
370
377
|
// replace all "import.meta.url" with "module.url"
|
|
@@ -379,4 +386,8 @@ const ModuleTransformVisitor = exports.ModuleTransformVisitor = {
|
|
|
379
386
|
}
|
|
380
387
|
}
|
|
381
388
|
}
|
|
382
|
-
};
|
|
389
|
+
};
|
|
390
|
+
function hasIgnoreImportPragma(node) {
|
|
391
|
+
var _node$leadingComments;
|
|
392
|
+
return ((_node$leadingComments = node.leadingComments) !== null && _node$leadingComments !== void 0 ? _node$leadingComments : []).some(comment => comment.type === "CommentBlock" && comment.value.trim() === "@ui5-ignore-import");
|
|
393
|
+
}
|