@angular-devkit/build-optimizer 0.803.4 → 0.803.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-devkit/build-optimizer",
3
- "version": "0.803.4",
3
+ "version": "0.803.8",
4
4
  "description": "Angular Build Optimizer",
5
5
  "experimental": true,
6
6
  "main": "src/index.js",
@@ -47,16 +47,14 @@ function scrubFileTransformer(checker, isAngularCoreFile) {
47
47
  if (isDecoratorAssignmentExpression(exprStmt)) {
48
48
  nodes.push(...pickDecorationNodesToRemove(exprStmt, ngMetadata, checker));
49
49
  }
50
- if (isDecorateAssignmentExpression(exprStmt, tslibImports, checker)) {
50
+ else if (isDecorateAssignmentExpression(exprStmt, tslibImports, checker)
51
+ || isAngularDecoratorExpression(exprStmt, ngMetadata, tslibImports, checker)) {
51
52
  nodes.push(...pickDecorateNodesToRemove(exprStmt, tslibImports, ngMetadata, checker));
52
53
  }
53
- if (isAngularDecoratorMetadataExpression(exprStmt, ngMetadata, tslibImports, checker)) {
54
- nodes.push(node);
55
- }
56
- if (isPropDecoratorAssignmentExpression(exprStmt)) {
54
+ else if (isPropDecoratorAssignmentExpression(exprStmt)) {
57
55
  nodes.push(...pickPropDecorationNodesToRemove(exprStmt, ngMetadata, checker));
58
56
  }
59
- if (isCtorParamsAssignmentExpression(exprStmt)) {
57
+ else if (isCtorParamsAssignmentExpression(exprStmt)) {
60
58
  nodes.push(node);
61
59
  }
62
60
  }
@@ -199,7 +197,7 @@ function isDecorateAssignmentExpression(exprStmt, tslibImports, checker) {
199
197
  return true;
200
198
  }
201
199
  // Check if expression is `__decorate([smt, __metadata("design:type", Object)], ...)`.
202
- function isAngularDecoratorMetadataExpression(exprStmt, ngMetadata, tslibImports, checker) {
200
+ function isAngularDecoratorExpression(exprStmt, ngMetadata, tslibImports, checker) {
203
201
  if (exprStmt.expression.kind !== ts.SyntaxKind.CallExpression) {
204
202
  return false;
205
203
  }
@@ -215,26 +213,16 @@ function isAngularDecoratorMetadataExpression(exprStmt, ngMetadata, tslibImports
215
213
  }
216
214
  const decorateArray = callExpr.arguments[0];
217
215
  // Check first array entry for Angular decorators.
218
- if (decorateArray.elements[0].kind !== ts.SyntaxKind.CallExpression) {
219
- return false;
220
- }
221
- const decoratorCall = decorateArray.elements[0];
222
- if (decoratorCall.expression.kind !== ts.SyntaxKind.Identifier) {
223
- return false;
224
- }
225
- const decoratorId = decoratorCall.expression;
226
- if (!identifierIsMetadata(decoratorId, ngMetadata, checker)) {
216
+ if (decorateArray.elements.length === 0 || !ts.isCallExpression(decorateArray.elements[0])) {
227
217
  return false;
228
218
  }
229
- // Check second array entry for __metadata call.
230
- if (decorateArray.elements[1].kind !== ts.SyntaxKind.CallExpression) {
231
- return false;
232
- }
233
- const metadataCall = decorateArray.elements[1];
234
- if (!isTslibHelper(metadataCall, '__metadata', tslibImports, checker)) {
235
- return false;
236
- }
237
- return true;
219
+ return decorateArray.elements.some(decoratorCall => {
220
+ if (!ts.isCallExpression(decoratorCall) || !ts.isIdentifier(decoratorCall.expression)) {
221
+ return false;
222
+ }
223
+ const decoratorId = decoratorCall.expression;
224
+ return identifierIsMetadata(decoratorId, ngMetadata, checker);
225
+ });
238
226
  }
239
227
  // Check if assignment is `Clazz.propDecorators = [...];`.
240
228
  function isPropDecoratorAssignmentExpression(exprStmt) {
@@ -300,16 +288,20 @@ function pickDecorationNodesToRemove(exprStmt, ngMetadata, checker) {
300
288
  // Remove Angular decorators from `Clazz = __decorate([...], Clazz)`, or expression itself if all
301
289
  // are removed.
302
290
  function pickDecorateNodesToRemove(exprStmt, tslibImports, ngMetadata, checker) {
303
- const expr = expect(exprStmt.expression, ts.SyntaxKind.BinaryExpression);
304
291
  let callExpr;
305
- if (expr.right.kind === ts.SyntaxKind.CallExpression) {
306
- callExpr = expect(expr.right, ts.SyntaxKind.CallExpression);
292
+ if (ts.isCallExpression(exprStmt.expression)) {
293
+ callExpr = exprStmt.expression;
307
294
  }
308
- else if (expr.right.kind === ts.SyntaxKind.BinaryExpression) {
309
- const innerExpr = expr.right;
310
- callExpr = expect(innerExpr.right, ts.SyntaxKind.CallExpression);
295
+ else if (ts.isBinaryExpression(exprStmt.expression)) {
296
+ const expr = exprStmt.expression;
297
+ if (ts.isCallExpression(expr.right)) {
298
+ callExpr = expr.right;
299
+ }
300
+ else if (ts.isBinaryExpression(expr.right) && ts.isCallExpression(expr.right.right)) {
301
+ callExpr = expr.right.right;
302
+ }
311
303
  }
312
- else {
304
+ if (!callExpr) {
313
305
  return [];
314
306
  }
315
307
  const arrLiteral = expect(callExpr.arguments[0], ts.SyntaxKind.ArrayLiteralExpression);
@@ -335,10 +327,6 @@ function pickDecorateNodesToRemove(exprStmt, tslibImports, ngMetadata, checker)
335
327
  if (el.arguments[0].kind !== ts.SyntaxKind.StringLiteral) {
336
328
  return false;
337
329
  }
338
- const metadataTypeId = el.arguments[0];
339
- if (metadataTypeId.text !== 'design:paramtypes') {
340
- return false;
341
- }
342
330
  return true;
343
331
  });
344
332
  // Remove all __param calls.