From 8cb266ba3415b187d90de74968b6879cb1d0a1d8 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Fri, 16 Nov 2018 22:20:51 -0600 Subject: [PATCH] chore(types): add null checks (#16351) --- core/src/components/router/router.tsx | 8 +++++--- core/src/components/split-pane/split-pane.tsx | 4 ++-- .../src/components/virtual-scroll/virtual-scroll-utils.ts | 2 +- core/src/utils/framework-delegate.ts | 2 +- core/src/utils/keyboard.ts | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/components/router/router.tsx b/core/src/components/router/router.tsx index 7876defb46..b6d0ade2a2 100644 --- a/core/src/components/router/router.tsx +++ b/core/src/components/router/router.tsx @@ -160,12 +160,14 @@ export class Router implements ComponentInterface { } private historyDirection() { - if (this.win.history.state === null) { + const win = this.win; + + if (win.history.state === null) { this.state++; - this.win.history.replaceState(this.state, this.win.document.title, this.win.document.location.href); + win.history.replaceState(this.state, win.document.title, win.document.location && win.document.location.href); } - const state = this.win.history.state; + const state = win.history.state; const lastState = this.lastState; this.lastState = state; diff --git a/core/src/components/split-pane/split-pane.tsx b/core/src/components/split-pane/split-pane.tsx index 1a6121648b..93b9c101e0 100644 --- a/core/src/components/split-pane/split-pane.tsx +++ b/core/src/components/split-pane/split-pane.tsx @@ -112,8 +112,8 @@ export class SplitPane implements ComponentInterface { this.visible = q.matches; }; const mediaList = this.win.matchMedia(mediaQuery); - mediaList.addListener(callback); - this.rmL = () => mediaList.removeListener(callback); + mediaList.addListener(callback as any); + this.rmL = () => mediaList.removeListener(callback as any); this.visible = mediaList.matches; } diff --git a/core/src/components/virtual-scroll/virtual-scroll-utils.ts b/core/src/components/virtual-scroll/virtual-scroll-utils.ts index 17b0c72079..6ea895a50e 100644 --- a/core/src/components/virtual-scroll/virtual-scroll-utils.ts +++ b/core/src/components/virtual-scroll/virtual-scroll-utils.ts @@ -124,7 +124,7 @@ export function doRender( function createNode(el: HTMLElement, type: CellType): HTMLElement | null { const template = getTemplate(el, type); - if (template) { + if (template && el.ownerDocument) { return el.ownerDocument.importNode(template.content, true).children[0] as HTMLElement; } return null; diff --git a/core/src/utils/framework-delegate.ts b/core/src/utils/framework-delegate.ts index 05734dc36f..c65fa628e5 100644 --- a/core/src/utils/framework-delegate.ts +++ b/core/src/utils/framework-delegate.ts @@ -15,7 +15,7 @@ export async function attachComponent( } const el: any = (typeof component === 'string') - ? container.ownerDocument.createElement(component) + ? container.ownerDocument && container.ownerDocument.createElement(component) : component; if (cssClasses) { diff --git a/core/src/utils/keyboard.ts b/core/src/utils/keyboard.ts index 3c65d7dd13..b5ae9432f6 100644 --- a/core/src/utils/keyboard.ts +++ b/core/src/utils/keyboard.ts @@ -1,7 +1,7 @@ export function isTextInputFocused(doc: Document): boolean { const activeElement = doc.activeElement; - if (isTextInput(activeElement) && activeElement.parentElement) { + if (activeElement && isTextInput(activeElement) && activeElement.parentElement) { return activeElement.parentElement.querySelector(':focus') === activeElement; } return false;