@angular/core 20.0.0-next.1 → 20.0.0-next.3
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/fesm2022/core.mjs +770 -2144
- package/fesm2022/core.mjs.map +1 -1
- package/fesm2022/primitives/di.mjs +3 -2
- package/fesm2022/primitives/di.mjs.map +1 -1
- package/fesm2022/primitives/event-dispatch.mjs +2 -589
- package/fesm2022/primitives/event-dispatch.mjs.map +1 -1
- package/fesm2022/primitives/signals.mjs +44 -13
- package/fesm2022/primitives/signals.mjs.map +1 -1
- package/fesm2022/rxjs-interop.mjs +7 -39
- package/fesm2022/rxjs-interop.mjs.map +1 -1
- package/fesm2022/testing.mjs +116 -143
- package/fesm2022/testing.mjs.map +1 -1
- package/fesm2022/weak_ref-DrMdAIDh.mjs +12 -0
- package/fesm2022/weak_ref-DrMdAIDh.mjs.map +1 -0
- package/index.d.ts +14366 -15214
- package/navigation_types.d-u4EOrrdZ.d.ts +121 -0
- package/package.json +2 -2
- package/primitives/di/index.d.ts +66 -59
- package/primitives/event-dispatch/index.d.ts +205 -309
- package/primitives/signals/index.d.ts +161 -195
- package/rxjs-interop/index.d.ts +71 -100
- package/schematics/bundles/{apply_import_manager-e2a7fe5b.js → apply_import_manager-BXQEjo09.js} +15 -19
- package/schematics/bundles/{checker-af521da6.js → checker-BHb19MHt.js} +3695 -1175
- package/schematics/bundles/cleanup-unused-imports.js +56 -89
- package/schematics/bundles/{compiler_host-5a29293c.js → compiler_host-Bk3repE2.js} +19 -23
- package/schematics/bundles/control-flow-migration.js +81 -38
- package/schematics/bundles/{imports-047fbbc8.js → imports-CIX-JgAN.js} +9 -14
- package/schematics/bundles/{index-1bef3025.js → index-BL9kAIe5.js} +62 -66
- package/schematics/bundles/{program-a449f9bf.js → index-I8VbxQcO.js} +1508 -3178
- package/schematics/bundles/inject-flags.js +147 -0
- package/schematics/bundles/inject-migration.js +121 -127
- package/schematics/bundles/{leading_space-f8944434.js → leading_space-D9nQ8UQC.js} +1 -1
- package/schematics/bundles/{migrate_ts_type_references-2a3e9e6b.js → migrate_ts_type_references-KlOTWeDl.js} +121 -126
- package/schematics/bundles/{ng_decorators-b0d8b324.js → ng_decorators-DznZ5jMl.js} +4 -8
- package/schematics/bundles/{nodes-7758dbf6.js → nodes-B16H9JUd.js} +2 -6
- package/schematics/bundles/output-migration.js +94 -128
- package/schematics/bundles/{project_tsconfig_paths-b558633b.js → project_tsconfig_paths-CDVxT6Ov.js} +1 -1
- package/schematics/bundles/{property_name-ac18447e.js → property_name-BBwFuqMe.js} +3 -7
- package/schematics/bundles/route-lazy-loading.js +35 -41
- package/schematics/bundles/{project_paths-17dc204d.js → run_in_devkit-C0JPtK2u.js} +283 -216
- package/schematics/bundles/self-closing-tags-migration.js +55 -91
- package/schematics/bundles/signal-input-migration.js +121 -156
- package/schematics/bundles/signal-queries-migration.js +119 -154
- package/schematics/bundles/signals.js +12 -14
- package/schematics/bundles/standalone-migration.js +180 -200
- package/schematics/bundles/symbol-VPWguRxr.js +25 -0
- package/schematics/bundles/test-bed-get.js +98 -0
- package/schematics/migrations.json +8 -14
- package/testing/index.d.ts +289 -471
- package/weak_ref.d-ttyj86RV.d.ts +9 -0
- package/schematics/bundles/explicit-standalone-flag.js +0 -184
- package/schematics/bundles/index-ef1bffbb.js +0 -30
- package/schematics/bundles/pending-tasks.js +0 -103
- package/schematics/bundles/provide-initializer.js +0 -186
|
@@ -1,36 +1,29 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
/**
|
|
3
|
-
* @license Angular v20.0.0-next.
|
|
3
|
+
* @license Angular v20.0.0-next.3
|
|
4
4
|
* (c) 2010-2025 Google LLC. https://angular.io/
|
|
5
5
|
* License: MIT
|
|
6
6
|
*/
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var schematics = require('@angular-devkit/schematics');
|
|
12
|
-
var migrate_ts_type_references = require('./migrate_ts_type_references-2a3e9e6b.js');
|
|
9
|
+
var migrate_ts_type_references = require('./migrate_ts_type_references-KlOTWeDl.js');
|
|
13
10
|
var ts = require('typescript');
|
|
14
11
|
require('os');
|
|
15
|
-
var checker = require('./checker-
|
|
16
|
-
var
|
|
12
|
+
var checker = require('./checker-BHb19MHt.js');
|
|
13
|
+
var index$1 = require('./index-I8VbxQcO.js');
|
|
17
14
|
require('path');
|
|
18
|
-
var
|
|
19
|
-
var index = require('./index-
|
|
15
|
+
var run_in_devkit = require('./run_in_devkit-C0JPtK2u.js');
|
|
16
|
+
var index = require('./index-BL9kAIe5.js');
|
|
20
17
|
var assert = require('assert');
|
|
21
|
-
var apply_import_manager = require('./apply_import_manager-
|
|
22
|
-
|
|
23
|
-
require('
|
|
18
|
+
var apply_import_manager = require('./apply_import_manager-BXQEjo09.js');
|
|
19
|
+
require('@angular-devkit/core');
|
|
20
|
+
require('node:path/posix');
|
|
21
|
+
require('./leading_space-D9nQ8UQC.js');
|
|
24
22
|
require('fs');
|
|
25
23
|
require('module');
|
|
26
24
|
require('url');
|
|
27
|
-
require('@angular-devkit/
|
|
28
|
-
require('
|
|
29
|
-
|
|
30
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
31
|
-
|
|
32
|
-
var ts__default = /*#__PURE__*/_interopDefaultLegacy(ts);
|
|
33
|
-
var assert__default = /*#__PURE__*/_interopDefaultLegacy(assert);
|
|
25
|
+
require('@angular-devkit/schematics');
|
|
26
|
+
require('./project_tsconfig_paths-CDVxT6Ov.js');
|
|
34
27
|
|
|
35
28
|
/**
|
|
36
29
|
* Class that holds information about a given directive and its input fields.
|
|
@@ -102,14 +95,14 @@ class MigrationHost {
|
|
|
102
95
|
|
|
103
96
|
function getInputDescriptor(hostOrInfo, node) {
|
|
104
97
|
let className;
|
|
105
|
-
if (
|
|
98
|
+
if (ts.isAccessor(node)) {
|
|
106
99
|
className = node.parent.name?.text || '<anonymous>';
|
|
107
100
|
}
|
|
108
101
|
else {
|
|
109
102
|
className = node.parent.name?.text ?? '<anonymous>';
|
|
110
103
|
}
|
|
111
104
|
const info = hostOrInfo instanceof MigrationHost ? hostOrInfo.programInfo : hostOrInfo;
|
|
112
|
-
const file =
|
|
105
|
+
const file = run_in_devkit.projectFile(node.getSourceFile(), info);
|
|
113
106
|
// Inputs may be detected in `.d.ts` files. Ensure that if the file IDs
|
|
114
107
|
// match regardless of extension. E.g. `/google3/blaze-out/bin/my_file.ts` should
|
|
115
108
|
// have the same ID as `/google3/my_file.ts`.
|
|
@@ -188,7 +181,7 @@ class KnownInputs {
|
|
|
188
181
|
}
|
|
189
182
|
const directiveInfo = this._classToDirectiveInfo.get(data.node.parent);
|
|
190
183
|
const inputInfo = {
|
|
191
|
-
file:
|
|
184
|
+
file: run_in_devkit.projectFile(data.node.getSourceFile(), this.programInfo),
|
|
192
185
|
metadata: data.metadata,
|
|
193
186
|
descriptor: data.descriptor,
|
|
194
187
|
container: directiveInfo,
|
|
@@ -282,8 +275,8 @@ function prepareAnalysisInfo(userProgram, compiler, programAbsoluteRootPaths) {
|
|
|
282
275
|
}
|
|
283
276
|
const typeChecker = userProgram.getTypeChecker();
|
|
284
277
|
const reflector = new checker.TypeScriptReflectionHost(typeChecker);
|
|
285
|
-
const evaluator = new
|
|
286
|
-
const dtsMetadataReader = new
|
|
278
|
+
const evaluator = new index$1.PartialEvaluator(reflector, typeChecker, null);
|
|
279
|
+
const dtsMetadataReader = new index$1.DtsMetadataReader(typeChecker, reflector);
|
|
287
280
|
return {
|
|
288
281
|
metaRegistry: metaReader,
|
|
289
282
|
dtsMetadataReader,
|
|
@@ -307,7 +300,7 @@ function prepareAnalysisInfo(userProgram, compiler, programAbsoluteRootPaths) {
|
|
|
307
300
|
* - imports that may need to be updated.
|
|
308
301
|
*/
|
|
309
302
|
class MigrationResult {
|
|
310
|
-
printer =
|
|
303
|
+
printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
|
311
304
|
// May be `null` if the input cannot be converted. This is also
|
|
312
305
|
// signified by an incompatibility- but the input is tracked here as it
|
|
313
306
|
// still is a "source input".
|
|
@@ -329,14 +322,14 @@ function extractDecoratorInput(node, host, reflector, metadataReader, evaluator)
|
|
|
329
322
|
*/
|
|
330
323
|
function extractDtsInput(node, metadataReader) {
|
|
331
324
|
if (!index.isInputContainerNode(node) ||
|
|
332
|
-
!
|
|
325
|
+
!ts.isIdentifier(node.name) ||
|
|
333
326
|
!node.getSourceFile().isDeclarationFile) {
|
|
334
327
|
return null;
|
|
335
328
|
}
|
|
336
329
|
// If the potential node is not part of a valid input class, skip.
|
|
337
|
-
if (!
|
|
330
|
+
if (!ts.isClassDeclaration(node.parent) ||
|
|
338
331
|
node.parent.name === undefined ||
|
|
339
|
-
!
|
|
332
|
+
!ts.isIdentifier(node.parent.name)) {
|
|
340
333
|
return null;
|
|
341
334
|
}
|
|
342
335
|
let directiveMetadata = null;
|
|
@@ -372,7 +365,7 @@ function extractDtsInput(node, metadataReader) {
|
|
|
372
365
|
*/
|
|
373
366
|
function extractSourceCodeInput(node, host, reflector, evaluator) {
|
|
374
367
|
if (!index.isInputContainerNode(node) ||
|
|
375
|
-
!
|
|
368
|
+
!ts.isIdentifier(node.name) ||
|
|
376
369
|
node.getSourceFile().isDeclarationFile) {
|
|
377
370
|
return null;
|
|
378
371
|
}
|
|
@@ -440,7 +433,7 @@ function parseTransformOfInput(evaluatedInputOpts, node, reflector) {
|
|
|
440
433
|
},
|
|
441
434
|
]);
|
|
442
435
|
try {
|
|
443
|
-
return
|
|
436
|
+
return checker.parseDecoratorInputTransformFunction(node.parent, node.name.text, transformValue, reflector, noopRefEmitter, checker.CompilationMode.FULL);
|
|
444
437
|
}
|
|
445
438
|
catch (e) {
|
|
446
439
|
if (!(e instanceof checker.FatalDiagnosticError)) {
|
|
@@ -464,16 +457,16 @@ function parseTransformOfInput(evaluatedInputOpts, node, reflector) {
|
|
|
464
457
|
*/
|
|
465
458
|
function prepareAndCheckForConversion(node, metadata, checker, options) {
|
|
466
459
|
// Accessor inputs cannot be migrated right now.
|
|
467
|
-
if (
|
|
460
|
+
if (ts.isAccessor(node)) {
|
|
468
461
|
return {
|
|
469
462
|
context: node,
|
|
470
463
|
reason: migrate_ts_type_references.FieldIncompatibilityReason.Accessor,
|
|
471
464
|
};
|
|
472
465
|
}
|
|
473
|
-
|
|
466
|
+
assert(metadata.inputDecorator !== null, 'Expected an input decorator for inputs that are being migrated.');
|
|
474
467
|
let initialValue = node.initializer;
|
|
475
468
|
let isUndefinedInitialValue = node.initializer === undefined ||
|
|
476
|
-
(
|
|
469
|
+
(ts.isIdentifier(node.initializer) && node.initializer.text === 'undefined');
|
|
477
470
|
const strictNullChecksEnabled = options.strict === true || options.strictNullChecks === true;
|
|
478
471
|
const strictPropertyInitialization = options.strict === true || options.strictPropertyInitialization === true;
|
|
479
472
|
// Shorthand should never be used, as would expand the type of `T` to be `T|undefined`.
|
|
@@ -515,9 +508,9 @@ function prepareAndCheckForConversion(node, metadata, checker, options) {
|
|
|
515
508
|
};
|
|
516
509
|
}
|
|
517
510
|
if (!checker.isTypeAssignableTo(checker.getUndefinedType(), checker.getTypeFromTypeNode(typeToAdd))) {
|
|
518
|
-
typeToAdd =
|
|
511
|
+
typeToAdd = ts.factory.createUnionTypeNode([
|
|
519
512
|
typeToAdd,
|
|
520
|
-
|
|
513
|
+
ts.factory.createKeywordTypeNode(ts.SyntaxKind.UndefinedKeyword),
|
|
521
514
|
]);
|
|
522
515
|
}
|
|
523
516
|
}
|
|
@@ -538,7 +531,7 @@ function prepareAndCheckForConversion(node, metadata, checker, options) {
|
|
|
538
531
|
'Input is initialized to `undefined` but type does not allow this value. ' +
|
|
539
532
|
'This worked with `@Input` because your project uses `--strictPropertyInitialization=false`.';
|
|
540
533
|
isUndefinedInitialValue = false;
|
|
541
|
-
initialValue =
|
|
534
|
+
initialValue = ts.factory.createNonNullExpression(ts.factory.createIdentifier('undefined'));
|
|
542
535
|
}
|
|
543
536
|
// Attempt to extract type from input initial value. No explicit type, but input is required.
|
|
544
537
|
// Hence we need an explicit type, or fall back to `typeof`.
|
|
@@ -572,28 +565,28 @@ function inferImportableTypeForInput(checker, node, initialValue) {
|
|
|
572
565
|
// return a type node fully derived from the resolved type.
|
|
573
566
|
if (isPrimitiveImportableTypeNode(propertyType) ||
|
|
574
567
|
(propertyType.isUnion() && propertyType.types.every(isPrimitiveImportableTypeNode))) {
|
|
575
|
-
return checker.typeToTypeNode(propertyType, node,
|
|
568
|
+
return checker.typeToTypeNode(propertyType, node, ts.NodeBuilderFlags.NoTypeReduction) ?? null;
|
|
576
569
|
}
|
|
577
570
|
// Alternatively, try to infer a simple importable type from\
|
|
578
571
|
// the initializer.
|
|
579
|
-
if (
|
|
572
|
+
if (ts.isIdentifier(initialValue)) {
|
|
580
573
|
// @Input({required: true}) bla = SOME_DEFAULT;
|
|
581
|
-
return
|
|
574
|
+
return ts.factory.createTypeQueryNode(initialValue);
|
|
582
575
|
}
|
|
583
|
-
else if (
|
|
584
|
-
|
|
585
|
-
|
|
576
|
+
else if (ts.isPropertyAccessExpression(initialValue) &&
|
|
577
|
+
ts.isIdentifier(initialValue.name) &&
|
|
578
|
+
ts.isIdentifier(initialValue.expression)) {
|
|
586
579
|
// @Input({required: true}) bla = prop.SOME_DEFAULT;
|
|
587
|
-
return
|
|
580
|
+
return ts.factory.createTypeQueryNode(ts.factory.createQualifiedName(initialValue.name, initialValue.expression));
|
|
588
581
|
}
|
|
589
582
|
return null;
|
|
590
583
|
}
|
|
591
584
|
function isPrimitiveImportableTypeNode(type) {
|
|
592
|
-
return !!(type.flags &
|
|
593
|
-
type.flags &
|
|
594
|
-
type.flags &
|
|
595
|
-
type.flags &
|
|
596
|
-
type.flags &
|
|
585
|
+
return !!(type.flags & ts.TypeFlags.BooleanLike ||
|
|
586
|
+
type.flags & ts.TypeFlags.StringLike ||
|
|
587
|
+
type.flags & ts.TypeFlags.NumberLike ||
|
|
588
|
+
type.flags & ts.TypeFlags.Undefined ||
|
|
589
|
+
type.flags & ts.TypeFlags.Null);
|
|
597
590
|
}
|
|
598
591
|
|
|
599
592
|
/**
|
|
@@ -604,7 +597,7 @@ function pass1__IdentifySourceFileAndDeclarationInputs(sf, host, checker, reflec
|
|
|
604
597
|
const visitor = (node) => {
|
|
605
598
|
const decoratorInput = extractDecoratorInput(node, host, reflector, dtsMetadataReader, evaluator);
|
|
606
599
|
if (decoratorInput !== null) {
|
|
607
|
-
|
|
600
|
+
assert(index.isInputContainerNode(node), 'Expected input to be declared on accessor or property.');
|
|
608
601
|
const inputDescr = getInputDescriptor(host, node);
|
|
609
602
|
// track all inputs, even from declarations for reference resolution.
|
|
610
603
|
knownDecoratorInputs.register({ descriptor: inputDescr, metadata: decoratorInput, node });
|
|
@@ -623,10 +616,10 @@ function pass1__IdentifySourceFileAndDeclarationInputs(sf, host, checker, reflec
|
|
|
623
616
|
}
|
|
624
617
|
// track all imports to `Input` or `input`.
|
|
625
618
|
let importName = null;
|
|
626
|
-
if (
|
|
619
|
+
if (ts.isImportSpecifier(node) &&
|
|
627
620
|
((importName = (node.propertyName ?? node.name).text) === 'Input' ||
|
|
628
621
|
importName === 'input') &&
|
|
629
|
-
|
|
622
|
+
ts.isStringLiteral(node.parent.parent.parent.moduleSpecifier) &&
|
|
630
623
|
(host.isMigratingCore || node.parent.parent.parent.moduleSpecifier.text === '@angular/core')) {
|
|
631
624
|
if (!result.inputDecoratorSpecifiers.has(sf)) {
|
|
632
625
|
result.inputDecoratorSpecifiers.set(sf, []);
|
|
@@ -636,9 +629,9 @@ function pass1__IdentifySourceFileAndDeclarationInputs(sf, host, checker, reflec
|
|
|
636
629
|
node,
|
|
637
630
|
});
|
|
638
631
|
}
|
|
639
|
-
|
|
632
|
+
ts.forEachChild(node, visitor);
|
|
640
633
|
};
|
|
641
|
-
|
|
634
|
+
ts.forEachChild(sf, visitor);
|
|
642
635
|
}
|
|
643
636
|
|
|
644
637
|
/**
|
|
@@ -767,7 +760,7 @@ function pass4__checkInheritanceOfInputs(inheritanceGraph, metaRegistry, knownIn
|
|
|
767
760
|
isClassWithKnownFields: (clazz) => knownInputs.isInputContainingClass(clazz),
|
|
768
761
|
getFieldsForClass: (clazz) => {
|
|
769
762
|
const directiveInfo = knownInputs.getDirectiveInfoForClass(clazz);
|
|
770
|
-
|
|
763
|
+
assert(directiveInfo !== undefined, 'Expected directive info to exist for input.');
|
|
771
764
|
return Array.from(directiveInfo.inputFields.values()).map((i) => i.descriptor);
|
|
772
765
|
},
|
|
773
766
|
});
|
|
@@ -974,7 +967,7 @@ function convertToSignalInput(node, { resolvedMetadata: metadata, resolvedType,
|
|
|
974
967
|
if (metadata.bindingPropertyName !== metadata.classPropertyName || metadata.transform !== null) {
|
|
975
968
|
const properties = [];
|
|
976
969
|
if (metadata.bindingPropertyName !== metadata.classPropertyName) {
|
|
977
|
-
properties.push(
|
|
970
|
+
properties.push(ts.factory.createPropertyAssignment('alias', ts.factory.createStringLiteral(metadata.bindingPropertyName)));
|
|
978
971
|
}
|
|
979
972
|
if (metadata.transform !== null) {
|
|
980
973
|
const transformRes = extractTransformOfInput(metadata.transform, resolvedType, checker);
|
|
@@ -985,7 +978,7 @@ function convertToSignalInput(node, { resolvedMetadata: metadata, resolvedType,
|
|
|
985
978
|
(leadingTodoText ? `${leadingTodoText} ` : '') + transformRes.leadingTodoText;
|
|
986
979
|
}
|
|
987
980
|
}
|
|
988
|
-
optionsLiteral =
|
|
981
|
+
optionsLiteral = ts.factory.createObjectLiteralExpression(properties);
|
|
989
982
|
}
|
|
990
983
|
// The initial value is `undefined` or none is present:
|
|
991
984
|
// - We may be able to use the `input()` shorthand
|
|
@@ -993,14 +986,14 @@ function convertToSignalInput(node, { resolvedMetadata: metadata, resolvedType,
|
|
|
993
986
|
if (initialValue === undefined) {
|
|
994
987
|
// Shorthand not possible, so explicitly add `undefined`.
|
|
995
988
|
if (preferShorthandIfPossible === null) {
|
|
996
|
-
initialValue =
|
|
989
|
+
initialValue = ts.factory.createIdentifier('undefined');
|
|
997
990
|
}
|
|
998
991
|
else {
|
|
999
992
|
resolvedType = preferShorthandIfPossible.originalType;
|
|
1000
993
|
// When using the `input()` shorthand, try cutting of `undefined` from potential
|
|
1001
994
|
// union types. `undefined` will be automatically included in the type.
|
|
1002
|
-
if (
|
|
1003
|
-
resolvedType = migrate_ts_type_references.removeFromUnionIfPossible(resolvedType, (t) => t.kind !==
|
|
995
|
+
if (ts.isUnionTypeNode(resolvedType)) {
|
|
996
|
+
resolvedType = migrate_ts_type_references.removeFromUnionIfPossible(resolvedType, (t) => t.kind !== ts.SyntaxKind.UndefinedKeyword);
|
|
1004
997
|
}
|
|
1005
998
|
}
|
|
1006
999
|
}
|
|
@@ -1011,13 +1004,13 @@ function convertToSignalInput(node, { resolvedMetadata: metadata, resolvedType,
|
|
|
1011
1004
|
if (metadata.transform !== null) {
|
|
1012
1005
|
// Note: The TCB code generation may use the same type node and attach
|
|
1013
1006
|
// synthetic comments for error reporting. We remove those explicitly here.
|
|
1014
|
-
typeArguments.push(
|
|
1007
|
+
typeArguments.push(ts.setSyntheticTrailingComments(metadata.transform.type.node, undefined));
|
|
1015
1008
|
}
|
|
1016
1009
|
}
|
|
1017
1010
|
// Always add an initial value when the input is optional, and we have one, or we need one
|
|
1018
1011
|
// to be able to pass options as the second argument.
|
|
1019
1012
|
if (!metadata.required && (initialValue !== undefined || optionsLiteral !== null)) {
|
|
1020
|
-
inputArgs.push(initialValue ??
|
|
1013
|
+
inputArgs.push(initialValue ?? ts.factory.createIdentifier('undefined'));
|
|
1021
1014
|
}
|
|
1022
1015
|
if (optionsLiteral !== null) {
|
|
1023
1016
|
inputArgs.push(optionsLiteral);
|
|
@@ -1028,21 +1021,21 @@ function convertToSignalInput(node, { resolvedMetadata: metadata, resolvedType,
|
|
|
1028
1021
|
requestedFile: node.getSourceFile(),
|
|
1029
1022
|
});
|
|
1030
1023
|
const inputInitializerFn = metadata.required
|
|
1031
|
-
?
|
|
1024
|
+
? ts.factory.createPropertyAccessExpression(inputFnRef, 'required')
|
|
1032
1025
|
: inputFnRef;
|
|
1033
|
-
const inputInitializer =
|
|
1026
|
+
const inputInitializer = ts.factory.createCallExpression(inputInitializerFn, typeArguments, inputArgs);
|
|
1034
1027
|
let modifiersWithoutInputDecorator = node.modifiers?.filter((m) => m !== originalInputDecorator.node) ?? [];
|
|
1035
1028
|
// Add `readonly` to all new signal input declarations.
|
|
1036
|
-
if (!modifiersWithoutInputDecorator?.some((s) => s.kind ===
|
|
1037
|
-
modifiersWithoutInputDecorator.push(
|
|
1029
|
+
if (!modifiersWithoutInputDecorator?.some((s) => s.kind === ts.SyntaxKind.ReadonlyKeyword)) {
|
|
1030
|
+
modifiersWithoutInputDecorator.push(ts.factory.createModifier(ts.SyntaxKind.ReadonlyKeyword));
|
|
1038
1031
|
}
|
|
1039
|
-
const newNode =
|
|
1040
|
-
const newPropertyText = result.printer.printNode(
|
|
1032
|
+
const newNode = ts.factory.createPropertyDeclaration(modifiersWithoutInputDecorator, node.name, undefined, undefined, inputInitializer);
|
|
1033
|
+
const newPropertyText = result.printer.printNode(ts.EmitHint.Unspecified, newNode, node.getSourceFile());
|
|
1041
1034
|
const replacements = [];
|
|
1042
1035
|
if (leadingTodoText !== null) {
|
|
1043
1036
|
replacements.push(migrate_ts_type_references.insertPrecedingLine(node, info, '// TODO: Notes from signal input migration:'), ...migrate_ts_type_references.cutStringToLineLimit(leadingTodoText, 70).map((line) => migrate_ts_type_references.insertPrecedingLine(node, info, `// ${line}`)));
|
|
1044
1037
|
}
|
|
1045
|
-
replacements.push(new
|
|
1038
|
+
replacements.push(new run_in_devkit.Replacement(run_in_devkit.projectFile(node.getSourceFile(), info), new run_in_devkit.TextUpdate({
|
|
1046
1039
|
position: node.getStart(),
|
|
1047
1040
|
end: node.getEnd(),
|
|
1048
1041
|
toInsert: newPropertyText,
|
|
@@ -1054,29 +1047,29 @@ function convertToSignalInput(node, { resolvedMetadata: metadata, resolvedType,
|
|
|
1054
1047
|
* that works for the new signal `input()` API.
|
|
1055
1048
|
*/
|
|
1056
1049
|
function extractTransformOfInput(transform, resolvedType, checker) {
|
|
1057
|
-
|
|
1050
|
+
assert(ts.isExpression(transform.node), `Expected transform to be an expression.`);
|
|
1058
1051
|
let transformFn = transform.node;
|
|
1059
1052
|
let leadingTodoText = null;
|
|
1060
1053
|
// If there is an explicit type, check if the transform return type actually works.
|
|
1061
1054
|
// In some cases, the transform function is not compatible because with decorator inputs,
|
|
1062
1055
|
// those were not checked. We cast the transform to `any` and add a TODO.
|
|
1063
1056
|
// TODO: Capture this in the design doc.
|
|
1064
|
-
if (resolvedType !== undefined && !
|
|
1057
|
+
if (resolvedType !== undefined && !ts.isSyntheticExpression(resolvedType)) {
|
|
1065
1058
|
// Note: If the type is synthetic, we cannot check, and we accept that in the worst case
|
|
1066
1059
|
// we will create code that is not necessarily compiling. This is unlikely, but notably
|
|
1067
1060
|
// the errors would be correct and valuable.
|
|
1068
1061
|
const transformType = checker.getTypeAtLocation(transform.node);
|
|
1069
1062
|
const transformSignature = transformType.getCallSignatures()[0];
|
|
1070
|
-
|
|
1063
|
+
assert(transformSignature !== undefined, 'Expected transform to be an invoke-able.');
|
|
1071
1064
|
if (!checker.isTypeAssignableTo(checker.getReturnTypeOfSignature(transformSignature), checker.getTypeFromTypeNode(resolvedType))) {
|
|
1072
1065
|
leadingTodoText =
|
|
1073
1066
|
'Input type is incompatible with transform. The migration added an `any` cast. ' +
|
|
1074
1067
|
'This worked previously because Angular was unable to check transforms.';
|
|
1075
|
-
transformFn =
|
|
1068
|
+
transformFn = ts.factory.createAsExpression(ts.factory.createParenthesizedExpression(transformFn), ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword));
|
|
1076
1069
|
}
|
|
1077
1070
|
}
|
|
1078
1071
|
return {
|
|
1079
|
-
node:
|
|
1072
|
+
node: ts.factory.createPropertyAssignment('transform', transformFn),
|
|
1080
1073
|
leadingTodoText,
|
|
1081
1074
|
};
|
|
1082
1075
|
}
|
|
@@ -1104,8 +1097,8 @@ function pass6__migrateInputDeclarations(host, checker, result, knownInputs, imp
|
|
|
1104
1097
|
filesWithIncompatibleInputs.add(sf);
|
|
1105
1098
|
continue;
|
|
1106
1099
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1100
|
+
assert(metadata !== null, `Expected metadata to exist for input isn't marked incompatible.`);
|
|
1101
|
+
assert(!ts.isAccessor(input.node), 'Accessor inputs are incompatible.');
|
|
1109
1102
|
filesWithMigratedInputs.add(sf);
|
|
1110
1103
|
result.replacements.push(...convertToSignalInput(input.node, metadata, info, checker, importManager, result));
|
|
1111
1104
|
}
|
|
@@ -1160,7 +1153,7 @@ function pass7__migrateTemplateReferences(host, references) {
|
|
|
1160
1153
|
const appendText = reference.from.isObjectShorthandExpression
|
|
1161
1154
|
? `: ${reference.from.read.name}()`
|
|
1162
1155
|
: `()`;
|
|
1163
|
-
host.replacements.push(new
|
|
1156
|
+
host.replacements.push(new run_in_devkit.Replacement(reference.from.templateFile, new run_in_devkit.TextUpdate({
|
|
1164
1157
|
position: reference.from.read.sourceSpan.end,
|
|
1165
1158
|
end: reference.from.read.sourceSpan.end,
|
|
1166
1159
|
toInsert: appendText,
|
|
@@ -1200,7 +1193,7 @@ function pass8__migrateHostBindings(host, references, info) {
|
|
|
1200
1193
|
const appendText = reference.from.isObjectShorthandExpression
|
|
1201
1194
|
? `: ${reference.from.read.name}()`
|
|
1202
1195
|
: `()`;
|
|
1203
|
-
host.replacements.push(new
|
|
1196
|
+
host.replacements.push(new run_in_devkit.Replacement(run_in_devkit.projectFile(bindingField.getSourceFile(), info), new run_in_devkit.TextUpdate({ position: readEndPos, end: readEndPos, toInsert: appendText })));
|
|
1204
1197
|
}
|
|
1205
1198
|
}
|
|
1206
1199
|
|
|
@@ -1263,7 +1256,7 @@ function filterIncompatibilitiesForBestEffortMode(knownInputs) {
|
|
|
1263
1256
|
* Tsurge migration for migrating Angular `@Input()` declarations to
|
|
1264
1257
|
* signal inputs, with support for batch execution.
|
|
1265
1258
|
*/
|
|
1266
|
-
class SignalInputMigration extends
|
|
1259
|
+
class SignalInputMigration extends run_in_devkit.TsurgeComplexMigration {
|
|
1267
1260
|
config;
|
|
1268
1261
|
upgradedAnalysisPhaseResults = null;
|
|
1269
1262
|
constructor(config = {}) {
|
|
@@ -1272,7 +1265,7 @@ class SignalInputMigration extends project_paths.TsurgeComplexMigration {
|
|
|
1272
1265
|
}
|
|
1273
1266
|
// Override the default program creation, to add extra flags.
|
|
1274
1267
|
createProgram(tsconfigAbsPath, fs) {
|
|
1275
|
-
return
|
|
1268
|
+
return run_in_devkit.createBaseProgramInfo(tsconfigAbsPath, fs, {
|
|
1276
1269
|
_compilePoisonedComponents: true,
|
|
1277
1270
|
// We want to migrate non-exported classes too.
|
|
1278
1271
|
compileNonExportedClasses: true,
|
|
@@ -1344,13 +1337,13 @@ class SignalInputMigration extends project_paths.TsurgeComplexMigration {
|
|
|
1344
1337
|
knownInputs,
|
|
1345
1338
|
};
|
|
1346
1339
|
}
|
|
1347
|
-
return
|
|
1340
|
+
return run_in_devkit.confirmAsSerializable(unitData);
|
|
1348
1341
|
}
|
|
1349
1342
|
async combine(unitA, unitB) {
|
|
1350
|
-
return
|
|
1343
|
+
return run_in_devkit.confirmAsSerializable(combineCompilationUnitData(unitA, unitB));
|
|
1351
1344
|
}
|
|
1352
1345
|
async globalMeta(combinedData) {
|
|
1353
|
-
return
|
|
1346
|
+
return run_in_devkit.confirmAsSerializable(convertToGlobalMeta(combinedData));
|
|
1354
1347
|
}
|
|
1355
1348
|
async migrate(globalMetadata, info, nonBatchData) {
|
|
1356
1349
|
const knownInputs = nonBatchData?.knownInputs ?? new KnownInputs(info, this.config);
|
|
@@ -1440,82 +1433,54 @@ function createMigrationHost(info, config) {
|
|
|
1440
1433
|
|
|
1441
1434
|
function migrate(options) {
|
|
1442
1435
|
return async (tree, context) => {
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1436
|
+
await run_in_devkit.runMigrationInDevkit({
|
|
1437
|
+
tree,
|
|
1438
|
+
getMigration: (fs) => new SignalInputMigration({
|
|
1439
|
+
bestEffortMode: options.bestEffortMode,
|
|
1440
|
+
insertTodosForSkippedFields: options.insertTodos,
|
|
1441
|
+
shouldMigrateInput: (input) => {
|
|
1442
|
+
return (input.file.rootRelativePath.startsWith(fs.normalize(options.path)) &&
|
|
1443
|
+
!/(^|\/)node_modules\//.test(input.file.rootRelativePath));
|
|
1444
|
+
},
|
|
1445
|
+
}),
|
|
1446
|
+
beforeProgramCreation: (tsconfigPath) => {
|
|
1447
|
+
context.logger.info(`Preparing analysis for: ${tsconfigPath}...`);
|
|
1455
1448
|
},
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
const info = migration.prepareProgram(baseInfo);
|
|
1463
|
-
// Support restricting the analysis to subfolders for larger projects.
|
|
1464
|
-
if (analysisPath !== '/') {
|
|
1465
|
-
info.sourceFiles = info.sourceFiles.filter((sf) => sf.fileName.startsWith(analysisPath));
|
|
1466
|
-
info.fullProgramSourceFiles = info.fullProgramSourceFiles.filter((sf) => sf.fileName.startsWith(analysisPath));
|
|
1467
|
-
}
|
|
1468
|
-
return { info, tsconfigPath };
|
|
1469
|
-
});
|
|
1470
|
-
// Analyze phase. Treat all projects as compilation units as
|
|
1471
|
-
// this allows us to support references between those.
|
|
1472
|
-
for (const { info, tsconfigPath } of programInfos) {
|
|
1473
|
-
context.logger.info(`Scanning for inputs: ${tsconfigPath}..`);
|
|
1474
|
-
unitResults.push(await migration.analyze(info));
|
|
1475
|
-
}
|
|
1476
|
-
context.logger.info(``);
|
|
1477
|
-
context.logger.info(`Processing analysis data between targets..`);
|
|
1478
|
-
context.logger.info(``);
|
|
1479
|
-
const combined = await project_paths.synchronouslyCombineUnitData(migration, unitResults);
|
|
1480
|
-
if (combined === null) {
|
|
1481
|
-
context.logger.error('Migration failed unexpectedly with no analysis data');
|
|
1482
|
-
return;
|
|
1483
|
-
}
|
|
1484
|
-
const globalMeta = await migration.globalMeta(combined);
|
|
1485
|
-
const replacementsPerFile = new Map();
|
|
1486
|
-
for (const { info, tsconfigPath } of programInfos) {
|
|
1487
|
-
context.logger.info(`Migrating: ${tsconfigPath}..`);
|
|
1488
|
-
const { replacements } = await migration.migrate(globalMeta, info);
|
|
1489
|
-
const changesPerFile = project_paths.groupReplacementsByFile(replacements);
|
|
1490
|
-
for (const [file, changes] of changesPerFile) {
|
|
1491
|
-
if (!replacementsPerFile.has(file)) {
|
|
1492
|
-
replacementsPerFile.set(file, changes);
|
|
1449
|
+
afterProgramCreation: (info, fs) => {
|
|
1450
|
+
const analysisPath = fs.resolve(options.analysisDir);
|
|
1451
|
+
// Support restricting the analysis to subfolders for larger projects.
|
|
1452
|
+
if (analysisPath !== '/') {
|
|
1453
|
+
info.sourceFiles = info.sourceFiles.filter((sf) => sf.fileName.startsWith(analysisPath));
|
|
1454
|
+
info.fullProgramSourceFiles = info.fullProgramSourceFiles.filter((sf) => sf.fileName.startsWith(analysisPath));
|
|
1493
1455
|
}
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1456
|
+
},
|
|
1457
|
+
beforeUnitAnalysis: (tsconfigPath) => {
|
|
1458
|
+
context.logger.info(`Scanning for inputs: ${tsconfigPath}...`);
|
|
1459
|
+
},
|
|
1460
|
+
afterAllAnalyzed: () => {
|
|
1461
|
+
context.logger.info(``);
|
|
1462
|
+
context.logger.info(`Processing analysis data between targets...`);
|
|
1463
|
+
context.logger.info(``);
|
|
1464
|
+
},
|
|
1465
|
+
afterAnalysisFailure: () => {
|
|
1466
|
+
context.logger.error('Migration failed unexpectedly with no analysis data');
|
|
1467
|
+
},
|
|
1468
|
+
whenDone: ({ counters }) => {
|
|
1469
|
+
const { sourceInputs, incompatibleInputs } = counters;
|
|
1470
|
+
const migratedInputs = sourceInputs - incompatibleInputs;
|
|
1471
|
+
context.logger.info('');
|
|
1472
|
+
context.logger.info(`Successfully migrated to signal inputs 🎉`);
|
|
1473
|
+
context.logger.info(` -> Migrated ${migratedInputs}/${sourceInputs} inputs.`);
|
|
1474
|
+
if (incompatibleInputs > 0 && !options.insertTodos) {
|
|
1475
|
+
context.logger.warn(`To see why ${incompatibleInputs} inputs couldn't be migrated`);
|
|
1476
|
+
context.logger.warn(`consider re-running with "--insert-todos" or "--best-effort-mode".`);
|
|
1477
|
+
}
|
|
1478
|
+
if (options.bestEffortMode) {
|
|
1479
|
+
context.logger.warn(`You ran with best effort mode. Manually verify all code ` +
|
|
1480
|
+
`works as intended, and fix where necessary.`);
|
|
1481
|
+
}
|
|
1482
|
+
},
|
|
1483
|
+
});
|
|
1519
1484
|
};
|
|
1520
1485
|
}
|
|
1521
1486
|
|