Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c8579d

Browse files
christopherthielenmergify[bot]
authored andcommitted
fix(IE9): Add safeConsole so IE9 doesn't break
It's 2020 I can't believe I'm adding IE9 compat :)
1 parent243e548 commit9c8579d

File tree

3 files changed

+51
-24
lines changed

3 files changed

+51
-24
lines changed

‎src/common/safeConsole.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/** workaround for missing console object in IE9 when dev tools haven't been opened o_O */
2+
/* tslint:disable:no-console */
3+
import{noop}from'./common';
4+
5+
constnoopConsoleStub={log:noop,error:noop,table:noop};
6+
7+
functionie9Console(console){
8+
constbound=(fn:Function)=>Function.prototype.bind.call(fn,console);
9+
return{
10+
log:bound(console.log),
11+
error:bound(console.log),
12+
table:bound(console.log),
13+
};
14+
}
15+
16+
functionfallbackConsole(console){
17+
constlog=console.log.bind(console);
18+
consterror=console.error ?console.error.bind(console) :log;
19+
consttable=console.table ?console.table.bind(console) :log;
20+
return{ log, error, table};
21+
}
22+
23+
functiongetSafeConsole(){
24+
//@ts-ignore
25+
constisIE9=document&&document.documentMode&&document.documentMode===9;
26+
if(isIE9){
27+
returnwindow&&window.console ?ie9Console(window.console) :noopConsoleStub;
28+
}elseif(!console.table||!console.error){
29+
returnfallbackConsole(console);
30+
}else{
31+
returnconsole;
32+
}
33+
}
34+
35+
exportconstsafeConsole=getSafeConsole();

