babel-plugin-transform-modules-ui5 7.0.5 → 7.1.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 +19 -0
- package/LICENSE +21 -0
- package/dist/classes/helpers/classes.js +28 -60
- package/dist/classes/helpers/decorators.js +0 -10
- package/dist/classes/helpers/jsdoc.js +9 -34
- package/dist/classes/visitor.js +17 -48
- package/dist/index.js +15 -19
- package/dist/modules/helpers/exports.js +6 -29
- package/dist/modules/helpers/wrapper.js +14 -36
- package/dist/modules/visitor.js +30 -60
- package/dist/utils/ast.js +27 -55
- package/dist/utils/templates.js +12 -12
- package/package.json +36 -30
package/dist/modules/visitor.js
CHANGED
|
@@ -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
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
function
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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, "/");
|
|
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
|
-
}
|
|
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;
|
|
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;
|
|
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;
|
package/dist/utils/ast.js
CHANGED
|
@@ -3,75 +3,66 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.isExtendsHelperExpression = isExtendsHelperExpression;
|
|
9
|
-
exports.isImport = isImport;
|
|
10
|
-
exports.isIdentifierNamed = isIdentifierNamed;
|
|
11
|
-
exports.isCommentBlock = isCommentBlock;
|
|
12
|
-
exports.getIdName = getIdName;
|
|
13
|
-
exports.isSuperCallExpression = isSuperCallExpression;
|
|
6
|
+
exports.convertDeclarationToExpression = convertDeclarationToExpression;
|
|
7
|
+
exports.convertFunctionDeclarationToExpression = convertFunctionDeclarationToExpression;
|
|
14
8
|
exports.findPropertiesOfNode = findPropertiesOfNode;
|
|
9
|
+
exports.getIdName = getIdName;
|
|
15
10
|
exports.getInternalStaticThingsOfClass = getInternalStaticThingsOfClass;
|
|
16
11
|
exports.getOtherPropertiesOfIdentifier = getOtherPropertiesOfIdentifier;
|
|
17
|
-
exports.getPropertiesOfObjectAssignOrExtendHelper = getPropertiesOfObjectAssignOrExtendHelper;
|
|
18
12
|
exports.getPropNames = getPropNames;
|
|
13
|
+
exports.getPropertiesOfObjectAssignOrExtendHelper = getPropertiesOfObjectAssignOrExtendHelper;
|
|
19
14
|
exports.groupPropertiesByName = groupPropertiesByName;
|
|
20
|
-
exports.convertFunctionDeclarationToExpression = convertFunctionDeclarationToExpression;
|
|
21
|
-
exports.convertDeclarationToExpression = convertDeclarationToExpression;
|
|
22
|
-
exports.isSuperPrototypeCallOf = isSuperPrototypeCallOf;
|
|
23
15
|
exports.isCallExpressionCalling = isCallExpressionCalling;
|
|
16
|
+
exports.isCommentBlock = isCommentBlock;
|
|
17
|
+
exports.isExtendsHelperExpression = isExtendsHelperExpression;
|
|
18
|
+
exports.isIdentifierNamed = isIdentifierNamed;
|
|
19
|
+
exports.isImport = isImport;
|
|
20
|
+
exports.isObjectAssignExpression = isObjectAssignExpression;
|
|
21
|
+
exports.isObjectAssignOrExtendsExpression = isObjectAssignOrExtendsExpression;
|
|
22
|
+
exports.isSuperCallExpression = isSuperCallExpression;
|
|
23
|
+
exports.isSuperPrototypeCallOf = isSuperPrototypeCallOf;
|
|
24
24
|
exports.isThisExpressionUsed = isThisExpressionUsed;
|
|
25
|
-
|
|
26
25
|
var _core = require("@babel/core");
|
|
27
|
-
|
|
28
|
-
var _arrayFlatten = _interopRequireDefault(require("array-flatten"));
|
|
29
|
-
|
|
30
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
|
-
|
|
26
|
+
var _arrayFlatten = require("array-flatten");
|
|
32
27
|
function isObjectAssignOrExtendsExpression(node) {
|
|
33
28
|
return isObjectAssignExpression(node) || isExtendsHelperExpression(node);
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
function isObjectAssignExpression(node) {
|
|
37
31
|
if (!_core.types.isCallExpression(node)) return false;
|
|
38
32
|
const callee = node && node.callee;
|
|
39
33
|
return !!(callee.object && callee.property && callee.object.name === "Object" && callee.property.name === "assign");
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
function isExtendsHelperExpression(node) {
|
|
43
36
|
if (!_core.types.isCallExpression(node)) return false;
|
|
44
37
|
const callee = node && node.callee;
|
|
45
38
|
return isIdentifierNamed(callee, "_extends");
|
|
46
|
-
}
|
|
47
|
-
|
|
39
|
+
}
|
|
48
40
|
|
|
41
|
+
// t.isImport only exists if the dynamic import syntax plugin is used, so avoid using that to make it optional.
|
|
49
42
|
function isImport(node) {
|
|
50
43
|
return node && node.type === "Import";
|
|
51
44
|
}
|
|
52
|
-
|
|
53
45
|
function isIdentifierNamed(node, name) {
|
|
54
46
|
return _core.types.isIdentifier(node, {
|
|
55
47
|
name: name
|
|
56
48
|
});
|
|
57
|
-
}
|
|
58
|
-
|
|
49
|
+
}
|
|
59
50
|
|
|
51
|
+
// This doesn't exist on babel-types
|
|
60
52
|
function isCommentBlock(node) {
|
|
61
53
|
return node && node.type === "CommentBlock";
|
|
62
54
|
}
|
|
63
|
-
|
|
64
55
|
function getIdName(node) {
|
|
65
56
|
return node.id && node.id.name;
|
|
66
57
|
}
|
|
67
|
-
|
|
68
58
|
function isSuperCallExpression(expression) {
|
|
69
59
|
return _core.types.isCallExpression(expression) && expression.callee.type === "Super";
|
|
70
|
-
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// export function isSuperExpressionStatement(node) {
|
|
71
63
|
// return isSuperCallExpression(node.expression)
|
|
72
64
|
// }
|
|
73
65
|
|
|
74
|
-
|
|
75
66
|
function findPropertiesOfNode(blockScopeNode, declaration) {
|
|
76
67
|
if (_core.types.isFunctionDeclaration(declaration) || _core.types.isArrowFunctionExpression(declaration)) {
|
|
77
68
|
return null;
|
|
@@ -84,13 +75,12 @@ function findPropertiesOfNode(blockScopeNode, declaration) {
|
|
|
84
75
|
} else if (isObjectAssignOrExtendsExpression(declaration)) {
|
|
85
76
|
return getPropertiesOfObjectAssignOrExtendHelper(declaration, blockScopeNode);
|
|
86
77
|
}
|
|
87
|
-
|
|
88
78
|
return null;
|
|
89
79
|
}
|
|
90
|
-
|
|
91
80
|
function getInternalStaticThingsOfClass(classNode) {
|
|
92
81
|
return classNode.body.body.filter(item => item.static);
|
|
93
82
|
}
|
|
83
|
+
|
|
94
84
|
/**
|
|
95
85
|
* Traverse the top-level of the scope (program or function body) looking for either:
|
|
96
86
|
* - ObjectExpression assignments to the object variable.
|
|
@@ -98,17 +88,14 @@ function getInternalStaticThingsOfClass(classNode) {
|
|
|
98
88
|
*
|
|
99
89
|
* @return Array<{key, value}>
|
|
100
90
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
91
|
function getOtherPropertiesOfIdentifier(blockScopeNode, idName) {
|
|
104
|
-
return (0, _arrayFlatten.
|
|
92
|
+
return (0, _arrayFlatten.flatten)(blockScopeNode.body.map(node => {
|
|
105
93
|
if (_core.types.isExpressionStatement(node)) {
|
|
106
94
|
// ID = value | ID.key = value | ID.key.nested = value
|
|
107
95
|
const {
|
|
108
96
|
left,
|
|
109
97
|
right
|
|
110
98
|
} = node.expression;
|
|
111
|
-
|
|
112
99
|
if (_core.types.isAssignmentExpression(node.expression)) {
|
|
113
100
|
if (_core.types.isIdentifier(left) && left.name === idName) {
|
|
114
101
|
// ID = value
|
|
@@ -121,7 +108,6 @@ function getOtherPropertiesOfIdentifier(blockScopeNode, idName) {
|
|
|
121
108
|
object,
|
|
122
109
|
property: key
|
|
123
110
|
} = left;
|
|
124
|
-
|
|
125
111
|
if (_core.types.isIdentifier(object) && object.name === idName) {
|
|
126
112
|
// ID.key = value
|
|
127
113
|
return {
|
|
@@ -136,10 +122,9 @@ function getOtherPropertiesOfIdentifier(blockScopeNode, idName) {
|
|
|
136
122
|
}
|
|
137
123
|
}).filter(item => item));
|
|
138
124
|
}
|
|
139
|
-
|
|
140
125
|
function getPropertiesOfObjectAssignOrExtendHelper(node, blockScopeNode) {
|
|
141
126
|
// Check all the args and recursively try to get props of identifiers (although they may be imported)
|
|
142
|
-
return (0, _arrayFlatten.
|
|
127
|
+
return (0, _arrayFlatten.flatten)(node.arguments.map(arg => {
|
|
143
128
|
if (_core.types.isObjectExpression(arg)) {
|
|
144
129
|
return arg.properties;
|
|
145
130
|
} else if (_core.types.isIdentifier(arg)) {
|
|
@@ -148,22 +133,18 @@ function getPropertiesOfObjectAssignOrExtendHelper(node, blockScopeNode) {
|
|
|
148
133
|
}
|
|
149
134
|
}));
|
|
150
135
|
}
|
|
151
|
-
|
|
152
136
|
function getPropNames(props) {
|
|
153
137
|
return props.map(prop => prop.key.name);
|
|
154
138
|
}
|
|
155
|
-
|
|
156
139
|
function groupPropertiesByName(properties) {
|
|
157
140
|
return properties && properties.reduce((accumulator, property) => {
|
|
158
141
|
accumulator[property.key.name] = property.value;
|
|
159
142
|
return accumulator;
|
|
160
143
|
}, {});
|
|
161
144
|
}
|
|
162
|
-
|
|
163
145
|
function convertFunctionDeclarationToExpression(declaration) {
|
|
164
146
|
return _core.types.functionExpression(declaration.id, declaration.params, declaration.body, declaration.generator, declaration.async);
|
|
165
147
|
}
|
|
166
|
-
|
|
167
148
|
function convertDeclarationToExpression(declaration) {
|
|
168
149
|
if (_core.types.isFunctionDeclaration(declaration)) {
|
|
169
150
|
return convertFunctionDeclarationToExpression(declaration);
|
|
@@ -171,10 +152,10 @@ function convertDeclarationToExpression(declaration) {
|
|
|
171
152
|
return declaration;
|
|
172
153
|
}
|
|
173
154
|
}
|
|
174
|
-
|
|
175
155
|
function isSuperPrototypeCallOf(expression, superClassName, superMethodName) {
|
|
176
156
|
return _core.types.isCallExpression(expression) && isCallExpressionCalling(expression, `${superClassName}.prototype.${superMethodName}.apply`);
|
|
177
157
|
}
|
|
158
|
+
|
|
178
159
|
/**
|
|
179
160
|
* Helper to see if a call expression is calling a given method such as sap.ui.define().
|
|
180
161
|
* The AST is structured in reverse (defined > ui > sap) so we reverse the method call to compare.
|
|
@@ -182,24 +163,21 @@ function isSuperPrototypeCallOf(expression, superClassName, superMethodName) {
|
|
|
182
163
|
* @param {CallExpression} expression
|
|
183
164
|
* @param {String} dotNotationString For example, sap.ui.define or Class.prototype.method.apply
|
|
184
165
|
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
166
|
function isCallExpressionCalling(expression, dotNotationString) {
|
|
188
167
|
if (!_core.types.isCallExpression(expression)) return false;
|
|
189
168
|
const callee = expression.callee;
|
|
190
169
|
const parts = dotNotationString.split(".");
|
|
191
170
|
let node = callee;
|
|
192
|
-
|
|
193
171
|
for (const nextNamePart of parts.reverse()) {
|
|
194
|
-
if (!node) return false;
|
|
195
|
-
|
|
172
|
+
if (!node) return false;
|
|
173
|
+
// property won't be there for an anonymous function
|
|
196
174
|
const nodeName = node.name || node.property && node.property.name;
|
|
197
175
|
if (nodeName !== nextNamePart) return false;
|
|
198
176
|
node = node.object;
|
|
199
177
|
}
|
|
200
|
-
|
|
201
178
|
return true;
|
|
202
179
|
}
|
|
180
|
+
|
|
203
181
|
/**
|
|
204
182
|
* Recursively search through some parts of a node's for use of 'this'.
|
|
205
183
|
* It checks the callee and the arguments and traverses into arrow functions.
|
|
@@ -222,25 +200,19 @@ function isCallExpressionCalling(expression, dotNotationString) {
|
|
|
222
200
|
*
|
|
223
201
|
* @param {*} node
|
|
224
202
|
*/
|
|
225
|
-
|
|
226
|
-
|
|
227
203
|
function isThisExpressionUsed(node) {
|
|
228
204
|
if (!node) {
|
|
229
205
|
return false;
|
|
230
206
|
}
|
|
231
|
-
|
|
232
207
|
if (Array.isArray(node)) {
|
|
233
208
|
return node.some(isThisExpressionUsed);
|
|
234
209
|
}
|
|
235
|
-
|
|
236
210
|
if (_core.types.isThisExpression(node)) {
|
|
237
211
|
return true;
|
|
238
212
|
}
|
|
239
|
-
|
|
240
213
|
if (_core.types.isFunctionExpression(node)) {
|
|
241
214
|
return false;
|
|
242
215
|
}
|
|
243
|
-
|
|
244
216
|
const traversableProps = ["body", "callee", "arguments", "expression", "object", "property"];
|
|
245
217
|
return traversableProps.some(prop => node[prop] && isThisExpressionUsed(node[prop]));
|
|
246
218
|
}
|
package/dist/utils/templates.js
CHANGED
|
@@ -3,15 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.buildInheritingFunction = exports.buildInheritingConstructor = exports.buildExtendAssign = exports.buildExportDefault = exports.buildDynamicImportHelper = exports.buildDefineGlobal = exports.buildDefine = exports.buildDefaultImportInterop = exports.buildDefaultImportDeconstructor = exports.buildDeclareExports = exports.buildConstDeclaration = exports.buildAssign = exports.buildAllExportHelper = exports.buildAllExport = void 0;
|
|
6
7
|
exports.buildNamedExport = buildNamedExport;
|
|
7
|
-
exports.
|
|
8
|
-
|
|
8
|
+
exports.exportsIdentifier = exports.buildTempExport = exports.buildReturnExports = exports.buildReturn = exports.buildNamedImportDestructor = void 0;
|
|
9
9
|
var _core = require("@babel/core");
|
|
10
|
-
|
|
11
10
|
const exportName = "__exports";
|
|
12
|
-
|
|
13
11
|
const exportsIdentifier = _core.types.identifier(exportName);
|
|
14
|
-
|
|
15
12
|
exports.exportsIdentifier = exportsIdentifier;
|
|
16
13
|
const buildAssign = (0, _core.template)(`
|
|
17
14
|
OBJECT.NAME = VALUE;
|
|
@@ -27,15 +24,17 @@ const buildDefineGlobal = (0, _core.template)(`
|
|
|
27
24
|
sap.ui.define(SOURCES, function (PARAMS) {
|
|
28
25
|
BODY;
|
|
29
26
|
}, true);
|
|
30
|
-
`);
|
|
27
|
+
`);
|
|
31
28
|
|
|
29
|
+
// Uses 'var' since it gets added during wrap
|
|
32
30
|
exports.buildDefineGlobal = buildDefineGlobal;
|
|
33
31
|
const buildDeclareExports = (0, _core.template)(`
|
|
34
32
|
var ${exportName} = {
|
|
35
33
|
__esModule: true
|
|
36
34
|
};
|
|
37
|
-
`);
|
|
35
|
+
`);
|
|
38
36
|
|
|
37
|
+
// Uses 'var' since it gets added during wrap
|
|
39
38
|
exports.buildDeclareExports = buildDeclareExports;
|
|
40
39
|
const buildTempExport = (0, _core.template)(`
|
|
41
40
|
var ${exportName} = VALUE;
|
|
@@ -49,7 +48,6 @@ const buildReturnExports = (0, _core.template)(`
|
|
|
49
48
|
return ${exportName};
|
|
50
49
|
`);
|
|
51
50
|
exports.buildReturnExports = buildReturnExports;
|
|
52
|
-
|
|
53
51
|
function buildNamedExport(obj) {
|
|
54
52
|
return buildAssign({
|
|
55
53
|
OBJECT: exportsIdentifier,
|
|
@@ -57,7 +55,6 @@ function buildNamedExport(obj) {
|
|
|
57
55
|
VALUE: obj.value
|
|
58
56
|
});
|
|
59
57
|
}
|
|
60
|
-
|
|
61
58
|
const buildAllExportHelper = (0, _core.template)(`
|
|
62
59
|
function extendExports(exports, obj) {
|
|
63
60
|
Object.keys(obj).forEach(function (key) {
|
|
@@ -86,8 +83,9 @@ const buildDefaultImportInterop = (0, _core.template)(`
|
|
|
86
83
|
exports.buildDefaultImportInterop = buildDefaultImportInterop;
|
|
87
84
|
const buildDefaultImportDeconstructor = (0, _core.template)(`
|
|
88
85
|
const LOCAL = _interopRequireDefault(MODULE);
|
|
89
|
-
`);
|
|
86
|
+
`);
|
|
90
87
|
|
|
88
|
+
// TODO: inject __extends instead of Object.assign unless useBuiltIns in set
|
|
91
89
|
exports.buildDefaultImportDeconstructor = buildDefaultImportDeconstructor;
|
|
92
90
|
const buildDynamicImportHelper = (0, _core.template)(`
|
|
93
91
|
function __ui5_require_async(path) {
|
|
@@ -119,8 +117,9 @@ const buildNamedImportDestructor = (0, _core.template)(`
|
|
|
119
117
|
exports.buildNamedImportDestructor = buildNamedImportDestructor;
|
|
120
118
|
const buildExtendAssign = (0, _core.template)(`
|
|
121
119
|
const NAME = SUPER.extend(FQN, OBJECT);
|
|
122
|
-
`);
|
|
120
|
+
`);
|
|
123
121
|
|
|
122
|
+
// This is use when there is not already the function, so always propagate arguments.
|
|
124
123
|
exports.buildExtendAssign = buildExtendAssign;
|
|
125
124
|
const buildInheritingFunction = (0, _core.template)(`
|
|
126
125
|
function NAME() {
|
|
@@ -128,8 +127,9 @@ const buildInheritingFunction = (0, _core.template)(`
|
|
|
128
127
|
SUPER.prototype.NAME.apply(this, arguments);
|
|
129
128
|
}
|
|
130
129
|
}
|
|
131
|
-
`);
|
|
130
|
+
`);
|
|
132
131
|
|
|
132
|
+
// This is use when there is not already the function, so always propagate arguments.
|
|
133
133
|
exports.buildInheritingFunction = buildInheritingFunction;
|
|
134
134
|
const buildInheritingConstructor = (0, _core.template)(`
|
|
135
135
|
function constructor() {
|