diff --git a/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/index.ts b/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/index.ts index 68f80e5d489d7..08738601392df 100644 --- a/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/index.ts +++ b/packages/core/schematics/migrations/undecorated-classes-with-decorated-fields/index.ts @@ -65,9 +65,14 @@ function runUndecoratedClassesMigration(tree: Tree, tsconfigPath: string, basePa file => !file.isDeclarationFile && !program.isSourceFileFromExternalLibrary(file)); sourceFiles.forEach(sourceFile => { - const update = tree.beginUpdate(relative(basePath, sourceFile.fileName)); const classes = getUndecoratedClassesWithDecoratedFields(sourceFile, typeChecker); + if (classes.length === 0) { + return; + } + + const update = tree.beginUpdate(relative(basePath, sourceFile.fileName)); + classes.forEach((current, index) => { // If it's the first class that we're processing in this file, add `Directive` to the imports. if (index === 0 && !hasNamedImport(current.importDeclaration, FALLBACK_DECORATOR)) {