@angular-devkit/build-optimizer 0.802.0-next.1 → 0.802.2

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.802.0-next.1",
3
+ "version": "0.802.2",
4
4
  "description": "Angular Build Optimizer",
5
5
  "experimental": true,
6
6
  "main": "src/index.js",
@@ -11,7 +11,8 @@
11
11
  "dependencies": {
12
12
  "loader-utils": "1.2.3",
13
13
  "source-map": "0.5.6",
14
- "typescript": "3.4.5",
14
+ "tslib": "1.10.0",
15
+ "typescript": "3.5.3",
15
16
  "webpack-sources": "1.3.0"
16
17
  },
17
18
  "keywords": [
@@ -106,7 +106,7 @@ function buildOptimizer(options) {
106
106
  if (!isWebpackBundle && (ignoreTest || import_tslib_1.testImportTslib(content))) {
107
107
  getTransforms.unshift(import_tslib_1.getImportTslibTransformer);
108
108
  }
109
- getTransforms.unshift(wrap_enums_1.getWrapEnumsTransformer);
109
+ getTransforms.push(wrap_enums_1.getWrapEnumsTransformer);
110
110
  const transformJavascriptOpts = {
111
111
  content: content,
112
112
  inputFilePath: options.inputFilePath,
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class BuildOptimizerWebpackPlugin {
4
4
  apply(compiler) {
5
- compiler.hooks.normalModuleFactory.tap("BuildOptimizerWebpackPlugin", nmf => {
6
- nmf.hooks.module.tap("BuildOptimizerWebpackPlugin", (module, data) => {
5
+ compiler.hooks.normalModuleFactory.tap('BuildOptimizerWebpackPlugin', nmf => {
6
+ nmf.hooks.module.tap('BuildOptimizerWebpackPlugin', (module, data) => {
7
7
  const resolveData = data.resourceResolveData;
8
8
  if (resolveData && resolveData.descriptionFileData) {
9
9
  // Only TS packages should use Build Optimizer.
@@ -1,11 +1,5 @@
1
- /**
2
- * @license
3
- * Copyright Google Inc. All Rights Reserved.
4
- *
5
- * Use of this source code is governed by an MIT-style license that can be
6
- * found in the LICENSE file at https://angular.io/license
7
- */
8
1
  import * as ts from 'typescript';
9
2
  export declare function collectDeepNodes<T extends ts.Node>(node: ts.Node, kind: ts.SyntaxKind): T[];
10
3
  export declare function addPureComment<T extends ts.Node>(node: T): T;
11
4
  export declare function hasPureComment(node: ts.Node): boolean;
5
+ export declare function isHelperName(name: string): boolean;
@@ -7,8 +7,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  * Use of this source code is governed by an MIT-style license that can be
8
8
  * found in the LICENSE file at https://angular.io/license
9
9
  */
10
+ const tslib = require("tslib");
10
11
  const ts = require("typescript");
11
12
  const pureFunctionComment = '@__PURE__';
13
+ // We include only exports that start with '__' because tslib helpers
14
+ // all start with a suffix of two underscores.
15
+ const tslibHelpers = new Set(Object.keys(tslib).filter(h => h.startsWith('__')));
12
16
  // Find all nodes from the AST in the subtree of node of SyntaxKind kind.
13
17
  function collectDeepNodes(node, kind) {
14
18
  const nodes = [];
@@ -34,3 +38,7 @@ function hasPureComment(node) {
34
38
  return !!leadingComment && leadingComment.some(comment => comment.text === pureFunctionComment);
35
39
  }
36
40
  exports.hasPureComment = hasPureComment;
41
+ function isHelperName(name) {
42
+ return tslibHelpers.has(name);
43
+ }
44
+ exports.isHelperName = isHelperName;
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
8
8
  * found in the LICENSE file at https://angular.io/license
9
9
  */
10
10
  const ts = require("typescript");
11
+ const ast_utils_1 = require("../helpers/ast-utils");
11
12
  /**
12
13
  * @deprecated From 0.9.0
13
14
  */
@@ -28,7 +29,7 @@ function getImportTslibTransformer() {
28
29
  const declarations = node.declarationList.declarations;
29
30
  if (declarations.length === 1 && ts.isIdentifier(declarations[0].name)) {
30
31
  const name = declarations[0].name.text;
31
- if (isHelperName(name)) {
32
+ if (ast_utils_1.isHelperName(name)) {
32
33
  // TODO: maybe add a few more checks, like checking the first part of the assignment.
33
34
  const tslibImport = createTslibImport(name, useRequire);
34
35
  tslibImports.push(tslibImport);
@@ -69,13 +70,3 @@ function createTslibImport(name, useRequire = false) {
69
70
  return newNode;
70
71
  }
71
72
  }
72
- function isHelperName(name) {
73
- // TODO: there are more helpers than these, should we replace them all?
74
- const tsHelpers = [
75
- '__extends',
76
- '__decorate',
77
- '__metadata',
78
- '__param',
79
- ];
80
- return tsHelpers.indexOf(name) !== -1;
81
- }
@@ -38,10 +38,8 @@ function findTopLevelFunctions(parentNode) {
38
38
  // need to mark function calls inside them as pure.
39
39
  // Class static initializers in ES2015 are an exception we don't cover. They would need similar
40
40
  // processing as enums to prevent property setting from causing the class to be retained.
41
- if (ts.isFunctionDeclaration(node)
42
- || ts.isFunctionExpression(node)
43
- || ts.isClassDeclaration(node)
44
- || ts.isClassExpression(node)
41
+ if (ts.isFunctionLike(node)
42
+ || ts.isClassLike(node)
45
43
  || ts.isArrowFunction(node)
46
44
  || ts.isMethodDeclaration(node)) {
47
45
  return;
@@ -68,6 +66,9 @@ function findTopLevelFunctions(parentNode) {
68
66
  }
69
67
  else if (ts.isCallExpression(innerNode)) {
70
68
  let expression = innerNode.expression;
69
+ if (ts.isIdentifier(expression) && ast_utils_1.isHelperName(expression.text)) {
70
+ return;
71
+ }
71
72
  while (expression && ts.isParenthesizedExpression(expression)) {
72
73
  expression = expression.expression;
73
74
  }
@@ -50,7 +50,7 @@ function visitBlockStatements(statements, context) {
50
50
  }
51
51
  }
52
52
  else {
53
- return ts.visitEachChild(node, visitor, context);
53
+ return node;
54
54
  }
55
55
  };
56
56
  // 'oIndex' is the original statement index; 'uIndex' is the updated statement index
@@ -96,7 +96,7 @@ function visitBlockStatements(statements, context) {
96
96
  // skip the export
97
97
  oIndex++;
98
98
  }
99
- const enumStatements = findStatements(name, statements, oIndex + 1);
99
+ const enumStatements = findStatements(name, statements, oIndex, 1);
100
100
  if (!enumStatements) {
101
101
  continue;
102
102
  }
@@ -233,7 +233,7 @@ function updateHostNode(hostNode, expression) {
233
233
  Foo = __decorate([]);
234
234
  ```
235
235
  */
236
- function findStatements(name, statements, statementIndex) {
236
+ function findStatements(name, statements, statementIndex, offset = 0) {
237
237
  let count = 1;
238
238
  for (let index = statementIndex + 1; index < statements.length; ++index) {
239
239
  const statement = statements[index];
@@ -277,7 +277,7 @@ function findStatements(name, statements, statementIndex) {
277
277
  break;
278
278
  }
279
279
  if (count > 1) {
280
- return statements.slice(statementIndex, statementIndex + count);
280
+ return statements.slice(statementIndex + offset, statementIndex + count);
281
281
  }
282
282
  return undefined;
283
283
  }