@angular-devkit/build-optimizer 0.802.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.
|
|
3
|
+
"version": "0.802.2",
|
|
4
4
|
"description": "Angular Build Optimizer",
|
|
5
5
|
"experimental": true,
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"loader-utils": "1.2.3",
|
|
13
13
|
"source-map": "0.5.6",
|
|
14
|
+
"tslib": "1.10.0",
|
|
14
15
|
"typescript": "3.5.3",
|
|
15
16
|
"webpack-sources": "1.3.0"
|
|
16
17
|
},
|
|
@@ -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;
|
package/src/helpers/ast-utils.js
CHANGED
|
@@ -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.
|
|
42
|
-
|| ts.
|
|
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
|
}
|