@@ -53,12 +53,27 @@ import {
5353import { ReferenceResult } from '../signal-migration/src/passes/reference_resolution/reference_result' ;
5454import { ReferenceKind } from '../signal-migration/src/passes/reference_resolution/reference_kinds' ;
5555
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 {
5772 file : ProjectFile ;
5873 replacements : Replacement [ ] ;
5974}
6075
61- interface CompilationUnitData {
76+ export interface CompilationUnitData {
6277 outputFields : Record < ClassFieldUniqueKey , OutputMigrationData > ;
6378 problematicUsages : Record < ClassFieldUniqueKey , true > ;
6479 importReplacements : Record < ProjectFileID , { add : Replacement [ ] ; addAndRemove : Replacement [ ] } > ;
@@ -68,6 +83,10 @@ export class OutputMigration extends TsurgeFunnelMigration<
6883 CompilationUnitData ,
6984 CompilationUnitData
7085> {
86+ constructor ( private readonly config : MigrationConfig = { } ) {
87+ super ( ) ;
88+ }
89+
7190 override async analyze ( info : ProgramInfo ) : Promise < Serializable < CompilationUnitData > > {
7291 const { sourceFiles, program} = info ;
7392 const outputFieldReplacements : Record < ClassFieldUniqueKey , OutputMigrationData > = { } ;
@@ -111,14 +130,24 @@ export class OutputMigration extends TsurgeFunnelMigration<
111130 const outputDef = extractSourceOutputDefinition ( node , reflector , info ) ;
112131 if ( outputDef !== null ) {
113132 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+ }
122151 }
123152 }
124153
0 commit comments