Skip to content

Commit 2832dc4

Browse files
Just Use Prettier™
1 parent 7e6b514 commit 2832dc4

10 files changed

+111
-130
lines changed

.prettierrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"singleQuote": true,
3-
"trailingComma": "all",
3+
"trailingComma": "es5",
44
"printWidth": 120
55
}

rollup.config.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import commonjs from 'rollup-plugin-commonjs';
66
let MINIFY = process.env.MINIFY;
77

88
let pkg = require('./package.json');
9-
let banner =
10-
`/**
9+
let banner = `/**
1110
* ${pkg.description}
1211
* @version v${pkg.version}
1312
* @link ${pkg.homepage}
@@ -16,20 +15,15 @@ let banner =
1615

1716
let uglifyOpts = { output: {} };
1817
// retain multiline comment with @license
19-
uglifyOpts.output.comments = (node, comment) =>
20-
comment.type === 'comment2' && /@license/i.test(comment.value);
18+
uglifyOpts.output.comments = (node, comment) => comment.type === 'comment2' && /@license/i.test(comment.value);
2119

22-
let plugins = [
23-
nodeResolve({ jsnext: true }),
24-
sourcemaps(),
25-
commonjs(),
26-
];
20+
let plugins = [nodeResolve({ jsnext: true }), sourcemaps(), commonjs()];
2721

2822
if (MINIFY) plugins.push(uglify(uglifyOpts));
2923

3024
let extension = MINIFY ? '.min.js' : '.js';
3125

32-
const onwarn = (warning) => {
26+
const onwarn = warning => {
3327
// Suppress this error message... https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
3428
const ignores = ['THIS_IS_UNDEFINED'];
3529
if (!ignores.some(code => code === warning.code)) {
@@ -61,7 +55,7 @@ const CONFIG = {
6155
exports: 'named',
6256
banner: banner,
6357
globals: {
64-
'tslib': 'tslib',
58+
tslib: 'tslib',
6559
'rxjs/ReplaySubject': 'Rx',
6660

6761
// Copied these from @angular/router rollup config

src/directives/uiSref.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class UISref implements OnChanges {
122122
constructor(
123123
_router: UIRouter,
124124
@Optional() _anchorUISref: AnchorUISref,
125-
@Inject(UIView.PARENT_INJECT) parent: ParentUIViewInject,
125+
@Inject(UIView.PARENT_INJECT) parent: ParentUIViewInject
126126
) {
127127
this._router = _router;
128128
this._anchorUISref = _anchorUISref;

src/directives/uiSrefStatus.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export class UISrefStatus {
223223
const transFinish$ = from(transResult);
224224

225225
return concat(transStart$, transFinish$);
226-
}),
226+
})
227227
);
228228

229229
// Watch the @ContentChildren UISref[] components and get their target states
@@ -233,7 +233,7 @@ export class UISrefStatus {
233233
this._srefChangesSub = this._srefs.changes.subscribe(srefs => this._srefs$.next(srefs));
234234

235235
const targetStates$: Observable<TargetState[]> = this._srefs$.pipe(
236-
switchMap((srefs: UISref[]) => combineLatest<TargetState>(srefs.map(sref => sref.targetState$))),
236+
switchMap((srefs: UISref[]) => combineLatest<TargetState>(srefs.map(sref => sref.targetState$)))
237237
);
238238

239239
// Calculate the status of each UISref based on the transition event.
@@ -245,9 +245,9 @@ export class UISrefStatus {
245245
map((targets: TargetState[]) => {
246246
const statuses: SrefStatus[] = targets.map(target => getSrefStatus(evt, target));
247247
return statuses.reduce(mergeSrefStatus);
248-
}),
248+
})
249249
);
250-
}),
250+
})
251251
)
252252
.subscribe(this._setStatus.bind(this));
253253
}

src/directives/uiView.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class UIView implements OnInit, OnDestroy {
146146
constructor(
147147
public router: UIRouter,
148148
@Inject(UIView.PARENT_INJECT) parent,
149-
public viewContainerRef: ViewContainerRef,
149+
public viewContainerRef: ViewContainerRef
150150
) {
151151
this._parent = parent;
152152
}
@@ -178,7 +178,7 @@ export class UIView implements OnInit, OnDestroy {
178178
});
179179

180180
this._deregisterUiOnParamsChangedHook = router.transitionService.onSuccess({}, trans =>
181-
this._invokeUiOnParamsChangedHook(trans),
181+
this._invokeUiOnParamsChangedHook(trans)
182182
);
183183

184184
this._deregisterUIView = router.viewService.registerUIView(this._uiViewData);
@@ -357,7 +357,7 @@ export class UIView implements OnInit, OnDestroy {
357357
// Supply resolve data to component as specified in the state's `bindings: {}`
358358
const explicitInputTuples = explicitBoundProps.reduce(
359359
(acc, key) => acc.concat([{ prop: renamedInputProp(key), token: bindings[key] }]),
360-
[],
360+
[]
361361
);
362362

363363
// Supply resolve data to matching @Input('prop') or inputs: ['prop']

src/lazyLoad/lazyLoadNgModule.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export type NgModuleToLoad = string | ModuleTypeCallback;
8181
* - Returns the new states array
8282
*/
8383
export function loadNgModule(
84-
moduleToLoad: NgModuleToLoad,
84+
moduleToLoad: NgModuleToLoad
8585
): (transition: Transition, stateObject: StateDeclaration) => Promise<LazyLoadResult> {
8686
return (transition: Transition, stateObject: StateDeclaration) => {
8787
const ng2Injector = transition.injector().get(NATIVE_INJECTOR_TOKEN);
@@ -142,7 +142,7 @@ export function applyNgModule(
142142
transition: Transition,
143143
ng2Module: NgModuleRef<any>,
144144
parentInjector: Injector,
145-
lazyLoadState: StateDeclaration,
145+
lazyLoadState: StateDeclaration
146146
): LazyLoadResult {
147147
const injector = ng2Module.injector;
148148
const uiRouter: UIRouter = injector.get(UIRouter);
@@ -157,11 +157,11 @@ export function applyNgModule(
157157

158158
const newRootModules = multiProviderParentChildDelta(parentInjector, injector, UIROUTER_ROOT_MODULE).reduce(
159159
uniqR,
160-
[],
160+
[]
161161
) as RootModule[];
162162
const newChildModules = multiProviderParentChildDelta(parentInjector, injector, UIROUTER_MODULE_TOKEN).reduce(
163163
uniqR,
164-
[],
164+
[]
165165
) as StatesModule[];
166166

167167
if (newRootModules.length) {
@@ -182,7 +182,7 @@ export function applyNgModule(
182182
`The lazy loaded NgModule must have a state named '${replacementName}' ` +
183183
`which replaces the (placeholder) '${originalName}' Future State. ` +
184184
`Add a '${replacementName}' state to the lazy loaded NgModule ` +
185-
`using UIRouterModule.forChild({ states: CHILD_STATES }).`,
185+
`using UIRouterModule.forChild({ states: CHILD_STATES }).`
186186
);
187187
}
188188
}

src/providers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export function uiRouterFactory(
124124
locationStrategy: LocationStrategy,
125125
rootModules: RootModule[],
126126
modules: StatesModule[],
127-
injector: Injector,
127+
injector: Injector
128128
) {
129129
if (rootModules.length !== 1) {
130130
throw new Error("Exactly one UIRouterModule.forRoot() should be in the bootstrapped app module's imports: []");
@@ -148,7 +148,7 @@ export function uiRouterFactory(
148148
router.locationService = new Ng2LocationServices(
149149
router,
150150
locationStrategy,
151-
isPlatformBrowser(injector.get(PLATFORM_ID)),
151+
isPlatformBrowser(injector.get(PLATFORM_ID))
152152
);
153153
router.locationConfig = new Ng2LocationConfig(router, locationStrategy);
154154

test/ngModule/deferInitialRender.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('deferInitialRender == false', () => {
5757
inject([UIRouter, ApplicationInitStatus], (_router, _status) => {
5858
router = _router;
5959
status = _status;
60-
}),
60+
})
6161
);
6262

6363
it('should not wait for initial transition', async done => {
@@ -90,7 +90,7 @@ describe('deferInitialRender == true', () => {
9090
inject([UIRouter, ApplicationInitStatus], (_router, _status) => {
9191
router = _router;
9292
status = _status;
93-
}),
93+
})
9494
);
9595

9696
it('should wait for initial transition', async done => {

test/ngModule/lazyModule.spec.ts

+73-82
Original file line numberDiff line numberDiff line change
@@ -44,92 +44,83 @@ describe('lazy loading', () => {
4444
});
4545
});
4646

47-
it(
48-
'should lazy load a module',
49-
async(
50-
inject([UIRouter], (router: UIRouter) => {
51-
const { stateRegistry, stateService, globals } = router;
52-
stateRegistry.register(futureFoo);
53-
54-
const fixture = TestBed.createComponent(UIView);
55-
fixture.detectChanges();
47+
it('should lazy load a module', async(
48+
inject([UIRouter], (router: UIRouter) => {
49+
const { stateRegistry, stateService, globals } = router;
50+
stateRegistry.register(futureFoo);
5651

57-
let names = stateRegistry
58-
.get()
59-
.map(state => state.name)
60-
.sort();
61-
expect(names.length).toBe(2);
62-
expect(names).toEqual(['', 'foo.**']);
63-
64-
stateService.go('foo').then(() => {
65-
expect(globals.current.name).toBe('foo');
66-
67-
names = stateRegistry
68-
.get()
69-
.map(state => state.name)
70-
.sort();
71-
expect(names.length).toBe(4);
72-
expect(names).toEqual(['', 'foo', 'foo.child1', 'foo.child2']);
73-
});
74-
}),
75-
),
76-
);
77-
78-
it(
79-
'should throw if no future state replacement is lazy loaded',
80-
async(
81-
inject([UIRouter], (router: UIRouter) => {
82-
const { stateRegistry, stateService } = router;
83-
stateService.defaultErrorHandler(() => null);
84-
stateRegistry.register(futureBar);
85-
86-
const fixture = TestBed.createComponent(UIView);
87-
fixture.detectChanges();
52+
const fixture = TestBed.createComponent(UIView);
53+
fixture.detectChanges();
8854

89-
const names = stateRegistry
90-
.get()
91-
.map(state => state.name)
92-
.sort();
93-
expect(names.length).toBe(2);
94-
expect(names).toEqual(['', 'bar.**']);
95-
96-
const success = () => {
97-
throw Error('success not expected');
98-
};
99-
const error = err => {
100-
expect(err.detail.message).toContain("The lazy loaded NgModule must have a state named 'bar'");
101-
};
102-
stateService.go('bar').then(success, error);
103-
}),
104-
),
105-
);
106-
107-
it(
108-
'should support loadChildren on non-future state (manual state cleanup)',
109-
async(
110-
inject([UIRouter], (router: UIRouter) => {
111-
const { stateRegistry, stateService } = router;
112-
stateRegistry.register(augment1);
113-
stateRegistry.register(augment2);
114-
115-
const fixture = TestBed.createComponent(UIView);
116-
fixture.detectChanges();
55+
let names = stateRegistry
56+
.get()
57+
.map(state => state.name)
58+
.sort();
59+
expect(names.length).toBe(2);
60+
expect(names).toEqual(['', 'foo.**']);
11761

118-
const names = stateRegistry
62+
stateService.go('foo').then(() => {
63+
expect(globals.current.name).toBe('foo');
64+
65+
names = stateRegistry
11966
.get()
12067
.map(state => state.name)
12168
.sort();
122-
expect(names).toEqual(['', 'augment1', 'augment1.augment2']);
123-
124-
const wait = delay => new Promise(resolve => setTimeout(resolve, delay));
125-
stateService.go('augment1.augment2').then(() => {
126-
fixture.detectChanges();
127-
expect(stateService.current.name).toBe('augment1.augment2');
128-
expect(fixture.debugElement.nativeElement.textContent.replace(/\s+/g, ' ').trim()).toBe(
129-
'Component 1 Component 2',
130-
);
131-
});
132-
}),
133-
),
134-
);
69+
expect(names.length).toBe(4);
70+
expect(names).toEqual(['', 'foo', 'foo.child1', 'foo.child2']);
71+
});
72+
})
73+
));
74+
75+
it('should throw if no future state replacement is lazy loaded', async(
76+
inject([UIRouter], (router: UIRouter) => {
77+
const { stateRegistry, stateService } = router;
78+
stateService.defaultErrorHandler(() => null);
79+
stateRegistry.register(futureBar);
80+
81+
const fixture = TestBed.createComponent(UIView);
82+
fixture.detectChanges();
83+
84+
const names = stateRegistry
85+
.get()
86+
.map(state => state.name)
87+
.sort();
88+
expect(names.length).toBe(2);
89+
expect(names).toEqual(['', 'bar.**']);
90+
91+
const success = () => {
92+
throw Error('success not expected');
93+
};
94+
const error = err => {
95+
expect(err.detail.message).toContain("The lazy loaded NgModule must have a state named 'bar'");
96+
};
97+
stateService.go('bar').then(success, error);
98+
})
99+
));
100+
101+
it('should support loadChildren on non-future state (manual state cleanup)', async(
102+
inject([UIRouter], (router: UIRouter) => {
103+
const { stateRegistry, stateService } = router;
104+
stateRegistry.register(augment1);
105+
stateRegistry.register(augment2);
106+
107+
const fixture = TestBed.createComponent(UIView);
108+
fixture.detectChanges();
109+
110+
const names = stateRegistry
111+
.get()
112+
.map(state => state.name)
113+
.sort();
114+
expect(names).toEqual(['', 'augment1', 'augment1.augment2']);
115+
116+
const wait = delay => new Promise(resolve => setTimeout(resolve, delay));
117+
stateService.go('augment1.augment2').then(() => {
118+
fixture.detectChanges();
119+
expect(stateService.current.name).toBe('augment1.augment2');
120+
expect(fixture.debugElement.nativeElement.textContent.replace(/\s+/g, ' ').trim()).toBe(
121+
'Component 1 Component 2'
122+
);
123+
});
124+
})
125+
));
135126
});

0 commit comments

Comments
 (0)