jest-preset-angular 12.2.3 → 12.2.4
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## [12.2.4](https://github.com/thymikee/jest-preset-angular/compare/v12.2.3...v12.2.4) (2023-01-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* support TypeScript 4.2 for Angular 12 ([8b59e79](https://github.com/thymikee/jest-preset-angular/commit/8b59e798b565679a26945d95e0539685cfc62a3c))
|
|
7
|
+
* Including Angular fix for downlevel-ctor transformer, see https://github.com/angular/angular/pull/48638
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
1
11
|
## [12.2.2](https://github.com/thymikee/jest-preset-angular/compare/v12.2.1...v12.2.2) (2022-08-29)
|
|
2
12
|
|
|
3
13
|
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.reflectObjectLiteral = exports.findMember = exports.filterToMembersWithDecorator = exports.reflectTypeEntityToDeclaration = exports.reflectIdentifierOfDeclaration = exports.reflectNameOfDeclaration = exports.TypeScriptReflectionHost = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
6
|
-
const ts_compatibility_1 = require("../../ts_compatibility");
|
|
7
6
|
const host_1 = require("./host");
|
|
8
7
|
const type_to_value_1 = require("./type_to_value");
|
|
9
8
|
const util_1 = require("./util");
|
|
@@ -12,7 +11,7 @@ class TypeScriptReflectionHost {
|
|
|
12
11
|
this.checker = checker;
|
|
13
12
|
}
|
|
14
13
|
getDecoratorsOfDeclaration(declaration) {
|
|
15
|
-
const decorators = (
|
|
14
|
+
const decorators = typescript_1.default.canHaveDecorators(declaration) ? typescript_1.default.getDecorators(declaration) : undefined;
|
|
16
15
|
return decorators !== undefined && decorators.length ?
|
|
17
16
|
decorators.map(decorator => this._reflectDecorator(decorator))
|
|
18
17
|
.filter((dec) => dec !== null) :
|
|
@@ -150,7 +149,7 @@ class TypeScriptReflectionHost {
|
|
|
150
149
|
if (typescript_1.default.isVariableDeclaration(decl) && typescript_1.default.isVariableDeclarationList(decl.parent)) {
|
|
151
150
|
topLevel = decl.parent.parent;
|
|
152
151
|
}
|
|
153
|
-
const modifiers = (
|
|
152
|
+
const modifiers = typescript_1.default.canHaveModifiers(topLevel) ? typescript_1.default.getModifiers(topLevel) : undefined;
|
|
154
153
|
if (modifiers !== undefined &&
|
|
155
154
|
modifiers.some(modifier => modifier.kind === typescript_1.default.SyntaxKind.ExportKeyword)) {
|
|
156
155
|
return true;
|
|
@@ -312,7 +311,7 @@ class TypeScriptReflectionHost {
|
|
|
312
311
|
return null;
|
|
313
312
|
}
|
|
314
313
|
const decorators = this.getDecoratorsOfDeclaration(node);
|
|
315
|
-
const modifiers =
|
|
314
|
+
const modifiers = typescript_1.default.getModifiers(node);
|
|
316
315
|
const isStatic = modifiers !== undefined && modifiers.some(mod => mod.kind === typescript_1.default.SyntaxKind.StaticKeyword);
|
|
317
316
|
return {
|
|
318
317
|
node,
|
|
@@ -7,66 +7,22 @@
|
|
|
7
7
|
* found in the LICENSE file at https://angular.io/license
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
10
|
+
exports.createIndexSignature = exports.createFunctionDeclaration = exports.createImportDeclaration = exports.createParameterDeclaration = void 0;
|
|
11
11
|
const tslib_1 = require("tslib");
|
|
12
12
|
const typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
13
|
-
const
|
|
14
|
-
exports.
|
|
15
|
-
typescript_1.default.factory.
|
|
16
|
-
(
|
|
17
|
-
exports.
|
|
18
|
-
typescript_1.default.factory.
|
|
19
|
-
(
|
|
20
|
-
exports.
|
|
21
|
-
typescript_1.default.factory.
|
|
22
|
-
(
|
|
23
|
-
exports.
|
|
24
|
-
typescript_1.default.factory.
|
|
25
|
-
(
|
|
26
|
-
exports.updateMethodDeclaration = IS_AFTER_TS_48 ?
|
|
27
|
-
typescript_1.default.factory.updateMethodDeclaration :
|
|
28
|
-
(node, modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body) => typescript_1.default.factory.updateMethodDeclaration(node, ...splitModifiers(modifiers), asteriskToken, name, questionToken, typeParameters, parameters, type, body);
|
|
29
|
-
exports.createMethodDeclaration = IS_AFTER_TS_48 ?
|
|
30
|
-
typescript_1.default.factory.createMethodDeclaration :
|
|
31
|
-
(modifiers, asteriskToken, name, questionToken, typeParameters, parameters, type, body) => typescript_1.default.factory.createMethodDeclaration(...splitModifiers(modifiers), asteriskToken, name, questionToken, typeParameters, parameters, type, body);
|
|
32
|
-
exports.updatePropertyDeclaration = IS_AFTER_TS_48 ?
|
|
33
|
-
typescript_1.default.factory.updatePropertyDeclaration :
|
|
34
|
-
(node, modifiers, name, questionOrExclamationToken, type, initializer) => typescript_1.default.factory.updatePropertyDeclaration(node, ...splitModifiers(modifiers), name, questionOrExclamationToken, type, initializer);
|
|
35
|
-
exports.createPropertyDeclaration = IS_AFTER_TS_48 ?
|
|
36
|
-
typescript_1.default.factory.createPropertyDeclaration :
|
|
37
|
-
(modifiers, name, questionOrExclamationToken, type, initializer) => typescript_1.default.factory.createPropertyDeclaration(...splitModifiers(modifiers), name, questionOrExclamationToken, type, initializer);
|
|
38
|
-
exports.updateGetAccessorDeclaration = IS_AFTER_TS_48 ?
|
|
39
|
-
typescript_1.default.factory.updateGetAccessorDeclaration :
|
|
40
|
-
(node, modifiers, name, parameters, type, body) => typescript_1.default.factory.updateGetAccessorDeclaration(node, ...splitModifiers(modifiers), name, parameters, type, body);
|
|
41
|
-
exports.createGetAccessorDeclaration = IS_AFTER_TS_48 ?
|
|
42
|
-
typescript_1.default.factory.createGetAccessorDeclaration :
|
|
43
|
-
(modifiers, name, parameters, type, body) => typescript_1.default.factory.createGetAccessorDeclaration(...splitModifiers(modifiers), name, parameters, type, body);
|
|
44
|
-
exports.updateSetAccessorDeclaration = IS_AFTER_TS_48 ?
|
|
45
|
-
typescript_1.default.factory.updateSetAccessorDeclaration :
|
|
46
|
-
(node, modifiers, name, parameters, body) => typescript_1.default.factory.updateSetAccessorDeclaration(node, ...splitModifiers(modifiers), name, parameters, body);
|
|
47
|
-
exports.createSetAccessorDeclaration = IS_AFTER_TS_48 ?
|
|
48
|
-
typescript_1.default.factory.createSetAccessorDeclaration :
|
|
49
|
-
(modifiers, name, parameters, body) => typescript_1.default.factory.createSetAccessorDeclaration(...splitModifiers(modifiers), name, parameters, body);
|
|
50
|
-
exports.updateConstructorDeclaration = IS_AFTER_TS_48 ?
|
|
51
|
-
typescript_1.default.factory.updateConstructorDeclaration :
|
|
52
|
-
(node, modifiers, parameters, body) => typescript_1.default.factory.updateConstructorDeclaration(node, undefined, modifiers, parameters, body);
|
|
53
|
-
exports.getDecorators = IS_AFTER_TS_48 ? typescript_1.default.getDecorators : node => node.decorators;
|
|
54
|
-
exports.getModifiers = IS_AFTER_TS_48 ? typescript_1.default.getModifiers : node => node.modifiers;
|
|
55
|
-
function combineModifiers(decorators, modifiers) {
|
|
56
|
-
const hasDecorators = decorators === null || decorators === void 0 ? void 0 : decorators.length;
|
|
57
|
-
const hasModifiers = modifiers === null || modifiers === void 0 ? void 0 : modifiers.length;
|
|
58
|
-
if (hasDecorators && hasModifiers) {
|
|
59
|
-
return [...decorators, ...modifiers];
|
|
60
|
-
}
|
|
61
|
-
if (hasDecorators && !hasModifiers) {
|
|
62
|
-
return decorators;
|
|
63
|
-
}
|
|
64
|
-
if (hasModifiers && !hasDecorators) {
|
|
65
|
-
return modifiers;
|
|
66
|
-
}
|
|
67
|
-
return undefined;
|
|
68
|
-
}
|
|
69
|
-
exports.combineModifiers = combineModifiers;
|
|
13
|
+
const IS_AFTER_TS_49 = isAfterVersion(4, 9);
|
|
14
|
+
exports.createParameterDeclaration = IS_AFTER_TS_49 ?
|
|
15
|
+
typescript_1.default.factory.createParameterDeclaration :
|
|
16
|
+
(modifiers, dotDotDotToken, name, questionToken, type, initializer) => typescript_1.default.factory.createParameterDeclaration(...splitModifiers(modifiers), dotDotDotToken, name, questionToken, type, initializer);
|
|
17
|
+
exports.createImportDeclaration = IS_AFTER_TS_49 ?
|
|
18
|
+
typescript_1.default.factory.createImportDeclaration :
|
|
19
|
+
(modifiers, importClause, moduleSpecifier, assertClause) => typescript_1.default.factory.createImportDeclaration(undefined, modifiers, importClause, moduleSpecifier, assertClause);
|
|
20
|
+
exports.createFunctionDeclaration = IS_AFTER_TS_49 ?
|
|
21
|
+
typescript_1.default.factory.createFunctionDeclaration :
|
|
22
|
+
(modifiers, asteriskToken, name, typeParameters, parameters, type, body) => typescript_1.default.factory.createFunctionDeclaration(...splitModifiers(modifiers), asteriskToken, name, typeParameters, parameters, type, body);
|
|
23
|
+
exports.createIndexSignature = IS_AFTER_TS_49 ?
|
|
24
|
+
typescript_1.default.factory.createIndexSignature :
|
|
25
|
+
(modifiers, parameters, type) => typescript_1.default.factory.createIndexSignature(modifiers, parameters, type);
|
|
70
26
|
function splitModifiers(allModifiers) {
|
|
71
27
|
if (!allModifiers) {
|
|
72
28
|
return [undefined, undefined];
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getDownlevelDecoratorsTransform = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const typescript_1 = tslib_1.__importDefault(require("typescript"));
|
|
6
|
-
const ts_compatibility_1 = require("../../ngtsc/ts_compatibility");
|
|
7
6
|
const patch_alias_reference_resolution_1 = require("./patch_alias_reference_resolution");
|
|
8
7
|
function isAngularDecorator(decorator, isCore) {
|
|
9
8
|
return isCore || (decorator.import !== null && decorator.import.from === '@angular/core');
|
|
@@ -62,7 +61,7 @@ function createCtorParametersClassProperty(diagnostics, entityNameToExpression,
|
|
|
62
61
|
params.push(typescript_1.default.factory.createObjectLiteralExpression(members));
|
|
63
62
|
}
|
|
64
63
|
const initializer = typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), typescript_1.default.factory.createArrayLiteralExpression(params, true));
|
|
65
|
-
const ctorProp =
|
|
64
|
+
const ctorProp = typescript_1.default.factory.createPropertyDeclaration([typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.StaticKeyword)], 'ctorParameters', undefined, undefined, initializer);
|
|
66
65
|
if (isClosureCompilerEnabled) {
|
|
67
66
|
typescript_1.default.setSyntheticLeadingComments(ctorProp, [
|
|
68
67
|
{
|
|
@@ -146,7 +145,7 @@ function getDownlevelDecoratorsTransform(typeChecker, host, diagnostics, isCore,
|
|
|
146
145
|
function createDecoratorClassProperty(decoratorList) {
|
|
147
146
|
const modifier = typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.StaticKeyword);
|
|
148
147
|
const initializer = typescript_1.default.factory.createArrayLiteralExpression(decoratorList, true);
|
|
149
|
-
const prop =
|
|
148
|
+
const prop = typescript_1.default.factory.createPropertyDeclaration([modifier], 'decorators', undefined, undefined, initializer);
|
|
150
149
|
addJSDocTypeAnnotation(prop, DECORATOR_INVOCATION_JSDOC_TYPE);
|
|
151
150
|
return prop;
|
|
152
151
|
}
|
|
@@ -156,7 +155,7 @@ function getDownlevelDecoratorsTransform(typeChecker, host, diagnostics, isCore,
|
|
|
156
155
|
entries.push(typescript_1.default.factory.createPropertyAssignment(name, typescript_1.default.factory.createArrayLiteralExpression(decorators.map(deco => extractMetadataFromSingleDecorator(deco, diagnostics)))));
|
|
157
156
|
}
|
|
158
157
|
const initializer = typescript_1.default.factory.createObjectLiteralExpression(entries, true);
|
|
159
|
-
const prop =
|
|
158
|
+
const prop = typescript_1.default.factory.createPropertyDeclaration([typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.StaticKeyword)], 'propDecorators', undefined, undefined, initializer);
|
|
160
159
|
addJSDocTypeAnnotation(prop, `!Object<string, ${DECORATOR_INVOCATION_JSDOC_TYPE}>`);
|
|
161
160
|
return prop;
|
|
162
161
|
}
|
|
@@ -210,9 +209,11 @@ function getDownlevelDecoratorsTransform(typeChecker, host, diagnostics, isCore,
|
|
|
210
209
|
});
|
|
211
210
|
return [undefined, element, []];
|
|
212
211
|
}
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
212
|
+
const elementModifiers = typescript_1.default.canHaveModifiers(element) ? typescript_1.default.getModifiers(element) : undefined;
|
|
213
|
+
let modifiers;
|
|
214
|
+
if (decoratorsToKeep.length || (elementModifiers === null || elementModifiers === void 0 ? void 0 : elementModifiers.length)) {
|
|
215
|
+
modifiers = typescript_1.default.setTextRange(typescript_1.default.factory.createNodeArray([...decoratorsToKeep, ...(elementModifiers || [])]), element.modifiers);
|
|
216
|
+
}
|
|
216
217
|
return [element.name.text, cloneClassElementWithModifiers(element, modifiers), toLower];
|
|
217
218
|
}
|
|
218
219
|
function transformConstructor(ctor) {
|
|
@@ -236,10 +237,15 @@ function getDownlevelDecoratorsTransform(typeChecker, host, diagnostics, isCore,
|
|
|
236
237
|
paramInfo.type = param.type;
|
|
237
238
|
}
|
|
238
239
|
parametersInfo.push(paramInfo);
|
|
239
|
-
|
|
240
|
+
let modifiers;
|
|
241
|
+
const paramModifiers = typescript_1.default.getModifiers(param);
|
|
242
|
+
if (decoratorsToKeep.length || (paramModifiers === null || paramModifiers === void 0 ? void 0 : paramModifiers.length)) {
|
|
243
|
+
modifiers = [...decoratorsToKeep, ...(paramModifiers || [])];
|
|
244
|
+
}
|
|
245
|
+
const newParam = typescript_1.default.factory.updateParameterDeclaration(param, modifiers, param.dotDotDotToken, param.name, param.questionToken, param.type, param.initializer);
|
|
240
246
|
newParameters.push(newParam);
|
|
241
247
|
}
|
|
242
|
-
const updated =
|
|
248
|
+
const updated = typescript_1.default.factory.updateConstructorDeclaration(ctor, typescript_1.default.getModifiers(ctor), newParameters, ctor.body);
|
|
243
249
|
return [updated, parametersInfo];
|
|
244
250
|
}
|
|
245
251
|
function transformClassDeclaration(classDecl) {
|
|
@@ -272,7 +278,7 @@ function getDownlevelDecoratorsTransform(typeChecker, host, diagnostics, isCore,
|
|
|
272
278
|
}
|
|
273
279
|
newMembers.push(typescript_1.default.visitEachChild(member, decoratorDownlevelVisitor, context));
|
|
274
280
|
}
|
|
275
|
-
const decoratorsToKeep = new Set(
|
|
281
|
+
const decoratorsToKeep = new Set(typescript_1.default.getDecorators(classDecl));
|
|
276
282
|
const possibleAngularDecorators = host.getDecoratorsOfDeclaration(classDecl) || [];
|
|
277
283
|
let hasAngularDecorator = false;
|
|
278
284
|
const decoratorsToLower = [];
|
|
@@ -299,7 +305,12 @@ function getDownlevelDecoratorsTransform(typeChecker, host, diagnostics, isCore,
|
|
|
299
305
|
newMembers.push(createPropDecoratorsClassProperty(diagnostics, decoratedProperties));
|
|
300
306
|
}
|
|
301
307
|
const members = typescript_1.default.setTextRange(typescript_1.default.factory.createNodeArray(newMembers, classDecl.members.hasTrailingComma), classDecl.members);
|
|
302
|
-
|
|
308
|
+
const classModifiers = typescript_1.default.getModifiers(classDecl);
|
|
309
|
+
let modifiers;
|
|
310
|
+
if (decoratorsToKeep.size || (classModifiers === null || classModifiers === void 0 ? void 0 : classModifiers.length)) {
|
|
311
|
+
modifiers = [...decoratorsToKeep, ...(classModifiers || [])];
|
|
312
|
+
}
|
|
313
|
+
return typescript_1.default.factory.updateClassDeclaration(classDecl, modifiers, classDecl.name, classDecl.typeParameters, classDecl.heritageClauses, members);
|
|
303
314
|
}
|
|
304
315
|
function decoratorDownlevelVisitor(node) {
|
|
305
316
|
if (typescript_1.default.isClassDeclaration(node)) {
|
|
@@ -316,17 +327,17 @@ exports.getDownlevelDecoratorsTransform = getDownlevelDecoratorsTransform;
|
|
|
316
327
|
function cloneClassElementWithModifiers(node, modifiers) {
|
|
317
328
|
let clone;
|
|
318
329
|
if (typescript_1.default.isMethodDeclaration(node)) {
|
|
319
|
-
clone =
|
|
330
|
+
clone = typescript_1.default.factory.createMethodDeclaration(modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, node.body);
|
|
320
331
|
}
|
|
321
332
|
else if (typescript_1.default.isPropertyDeclaration(node)) {
|
|
322
|
-
clone =
|
|
333
|
+
clone = typescript_1.default.factory.createPropertyDeclaration(modifiers, node.name, node.questionToken, node.type, node.initializer);
|
|
323
334
|
}
|
|
324
335
|
else if (typescript_1.default.isGetAccessor(node)) {
|
|
325
|
-
clone =
|
|
326
|
-
(0, ts_compatibility_1.createGetAccessorDeclaration)(modifiers, node.name, node.parameters, node.type, node.body);
|
|
336
|
+
clone = typescript_1.default.factory.createGetAccessorDeclaration(modifiers, node.name, node.parameters, node.type, node.body);
|
|
327
337
|
}
|
|
328
338
|
else if (typescript_1.default.isSetAccessor(node)) {
|
|
329
|
-
clone =
|
|
339
|
+
clone =
|
|
340
|
+
typescript_1.default.factory.createSetAccessorDeclaration(modifiers, node.name, node.parameters, node.body);
|
|
330
341
|
}
|
|
331
342
|
else {
|
|
332
343
|
throw new Error(`Unsupported decorated member with kind ${typescript_1.default.SyntaxKind[node.kind]}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jest-preset-angular",
|
|
3
|
-
"version": "12.2.
|
|
3
|
+
"version": "12.2.4",
|
|
4
4
|
"description": "Jest preset configuration for Angular projects",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@angular/core": ">=12.2.16 <16.0.0",
|
|
60
60
|
"@angular/platform-browser-dynamic": ">=12.2.16 <16.0.0",
|
|
61
61
|
"jest": "^28.0.0",
|
|
62
|
-
"typescript": ">=4.
|
|
62
|
+
"typescript": ">=4.2"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@angular-devkit/build-angular": "^15.0.0",
|