@ngtools/webpack 15.0.4 → 15.0.5
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
|
@@ -34,8 +34,6 @@ exports.getResourceUrl = exports.replaceResources = exports.NG_COMPONENT_RESOURC
|
|
|
34
34
|
const ts = __importStar(require("typescript"));
|
|
35
35
|
const inline_resource_1 = require("../loaders/inline-resource");
|
|
36
36
|
exports.NG_COMPONENT_RESOURCE_QUERY = 'ngResource';
|
|
37
|
-
/** Whether the current version of TypeScript is after 4.8. */
|
|
38
|
-
const IS_TS_48 = isAfterVersion(4, 8);
|
|
39
37
|
function replaceResources(shouldTransform, getTypeChecker, inlineStyleFileExtension) {
|
|
40
38
|
return (context) => {
|
|
41
39
|
const typeChecker = getTypeChecker();
|
|
@@ -43,8 +41,16 @@ function replaceResources(shouldTransform, getTypeChecker, inlineStyleFileExtens
|
|
|
43
41
|
const moduleKind = context.getCompilerOptions().module;
|
|
44
42
|
const nodeFactory = context.factory;
|
|
45
43
|
const visitNode = (node) => {
|
|
44
|
+
var _a;
|
|
46
45
|
if (ts.isClassDeclaration(node)) {
|
|
47
|
-
|
|
46
|
+
const decorators = ts.getDecorators(node);
|
|
47
|
+
if (!decorators || decorators.length === 0) {
|
|
48
|
+
return node;
|
|
49
|
+
}
|
|
50
|
+
return nodeFactory.updateClassDeclaration(node, [
|
|
51
|
+
...decorators.map((current) => visitDecorator(nodeFactory, current, typeChecker, resourceImportDeclarations, moduleKind, inlineStyleFileExtension)),
|
|
52
|
+
...((_a = ts.getModifiers(node)) !== null && _a !== void 0 ? _a : []),
|
|
53
|
+
], node.name, node.typeParameters, node.heritageClauses, node.members);
|
|
48
54
|
}
|
|
49
55
|
return ts.visitEachChild(node, visitNode, context);
|
|
50
56
|
};
|
|
@@ -65,42 +71,6 @@ function replaceResources(shouldTransform, getTypeChecker, inlineStyleFileExtens
|
|
|
65
71
|
};
|
|
66
72
|
}
|
|
67
73
|
exports.replaceResources = replaceResources;
|
|
68
|
-
/**
|
|
69
|
-
* Replaces the resources inside of a `ClassDeclaration`. This is a backwards-compatibility layer
|
|
70
|
-
* to support TypeScript versions older than 4.8 where the decorators of a node were in a separate
|
|
71
|
-
* array, rather than being part of its `modifiers` array.
|
|
72
|
-
*
|
|
73
|
-
* TODO: remove this function and use the `NodeFactory` directly once support for TypeScript
|
|
74
|
-
* 4.6 and 4.7 has been dropped.
|
|
75
|
-
*/
|
|
76
|
-
function visitClassDeclaration(nodeFactory, typeChecker, node, resourceImportDeclarations, moduleKind, inlineStyleFileExtension) {
|
|
77
|
-
var _a;
|
|
78
|
-
let decorators;
|
|
79
|
-
let modifiers;
|
|
80
|
-
if (IS_TS_48) {
|
|
81
|
-
(_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.forEach((modifier) => {
|
|
82
|
-
if (ts.isDecorator(modifier)) {
|
|
83
|
-
decorators !== null && decorators !== void 0 ? decorators : (decorators = []);
|
|
84
|
-
decorators.push(modifier);
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
modifiers = modifiers !== null && modifiers !== void 0 ? modifiers : (modifiers = []);
|
|
88
|
-
modifiers.push(modifier);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
decorators = node.decorators;
|
|
94
|
-
modifiers = node.modifiers;
|
|
95
|
-
}
|
|
96
|
-
if (!decorators || decorators.length === 0) {
|
|
97
|
-
return node;
|
|
98
|
-
}
|
|
99
|
-
decorators = decorators.map((current) => visitDecorator(nodeFactory, current, typeChecker, resourceImportDeclarations, moduleKind, inlineStyleFileExtension));
|
|
100
|
-
return IS_TS_48
|
|
101
|
-
? nodeFactory.updateClassDeclaration(node, [...decorators, ...(modifiers !== null && modifiers !== void 0 ? modifiers : [])], node.name, node.typeParameters, node.heritageClauses, node.members)
|
|
102
|
-
: nodeFactory.updateClassDeclaration(node, decorators, modifiers, node.name, node.typeParameters, node.heritageClauses, node.members);
|
|
103
|
-
}
|
|
104
74
|
function visitDecorator(nodeFactory, node, typeChecker, resourceImportDeclarations, moduleKind, inlineStyleFileExtension) {
|
|
105
75
|
if (!isComponentDecorator(node, typeChecker)) {
|
|
106
76
|
return node;
|
|
@@ -258,16 +228,3 @@ function getDecoratorOrigin(decorator, typeChecker) {
|
|
|
258
228
|
}
|
|
259
229
|
return null;
|
|
260
230
|
}
|
|
261
|
-
/** Checks if the current version of TypeScript is after the specified major/minor versions. */
|
|
262
|
-
function isAfterVersion(targetMajor, targetMinor) {
|
|
263
|
-
const [major, minor] = ts.versionMajorMinor.split('.').map((part) => parseInt(part));
|
|
264
|
-
if (major < targetMajor) {
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
else if (major > targetMajor) {
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
else {
|
|
271
|
-
return minor >= targetMinor;
|
|
272
|
-
}
|
|
273
|
-
}
|