@angular-devkit/build-optimizer 0.800.2 → 0.800.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/package.json +1 -1
- package/src/transforms/wrap-enums.js +23 -7
package/package.json
CHANGED
|
@@ -141,11 +141,14 @@ function visitBlockStatements(statements, context) {
|
|
|
141
141
|
newStatement = createWrappedClass(currentStatement, classStatements);
|
|
142
142
|
oIndex += classStatements.length - 1;
|
|
143
143
|
}
|
|
144
|
-
if (newStatement) {
|
|
144
|
+
if (newStatement && newStatement.length > 0) {
|
|
145
145
|
if (!updatedStatements) {
|
|
146
146
|
updatedStatements = [...statements];
|
|
147
147
|
}
|
|
148
|
-
updatedStatements.splice(uIndex, oldStatementsLength, newStatement);
|
|
148
|
+
updatedStatements.splice(uIndex, oldStatementsLength, ...newStatement);
|
|
149
|
+
// When having more than a single new statement
|
|
150
|
+
// we need to update the update Index
|
|
151
|
+
uIndex += (newStatement ? newStatement.length - 1 : 0);
|
|
149
152
|
}
|
|
150
153
|
const result = ts.visitNode(currentStatement, visitor);
|
|
151
154
|
if (result !== currentStatement) {
|
|
@@ -232,7 +235,12 @@ function findTs2_3EnumIife(name, statement) {
|
|
|
232
235
|
return null;
|
|
233
236
|
}
|
|
234
237
|
const memberArgument = assignment.argumentExpression;
|
|
235
|
-
|
|
238
|
+
// String enum
|
|
239
|
+
if (ts.isStringLiteral(memberArgument)) {
|
|
240
|
+
return [callExpression, exportExpression];
|
|
241
|
+
}
|
|
242
|
+
// Non string enums
|
|
243
|
+
if (!ts.isBinaryExpression(memberArgument)
|
|
236
244
|
|| memberArgument.operatorToken.kind !== ts.SyntaxKind.FirstAssignment) {
|
|
237
245
|
return null;
|
|
238
246
|
}
|
|
@@ -413,7 +421,7 @@ function updateEnumIife(hostNode, iife, exportAssignment) {
|
|
|
413
421
|
if (exportAssignment) {
|
|
414
422
|
value = ts.createBinary(exportAssignment, ts.SyntaxKind.FirstAssignment, updatedIife);
|
|
415
423
|
}
|
|
416
|
-
return updateHostNode(hostNode, value);
|
|
424
|
+
return [updateHostNode(hostNode, value)];
|
|
417
425
|
}
|
|
418
426
|
function createWrappedEnum(name, hostNode, statements, literalInitializer = ts.createObjectLiteral(), addExportModifier = false) {
|
|
419
427
|
const node = addExportModifier
|
|
@@ -428,7 +436,7 @@ function createWrappedEnum(name, hostNode, statements, literalInitializer = ts.c
|
|
|
428
436
|
...statements,
|
|
429
437
|
innerReturn,
|
|
430
438
|
]);
|
|
431
|
-
return updateHostNode(node, ast_utils_1.addPureComment(ts.createParen(iife)));
|
|
439
|
+
return [updateHostNode(node, ast_utils_1.addPureComment(ts.createParen(iife)))];
|
|
432
440
|
}
|
|
433
441
|
function createWrappedClass(hostNode, statements) {
|
|
434
442
|
const name = hostNode.name.text;
|
|
@@ -440,7 +448,15 @@ function createWrappedClass(hostNode, statements) {
|
|
|
440
448
|
...updatedStatements,
|
|
441
449
|
ts.createReturn(ts.createIdentifier(name)),
|
|
442
450
|
]));
|
|
443
|
-
|
|
451
|
+
const modifiers = hostNode.modifiers;
|
|
452
|
+
const isDefault = !!modifiers
|
|
453
|
+
&& modifiers.some(x => x.kind === ts.SyntaxKind.DefaultKeyword);
|
|
454
|
+
const newStatement = [];
|
|
455
|
+
newStatement.push(ts.createVariableStatement(isDefault ? undefined : modifiers, ts.createVariableDeclarationList([
|
|
444
456
|
ts.createVariableDeclaration(name, undefined, pureIife),
|
|
445
|
-
], ts.NodeFlags.Const));
|
|
457
|
+
], ts.NodeFlags.Const)));
|
|
458
|
+
if (isDefault) {
|
|
459
|
+
newStatement.push(ts.createExportAssignment(undefined, undefined, false, ts.createIdentifier(name)));
|
|
460
|
+
}
|
|
461
|
+
return newStatement;
|
|
446
462
|
}
|