-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdk/schematics): add migration for removed symbols (#23530)
Sets up a new migration that will log a message for symbols that have been removed from a specific module.
- Loading branch information
Showing
10 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {VersionChanges} from '../../update-tool/version-changes'; | ||
|
||
export interface SymbolRemovalUpgradeData { | ||
/** Module that the symbol was removed from. */ | ||
module: string; | ||
|
||
/** Name of the symbol being removed. */ | ||
name: string; | ||
|
||
/** Message to log explaining why the symbol was removed. */ | ||
message: string; | ||
} | ||
|
||
export const symbolRemoval: VersionChanges<SymbolRemovalUpgradeData> = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import * as ts from 'typescript'; | ||
import {Migration} from '../../update-tool/migration'; | ||
import {SymbolRemovalUpgradeData} from '../data'; | ||
import {getVersionUpgradeData, UpgradeData} from '../upgrade-data'; | ||
|
||
/** Migration that flags imports for symbols that have been removed. */ | ||
export class SymbolRemovalMigration extends Migration<UpgradeData> { | ||
/** Change data that upgrades to the specified target version. */ | ||
data: SymbolRemovalUpgradeData[] = getVersionUpgradeData(this, 'symbolRemoval'); | ||
|
||
// Only enable the migration rule if there is upgrade data. | ||
enabled = this.data.length !== 0; | ||
|
||
override visitNode(node: ts.Node): void { | ||
if (!ts.isImportDeclaration(node) || !ts.isStringLiteral(node.moduleSpecifier)) { | ||
return; | ||
} | ||
|
||
const namedBindings = node.importClause && node.importClause.namedBindings; | ||
|
||
if (!namedBindings || !ts.isNamedImports(namedBindings)) { | ||
return; | ||
} | ||
|
||
const moduleNameMatches = this.data.filter(entry => | ||
(node.moduleSpecifier as ts.StringLiteral).text === entry.module); | ||
|
||
if (!moduleNameMatches.length) { | ||
return; | ||
} | ||
|
||
namedBindings.elements.forEach(element => { | ||
const elementName = element.propertyName?.text || element.name.text; | ||
|
||
moduleNameMatches.forEach(match => { | ||
if (match.name === elementName) { | ||
this.createFailureAtNode(element, match.message); | ||
} | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {SymbolRemovalUpgradeData, TargetVersion, VersionChanges} from '@angular/cdk/schematics'; | ||
|
||
export const symbolRemoval: VersionChanges<SymbolRemovalUpgradeData> = { | ||
[TargetVersion.V13]: [ | ||
{ | ||
pr: 'https://github.com/angular/components/pull/23529', | ||
changes: [ | ||
'CanColorCtor', | ||
'CanDisableRippleCtor', | ||
'CanDisableCtor', | ||
'CanUpdateErrorStateCtor', | ||
'HasInitializedCtor', | ||
'HasTabIndexCtor' | ||
].map(name => ({ | ||
name, | ||
module: '@angular/material/core', | ||
message: `\`${name}\` is no longer necessary and has been removed.` | ||
})) | ||
} | ||
] | ||
}; |
30 changes: 30 additions & 0 deletions
30
src/material/schematics/ng-update/test-cases/misc/symbol-removal.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import {createTestCaseSetup, resolveBazelPath} from '@angular/cdk/schematics/testing'; | ||
import {MIGRATION_PATH} from '../../../paths'; | ||
|
||
describe('symbol removal check', () => { | ||
it('should report symbols that have been removed', async () => { | ||
const {runFixers} = await createTestCaseSetup( | ||
'migration-v13', MIGRATION_PATH, | ||
[resolveBazelPath(__dirname, './symbol-removal_input.ts')]); | ||
|
||
const {logOutput} = await runFixers(); | ||
|
||
expect(logOutput) | ||
.not | ||
.withContext('Expected check not to report symbols that have not been removed.') | ||
.toContain('MatRipple'); | ||
|
||
expect(logOutput) | ||
.not | ||
.withContext('Expected check not to report symbols with the same name as a ' + | ||
'removed symbol, but from a different module.').toContain('HasInitializedCtor'); | ||
|
||
expect(logOutput) | ||
.withContext('Expected check to report a removed symbol') | ||
.toContain('@2:3 - `CanColorCtor` is no longer necessary and has been removed.'); | ||
|
||
expect(logOutput) | ||
.withContext('Expected check to report a removed symbol that has been aliased') | ||
.toContain('@3:3 - `CanDisableRippleCtor` is no longer necessary and has been removed.'); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
src/material/schematics/ng-update/test-cases/misc/symbol-removal_input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { | ||
CanColorCtor, | ||
CanDisableRippleCtor as DisableRippleCtorAlias, | ||
MatRipple, | ||
} from '@angular/material/core'; | ||
import {HasInitializedCtor} from '@not-angular/material/core'; | ||
|
||
export declare const colorCtor: CanColorCtor; | ||
export declare const disableRIppleCtor: DisableRippleCtorAlias; | ||
export declare const ripple: MatRipple; | ||
export declare const initCtor: HasInitializedCtor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters