babel-plugin-transform-modules-ui5 7.0.4 → 7.0.6

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/dist/index.js CHANGED
@@ -1,17 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _visitor = require("./classes/visitor");
4
-
5
4
  var _visitor2 = require("./modules/visitor");
6
-
7
5
  var _wrapper = require("./modules/helpers/wrapper");
8
-
9
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
10
-
11
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
12
-
13
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
-
6
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
10
+ 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); }
15
11
  /*
16
12
  References:
17
13
  Babel Plugin Handbook: https://github.com/thejameskyle/babel-handbook/blob/master/translations/en/plugin-handbook.md
@@ -19,6 +15,7 @@ AST Spec: https://github.com/babel/babel/blob/master/packages/babel-parser/ast/s
19
15
  Babel Types (t.*) https://github.com/babel/babel/tree/master/packages/babel-types
20
16
  AST Explorer: https://astexplorer.net/
21
17
  */
18
+
22
19
  module.exports = () => {
23
20
  const UI5Visitor = _objectSpread({
24
21
  Program: {
@@ -27,20 +24,20 @@ module.exports = () => {
27
24
  }) {
28
25
  if (this.ran) return;
29
26
  this.ran = true;
30
-
31
27
  if (opts.onlyConvertNamedClass == false) {
32
28
  throw new Error("ERROR: onlyConvertNamedClass=false is no longer supported. Use autoConvertAllExtendClassesByDefault=true");
33
- } // TODO: enable this in a later version
29
+ }
30
+ // TODO: enable this in a later version
34
31
  // else if (opts.onlyConvertNamedClass == true) {
35
32
  // console.warn('WARN: onlyConvertNamedClass=true is now the default behaviour') // eslint-disable-line no-console
36
33
  // }
37
- // Opts
38
-
39
34
 
35
+ // Opts
40
36
  this.namespacePrefix = opts.namespacePrefix;
41
37
  this.noImportInteropPrefixes = opts.noImportInteropPrefixes || ["sap/"];
42
- this.noImportInteropPrefixesRegexp = new RegExp(this.noImportInteropPrefixes.map(p => `(^${p}.*)`).join("|")); // Properties for Module Transform
38
+ this.noImportInteropPrefixesRegexp = new RegExp(this.noImportInteropPrefixes.map(p => `(^${p}.*)`).join("|"));
43
39
 
40
+ // Properties for Module Transform
44
41
  this.programNode = path.node;
45
42
  this.defaultExport = null;
46
43
  this.defaultExportNode = null;
@@ -48,22 +45,21 @@ module.exports = () => {
48
45
  this.ignoredImports = [];
49
46
  this.imports = [];
50
47
  this.namedExports = [];
51
- this.injectDynamicImportHelper = false; // Properties for Class Transform
48
+ this.injectDynamicImportHelper = false;
52
49
 
53
- this.importNames = []; // The classes must be converted right away before any other class transforms get a chance to run.
50
+ // Properties for Class Transform
51
+ this.importNames = [];
54
52
 
53
+ // The classes must be converted right away before any other class transforms get a chance to run.
55
54
  path.traverse(_visitor.ClassTransformVisitor, this);
56
55
  },
57
-
58
56
  exit(path, {
59
57
  opts
60
58
  }) {
61
59
  (0, _wrapper.wrap)(this, path.node, opts);
62
60
  }
63
-
64
61
  }
65
62
  }, _visitor2.ModuleTransformVisitor);
66
-
67
63
  return {
68
64
  visitor: UI5Visitor
69
65
  };
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.collapseNamedExports = collapseNamedExports;
7
7
  exports.getDefaultExportName = getDefaultExportName;
8
-
9
8
  var _core = require("@babel/core");
10
-
11
9
  var th = _interopRequireWildcard(require("../../utils/templates"));
12
-
13
10
  var ast = _interopRequireWildcard(require("../../utils/ast"));
14
-
15
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
16
-
17
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
-
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
13
  /**
20
14
  * Collapse named exports onto the default export so that the default export can be returned directly,
21
15
  * so that exports can be easily used by code that does not include an import interop.
@@ -33,14 +27,12 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
33
27
  */
