chore: adjust formatting to new clang-format.

- fixes wrapping for object literal keys called `template`.
- spacing in destructuring expressions.
- changes to keep trailing return types of functions closer to their
  function declaration.
- better formatting of string literals.

Closes #4828
This commit is contained in:
Martin Probst
2015-10-28 08:59:19 +01:00
parent 4a1b873fad
commit c02f2bdab0
50 changed files with 245 additions and 236 deletions
@@ -39,8 +39,8 @@ function _createEventRecords(expression: string): BindingRecord[] {
return [BindingRecord.createForEvent(ast, eventName, 0)];
}
function _createHostEventRecords(expression: string, directiveRecord: DirectiveRecord):
BindingRecord[] {
function _createHostEventRecords(expression: string,
directiveRecord: DirectiveRecord): BindingRecord[] {
var parts = expression.split("=");
var eventName = parts[0].substring(1, parts[0].length - 1);
var exp = parts[1].substring(1, parts[1].length - 1);
@@ -315,48 +315,46 @@ class _DirectiveUpdating {
* Map from test id to _DirectiveUpdating.
* Definitions in this map define definitions which allow testing directive updating.
*/
static availableDefinitions:
{[key: string]: _DirectiveUpdating} = {
'directNoDispatcher': new _DirectiveUpdating(
[_DirectiveUpdating.updateA('42', _DirectiveUpdating.basicRecords[0])],
static availableDefinitions: {[key: string]: _DirectiveUpdating} = {
'directNoDispatcher': new _DirectiveUpdating(
[_DirectiveUpdating.updateA('42', _DirectiveUpdating.basicRecords[0])],
[_DirectiveUpdating.basicRecords[0]]),
'groupChanges':
new _DirectiveUpdating(
[
_DirectiveUpdating.updateA('1', _DirectiveUpdating.basicRecords[0]),
_DirectiveUpdating.updateB('2', _DirectiveUpdating.basicRecords[0]),
BindingRecord.createDirectiveOnChanges(_DirectiveUpdating.basicRecords[0]),
_DirectiveUpdating.updateA('3', _DirectiveUpdating.basicRecords[1]),
BindingRecord.createDirectiveOnChanges(_DirectiveUpdating.basicRecords[1])
],
[_DirectiveUpdating.basicRecords[0], _DirectiveUpdating.basicRecords[1]]),
'directiveDoCheck': new _DirectiveUpdating(
[BindingRecord.createDirectiveDoCheck(_DirectiveUpdating.basicRecords[0])],
[_DirectiveUpdating.basicRecords[0]]),
'directiveOnInit': new _DirectiveUpdating(
[BindingRecord.createDirectiveOnInit(_DirectiveUpdating.basicRecords[0])],
[_DirectiveUpdating.basicRecords[0]]),
'emptyWithDirectiveRecords': new _DirectiveUpdating(
[], [_DirectiveUpdating.basicRecords[0], _DirectiveUpdating.basicRecords[1]]),
'noCallbacks': new _DirectiveUpdating(
[_DirectiveUpdating.updateA('1', _DirectiveUpdating.recordNoCallbacks)],
[_DirectiveUpdating.recordNoCallbacks]),
'readingDirectives':
new _DirectiveUpdating(
[
BindingRecord.createForHostProperty(
new DirectiveIndex(0, 0), _getParser().parseBinding('a', 'location'), PROP_NAME)
],
[_DirectiveUpdating.basicRecords[0]]),
'groupChanges':
new _DirectiveUpdating(
[
_DirectiveUpdating.updateA('1', _DirectiveUpdating.basicRecords[0]),
_DirectiveUpdating.updateB('2', _DirectiveUpdating.basicRecords[0]),
BindingRecord.createDirectiveOnChanges(_DirectiveUpdating.basicRecords[0]),
_DirectiveUpdating.updateA('3', _DirectiveUpdating.basicRecords[1]),
BindingRecord.createDirectiveOnChanges(_DirectiveUpdating.basicRecords[1])
],
[_DirectiveUpdating.basicRecords[0], _DirectiveUpdating.basicRecords[1]]),
'directiveDoCheck': new _DirectiveUpdating(
[BindingRecord.createDirectiveDoCheck(_DirectiveUpdating.basicRecords[0])],
[_DirectiveUpdating.basicRecords[0]]),
'directiveOnInit': new _DirectiveUpdating(
[BindingRecord.createDirectiveOnInit(_DirectiveUpdating.basicRecords[0])],
[_DirectiveUpdating.basicRecords[0]]),
'emptyWithDirectiveRecords': new _DirectiveUpdating(
[], [_DirectiveUpdating.basicRecords[0], _DirectiveUpdating.basicRecords[1]]),
'noCallbacks': new _DirectiveUpdating(
[_DirectiveUpdating.updateA('1', _DirectiveUpdating.recordNoCallbacks)],
[_DirectiveUpdating.recordNoCallbacks]),
'readingDirectives':
new _DirectiveUpdating(
[
BindingRecord.createForHostProperty(new DirectiveIndex(0, 0),
_getParser().parseBinding('a', 'location'),
PROP_NAME)
],
[_DirectiveUpdating.basicRecords[0]]),
'interpolation':
new _DirectiveUpdating(
[
BindingRecord.createForElementProperty(
_getParser().parseInterpolation('B{{a}}A', 'location'), 0, PROP_NAME)
],
[])
};
'interpolation':
new _DirectiveUpdating(
[
BindingRecord.createForElementProperty(
_getParser().parseInterpolation('B{{a}}A', 'location'), 0, PROP_NAME)
],
[])
};
}
/**
@@ -13,15 +13,15 @@ import {isBlank} from 'angular2/src/core/facade/lang';
import {RecordType, ProtoRecord} from 'angular2/src/core/change_detection/proto_record';
export function main() {
function r({lastInBinding, mode, name, directiveIndex, argumentToPureFunction, referencedBySelf}:
{
lastInBinding?: any,
mode?: any,
name?: any,
directiveIndex?: any,
argumentToPureFunction?: boolean,
referencedBySelf?: boolean
} = {}) {
function r(
{lastInBinding, mode, name, directiveIndex, argumentToPureFunction, referencedBySelf}: {
lastInBinding?: any,
mode?: any,
name?: any,
directiveIndex?: any,
argumentToPureFunction?: boolean,
referencedBySelf?: boolean
} = {}) {
if (isBlank(lastInBinding)) lastInBinding = false;
if (isBlank(mode)) mode = RecordType.PropertyRead;
if (isBlank(name)) name = "name";
@@ -108,9 +108,9 @@ export function main() {
});
describe('compileComponentCodeGen', () => {
function detectChanges(compiler: ChangeDetectionCompiler, template: string,
directives: CompileDirectiveMetadata[] = CONST_EXPR([])):
Promise<string[]> {
function detectChanges(
compiler: ChangeDetectionCompiler, template: string,
directives: CompileDirectiveMetadata[] = CONST_EXPR([])): Promise<string[]> {
var type =
new CompileTypeMetadata({name: stringify(SomeComponent), moduleUrl: THIS_MODULE_URL});
var parsedTemplate = parser.parse(template, directives, 'TestComp');
@@ -133,8 +133,8 @@ export function main() {
});
}
function createTestableModule(source: SourceExpressions, changeDetectorIndex: number):
SourceModule {
function createTestableModule(source: SourceExpressions,
changeDetectorIndex: number): SourceModule {
var resultExpression =
`${THIS_MODULE_REF}testChangeDetector(([${source.expressions.join(',')}])[${changeDetectorIndex}])`;
var testableSource = `${source.declarations.join('\n')}
@@ -120,8 +120,8 @@ export function main() {
});
}
function createDirective(type: CompileTypeMetadata, selector: string, exportAs: string = null):
CompileDirectiveMetadata {
function createDirective(type: CompileTypeMetadata, selector: string,
exportAs: string = null): CompileDirectiveMetadata {
return CompileDirectiveMetadata.create(
{selector: selector, exportAs: exportAs, isComponent: false, type: type});
}
@@ -42,7 +42,8 @@ export function main() {
selector: 'someSelector',
isComponent: true,
dynamicLoadable: true,
type: fullTypeMeta, template: fullTemplateMeta,
type: fullTypeMeta,
template: fullTemplateMeta,
changeDetection: ChangeDetectionStrategy.Default,
inputs: ['someProp'],
outputs: ['someEvent'],
@@ -74,8 +74,8 @@ export function main() {
`a {color: green}@import ${IMPORT_REL_STYLESHEET_URL};`;
});
function compile(styles: string[], styleAbsUrls: string[], encapsulation: ViewEncapsulation):
Promise<string[]> {
function compile(styles: string[], styleAbsUrls: string[],
encapsulation: ViewEncapsulation): Promise<string[]> {
// Note: Can't use MockXHR as the xhr is called recursively,
// so we can't trigger flush.
xhr.spy('get').andCallFake((url) => {
@@ -203,8 +203,8 @@ export function main() {
});
describe('compileComponentCodeGen', () => {
function compile(styles: string[], styleAbsUrls: string[], encapsulation: ViewEncapsulation):
Promise<string[]> {
function compile(styles: string[], styleAbsUrls: string[],
encapsulation: ViewEncapsulation): Promise<string[]> {
var sourceExpression = compiler.compileComponentCodeGen(
`'${appId}'`, `${templateId}`,
new CompileTemplateMetadata(
@@ -190,8 +190,8 @@ export function main() {
});
describe('compileTemplatesCodeGen', () => {
function normalizeComponent(component: Type):
Promise<NormalizedComponentWithViewDirectives> {
function normalizeComponent(
component: Type): Promise<NormalizedComponentWithViewDirectives> {
var compAndViewDirMetas = [runtimeMetadataResolver.getMetadata(component)].concat(
runtimeMetadataResolver.getViewDirectivesMetadata(component));
return PromiseWrapper.all(compAndViewDirMetas.map(
@@ -316,8 +316,8 @@ class CompWithEmbeddedTemplate {
class NonComponent {
}
function testableTemplateModule(sourceModule: SourceModule, normComp: CompileDirectiveMetadata):
SourceModule {
function testableTemplateModule(sourceModule: SourceModule,
normComp: CompileDirectiveMetadata): SourceModule {
var resultExpression =
`${THIS_MODULE_REF}humanizeTemplate(Host${normComp.type.name}Template.getTemplate())`;
var testableSource = `${sourceModule.sourceWithModuleRefs}
@@ -332,9 +332,9 @@ function testableStylesModule(sourceModule: SourceModule): SourceModule {
}
// Attention: read by eval!
export function humanizeTemplate(template: CompiledTemplate,
humanizedTemplates: Map<number, {[key: string]: any}> = null):
{[key: string]: any} {
export function humanizeTemplate(
template: CompiledTemplate,
humanizedTemplates: Map<number, {[key: string]: any}> = null): {[key: string]: any} {
if (isBlank(humanizedTemplates)) {
humanizedTemplates = new Map<number, {[key: string]: any}>();
}
@@ -553,7 +553,8 @@ There is no directive with "exportAs" set to "dirA" at TestComp > div:nth-child(
selector: '[a]',
isComponent: true,
type: new CompileTypeMetadata({name: 'DirA'}),
exportAs: 'dirA', template: new CompileTemplateMetadata({ngContentSelectors: []})
exportAs: 'dirA',
template: new CompileTemplateMetadata({ngContentSelectors: []})
});
expect(humanizeTemplateAsts(parse('<div a #a></div>', [dirA])))
.toEqual([
@@ -686,8 +687,8 @@ There is no directive with "exportAs" set to "dirA" at TestComp > div:nth-child(
});
describe('content projection', () => {
function createComp(selector: string, ngContentSelectors: string[]):
CompileDirectiveMetadata {
function createComp(selector: string,
ngContentSelectors: string[]): CompileDirectiveMetadata {
return CompileDirectiveMetadata.create({
selector: selector,
isComponent: true,
@@ -52,7 +52,7 @@ class MessageDir {
<span class="childnested" message="nestedchild">Child</span>
</div>
<span class="child" [inner-html]="childBinding"></span>`,
directives: [MessageDir]
directives: [MessageDir],
})
@Injectable()
class ChildComp {
@@ -64,7 +64,7 @@ class ChildComp {
@Component({selector: 'cond-content-comp', viewProviders: [Logger]})
@View({
template: `<div class="child" message="child" *ng-if="false"><ng-content></ng-content></div>`,
directives: [NgIf, MessageDir]
directives: [NgIf, MessageDir],
})
@Injectable()
class ConditionalContentComp {
@@ -78,7 +78,7 @@ class ConditionalContentComp {
<span class="parent" [inner-html]="parentBinding"></span>
<child-comp class="child-comp-class"></child-comp>
<cond-content-comp class="cond-content-comp-class"></cond-content-comp>`,
directives: [ChildComp, MessageDir, ConditionalContentComp]
directives: [ChildComp, MessageDir, ConditionalContentComp],
})
@Injectable()
class ParentComp {
@@ -98,7 +98,7 @@ class CustomEmitter {
@View({
template: `<button (click)="handleClick()"></button>
<custom-emitter (myevent)="handleCustom()"></custom-emitter>`,
directives: [CustomEmitter]
directives: [CustomEmitter],
})
@Injectable()
class EventsComp {
@@ -121,7 +121,7 @@ class EventsComp {
<ul message="list">
<li *ng-for="#item of stuff" [inner-html]="item"></li>
</ul>`,
directives: [NgFor, MessageDir]
directives: [NgFor, MessageDir],
})
@Injectable()
class UsingFor {
@@ -78,27 +78,29 @@ export function main() {
}));
it("should emit ng-submit event on submit",
inject(
[TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var t =
`<div><form [ng-form-model]="form" (ng-submit)="name='updated'"></form><span>{{name}}</span></div>`;
inject([TestComponentBuilder], fakeAsync((tcb: TestComponentBuilder) => {
var t = `<div>
<form [ng-form-model]="form" (ng-submit)="name='updated'"></form>
<span>{{name}}</span>
</div>`;
var rootTC: RootTestComponent;
var rootTC: RootTestComponent;
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then((root) => { rootTC = root; });
tick();
tcb.overrideTemplate(MyComp, t).createAsync(MyComp).then(
(root) => { rootTC = root; });
tick();
rootTC.debugElement.componentInstance.form = new ControlGroup({});
rootTC.debugElement.componentInstance.name = 'old';
rootTC.debugElement.componentInstance.form = new ControlGroup({});
rootTC.debugElement.componentInstance.name = 'old';
tick();
tick();
var form = rootTC.debugElement.query(By.css("form"));
dispatchEvent(form.nativeElement, "submit");
var form = rootTC.debugElement.query(By.css("form"));
dispatchEvent(form.nativeElement, "submit");
tick();
expect(rootTC.debugElement.componentInstance.name).toEqual('updated');
})));
tick();
expect(rootTC.debugElement.componentInstance.name).toEqual('updated');
})));
it("should work with single controls",
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
@@ -43,7 +43,7 @@ export function main() {
@Component({selector: 'app', viewProviders: [forwardRef(() => Frame)]})
@View({
template: `<door><lock></lock></door>`,
directives: [forwardRef(() => Door), forwardRef(() => Lock)]
directives: [forwardRef(() => Door), forwardRef(() => Lock)],
})
class App {
}
@@ -51,7 +51,7 @@ class App {
@Component({selector: 'Lock'})
@View({
directives: [NgFor],
template: `{{frame.name}}(<span *ng-for="var lock of locks">{{lock.name}}</span>)`
template: `{{frame.name}}(<span *ng-for="var lock of locks">{{lock.name}}</span>)`,
})
class Door {
locks: QueryList<Lock>;
@@ -2321,7 +2321,8 @@ class DirectiveThrowingAnError {
@Component({
selector: 'component-with-template',
directives: [NgFor], template: `No View Decorator: <div *ng-for="#item of items">{{item}}</div>`
directives: [NgFor],
template: `No View Decorator: <div *ng-for="#item of items">{{item}}</div>`
})
class ComponentWithTemplate {
items = [1, 2, 3];
@@ -470,32 +470,32 @@ export function main() {
it('should allow to switch the order of nested components via ng-content',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(
MainComp,
new ViewMetadata(
{template: `<cmp-a><cmp-b></cmp-b></cmp-a>`, directives: [CmpA, CmpB]}))
tcb.overrideView(MainComp, new ViewMetadata({
template: `<cmp-a><cmp-b></cmp-b></cmp-a>`,
directives: [CmpA, CmpB],
}))
.createAsync(MainComp)
.then((main) => {
main.detectChanges();
expect(DOM.getInnerHTML(main.debugElement.nativeElement))
.toEqual(
'<cmp-a><cmp-b><cmp-d><d>cmp-d</d></cmp-d></cmp-b><cmp-c><c>cmp-c</c></cmp-c></cmp-a>');
.toEqual('<cmp-a><cmp-b><cmp-d><d>cmp-d</d></cmp-d></cmp-b>' +
'<cmp-c><c>cmp-c</c></cmp-c></cmp-a>');
async.done();
});
}));
it('should create nested components in the right order',
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
tcb.overrideView(
MainComp,
new ViewMetadata(
{template: `<cmp-a1></cmp-a1><cmp-a2></cmp-a2>`, directives: [CmpA1, CmpA2]}))
tcb.overrideView(MainComp, new ViewMetadata({
template: `<cmp-a1></cmp-a1><cmp-a2></cmp-a2>`,
directives: [CmpA1, CmpA2],
}))
.createAsync(MainComp)
.then((main) => {
main.detectChanges();
expect(DOM.getInnerHTML(main.debugElement.nativeElement))
.toEqual(
'<cmp-a1>a1<cmp-b11>b11</cmp-b11><cmp-b12>b12</cmp-b12></cmp-a1><cmp-a2>a2<cmp-b21>b21</cmp-b21><cmp-b22>b22</cmp-b22></cmp-a2>');
.toEqual('<cmp-a1>a1<cmp-b11>b11</cmp-b11><cmp-b12>b12</cmp-b12></cmp-a1>' +
'<cmp-a2>a2<cmp-b21>b21</cmp-b21><cmp-b22>b22</cmp-b22></cmp-a2>');
async.done();
});
}));
+1 -1
View File
@@ -31,7 +31,7 @@ import {
} from 'angular2/http';
var Rx = require('@reactivex/rxjs/dist/cjs/Rx');
let{Observable, Subject} = Rx;
let {Observable, Subject} = Rx;
class SpyObserver extends SpyObject {
onNext: Function;
@@ -288,16 +288,24 @@ function parentLoader() {
}
@Component({selector: 'parent-cmp'})
@View({template: "inner { <router-outlet></router-outlet> }", directives: [RouterOutlet]})
@RouteConfig(
[new Route({path: '/b', component: HelloCmp}), new Route({path: '/', component: HelloCmp})])
@View({
template: "inner { <router-outlet></router-outlet> }",
directives: [RouterOutlet],
})
@RouteConfig([
new Route({path: '/b', component: HelloCmp}),
new Route({path: '/', component: HelloCmp}),
])
class ParentCmp {
constructor() {}
}
@Component({selector: 'team-cmp'})
@View({template: "team {{id}} { <router-outlet></router-outlet> }", directives: [RouterOutlet]})
@View({
template: "team {{id}} { <router-outlet></router-outlet> }",
directives: [RouterOutlet],
})
@RouteConfig([new Route({path: '/user/:name', component: UserCmp})])
class TeamCmp {
id: string;
@@ -320,13 +328,13 @@ class ModalCmp {
@Component({selector: 'aux-cmp'})
@View({
template:
`main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`,
directives: [RouterOutlet]
template: 'main {<router-outlet></router-outlet>} | ' +
'aux {<router-outlet name="modal"></router-outlet>}',
directives: [RouterOutlet],
})
@RouteConfig([
new Route({path: '/hello', component: HelloCmp}),
new AuxRoute({path: '/modal', component: ModalCmp})
new AuxRoute({path: '/modal', component: ModalCmp}),
])
class AuxCmp {
}