-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): add the
removeMetadataProperty
function
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
packages/angular/src/lib/metadata/__snapshots__/remove-metadata-property.spec.ts.snap
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,7 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`removeMetadataProperty > should remove the providers property 1`] = ` | ||
" | ||
@Component({}) class AppComponent {} | ||
" | ||
`; |
32 changes: 32 additions & 0 deletions
32
packages/angular/src/lib/metadata/remove-metadata-property.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,32 @@ | ||
import { Tree } from '@angular-devkit/schematics'; | ||
|
||
import { createSourceFile, readFileSync, saveProject } from '@mutates/core'; | ||
|
||
import { createTestingTree } from '../../testing'; | ||
import { getComponents } from '../component'; | ||
import { createAngularProject } from '../create-angular-project'; | ||
import { removeMetadataProperty } from './remove-metadata-property'; | ||
|
||
describe('removeMetadataProperty', () => { | ||
let host: Tree; | ||
beforeEach(() => { | ||
host = createTestingTree(); | ||
|
||
createAngularProject(host); | ||
}); | ||
|
||
it('should remove the providers property', () => { | ||
createSourceFile( | ||
'src/main.ts', | ||
` | ||
@Component({providers: [Set, Map]}) class AppComponent {} | ||
`, | ||
); | ||
|
||
removeMetadataProperty(getComponents('src/main.ts').at(0)!, 'providers'); | ||
|
||
saveProject(); | ||
|
||
expect(readFileSync('src/main.ts')).matchSnapshot(); | ||
}); | ||
}); |
19 changes: 19 additions & 0 deletions
19
packages/angular/src/lib/metadata/remove-metadata-property.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,19 @@ | ||
import { ClassDeclaration } from 'ts-morph'; | ||
|
||
import { getObjectProperties } from '@mutates/core'; | ||
|
||
import { MetadataProperty } from '../types/metadata-property'; | ||
import { getMetadata } from './get-metadata'; | ||
|
||
export function removeMetadataProperty<T extends MetadataProperty>( | ||
klass: ClassDeclaration, | ||
property: T, | ||
): void { | ||
const [metadata] = getMetadata(klass); | ||
|
||
const prop = getObjectProperties(metadata, { | ||
name: property as string, | ||
}).at(0); | ||
|
||
prop?.remove(); | ||
} |