@@ -53,12 +53,27 @@ import {
53
53
import { ReferenceResult } from '../signal-migration/src/passes/reference_resolution/reference_result' ;
54
54
import { ReferenceKind } from '../signal-migration/src/passes/reference_resolution/reference_kinds' ;
55
55
56
- interface OutputMigrationData {
56
+ export interface MigrationConfig {
57
+ /**
58
+ * Whether the given output definition should be migrated.
59
+ *
60
+ * Treating an output as non-migrated means that no references to it are
61
+ * migrated, nor the actual declaration (if it's part of the sources).
62
+ *
63
+ * If no function is specified here, the migration will migrate all
64
+ * output and references it discovers in compilation units. This is the
65
+ * running assumption for batch mode and LSC mode where the migration
66
+ * assumes all seen output are migrated.
67
+ */
68
+ shouldMigrate ?: ( definition : ClassFieldDescriptor , containingFile : ProjectFile ) => boolean ;
69
+ }
70
+
71
+ export interface OutputMigrationData {
57
72
file : ProjectFile ;
58
73
replacements : Replacement [ ] ;
59
74
}
60
75
61
- interface CompilationUnitData {
76
+ export interface CompilationUnitData {
62
77
outputFields : Record < ClassFieldUniqueKey , OutputMigrationData > ;
63
78
problematicUsages : Record < ClassFieldUniqueKey , true > ;
64
79
importReplacements : Record < ProjectFileID , { add : Replacement [ ] ; addAndRemove : Replacement [ ] } > ;
@@ -68,6 +83,10 @@ export class OutputMigration extends TsurgeFunnelMigration<
68
83
CompilationUnitData ,
69
84
CompilationUnitData
70
85
> {
86
+ constructor ( private readonly config : MigrationConfig = { } ) {
87
+ super ( ) ;
88
+ }
89
+
71
90
override async analyze ( info : ProgramInfo ) : Promise < Serializable < CompilationUnitData > > {
72
91
const { sourceFiles, program} = info ;
73
92
const outputFieldReplacements : Record < ClassFieldUniqueKey , OutputMigrationData > = { } ;
@@ -111,14 +130,24 @@ export class OutputMigration extends TsurgeFunnelMigration<
111
130
const outputDef = extractSourceOutputDefinition ( node , reflector , info ) ;
112
131
if ( outputDef !== null ) {
113
132
const outputFile = projectFile ( node . getSourceFile ( ) , info ) ;
114
-
115
- filesWithOutputDeclarations . add ( node . getSourceFile ( ) ) ;
116
- addOutputReplacement (
117
- outputFieldReplacements ,
118
- outputDef . id ,
119
- outputFile ,
120
- calculateDeclarationReplacement ( info , node , outputDef . aliasParam ) ,
121
- ) ;
133
+ if (
134
+ this . config . shouldMigrate === undefined ||
135
+ this . config . shouldMigrate (
136
+ {
137
+ key : outputDef . id ,
138
+ node : node ,
139
+ } ,
140
+ outputFile ,
141
+ )
142
+ ) {
143
+ filesWithOutputDeclarations . add ( node . getSourceFile ( ) ) ;
144
+ addOutputReplacement (
145
+ outputFieldReplacements ,
146
+ outputDef . id ,
147
+ outputFile ,
148
+ calculateDeclarationReplacement ( info , node , outputDef . aliasParam ) ,
149
+ ) ;
150
+ }
122
151
}
123
152
}
124
153
0 commit comments