@schematics/angular 21.0.0-next.7 → 21.0.0-next.8
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/ai-config/index.js +1 -0
- package/ai-config/index.js.map +1 -0
- package/ai-config/schema.js +1 -0
- package/ai-config/schema.js.map +1 -0
- package/app-shell/index.js +1 -0
- package/app-shell/index.js.map +1 -0
- package/app-shell/schema.js +1 -0
- package/app-shell/schema.js.map +1 -0
- package/application/index.js +1 -0
- package/application/index.js.map +1 -0
- package/application/schema.js +1 -0
- package/application/schema.js.map +1 -0
- package/application/schema.json +0 -1
- package/class/index.js +1 -0
- package/class/index.js.map +1 -0
- package/class/schema.js +1 -0
- package/class/schema.js.map +1 -0
- package/collection.json +6 -0
- package/component/index.js +1 -0
- package/component/index.js.map +1 -0
- package/component/schema.js +1 -0
- package/component/schema.js.map +1 -0
- package/config/index.js +1 -0
- package/config/index.js.map +1 -0
- package/config/schema.js +1 -0
- package/config/schema.js.map +1 -0
- package/directive/index.js +1 -0
- package/directive/index.js.map +1 -0
- package/directive/schema.js +1 -0
- package/directive/schema.js.map +1 -0
- package/e2e/index.js +1 -0
- package/e2e/index.js.map +1 -0
- package/e2e/schema.js +1 -0
- package/e2e/schema.js.map +1 -0
- package/enum/index.js +1 -0
- package/enum/index.js.map +1 -0
- package/enum/schema.js +1 -0
- package/enum/schema.js.map +1 -0
- package/environments/index.js +1 -0
- package/environments/index.js.map +1 -0
- package/environments/schema.js +1 -0
- package/environments/schema.js.map +1 -0
- package/guard/index.js +1 -0
- package/guard/index.js.map +1 -0
- package/guard/schema.js +1 -0
- package/guard/schema.js.map +1 -0
- package/interceptor/index.js +1 -0
- package/interceptor/index.js.map +1 -0
- package/interceptor/schema.js +1 -0
- package/interceptor/schema.js.map +1 -0
- package/interface/index.js +1 -0
- package/interface/index.js.map +1 -0
- package/interface/schema.js +1 -0
- package/interface/schema.js.map +1 -0
- package/library/index.js +1 -0
- package/library/index.js.map +1 -0
- package/library/schema.js +1 -0
- package/library/schema.js.map +1 -0
- package/migrations/karma/karma-config-analyzer.js +1 -0
- package/migrations/karma/karma-config-analyzer.js.map +1 -0
- package/migrations/karma/karma-config-comparer.js +1 -0
- package/migrations/karma/karma-config-comparer.js.map +1 -0
- package/migrations/karma/migration.js +1 -0
- package/migrations/karma/migration.js.map +1 -0
- package/migrations/migration-collection.json +5 -0
- package/migrations/update-module-resolution/migration.d.ts +9 -0
- package/migrations/update-module-resolution/migration.js +53 -0
- package/migrations/update-module-resolution/migration.js.map +1 -0
- package/migrations/update-typescript-lib/migration.js +1 -0
- package/migrations/update-typescript-lib/migration.js.map +1 -0
- package/migrations/use-application-builder/css-import-lexer.js +1 -0
- package/migrations/use-application-builder/css-import-lexer.js.map +1 -0
- package/migrations/use-application-builder/migration.js +1 -0
- package/migrations/use-application-builder/migration.js.map +1 -0
- package/migrations/use-application-builder/stylesheet-updates.js +1 -0
- package/migrations/use-application-builder/stylesheet-updates.js.map +1 -0
- package/module/index.js +1 -0
- package/module/index.js.map +1 -0
- package/module/schema.js +1 -0
- package/module/schema.js.map +1 -0
- package/ng-new/index.js +1 -0
- package/ng-new/index.js.map +1 -0
- package/ng-new/schema.js +1 -0
- package/ng-new/schema.js.map +1 -0
- package/package.json +4 -4
- package/pipe/index.js +1 -0
- package/pipe/index.js.map +1 -0
- package/pipe/schema.js +1 -0
- package/pipe/schema.js.map +1 -0
- package/refactor/jasmine-vitest/index.d.ts +10 -0
- package/refactor/jasmine-vitest/index.js +103 -0
- package/refactor/jasmine-vitest/index.js.map +1 -0
- package/refactor/jasmine-vitest/schema.d.ts +25 -0
- package/refactor/jasmine-vitest/schema.js +5 -0
- package/refactor/jasmine-vitest/schema.js.map +1 -0
- package/refactor/jasmine-vitest/schema.json +30 -0
- package/refactor/jasmine-vitest/test-file-transformer.d.ts +16 -0
- package/refactor/jasmine-vitest/test-file-transformer.js +113 -0
- package/refactor/jasmine-vitest/test-file-transformer.js.map +1 -0
- package/refactor/jasmine-vitest/transformers/jasmine-lifecycle.d.ts +18 -0
- package/refactor/jasmine-vitest/transformers/jasmine-lifecycle.js +250 -0
- package/refactor/jasmine-vitest/transformers/jasmine-lifecycle.js.map +1 -0
- package/refactor/jasmine-vitest/transformers/jasmine-matcher.d.ts +26 -0
- package/refactor/jasmine-vitest/transformers/jasmine-matcher.js +398 -0
- package/refactor/jasmine-vitest/transformers/jasmine-matcher.js.map +1 -0
- package/refactor/jasmine-vitest/transformers/jasmine-misc.d.ts +21 -0
- package/refactor/jasmine-vitest/transformers/jasmine-misc.js +164 -0
- package/refactor/jasmine-vitest/transformers/jasmine-misc.js.map +1 -0
- package/refactor/jasmine-vitest/transformers/jasmine-spy.d.ts +19 -0
- package/refactor/jasmine-vitest/transformers/jasmine-spy.js +284 -0
- package/refactor/jasmine-vitest/transformers/jasmine-spy.js.map +1 -0
- package/refactor/jasmine-vitest/utils/ast-helpers.d.ts +11 -0
- package/refactor/jasmine-vitest/utils/ast-helpers.js +29 -0
- package/refactor/jasmine-vitest/utils/ast-helpers.js.map +1 -0
- package/refactor/jasmine-vitest/utils/ast-validation.d.ts +25 -0
- package/refactor/jasmine-vitest/utils/ast-validation.js +44 -0
- package/refactor/jasmine-vitest/utils/ast-validation.js.map +1 -0
- package/refactor/jasmine-vitest/utils/comment-helpers.d.ts +29 -0
- package/refactor/jasmine-vitest/utils/comment-helpers.js +37 -0
- package/refactor/jasmine-vitest/utils/comment-helpers.js.map +1 -0
- package/refactor/jasmine-vitest/utils/refactor-context.d.ts +26 -0
- package/refactor/jasmine-vitest/utils/refactor-context.js +10 -0
- package/refactor/jasmine-vitest/utils/refactor-context.js.map +1 -0
- package/refactor/jasmine-vitest/utils/refactor-reporter.d.ts +24 -0
- package/refactor/jasmine-vitest/utils/refactor-reporter.js +72 -0
- package/refactor/jasmine-vitest/utils/refactor-reporter.js.map +1 -0
- package/refactor/jasmine-vitest/utils/todo-notes.d.ts +132 -0
- package/refactor/jasmine-vitest/utils/todo-notes.js +108 -0
- package/refactor/jasmine-vitest/utils/todo-notes.js.map +1 -0
- package/resolver/index.js +1 -0
- package/resolver/index.js.map +1 -0
- package/resolver/schema.js +1 -0
- package/resolver/schema.js.map +1 -0
- package/server/index.js +1 -0
- package/server/index.js.map +1 -0
- package/server/schema.js +1 -0
- package/server/schema.js.map +1 -0
- package/service/index.js +1 -0
- package/service/index.js.map +1 -0
- package/service/schema.js +1 -0
- package/service/schema.js.map +1 -0
- package/service-worker/index.js +1 -0
- package/service-worker/index.js.map +1 -0
- package/service-worker/schema.js +1 -0
- package/service-worker/schema.js.map +1 -0
- package/ssr/index.js +1 -0
- package/ssr/index.js.map +1 -0
- package/ssr/schema.js +1 -0
- package/ssr/schema.js.map +1 -0
- package/ssr/tty.js +1 -0
- package/ssr/tty.js.map +1 -0
- package/tailwind/index.js +1 -0
- package/tailwind/index.js.map +1 -0
- package/tailwind/schema.js +1 -0
- package/tailwind/schema.js.map +1 -0
- package/utility/add-declaration-to-ng-module.js +1 -0
- package/utility/add-declaration-to-ng-module.js.map +1 -0
- package/utility/ast-utils.js +1 -0
- package/utility/ast-utils.js.map +1 -0
- package/utility/change.js +1 -0
- package/utility/change.js.map +1 -0
- package/utility/dependencies.js +1 -0
- package/utility/dependencies.js.map +1 -0
- package/utility/dependency.js +1 -0
- package/utility/dependency.js.map +1 -0
- package/utility/eol.js +1 -0
- package/utility/eol.js.map +1 -0
- package/utility/find-module.js +1 -0
- package/utility/find-module.js.map +1 -0
- package/utility/generate-from-files.js +1 -0
- package/utility/generate-from-files.js.map +1 -0
- package/utility/index.js +1 -0
- package/utility/index.js.map +1 -0
- package/utility/json-file.js +1 -0
- package/utility/json-file.js.map +1 -0
- package/utility/latest-versions.js +4 -3
- package/utility/latest-versions.js.map +1 -0
- package/utility/ng-ast-utils.js +1 -0
- package/utility/ng-ast-utils.js.map +1 -0
- package/utility/parse-name.js +1 -0
- package/utility/parse-name.js.map +1 -0
- package/utility/paths.js +1 -0
- package/utility/paths.js.map +1 -0
- package/utility/project-targets.js +1 -0
- package/utility/project-targets.js.map +1 -0
- package/utility/project.js +1 -0
- package/utility/project.js.map +1 -0
- package/utility/standalone/app_component.js +1 -0
- package/utility/standalone/app_component.js.map +1 -0
- package/utility/standalone/app_config.js +1 -0
- package/utility/standalone/app_config.js.map +1 -0
- package/utility/standalone/code_block.js +1 -0
- package/utility/standalone/code_block.js.map +1 -0
- package/utility/standalone/index.js +1 -0
- package/utility/standalone/index.js.map +1 -0
- package/utility/standalone/rules.js +1 -0
- package/utility/standalone/rules.js.map +1 -0
- package/utility/standalone/util.js +1 -0
- package/utility/standalone/util.js.map +1 -0
- package/utility/validation.js +1 -0
- package/utility/validation.js.map +1 -0
- package/utility/workspace-models.js +1 -0
- package/utility/workspace-models.js.map +1 -0
- package/utility/workspace.js +1 -0
- package/utility/workspace.js.map +1 -0
- package/web-worker/index.js +1 -0
- package/web-worker/index.js.map +1 -0
- package/web-worker/schema.js +1 -0
- package/web-worker/schema.js.map +1 -0
- package/workspace/index.js +1 -0
- package/workspace/index.js.map +1 -0
- package/workspace/schema.js +1 -0
- package/workspace/schema.js.map +1 -0
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.transformSpies = transformSpies;
|
|
14
|
+
exports.transformCreateSpyObj = transformCreateSpyObj;
|
|
15
|
+
exports.transformSpyReset = transformSpyReset;
|
|
16
|
+
exports.transformSpyCallInspection = transformSpyCallInspection;
|
|
17
|
+
/**
|
|
18
|
+
* @fileoverview This file contains transformers dedicated to converting Jasmine's spying
|
|
19
|
+
* functionality to Vitest's mocking APIs. It handles the creation of spies (`spyOn`,
|
|
20
|
+
* `createSpy`, `createSpyObj`), spy strategies (`and.returnValue`, `and.callFake`),
|
|
21
|
+
* and the inspection of spy calls (`spy.calls.reset`, `spy.calls.mostRecent`).
|
|
22
|
+
*/
|
|
23
|
+
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
24
|
+
const ast_helpers_1 = require("../utils/ast-helpers");
|
|
25
|
+
const ast_validation_1 = require("../utils/ast-validation");
|
|
26
|
+
const comment_helpers_1 = require("../utils/comment-helpers");
|
|
27
|
+
function transformSpies(node, refactorCtx) {
|
|
28
|
+
const { sourceFile, reporter } = refactorCtx;
|
|
29
|
+
if (!typescript_1.default.isCallExpression(node)) {
|
|
30
|
+
return node;
|
|
31
|
+
}
|
|
32
|
+
if (typescript_1.default.isIdentifier(node.expression) &&
|
|
33
|
+
(node.expression.text === 'spyOn' || node.expression.text === 'spyOnProperty')) {
|
|
34
|
+
reporter.reportTransformation(sourceFile, node, `Transformed \`${node.expression.text}\` to \`vi.spyOn\`.`);
|
|
35
|
+
return typescript_1.default.factory.updateCallExpression(node, (0, ast_helpers_1.createPropertyAccess)('vi', 'spyOn'), node.typeArguments, node.arguments);
|
|
36
|
+
}
|
|
37
|
+
if (typescript_1.default.isPropertyAccessExpression(node.expression)) {
|
|
38
|
+
const pae = node.expression;
|
|
39
|
+
if (typescript_1.default.isPropertyAccessExpression(pae.expression) &&
|
|
40
|
+
typescript_1.default.isIdentifier(pae.expression.name) &&
|
|
41
|
+
pae.expression.name.text === 'and') {
|
|
42
|
+
const spyCall = pae.expression.expression;
|
|
43
|
+
let newMethodName;
|
|
44
|
+
if (typescript_1.default.isIdentifier(pae.name)) {
|
|
45
|
+
const strategyName = pae.name.text;
|
|
46
|
+
switch (strategyName) {
|
|
47
|
+
case 'returnValue':
|
|
48
|
+
newMethodName = 'mockReturnValue';
|
|
49
|
+
break;
|
|
50
|
+
case 'resolveTo':
|
|
51
|
+
newMethodName = 'mockResolvedValue';
|
|
52
|
+
break;
|
|
53
|
+
case 'rejectWith':
|
|
54
|
+
newMethodName = 'mockRejectedValue';
|
|
55
|
+
break;
|
|
56
|
+
case 'returnValues': {
|
|
57
|
+
reporter.reportTransformation(sourceFile, node, 'Transformed `.and.returnValues()` to chained `.mockReturnValueOnce()` calls.');
|
|
58
|
+
const returnValues = node.arguments;
|
|
59
|
+
if (returnValues.length === 0) {
|
|
60
|
+
// No values, so it's a no-op. Just transform the spyOn call.
|
|
61
|
+
return transformSpies(spyCall, refactorCtx);
|
|
62
|
+
}
|
|
63
|
+
// spy.and.returnValues(a, b) -> spy.mockReturnValueOnce(a).mockReturnValueOnce(b)
|
|
64
|
+
let chainedCall = spyCall;
|
|
65
|
+
for (const value of returnValues) {
|
|
66
|
+
const mockCall = typescript_1.default.factory.createCallExpression((0, ast_helpers_1.createPropertyAccess)(chainedCall, 'mockReturnValueOnce'), undefined, [value]);
|
|
67
|
+
chainedCall = mockCall;
|
|
68
|
+
}
|
|
69
|
+
return chainedCall;
|
|
70
|
+
}
|
|
71
|
+
case 'callFake':
|
|
72
|
+
newMethodName = 'mockImplementation';
|
|
73
|
+
break;
|
|
74
|
+
case 'callThrough':
|
|
75
|
+
reporter.reportTransformation(sourceFile, node, 'Removed redundant `.and.callThrough()` call.');
|
|
76
|
+
return transformSpies(spyCall, refactorCtx); // .and.callThrough() is redundant, just transform spyOn.
|
|
77
|
+
case 'stub': {
|
|
78
|
+
reporter.reportTransformation(sourceFile, node, 'Transformed `.and.stub()` to `.mockImplementation()`.');
|
|
79
|
+
const newExpression = (0, ast_helpers_1.createPropertyAccess)(spyCall, 'mockImplementation');
|
|
80
|
+
const arrowFn = typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), typescript_1.default.factory.createBlock([], /* multiline */ true));
|
|
81
|
+
return typescript_1.default.factory.createCallExpression(newExpression, undefined, [arrowFn]);
|
|
82
|
+
}
|
|
83
|
+
case 'throwError': {
|
|
84
|
+
reporter.reportTransformation(sourceFile, node, 'Transformed `.and.throwError()` to `.mockImplementation()`.');
|
|
85
|
+
const errorArg = node.arguments[0];
|
|
86
|
+
const throwStatement = typescript_1.default.factory.createThrowStatement(typescript_1.default.isNewExpression(errorArg)
|
|
87
|
+
? errorArg
|
|
88
|
+
: typescript_1.default.factory.createNewExpression(typescript_1.default.factory.createIdentifier('Error'), undefined, node.arguments));
|
|
89
|
+
const arrowFunction = typescript_1.default.factory.createArrowFunction(undefined, undefined, [], undefined, typescript_1.default.factory.createToken(typescript_1.default.SyntaxKind.EqualsGreaterThanToken), typescript_1.default.factory.createBlock([throwStatement], true));
|
|
90
|
+
const newExpression = (0, ast_helpers_1.createPropertyAccess)(spyCall, 'mockImplementation');
|
|
91
|
+
return typescript_1.default.factory.createCallExpression(newExpression, undefined, [arrowFunction]);
|
|
92
|
+
}
|
|
93
|
+
default: {
|
|
94
|
+
const category = 'unsupported-spy-strategy';
|
|
95
|
+
reporter.recordTodo(category);
|
|
96
|
+
(0, comment_helpers_1.addTodoComment)(node, category, { name: strategyName });
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (newMethodName) {
|
|
101
|
+
reporter.reportTransformation(sourceFile, node, `Transformed spy strategy \`.and.${strategyName}()\` to \`.${newMethodName}()\`.`);
|
|
102
|
+
const newExpression = typescript_1.default.factory.updatePropertyAccessExpression(pae, spyCall, typescript_1.default.factory.createIdentifier(newMethodName));
|
|
103
|
+
return typescript_1.default.factory.updateCallExpression(node, newExpression, node.typeArguments, node.arguments);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const jasmineMethodName = (0, ast_validation_1.getJasmineMethodName)(node);
|
|
109
|
+
switch (jasmineMethodName) {
|
|
110
|
+
case 'createSpy':
|
|
111
|
+
reporter.reportTransformation(sourceFile, node, 'Transformed `jasmine.createSpy()` to `vi.fn()`.');
|
|
112
|
+
// jasmine.createSpy(name, originalFn) -> vi.fn(originalFn)
|
|
113
|
+
return (0, ast_helpers_1.createViCallExpression)('fn', node.arguments.length > 1 ? [node.arguments[1]] : []);
|
|
114
|
+
case 'spyOnAllFunctions': {
|
|
115
|
+
reporter.reportTransformation(sourceFile, node, 'Found unsupported `jasmine.spyOnAllFunctions()`.');
|
|
116
|
+
const category = 'spyOnAllFunctions';
|
|
117
|
+
reporter.recordTodo(category);
|
|
118
|
+
(0, comment_helpers_1.addTodoComment)(node, category);
|
|
119
|
+
return node;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return node;
|
|
123
|
+
}
|
|
124
|
+
function transformCreateSpyObj(node, { sourceFile, reporter }) {
|
|
125
|
+
if (!(0, ast_validation_1.isJasmineCallExpression)(node, 'createSpyObj')) {
|
|
126
|
+
return node;
|
|
127
|
+
}
|
|
128
|
+
reporter.reportTransformation(sourceFile, node, 'Transformed `jasmine.createSpyObj()` to an object literal with `vi.fn()`.');
|
|
129
|
+
if (node.arguments.length < 2) {
|
|
130
|
+
const category = 'createSpyObj-single-argument';
|
|
131
|
+
reporter.recordTodo(category);
|
|
132
|
+
(0, comment_helpers_1.addTodoComment)(node, category);
|
|
133
|
+
return node;
|
|
134
|
+
}
|
|
135
|
+
const methods = node.arguments[1];
|
|
136
|
+
const propertiesArg = node.arguments[2];
|
|
137
|
+
let properties = [];
|
|
138
|
+
if (typescript_1.default.isArrayLiteralExpression(methods)) {
|
|
139
|
+
properties = createSpyObjWithArray(methods);
|
|
140
|
+
}
|
|
141
|
+
else if (typescript_1.default.isObjectLiteralExpression(methods)) {
|
|
142
|
+
properties = createSpyObjWithObject(methods);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const category = 'createSpyObj-dynamic-variable';
|
|
146
|
+
reporter.recordTodo(category);
|
|
147
|
+
(0, comment_helpers_1.addTodoComment)(node, category);
|
|
148
|
+
return node;
|
|
149
|
+
}
|
|
150
|
+
if (propertiesArg) {
|
|
151
|
+
if (typescript_1.default.isObjectLiteralExpression(propertiesArg)) {
|
|
152
|
+
properties.push(...propertiesArg.properties);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const category = 'createSpyObj-dynamic-property-map';
|
|
156
|
+
reporter.recordTodo(category);
|
|
157
|
+
(0, comment_helpers_1.addTodoComment)(node, category);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return typescript_1.default.factory.createObjectLiteralExpression(properties, true);
|
|
161
|
+
}
|
|
162
|
+
function createSpyObjWithArray(methods) {
|
|
163
|
+
return methods.elements
|
|
164
|
+
.map((element) => {
|
|
165
|
+
if (typescript_1.default.isStringLiteral(element)) {
|
|
166
|
+
return typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(element.text), (0, ast_helpers_1.createViCallExpression)('fn'));
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
})
|
|
170
|
+
.filter((p) => !!p);
|
|
171
|
+
}
|
|
172
|
+
function createSpyObjWithObject(methods) {
|
|
173
|
+
return methods.properties
|
|
174
|
+
.map((prop) => {
|
|
175
|
+
if (typescript_1.default.isPropertyAssignment(prop) && typescript_1.default.isIdentifier(prop.name)) {
|
|
176
|
+
const methodName = prop.name.text;
|
|
177
|
+
const returnValue = prop.initializer;
|
|
178
|
+
const mockFn = (0, ast_helpers_1.createViCallExpression)('fn');
|
|
179
|
+
const mockReturnValue = (0, ast_helpers_1.createPropertyAccess)(mockFn, 'mockReturnValue');
|
|
180
|
+
return typescript_1.default.factory.createPropertyAssignment(typescript_1.default.factory.createIdentifier(methodName), typescript_1.default.factory.createCallExpression(mockReturnValue, undefined, [returnValue]));
|
|
181
|
+
}
|
|
182
|
+
return undefined;
|
|
183
|
+
})
|
|
184
|
+
.filter((p) => !!p);
|
|
185
|
+
}
|
|
186
|
+
function transformSpyReset(node, { sourceFile, reporter }) {
|
|
187
|
+
if (typescript_1.default.isCallExpression(node) &&
|
|
188
|
+
typescript_1.default.isPropertyAccessExpression(node.expression) &&
|
|
189
|
+
typescript_1.default.isIdentifier(node.expression.name) &&
|
|
190
|
+
node.expression.name.text === 'reset' &&
|
|
191
|
+
typescript_1.default.isPropertyAccessExpression(node.expression.expression)) {
|
|
192
|
+
const callsPae = node.expression.expression;
|
|
193
|
+
if (typescript_1.default.isIdentifier(callsPae.name) && callsPae.name.text === 'calls') {
|
|
194
|
+
reporter.reportTransformation(sourceFile, node, 'Transformed `spy.calls.reset()` to `.mockClear()`.');
|
|
195
|
+
const spyIdentifier = callsPae.expression;
|
|
196
|
+
const newExpression = (0, ast_helpers_1.createPropertyAccess)(spyIdentifier, 'mockClear');
|
|
197
|
+
return typescript_1.default.factory.updateCallExpression(node, newExpression, node.typeArguments, []);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return node;
|
|
201
|
+
}
|
|
202
|
+
function getSpyIdentifierFromCalls(node) {
|
|
203
|
+
if (typescript_1.default.isIdentifier(node.name) && node.name.text === 'calls') {
|
|
204
|
+
return node.expression;
|
|
205
|
+
}
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
function createMockedSpyMockProperty(spyIdentifier) {
|
|
209
|
+
const mockedSpy = typescript_1.default.factory.createCallExpression((0, ast_helpers_1.createPropertyAccess)('vi', 'mocked'), undefined, [spyIdentifier]);
|
|
210
|
+
return (0, ast_helpers_1.createPropertyAccess)(mockedSpy, 'mock');
|
|
211
|
+
}
|
|
212
|
+
function transformSpyCallInspection(node, { sourceFile, reporter }) {
|
|
213
|
+
// mySpy.calls.mostRecent().args -> vi.mocked(mySpy).mock.lastCall
|
|
214
|
+
if (typescript_1.default.isPropertyAccessExpression(node) &&
|
|
215
|
+
typescript_1.default.isIdentifier(node.name) &&
|
|
216
|
+
node.name.text === 'args') {
|
|
217
|
+
const mostRecentCall = node.expression;
|
|
218
|
+
if (typescript_1.default.isCallExpression(mostRecentCall) &&
|
|
219
|
+
typescript_1.default.isPropertyAccessExpression(mostRecentCall.expression)) {
|
|
220
|
+
const mostRecentPae = mostRecentCall.expression; // mySpy.calls.mostRecent
|
|
221
|
+
if (typescript_1.default.isIdentifier(mostRecentPae.name) &&
|
|
222
|
+
mostRecentPae.name.text === 'mostRecent' &&
|
|
223
|
+
typescript_1.default.isPropertyAccessExpression(mostRecentPae.expression)) {
|
|
224
|
+
const spyIdentifier = getSpyIdentifierFromCalls(mostRecentPae.expression);
|
|
225
|
+
if (spyIdentifier) {
|
|
226
|
+
reporter.reportTransformation(sourceFile, node, 'Transformed `spy.calls.mostRecent().args` to `vi.mocked(spy).mock.lastCall`.');
|
|
227
|
+
const mockProperty = createMockedSpyMockProperty(spyIdentifier);
|
|
228
|
+
return (0, ast_helpers_1.createPropertyAccess)(mockProperty, 'lastCall');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if (typescript_1.default.isCallExpression(node) && typescript_1.default.isPropertyAccessExpression(node.expression)) {
|
|
234
|
+
const pae = node.expression; // e.g., mySpy.calls.count
|
|
235
|
+
const spyIdentifier = typescript_1.default.isPropertyAccessExpression(pae.expression)
|
|
236
|
+
? getSpyIdentifierFromCalls(pae.expression)
|
|
237
|
+
: undefined;
|
|
238
|
+
if (spyIdentifier) {
|
|
239
|
+
const mockProperty = createMockedSpyMockProperty(spyIdentifier);
|
|
240
|
+
const callsProperty = (0, ast_helpers_1.createPropertyAccess)(mockProperty, 'calls');
|
|
241
|
+
const callName = pae.name.text;
|
|
242
|
+
let newExpression;
|
|
243
|
+
let message;
|
|
244
|
+
switch (callName) {
|
|
245
|
+
case 'any':
|
|
246
|
+
message = 'Transformed `spy.calls.any()` to a check on `mock.calls.length`.';
|
|
247
|
+
newExpression = typescript_1.default.factory.createBinaryExpression((0, ast_helpers_1.createPropertyAccess)(callsProperty, 'length'), typescript_1.default.SyntaxKind.GreaterThanToken, typescript_1.default.factory.createNumericLiteral(0));
|
|
248
|
+
break;
|
|
249
|
+
case 'count':
|
|
250
|
+
message = 'Transformed `spy.calls.count()` to `mock.calls.length`.';
|
|
251
|
+
newExpression = (0, ast_helpers_1.createPropertyAccess)(callsProperty, 'length');
|
|
252
|
+
break;
|
|
253
|
+
case 'first':
|
|
254
|
+
message = 'Transformed `spy.calls.first()` to `mock.calls[0]`.';
|
|
255
|
+
newExpression = typescript_1.default.factory.createElementAccessExpression(callsProperty, 0);
|
|
256
|
+
break;
|
|
257
|
+
case 'all':
|
|
258
|
+
case 'allArgs':
|
|
259
|
+
message = `Transformed \`spy.calls.${callName}()\` to \`mock.calls\`.`;
|
|
260
|
+
newExpression = callsProperty;
|
|
261
|
+
break;
|
|
262
|
+
case 'argsFor':
|
|
263
|
+
message = 'Transformed `spy.calls.argsFor()` to `mock.calls[i]`.';
|
|
264
|
+
newExpression = typescript_1.default.factory.createElementAccessExpression(callsProperty, node.arguments[0]);
|
|
265
|
+
break;
|
|
266
|
+
case 'mostRecent':
|
|
267
|
+
if (!typescript_1.default.isPropertyAccessExpression(node.parent) ||
|
|
268
|
+
!typescript_1.default.isIdentifier(node.parent.name) ||
|
|
269
|
+
node.parent.name.text !== 'args') {
|
|
270
|
+
const category = 'mostRecent-without-args';
|
|
271
|
+
reporter.recordTodo(category);
|
|
272
|
+
(0, comment_helpers_1.addTodoComment)(node, category);
|
|
273
|
+
}
|
|
274
|
+
return node;
|
|
275
|
+
}
|
|
276
|
+
if (newExpression && message) {
|
|
277
|
+
reporter.reportTransformation(sourceFile, node, message);
|
|
278
|
+
return newExpression;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return node;
|
|
283
|
+
}
|
|
284
|
+
//# sourceMappingURL=jasmine-spy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jasmine-spy.js","sourceRoot":"","sources":["jasmine-spy.ts"],"names":[],"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OAAO,CAAC,6BAA6B,CACtD,aAAa,EACb,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAClB,CAAC;oBACF,MAAM;gBACR,KAAK,YAAY;oBACf,IACE,CAAC,oBAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,MAAM,CAAC;wBAC3C,CAAC,oBAAE,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;wBAClC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,EAChC,CAAC;wBACD,MAAM,QAAQ,GAAG,yBAAyB,CAAC;wBAC3C,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;wBAC9B,IAAA,gCAAc,EAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;oBACjC,CAAC;oBAED,OAAO,IAAI,CAAC;YAChB,CAAC;YAED,IAAI,aAAa,IAAI,OAAO,EAAE,CAAC;gBAC7B,QAAQ,CAAC,oBAAoB,CAAC,UAAU,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;gBAEzD,OAAO,aAAa,CAAC;YACvB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC 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.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
9
|
+
export declare function createViCallExpression(methodName: string, args?: readonly ts.Expression[], typeArgs?: ts.TypeNode[] | undefined): ts.CallExpression;
|
|
10
|
+
export declare function createExpectCallExpression(args: ts.Expression[], typeArgs?: ts.TypeNode[] | undefined): ts.CallExpression;
|
|
11
|
+
export declare function createPropertyAccess(expressionOrIndentifierText: ts.Expression | string, name: string | ts.MemberName): ts.PropertyAccessExpression;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.createViCallExpression = createViCallExpression;
|
|
14
|
+
exports.createExpectCallExpression = createExpectCallExpression;
|
|
15
|
+
exports.createPropertyAccess = createPropertyAccess;
|
|
16
|
+
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
17
|
+
function createViCallExpression(methodName, args = [], typeArgs = undefined) {
|
|
18
|
+
const callee = typescript_1.default.factory.createPropertyAccessExpression(typescript_1.default.factory.createIdentifier('vi'), methodName);
|
|
19
|
+
return typescript_1.default.factory.createCallExpression(callee, typeArgs, args);
|
|
20
|
+
}
|
|
21
|
+
function createExpectCallExpression(args, typeArgs = undefined) {
|
|
22
|
+
return typescript_1.default.factory.createCallExpression(typescript_1.default.factory.createIdentifier('expect'), typeArgs, args);
|
|
23
|
+
}
|
|
24
|
+
function createPropertyAccess(expressionOrIndentifierText, name) {
|
|
25
|
+
return typescript_1.default.factory.createPropertyAccessExpression(typeof expressionOrIndentifierText === 'string'
|
|
26
|
+
? typescript_1.default.factory.createIdentifier(expressionOrIndentifierText)
|
|
27
|
+
: expressionOrIndentifierText, name);
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=ast-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-helpers.js","sourceRoot":"","sources":["ast-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAIH,wDAWC;AAED,gEAKC;AAED,oDAUC;AAhCD,qHAAqF;AAErF,SAAgB,sBAAsB,CACpC,UAAkB,EAClB,OAAiC,EAAE,EACnC,WAAsC,SAAS;IAE/C,MAAM,MAAM,GAAG,oBAAE,CAAC,OAAO,CAAC,8BAA8B,CACtD,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,EACjC,UAAU,CACX,CAAC;IAEF,OAAO,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC;AAED,SAAgB,0BAA0B,CACxC,IAAqB,EACrB,WAAsC,SAAS;IAE/C,OAAO,oBAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;AAChG,CAAC;AAED,SAAgB,oBAAoB,CAClC,2BAAmD,EACnD,IAA4B;IAE5B,OAAO,oBAAE,CAAC,OAAO,CAAC,8BAA8B,CAC9C,OAAO,2BAA2B,KAAK,QAAQ;QAC7C,CAAC,CAAC,oBAAE,CAAC,OAAO,CAAC,gBAAgB,CAAC,2BAA2B,CAAC;QAC1D,CAAC,CAAC,2BAA2B,EAC/B,IAAI,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC 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.dev/license
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @fileoverview This file contains helper functions for validating the structure of
|
|
10
|
+
* TypeScript AST nodes, particularly for identifying specific patterns in Jasmine tests.
|
|
11
|
+
*/
|
|
12
|
+
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
13
|
+
/**
|
|
14
|
+
* If a node is a `jasmine.method()` call, returns the method name.
|
|
15
|
+
* @param node The node to check.
|
|
16
|
+
* @returns The name of the method if it's a jasmine call, otherwise undefined.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getJasmineMethodName(node: ts.Node): string | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Checks if a node is a call expression for a specific method on the `jasmine` object.
|
|
21
|
+
* @param node The node to check.
|
|
22
|
+
* @param methodName The name of the method on the `jasmine` object.
|
|
23
|
+
* @returns True if the node is a `jasmine.<methodName>()` call.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isJasmineCallExpression(node: ts.Node, methodName: string): node is ts.CallExpression;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.getJasmineMethodName = getJasmineMethodName;
|
|
14
|
+
exports.isJasmineCallExpression = isJasmineCallExpression;
|
|
15
|
+
/**
|
|
16
|
+
* @fileoverview This file contains helper functions for validating the structure of
|
|
17
|
+
* TypeScript AST nodes, particularly for identifying specific patterns in Jasmine tests.
|
|
18
|
+
*/
|
|
19
|
+
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
20
|
+
/**
|
|
21
|
+
* If a node is a `jasmine.method()` call, returns the method name.
|
|
22
|
+
* @param node The node to check.
|
|
23
|
+
* @returns The name of the method if it's a jasmine call, otherwise undefined.
|
|
24
|
+
*/
|
|
25
|
+
function getJasmineMethodName(node) {
|
|
26
|
+
if (!typescript_1.default.isCallExpression(node) || !typescript_1.default.isPropertyAccessExpression(node.expression)) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const pae = node.expression;
|
|
30
|
+
if (!typescript_1.default.isIdentifier(pae.expression) || pae.expression.text !== 'jasmine') {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
return typescript_1.default.isIdentifier(pae.name) ? pae.name.text : undefined;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Checks if a node is a call expression for a specific method on the `jasmine` object.
|
|
37
|
+
* @param node The node to check.
|
|
38
|
+
* @param methodName The name of the method on the `jasmine` object.
|
|
39
|
+
* @returns True if the node is a `jasmine.<methodName>()` call.
|
|
40
|
+
*/
|
|
41
|
+
function isJasmineCallExpression(node, methodName) {
|
|
42
|
+
return getJasmineMethodName(node) === methodName;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=ast-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast-validation.js","sourceRoot":"","sources":["ast-validation.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAcH,oDAWC;AAQD,0DAKC;AApCD;;;GAGG;AAEH,qHAAqF;AAErF;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,IAAa;IAChD,IAAI,CAAC,oBAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAE,CAAC,0BAA0B,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAClF,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC;IAC5B,IAAI,CAAC,oBAAE,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC1E,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,oBAAE,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,SAAgB,uBAAuB,CACrC,IAAa,EACb,UAAkB;IAElB,OAAO,oBAAoB,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC 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.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
9
|
+
import { TodoCategory, TodoContextMap } from './todo-notes';
|
|
10
|
+
type CategoriesWithNoContext = {
|
|
11
|
+
[K in TodoCategory]: TodoContextMap[K] extends never ? K : never;
|
|
12
|
+
}[TodoCategory];
|
|
13
|
+
/**
|
|
14
|
+
* Adds a TODO comment to a TypeScript node for manual migration.
|
|
15
|
+
* This overload handles categories that do not require a context object.
|
|
16
|
+
* @param node The AST node to which the comment will be added.
|
|
17
|
+
* @param category The category of the TODO, used to look up the message and URL.
|
|
18
|
+
*/
|
|
19
|
+
export declare function addTodoComment<T extends CategoriesWithNoContext>(node: ts.Node, category: T): void;
|
|
20
|
+
/**
|
|
21
|
+
* Adds a TODO comment to a TypeScript node for manual migration.
|
|
22
|
+
* This overload handles categories that require a context object, ensuring it is
|
|
23
|
+
* provided and correctly typed.
|
|
24
|
+
* @param node The AST node to which the comment will be added.
|
|
25
|
+
* @param category The category of the TODO, used to look up the message and URL.
|
|
26
|
+
* @param context The context object providing dynamic values for the message.
|
|
27
|
+
*/
|
|
28
|
+
export declare function addTodoComment<T extends TodoCategory>(node: ts.Node, category: T, context: TodoContextMap[T]): void;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.addTodoComment = addTodoComment;
|
|
14
|
+
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
15
|
+
const todo_notes_1 = require("./todo-notes");
|
|
16
|
+
// Implementation that covers both overloads.
|
|
17
|
+
function addTodoComment(node, category, context) {
|
|
18
|
+
const note = todo_notes_1.TODO_NOTES[category];
|
|
19
|
+
// The type assertion is safe here because the overloads guarantee the correct context is passed.
|
|
20
|
+
const message = typeof note.message === 'function' ? note.message(context) : note.message;
|
|
21
|
+
const url = 'url' in note && note.url ? ` See: ${note.url}` : '';
|
|
22
|
+
const commentText = ` TODO: vitest-migration: ${message}${url}`;
|
|
23
|
+
let statement = node;
|
|
24
|
+
// Traverse up the AST to find the containing statement for the node.
|
|
25
|
+
// This ensures that the comment is placed before the entire statement,
|
|
26
|
+
// rather than being attached to a deeply nested node. For example, if the
|
|
27
|
+
// node is an `Identifier`, we want the comment on the `VariableStatement`
|
|
28
|
+
// or `ExpressionStatement` that contains it.
|
|
29
|
+
while (statement.parent && !typescript_1.default.isBlock(statement.parent) && !typescript_1.default.isSourceFile(statement.parent)) {
|
|
30
|
+
if (typescript_1.default.isExpressionStatement(statement) || typescript_1.default.isVariableStatement(statement)) {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
statement = statement.parent;
|
|
34
|
+
}
|
|
35
|
+
typescript_1.default.addSyntheticLeadingComment(statement, typescript_1.default.SyntaxKind.SingleLineCommentTrivia, commentText, true);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=comment-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-helpers.js","sourceRoot":"","sources":["comment-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;AAiCH,wCAgCC;AA/DD,qHAAqF;AACrF,6CAAwE;AA6BxE,6CAA6C;AAC7C,SAAgB,cAAc,CAC5B,IAAa,EACb,QAAsB,EACtB,OAAiC;IAEjC,MAAM,IAAI,GAAG,uBAAU,CAAC,QAAQ,CAAC,CAAC;IAClC,iGAAiG;IACjG,MAAM,OAAO,GACX,OAAO,IAAI,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,OAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;IACrF,MAAM,GAAG,GAAG,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACjE,MAAM,WAAW,GAAG,4BAA4B,OAAO,GAAG,GAAG,EAAE,CAAC;IAEhE,IAAI,SAAS,GAAY,IAAI,CAAC;IAE9B,qEAAqE;IACrE,uEAAuE;IACvE,0EAA0E;IAC1E,0EAA0E;IAC1E,6CAA6C;IAC7C,OAAO,SAAS,CAAC,MAAM,IAAI,CAAC,oBAAE,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAE,CAAC,YAAY,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/F,IAAI,oBAAE,CAAC,qBAAqB,CAAC,SAAS,CAAC,IAAI,oBAAE,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7E,MAAM;QACR,CAAC;QACD,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,oBAAE,CAAC,0BAA0B,CAC3B,SAAS,EACT,oBAAE,CAAC,UAAU,CAAC,uBAAuB,EACrC,WAAW,EACX,IAAI,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC 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.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
9
|
+
import { RefactorReporter } from './refactor-reporter';
|
|
10
|
+
/**
|
|
11
|
+
* A context object that provides access to shared utilities and state
|
|
12
|
+
* throughout the transformation process.
|
|
13
|
+
*/
|
|
14
|
+
export interface RefactorContext {
|
|
15
|
+
/** The root ts.SourceFile node of the file being transformed. */
|
|
16
|
+
readonly sourceFile: ts.SourceFile;
|
|
17
|
+
/** The reporter for logging changes and TODOs. */
|
|
18
|
+
readonly reporter: RefactorReporter;
|
|
19
|
+
/** The official context from the TypeScript Transformer API. */
|
|
20
|
+
readonly tsContext: ts.TransformationContext;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A generic transformer function that operates on a specific type of ts.Node.
|
|
24
|
+
* @template T The specific type of AST node this transformer works on (e.g., ts.CallExpression).
|
|
25
|
+
*/
|
|
26
|
+
export type NodeTransformer<T extends ts.Node> = (node: T, refactorCtx: RefactorContext) => ts.Node | readonly ts.Node[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
//# sourceMappingURL=refactor-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refactor-context.js","sourceRoot":"","sources":["refactor-context.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright Google LLC 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.dev/license
|
|
7
|
+
*/
|
|
8
|
+
import { logging } from '@angular-devkit/core';
|
|
9
|
+
import ts from '../../../third_party/github.com/Microsoft/TypeScript/lib/typescript';
|
|
10
|
+
import { TodoCategory } from './todo-notes';
|
|
11
|
+
export declare class RefactorReporter {
|
|
12
|
+
private logger;
|
|
13
|
+
private filesScanned;
|
|
14
|
+
private filesTransformed;
|
|
15
|
+
private readonly todos;
|
|
16
|
+
private readonly verboseLogs;
|
|
17
|
+
constructor(logger: logging.LoggerApi);
|
|
18
|
+
get hasTodos(): boolean;
|
|
19
|
+
incrementScannedFiles(): void;
|
|
20
|
+
incrementTransformedFiles(): void;
|
|
21
|
+
recordTodo(category: TodoCategory): void;
|
|
22
|
+
reportTransformation(sourceFile: ts.SourceFile, node: ts.Node, message: string): void;
|
|
23
|
+
printSummary(verbose?: boolean): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright Google LLC All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* Use of this source code is governed by an MIT-style license that can be
|
|
7
|
+
* found in the LICENSE file at https://angular.dev/license
|
|
8
|
+
*/
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.RefactorReporter = void 0;
|
|
14
|
+
const typescript_1 = __importDefault(require("../../../third_party/github.com/Microsoft/TypeScript/lib/typescript"));
|
|
15
|
+
class RefactorReporter {
|
|
16
|
+
logger;
|
|
17
|
+
filesScanned = 0;
|
|
18
|
+
filesTransformed = 0;
|
|
19
|
+
todos = new Map();
|
|
20
|
+
verboseLogs = new Map();
|
|
21
|
+
constructor(logger) {
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
}
|
|
24
|
+
get hasTodos() {
|
|
25
|
+
return this.todos.size > 0;
|
|
26
|
+
}
|
|
27
|
+
incrementScannedFiles() {
|
|
28
|
+
this.filesScanned++;
|
|
29
|
+
}
|
|
30
|
+
incrementTransformedFiles() {
|
|
31
|
+
this.filesTransformed++;
|
|
32
|
+
}
|
|
33
|
+
recordTodo(category) {
|
|
34
|
+
this.todos.set(category, (this.todos.get(category) ?? 0) + 1);
|
|
35
|
+
}
|
|
36
|
+
reportTransformation(sourceFile, node, message) {
|
|
37
|
+
const { line } = typescript_1.default.getLineAndCharacterOfPosition(sourceFile, typescript_1.default.getOriginalNode(node).getStart());
|
|
38
|
+
const filePath = sourceFile.fileName;
|
|
39
|
+
let logs = this.verboseLogs.get(filePath);
|
|
40
|
+
if (!logs) {
|
|
41
|
+
logs = [];
|
|
42
|
+
this.verboseLogs.set(filePath, logs);
|
|
43
|
+
}
|
|
44
|
+
logs.push(`L${line + 1}: ${message}`);
|
|
45
|
+
}
|
|
46
|
+
printSummary(verbose = false) {
|
|
47
|
+
if (verbose && this.verboseLogs.size > 0) {
|
|
48
|
+
this.logger.info('Detailed Transformation Log:');
|
|
49
|
+
for (const [filePath, logs] of this.verboseLogs) {
|
|
50
|
+
this.logger.info(`Processing: ${filePath}`);
|
|
51
|
+
logs.forEach((log) => this.logger.info(` - ${log}`));
|
|
52
|
+
}
|
|
53
|
+
this.logger.info(''); // Add a blank line for separation
|
|
54
|
+
}
|
|
55
|
+
this.logger.info('Jasmine to Vitest Refactoring Summary:');
|
|
56
|
+
this.logger.info(`- ${this.filesScanned} test file(s) scanned.`);
|
|
57
|
+
this.logger.info(`- ${this.filesTransformed} file(s) transformed.`);
|
|
58
|
+
const filesSkipped = this.filesScanned - this.filesTransformed;
|
|
59
|
+
if (filesSkipped > 0) {
|
|
60
|
+
this.logger.info(`- ${filesSkipped} file(s) skipped (no changes needed).`);
|
|
61
|
+
}
|
|
62
|
+
if (this.todos.size > 0) {
|
|
63
|
+
const totalTodos = [...this.todos.values()].reduce((a, b) => a + b, 0);
|
|
64
|
+
this.logger.warn(`- ${totalTodos} TODO(s) added for manual review:`);
|
|
65
|
+
for (const [category, count] of this.todos) {
|
|
66
|
+
this.logger.warn(` - ${count}x ${category}`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.RefactorReporter = RefactorReporter;
|
|
72
|
+
//# sourceMappingURL=refactor-reporter.js.map
|