‎src/common/trace.ts‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
*
3333
*@publicapi@module trace
3434
*/
35-
/* tslint:disable:no-console */
3635
import{parse}from'../common/hof';
3736
import{isFunction,isNumber}from'../common/predicates';
3837
import{Transition}from'../transition/transition';
3938
import{ViewTuple}from'../view';
4039
import{ActiveUIView,ViewConfig,ViewContext}from'../view/interface';
4140
import{stringify,functionToString,maxLength,padString}from'./strings';
41+
import{safeConsole}from'./safeConsole';
4242
import{Resolvable}from'../resolve/resolvable';
4343
import{PathNode}from'../path/pathNode';
4444
import{PolicyWhen}from'../resolve/interface';
@@ -57,22 +57,14 @@ function uiViewString(uiview: ActiveUIView) {
5757
constviewConfigString=(viewConfig:ViewConfig)=>{
5858
constview=viewConfig.viewDecl;
5959
conststate=view.$context.name||'(root)';
60-
return`[View#${viewConfig.$id} from '${state}' state]: target ui-view: '${view.$uiViewName}@${
61-
view.$uiViewContextAnchor
62-
}'`;
60+
return`[View#${viewConfig.$id} from '${state}' state]: target ui-view: '${view.$uiViewName}@${view.$uiViewContextAnchor}'`;
6361
};
6462

6563
/**@hidden */
6664
functionnormalizedCat(input:Category|string):string{
6765
returnisNumber(input) ?Category[input] :Category[Category[input]];
6866
}
6967

70-
/**@hidden */
71-
constconsoleLog=Function.prototype.bind.call(console.log,console);
72-
73-
/**@hidden */
74-
constconsoletable=isFunction(console.table) ?console.table.bind(console) :consoleLog.bind(console);
75-
7668
/**
7769
* Trace categories Enum
7870
*
@@ -176,13 +168,13 @@ export class Trace {
176168
/**@internalapi called by ui-router code */
177169
traceTransitionStart(trans:Transition){
178170
if(!this.enabled(Category.TRANSITION))return;
179-
console.log(`${transLbl(trans)}: Started ->${stringify(trans)}`);
171+
safeConsole.log(`${transLbl(trans)}: Started ->${stringify(trans)}`);
180172
}
181173

182174
/**@internalapi called by ui-router code */
183175
traceTransitionIgnored(trans:Transition){
184176
if(!this.enabled(Category.TRANSITION))return;
185-
console.log(`${transLbl(trans)}: Ignored <>${stringify(trans)}`);
177+
safeConsole.log(`${transLbl(trans)}: Ignored <>${stringify(trans)}`);
186178
}
187179

188180
/**@internalapi called by ui-router code */
@@ -191,45 +183,45 @@ export class Trace {
191183
constevent=parse('traceData.hookType')(options)||'internal',
192184
context=parse('traceData.context.state.name')(options)||parse('traceData.context')(options)||'unknown',
193185
name=functionToString((stepasany).registeredHook.callback);
194-
console.log(`${transLbl(trans)}: Hook ->${event} context:${context},${maxLength(200,name)}`);
186+
safeConsole.log(`${transLbl(trans)}: Hook ->${event} context:${context},${maxLength(200,name)}`);
195187
}
196188

197189
/**@internalapi called by ui-router code */
198190
traceHookResult(hookResult:HookResult,trans:Transition,transitionOptions:any){
199191
if(!this.enabled(Category.HOOK))return;
200-
console.log(`${transLbl(trans)}: <- Hook returned:${maxLength(200,stringify(hookResult))}`);
192+
safeConsole.log(`${transLbl(trans)}: <- Hook returned:${maxLength(200,stringify(hookResult))}`);
201193
}
202194

203195
/**@internalapi called by ui-router code */
204196
traceResolvePath(path:PathNode[],when:PolicyWhen,trans?:Transition){
205197
if(!this.enabled(Category.RESOLVE))return;
206-
console.log(`${transLbl(trans)}: Resolving${path} (${when})`);
198+
safeConsole.log(`${transLbl(trans)}: Resolving${path} (${when})`);
207199
}
208200

209201
/**@internalapi called by ui-router code */
210202
traceResolvableResolved(resolvable:Resolvable,trans?:Transition){
211203
if(!this.enabled(Category.RESOLVE))return;
212-
console.log(
204+
safeConsole.log(
213205
`${transLbl(trans)}: <- Resolved${resolvable} to:${maxLength(200,stringify(resolvable.data))}`
214206
);
215207
}
216208

217209
/**@internalapi called by ui-router code */
218210
traceError(reason:any,trans:Transition){
219211
if(!this.enabled(Category.TRANSITION))return;
220-
console.log(`${transLbl(trans)}: <- Rejected${stringify(trans)}, reason:${reason}`);
212+
safeConsole.log(`${transLbl(trans)}: <- Rejected${stringify(trans)}, reason:${reason}`);
221213
}
222214

223215
/**@internalapi called by ui-router code */
224216
traceSuccess(finalState:StateObject,trans:Transition){
225217
if(!this.enabled(Category.TRANSITION))return;
226-
console.log(`${transLbl(trans)}: <- Success${stringify(trans)}, final state:${finalState.name}`);
218+
safeConsole.log(`${transLbl(trans)}: <- Success${stringify(trans)}, final state:${finalState.name}`);
227219
}
228220

229221
/**@internalapi called by ui-router code */
230222
traceUIViewEvent(event:string,viewData:ActiveUIView,extra=''){
231223
if(!this.enabled(Category.UIVIEW))return;
232-
console.log(`ui-view:${padString(30,event)}${uiViewString(viewData)}${extra}`);
224+
safeConsole.log(`ui-view:${padString(30,event)}${uiViewString(viewData)}${extra}`);
233225
}
234226

235227
/**@internalapi called by ui-router code */
@@ -257,19 +249,19 @@ export class Trace {
257249
})
258250
.sort((a,b)=>(a[uivheader]||'').localeCompare(b[uivheader]||''));
259251

260-
consoletable(mapping);
252+
safeConsole.table(mapping);
261253
}
262254

263255
/**@internalapi called by ui-router code */
264256
traceViewServiceEvent(event:string,viewConfig:ViewConfig){
265257
if(!this.enabled(Category.VIEWCONFIG))return;
266-
console.log(`VIEWCONFIG:${event}${viewConfigString(viewConfig)}`);
258+
safeConsole.log(`VIEWCONFIG:${event}${viewConfigString(viewConfig)}`);
267259
}
268260

269261
/**@internalapi called by ui-router code */
270262
traceViewServiceUIViewEvent(event:string,viewData:ActiveUIView){
271263
if(!this.enabled(Category.VIEWCONFIG))return;
272-
console.log(`VIEWCONFIG:${event}${uiViewString(viewData)}`);
264+
safeConsole.log(`VIEWCONFIG:${event}${uiViewString(viewData)}`);
273265
}
274266
}
275267

‎src/state/stateMatcher.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { isString } from '../common/predicates';
33
import{StateOrName}from'./interface';
44
import{StateObject}from'./stateObject';
55
import{values}from'../common/common';
6+
import{safeConsole}from'../common/safeConsole';
67

78
exportclassStateMatcher{
89
constructor(private_states:{[key:string]:StateObject}){}
@@ -29,8 +30,7 @@ export class StateMatcher {
2930
);
3031

3132
if(matches.length>1){
32-
// tslint:disable-next-line:no-console
33-
console.log(
33+
safeConsole.error(
3434
`stateMatcher.find: Found multiple matches for${name} using glob: `,
3535
matches.map(match=>match.name)
3636
);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp