@ngtools/webpack 14.2.0-next.0 → 14.2.0-next.1
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
|
@@ -48,7 +48,7 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
48
48
|
const usedSymbols = new Set();
|
|
49
49
|
const imports = [];
|
|
50
50
|
ts.forEachChild(sourceFile, function visit(node) {
|
|
51
|
-
var _a
|
|
51
|
+
var _a;
|
|
52
52
|
// Skip removed nodes.
|
|
53
53
|
if (removedNodes.includes(node)) {
|
|
54
54
|
return;
|
|
@@ -66,35 +66,8 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
66
66
|
}
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (!compilerOptions.emitDecoratorMetadata) {
|
|
72
|
-
// Skip and mark as unused if emitDecoratorMetadata is disabled.
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const parent = node.parent;
|
|
76
|
-
let isTypeReferenceForDecoratoredNode = false;
|
|
77
|
-
switch (parent.kind) {
|
|
78
|
-
case ts.SyntaxKind.GetAccessor:
|
|
79
|
-
case ts.SyntaxKind.PropertyDeclaration:
|
|
80
|
-
case ts.SyntaxKind.MethodDeclaration:
|
|
81
|
-
isTypeReferenceForDecoratoredNode = !!((_b = parent.decorators) === null || _b === void 0 ? void 0 : _b.length);
|
|
82
|
-
break;
|
|
83
|
-
case ts.SyntaxKind.Parameter:
|
|
84
|
-
// - A constructor parameter can be decorated or the class itself is decorated.
|
|
85
|
-
// - The parent of the parameter is decorated example a method declaration or a set accessor.
|
|
86
|
-
// In all cases we need the type reference not to be elided.
|
|
87
|
-
isTypeReferenceForDecoratoredNode = !!(((_c = parent.decorators) === null || _c === void 0 ? void 0 : _c.length) ||
|
|
88
|
-
(ts.isSetAccessor(parent.parent) && !!((_d = parent.parent.decorators) === null || _d === void 0 ? void 0 : _d.length)) ||
|
|
89
|
-
(ts.isConstructorDeclaration(parent.parent) &&
|
|
90
|
-
!!((_e = parent.parent.parent.decorators) === null || _e === void 0 ? void 0 : _e.length)));
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
if (isTypeReferenceForDecoratoredNode) {
|
|
94
|
-
symbol = typeChecker.getSymbolAtLocation(node.typeName);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
69
|
+
if (!ts.isTypeReferenceNode(node)) {
|
|
70
|
+
let symbol;
|
|
98
71
|
switch (node.kind) {
|
|
99
72
|
case ts.SyntaxKind.Identifier:
|
|
100
73
|
const parent = node.parent;
|
|
@@ -115,9 +88,9 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
115
88
|
symbol = typeChecker.getShorthandAssignmentValueSymbol(node);
|
|
116
89
|
break;
|
|
117
90
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
91
|
+
if (symbol) {
|
|
92
|
+
usedSymbols.add(symbol);
|
|
93
|
+
}
|
|
121
94
|
}
|
|
122
95
|
ts.forEachChild(node, visit);
|
|
123
96
|
});
|
|
@@ -152,7 +125,7 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
152
125
|
let removedClausesCount = 0;
|
|
153
126
|
clausesCount += namedBindings.elements.length;
|
|
154
127
|
for (const specifier of namedBindings.elements) {
|
|
155
|
-
if (isUnused(specifier.name)) {
|
|
128
|
+
if (specifier.isTypeOnly || isUnused(specifier.name)) {
|
|
156
129
|
removedClausesCount++;
|
|
157
130
|
// in case we don't have any more namedImports we should remove the parent ie the {}
|
|
158
131
|
const nodeToRemove = clausesCount === removedClausesCount ? specifier.parent : specifier;
|
|
@@ -163,7 +136,7 @@ function elideImports(sourceFile, removedNodes, getTypeChecker, compilerOptions)
|
|
|
163
136
|
// "import XYZ from 'abc';"
|
|
164
137
|
if (node.importClause.name) {
|
|
165
138
|
clausesCount++;
|
|
166
|
-
if (isUnused(node.importClause.name)) {
|
|
139
|
+
if (node.importClause.isTypeOnly || isUnused(node.importClause.name)) {
|
|
167
140
|
specifierNodeRemovals.push(node.importClause.name);
|
|
168
141
|
}
|
|
169
142
|
}
|