-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(template): add parentheses () wrapper for name when kind is Output
- Loading branch information
1 parent
365f323
commit d91143d
Showing
6 changed files
with
106 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
"src/assets/styles" | ||
] | ||
}, | ||
"whitelistedNonPeerDependencies": [ | ||
"allowedNonPeerDependencies": [ | ||
"docsearch.js" | ||
] | ||
} |
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
79 changes: 79 additions & 0 deletions
79
packages/template/src/shared/pipes/property-name.pipe.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,79 @@ | ||
import { PropertyNamePipe } from './property-name.pipe'; | ||
|
||
describe('property-name', () => { | ||
it('should get property name for Input', () => { | ||
const result = new PropertyNamePipe().transform({ | ||
kind: 'Input', | ||
name: 'thyType', | ||
type: 'string' | ||
}); | ||
expect(result).toEqual('thyType'); | ||
}); | ||
|
||
it('should get property name with alias name for Input', () => { | ||
const result = new PropertyNamePipe().transform({ | ||
kind: 'Input', | ||
name: 'thyType', | ||
type: 'string', | ||
aliasName: 'thyTypeAlias' | ||
}); | ||
expect(result).toEqual('thyTypeAlias'); | ||
}); | ||
|
||
it('should get property name for Output', () => { | ||
const result = new PropertyNamePipe().transform({ | ||
kind: 'Output', | ||
name: 'thyChange', | ||
type: 'EventEmitter<boolean>' | ||
}); | ||
expect(result).toEqual('(thyChange)'); | ||
}); | ||
|
||
it('should get property name with alias name for Output', () => { | ||
const result = new PropertyNamePipe().transform({ | ||
kind: 'Output', | ||
name: 'thyChange', | ||
aliasName: 'thyChangeAlias', | ||
type: 'EventEmitter<boolean>' | ||
}); | ||
expect(result).toEqual('(thyChangeAlias)'); | ||
}); | ||
|
||
it('should get property name for ContentChild', () => { | ||
const result = new PropertyNamePipe().transform({ | ||
kind: 'ContentChild', | ||
name: 'header', | ||
type: 'TemplateRef<unknown>' | ||
}); | ||
expect(result).toEqual('#header'); | ||
}); | ||
|
||
it('should get property name with alias name for ContentChild', () => { | ||
const result = new PropertyNamePipe().transform({ | ||
kind: 'ContentChild', | ||
name: 'header', | ||
aliasName: 'headerAlias', | ||
type: 'TemplateRef<unknown>' | ||
}); | ||
expect(result).toEqual('#headerAlias'); | ||
}); | ||
|
||
it('should get property name for ContentChildren', () => { | ||
const result = new PropertyNamePipe().transform({ | ||
kind: 'ContentChildren', | ||
name: 'header', | ||
type: 'TemplateRef<unknown>' | ||
}); | ||
expect(result).toEqual('#header'); | ||
}); | ||
|
||
it('should get property name with alias name for ContentChildren', () => { | ||
const result = new PropertyNamePipe().transform({ | ||
kind: 'ContentChildren', | ||
name: 'header', | ||
aliasName: 'headerAlias', | ||
type: 'TemplateRef<unknown>' | ||
}); | ||
expect(result).toEqual('#headerAlias'); | ||
}); | ||
}); |
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 @@ | ||
import { NavigationItem } from './../../interfaces/navigation-item'; | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
import { PropertyDeclaration } from '../../interfaces'; | ||
import { IsNgContentChildKindPipe } from './ng-kind.pipe'; | ||
|
||
@Pipe({ name: 'dgPropertyName' }) | ||
export class PropertyNamePipe implements PipeTransform { | ||
constructor() {} | ||
|
||
transform(property: PropertyDeclaration): string { | ||
const ngContentChildKind = new IsNgContentChildKindPipe(); | ||
const isContentChild = ngContentChildKind.transform(property.kind); | ||
const name = property.aliasName || property.name; | ||
if (isContentChild) { | ||
return `#${name}`; | ||
} else if (property.kind === 'Output') { | ||
return `(${name})`; | ||
} else { | ||
return `${name}`; | ||
} | ||
} | ||
} |
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