34
28
  function collapseNamedExports(programNode, defaultExport, namedExports, opts) {
35
29
  namedExports = filterOutExportsWhichAlreadyMatchPropsOnDefault(programNode, defaultExport, namedExports);
36
-
37
30
  if (!namedExports.length || opts.noExportExtend) {
38
31
  return {
39
32
  filteredExports: namedExports,
40
33
  newDefaultExportIdentifier: null
41
34
  };
42
35
  }
43
-
44
36
  if (namedExports.some(exp => exp.conflict)) {
45
37
  return {
46
38
  filteredExports: namedExports,
@@ -48,10 +40,8 @@ function collapseNamedExports(programNode, defaultExport, namedExports, opts) {
48
40
  newDefaultExportIdentifier: null
49
41
  };
50
42
  }
51
-
52
43
  let exportVariableName = getDefaultExportName(defaultExport);
53
44
  let newDefaultExportIdentifier = null;
54
-
55
45
  if (!exportVariableName) {
56
46
  // Something anonymous (literal, anon function, etc...)
57
47
  programNode.body.push(th.buildTempExport({
@@ -60,9 +50,7 @@ function collapseNamedExports(programNode, defaultExport, namedExports, opts) {
60
50
  newDefaultExportIdentifier = th.exportsIdentifier;
61
51
  exportVariableName = newDefaultExportIdentifier.name;
62
52
  }
63
-
64
53
  const id = _core.types.identifier(exportVariableName);
65
-
66
54
  for (const namedExport of namedExports) {
67
55
  programNode.body.push(th.buildAssign({
68
56
  OBJECT: id,
@@ -70,35 +58,29 @@ function collapseNamedExports(programNode, defaultExport, namedExports, opts) {
70
58
  VALUE: namedExport.value
71
59
  }));
72
60
  }
73
-
74
61
  return {
75
62
  filteredExports: [],
76
63
  conflictingExports: [],
77
64
  newDefaultExportIdentifier: newDefaultExportIdentifier
78
65
  };
79
66
  }
80
-
81
67
  function getDefaultExportName(defaultExport) {
82
68
  return defaultExport.name || ast.getIdName(defaultExport);
83
69
  }
84
-
85
70
  function filterOutExportsWhichAlreadyMatchPropsOnDefault(programNode, defaultExport, namedExports) {
86
71
  namedExports = [...namedExports]; // Shallow clone for safe splicing
72
+ const defaultObjectProperties = ast.findPropertiesOfNode(programNode, defaultExport);
87
73
 
88
- const defaultObjectProperties = ast.findPropertiesOfNode(programNode, defaultExport); // Loop through the default object's props and see if it already has a matching definition of the named exports.
74
+ // Loop through the default object's props and see if it already has a matching definition of the named exports.
89
75
  // If the definition matches, we can ignore the named export. If the definition does not match, mark it as a conflict.
90
-
91
76
  if (defaultObjectProperties) {
92
77
  for (const defaultExportProperty of defaultObjectProperties) {
93
78
  if (!defaultExportProperty.key) {
94
79
  // i.e. SpreadProperty
95
80
  continue;
96
81
  }
97
-
98
82
  const matchingNamedExportIndex = namedExports.findIndex(namedExport => namedExport.key.name === defaultExportProperty.key.name); // get the index for splicing
99
-
100
83
  const matchingNamedExport = namedExports[matchingNamedExportIndex];
101
-
102
84
  if (matchingNamedExport && !matchingNamedExport.conflict) {
103
85
  if (areSame(defaultExportProperty, matchingNamedExport)) {
104
86
  namedExports.splice(matchingNamedExportIndex, 1);
@@ -108,20 +90,16 @@ function filterOutExportsWhichAlreadyMatchPropsOnDefault(programNode, defaultExp
108
90
  }
109
91
  }
110
92
  }
111
-
112
93
  return namedExports;
113
94
  }
114
-
115
95
  function areSame(defaultExportProperty, matchingNamedExport) {
116
96
  const defaultExportValue = defaultExportProperty.value;
117
97
  const declaration = matchingNamedExport.declaration; // i.e. 'export const a = 1' or 'export let a = b'
118
-
119
98
  if (!defaultExportValue) {
120
99
  // i.e. object method
121
100
  return false; // always a conflict
122
101
  } else if (_core.types.isIdentifier(defaultExportValue)) {
123
102
  const valueName = defaultExportValue.name;
124
-
125
103
  if (valueName === matchingNamedExport.value.name) {
126
104
  // Same identifier reference. Safe to ignore
127
105
  return true;
@@ -137,8 +115,7 @@ function areSame(defaultExportProperty, matchingNamedExport) {
137
115
  // Same literal. Safe to ignore
138
116
  return true;
139
117
  }
140
- } // Either a conflicting value or no value at all (i.e. method)
141
-
142
-
118
+ }
119
+ // Either a conflicting value or no value at all (i.e. method)
143
120
  return false;
144
121
  }
@@ -4,24 +4,17 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.wrap = wrap;
7
-
8
7
  var _core = require("@babel/core");
9
-
10
8
  var eh = _interopRequireWildcard(require("./exports"));
11
-
12
9
  var th = _interopRequireWildcard(require("../../utils/templates"));
13
-
14
10
  var ast = _interopRequireWildcard(require("../../utils/ast"));
15
-
16
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
17
-
18
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
11
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
13
  function wrap(visitor, programNode, opts) {
21
14
  let {
22
15
  defaultExport,
23
16
  exportGlobal,
24
- firstImport,
17
+ firstImportMarked,
25
18
  imports,
26
19
  namedExports,
27
20
  ignoredImports,
@@ -34,62 +27,54 @@ function wrap(visitor, programNode, opts) {
34
27
  } = programNode;
35
28
  let allExportHelperAdded = false;
36
29
  let extendAdded = false;
37
- opts.collapse = !opts.noExportCollapse; // opts.extend = !opts.noExportExtend
38
- // Before adding anything, see if the named exports can be collapsed into the default export.
30
+ opts.collapse = !opts.noExportCollapse;
31
+ // opts.extend = !opts.noExportExtend
39
32
 
33
+ // Before adding anything, see if the named exports can be collapsed into the default export.
40
34
  if (defaultExport && namedExports.length && opts.collapse) {
41
35
  let {
42
36
  filteredExports,
43
37
  conflictingExports,
44
38
  newDefaultExportIdentifier
45
39
  } = eh.collapseNamedExports(programNode, defaultExport, namedExports, opts);
46
-
47
40
  if (filteredExports.length && !opts.allowUnsafeMixedExports) {
48
41
  throw new Error(`Unsafe mixing of conflicting default and named exports. The following named exports are conflicting: (${ast.getPropNames(conflictingExports).join(", ")}).`);
49
42
  } else {
50
43
  namedExports = filteredExports;
51
- } // The default export may have changed if the collapse logic needed to assign a prop when the default export was previously anonymous.
52
-
44
+ }
53
45
 
46
+ // The default export may have changed if the collapse logic needed to assign a prop when the default export was previously anonymous.
54
47
  if (newDefaultExportIdentifier) {
55
48
  extendAdded = true; // If an anonymous default export needed to be assigned to a a variable, it uses the exports name for convenience.
56
-
57
49
  defaultExport = newDefaultExportIdentifier;
58
50
  }
59
51
  }
60
-
61
- const preDefine = [...ignoredImports]; // If the noWrapBeforeImport opt is set, split any code before the first import and afterwards into separate arrays.
52
+ const preDefine = [...ignoredImports];
53
+ // If the noWrapBeforeImport opt is set, split any code before the first import and afterwards into separate arrays.
62
54
  // This should be done before any interops or other vars are injected.
63
-
64
- if (opts.noWrapBeforeImport && firstImport) {
55
+ if (opts.noWrapBeforeImport && firstImportMarked) {
65
56
  let reachedFirstImport = false;
66
57
  const fullBody = body;
67
58
  const newBody = [];
68
-
69
59
  for (const item of fullBody) {
70
- if (item === firstImport) {
71
- reachedFirstImport = true;
72
- }
73
-
74
60
  if (reachedFirstImport) {
75
61
  newBody.push(item);
76
62
  } else {
77
63
  preDefine.push(item);
78
64
  }
65
+ if (item.lastBeforeWrapping) {
66
+ reachedFirstImport = true;
67
+ }
79
68
  }
80
-
81
69
  if (preDefine.length && !hasUseStrict(programNode)) {
82
70
  programNode.directives = [_core.types.directive(_core.types.directiveLiteral("use strict")), ...(programNode.directives || [])];
83
71
  }
84
-
85
72
  body = newBody;
86
73
  }
87
-
88
74
  if (injectDynamicImportHelper) {
89
75
  // import() to sap.ui.require() w/ promise and interop
90
76
  body.unshift(th.buildDynamicImportHelper());
91
77
  }
92
-
93
78
  if (!namedExports.length && defaultExport) {
94
79
  // If there's no named exports, return the default export
95
80
  body.push(_core.types.returnStatement(defaultExport));
@@ -104,7 +89,6 @@ function wrap(visitor, programNode, opts) {
104
89
  body.push(th.buildAllExportHelper());
105
90
  allExportHelperAdded = true;
106
91
  }
107
-
108
92
  body.push(th.buildAllExport({
109
93
  LOCAL: namedExport.value
110
94
  }));
@@ -112,28 +96,22 @@ function wrap(visitor, programNode, opts) {
112
96
  body.push(th.buildNamedExport(namedExport));
113
97
  }
114
98
  }
115
-
116
99
  if (defaultExport) {
117
100
  body.push(th.buildNamedExport({
118
101
  key: _core.types.identifier("default"),
119
102
  value: defaultExport
120
103
  }));
121
104
  }
122
-
123
105
  body.push(th.buildReturnExports());
124
106
  }
125
-
126
107
  if (imports.some(imp => imp.interop)) {
127
108
  body.unshift(th.buildDefaultImportInterop());
128
109
  }
129
-
130
110
  programNode.body = [...preDefine, generateDefine(body, imports, exportGlobal || opts.exportAllGlobal)];
131
111
  }
132
-
133
112
  function hasUseStrict(node) {
134
113
  return (node.directives || []).some(directive => directive.value.value === "use strict");
135
114
  }
136
-
137
115
  function generateDefine(body, imports, exportGlobal) {
138
116
  const defineOpts = {
139
117
  SOURCES: _core.types.arrayExpression(imports.map(i => _core.types.stringLiteral(i.src))),
@@ -4,45 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ModuleTransformVisitor = void 0;
7
-
8
7
  var _core = require("@babel/core");
9
-
10
8
  var th = _interopRequireWildcard(require("../utils/templates"));
11
-
12
9
  var ast = _interopRequireWildcard(require("../utils/ast"));
13
-
14
10
  var _jsdoc = require("../classes/helpers/jsdoc");
15
-
16
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
17
-
18
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
21
-
22
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
-
24
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
-
11
+ const _excluded = ["opts"];
12
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
15
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
16
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
18
+ 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); }
26
19
  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; }
27
-
28
20
  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; }
29
-
30
21
  const tempModuleName = name => `__${name}`;
31
-
32
22
  const cleanImportSource = src => src.replace(/(\/)|(-)|(@)/g, "_").replace(/\./g, "");
33
-
34
23
  const hasGlobalExportFlag = node => (0, _jsdoc.hasJsdocGlobalExportFlag)(node);
35
-
36
24
  const ModuleTransformVisitor = {
37
25
  /*!
38
26
  * Removes the ES6 import and adds the details to the import array in our state.
39
27
  */
40
28
  ImportDeclaration(path, _ref) {
41
29
  let {
42
- opts = {}
43
- } = _ref,
44
- state = _objectWithoutProperties(_ref, ["opts"]);
45
-
30
+ opts = {}
31
+ } = _ref,
32
+ state = _objectWithoutProperties(_ref, _excluded);
46
33
  const {
47
34
  node
48
35
  } = path;
@@ -52,23 +39,24 @@ const ModuleTransformVisitor = {
52
39
  specifiers,
53
40
  source
54
41
  } = node;
55
- const src = source.value.replace(/\\/g, "/"); // When 'libs' are used, only 'libs' will be converted to UI5 imports.
42
+ const src = source.value.replace(/\\/g, "/");
56
43
 
44
+ // When 'libs' are used, only 'libs' will be converted to UI5 imports.
57
45
  const {
58
46
  libs = [".*"]
59
47
  } = opts;
60
48
  const isLibToConvert = new RegExp(`(${libs.join("|")})`).test(src);
61
-
62
49
  if (!isLibToConvert) {
63
50
  this.ignoredImports.push(node);
64
51
  path.remove();
65
52
  return;
66
- } //const testSrc = (opts.libs || ["^sap/"]).concat(opts.files || []);
53
+ }
54
+
55
+ //const testSrc = (opts.libs || ["^sap/"]).concat(opts.files || []);
67
56
  // const isUi5SrcRE = testSrc.length && new RegExp(`(${testSrc.join("|")})`);
68
57
  // const isUi5Src = isUi5SrcRE.test(src);
69
- // Importing using an interop is the default behaviour but can be opt-out using regex.
70
-
71
58
 
59
+ // Importing using an interop is the default behaviour but can be opt-out using regex.
72
60
  const shouldInterop = !this.noImportInteropPrefixesRegexp.test(src);
73
61
  const name = cleanImportSource(src); // default to the src for import without named var
74
62
 
@@ -83,8 +71,9 @@ const ModuleTransformVisitor = {
83
71
  file: {
84
72
  opts: state.file.opts
85
73
  }
86
- }) : modulesMap[src]) || src; // Note that existingImport may get mutated if there are multiple import lines from the same module.
74
+ }) : modulesMap[src]) || src;
87
75
 
76
+ // Note that existingImport may get mutated if there are multiple import lines from the same module.
88
77
  const existingImport = this.imports.find(imp => imp.src === mappedSrc);
89
78
  const imp = existingImport || {
90
79
  src: mappedSrc,
@@ -100,21 +89,20 @@ const ModuleTransformVisitor = {
100
89
  locked: false
101
90
  };
102
91
  const deconstructors = [];
103
-
104
92
  for (const specifier of specifiers) {
105
93
  if (_core.types.isImportDefaultSpecifier(specifier)) {
106
94
  // e.g. import X from 'X'
107
95
  imp.default = true;
108
- imp.interop = shouldInterop; // Shorten the imported-as name since it should be unique for default imports.
96
+ imp.interop = shouldInterop;
97
+
98
+ // Shorten the imported-as name since it should be unique for default imports.
109
99
  // The default import should always come first,
110
100
  // so this new name will be used for destructuring the other too.
111
-
112
101
  if (!imp.locked) {
113
102
  imp.name = specifier.local.name;
114
103
  imp.tmpName = shouldInterop ? tempModuleName(imp.name) : imp.name;
115
104
  imp.locked = true;
116
105
  }
117
-
118
106
  if (shouldInterop) {
119
107
  deconstructors.push(th.buildDefaultImportDeconstructor({
120
108
  MODULE: _core.types.identifier(imp.tmpName),
@@ -148,24 +136,22 @@ const ModuleTransformVisitor = {
148
136
  }
149
137
  }
150
138
 
139
+ // this is the very first import in noWrapBeforeImport mode and there are sibling nodes before this import
140
+ if (opts.noWrapBeforeImport && !this.firstImportMarked && path.inList && path.key > 0) {
141
+ // mark the direct predecessor as the last one to exclude from wrapping
142
+ path.getSibling(path.key - 1).node.lastBeforeWrapping = true;
143
+ this.firstImportMarked = true;
144
+ }
151
145
  path.replaceWithMultiple(deconstructors);
152
-
153
146
  if (deconstructors.length) {
154
147
  // Keep the same variable name if the same module is imported on another line.
155
148
  imp.locked = true;
156
149
  }
157
-
158
- imp.deconstructors = imp.deconstructors.concat(deconstructors); // TODO: now that we're saving deconstructors on the import, dynamically determine firstImport if needed.
159
-
160
- if (!this.firstImport && imp.deconstructors[0]) {
161
- this.firstImport = imp.deconstructors[0];
162
- }
163
-
150
+ imp.deconstructors = imp.deconstructors.concat(deconstructors);
164
151
  if (!existingImport) {
165
152
  this.imports.push(imp);
166
153
  }
167
154
  },
168
-
169
155
  /**
170
156
  * Push all exports to an array.
171
157
  * The reason we don't export in place is to handle the situation
@@ -181,7 +167,6 @@ const ModuleTransformVisitor = {
181
167
  source
182
168
  } = node;
183
169
  let fromSource = "";
184
-
185
170
  if (source) {
186
171
  // e.g. export { one, two } from 'x'
187
172
  const src = source.value;
@@ -194,7 +179,6 @@ const ModuleTransformVisitor = {
194
179
  });
195
180
  fromSource = tmpName + ".";
196
181
  }
197
-
198
182
  if (specifiers && specifiers.length) {
199
183
  // e.g. export { one, two }
200
184
  for (const specifier of path.node.specifiers) {
@@ -203,18 +187,14 @@ const ModuleTransformVisitor = {
203
187
  value: _core.types.identifier(`${fromSource}${specifier.local.name}`)
204
188
  });
205
189
  }
206
-
207
190
  path.remove();
208
191
  } else if (declaration) {
209
192
  // e.g. export const c = 1 | export function f() {}
210
193
  if (["TypeAlias", "InterfaceDeclaration", "TSInterfaceDeclaration", "TSTypeAliasDeclaration"].includes(declaration.type)) return; // TS or Flow-types
211
-
212
194
  const name = ast.getIdName(declaration);
213
-
214
195
  if (name) {
215
196
  // e.g. export function f() {}
216
197
  const id = _core.types.identifier(declaration.id.name);
217
-
218
198
  this.namedExports.push({
219
199
  key: id,
220
200
  value: id,
@@ -224,7 +204,6 @@ const ModuleTransformVisitor = {
224
204
  // e.g. export const c = 1
225
205
  for (const subDeclaration of declaration.declarations) {
226
206
  const id = _core.types.identifier(subDeclaration.id.name);
227
-
228
207
  this.namedExports.push({
229
208
  value: id,
230
209
  key: id,
@@ -234,14 +213,12 @@ const ModuleTransformVisitor = {
234
213
  } else {
235
214
  throw path.buildCodeFrameError("Unknown ExportNamedDeclaration shape.");
236
215
  }
237
-
238
216
  path.replaceWith(declaration);
239
217
  } else {
240
218
  path.remove();
241
219
  return;
242
220
  }
243
221
  },
244
-
245
222
  ExportDefaultDeclaration(path) {
246
223
  const {
247
224
  node
@@ -250,12 +227,10 @@ const ModuleTransformVisitor = {
250
227
  declaration
251
228
  } = node;
252
229
  const declarationName = ast.getIdName(declaration);
253
-
254
230
  if (hasGlobalExportFlag(node)) {
255
231
  // check for jsdoc @export
256
232
  this.exportGlobal = true;
257
233
  }
258
-
259
234
  if (declarationName) {
260
235
  // ClassDeclaration or FunctionDeclaration with name.
261
236
  // Leave the declaration in-line and preserve the identifier for the return statement.
@@ -275,7 +250,6 @@ const ModuleTransformVisitor = {
275
250
  } = declaration;
276
251
  declaration = _core.types.functionExpression(null, params, body, generator, isAsync);
277
252
  }
278
-
279
253
  const exportDeclaration = th.buildTempExport({
280
254
  VALUE: declaration
281
255
  });
@@ -283,7 +257,6 @@ const ModuleTransformVisitor = {
283
257
  this.defaultExport = th.exportsIdentifier;
284
258
  }
285
259
  },
286
-
287
260
  ExportAllDeclaration(path) {
288
261
  const src = path.node.source.value;
289
262
  const name = src.replace(/\//g, "_").replace(/\./g, "");
@@ -300,7 +273,6 @@ const ModuleTransformVisitor = {
300
273
  });
301
274
  path.remove();
302
275
  },
303
-
304
276
  /*!
305
277
  * Visits function calls to handle for dynamic imports.
306
278
  */
@@ -311,14 +283,12 @@ const ModuleTransformVisitor = {
311
283
  const {
312
284
  callee
313
285
  } = node;
314
-
315
286
  if (ast.isImport(callee)) {
316
287
  this.injectDynamicImportHelper = true;
317
- path.replaceWith(_objectSpread({}, node, {
288
+ path.replaceWith(_objectSpread(_objectSpread({}, node), {}, {
318
289
  callee: _core.types.identifier("__ui5_require_async")
319
290
  }));
320
291
  }
321
292
  }
322
-
323
293
  };
324
294
  exports.ModuleTransformVisitor = ModuleTransformVisitor;