From de0f38794f9b8f33e43666c667818cc8d74ff904 Mon Sep 17 00:00:00 2001 From: Hermann Rolfes Date: Fri, 24 Nov 2023 16:10:27 +0100 Subject: [PATCH] Support runtime execution under node (#58) --- src-runtime/typecheckTable.mjs | 33 ++++++++++++++++++++------------- src-runtime/validateType.mjs | 2 +- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src-runtime/typecheckTable.mjs b/src-runtime/typecheckTable.mjs index fab9d0b..f52f567 100644 --- a/src-runtime/typecheckTable.mjs +++ b/src-runtime/typecheckTable.mjs @@ -1,14 +1,21 @@ -const typecheckWarnedTable = document.createElement('table'); -const tr = document.createElement('tr'); -const th_0 = document.createElement('th'); -const th_1 = document.createElement('th'); -const th_2 = document.createElement('th'); -th_0.innerText = 'dbg;'; -th_1.innerText = 'Hits'; -th_2.innerText = 'Message'; -tr.append(th_0, th_1, th_2); -typecheckWarnedTable.append(tr); -//typecheckWarnedTable.style.maxHeight = '200px'; -//typecheckWarnedTable.style.overflow = 'scroll'; -//typecheckWarnedTable.style.textWrap = 'nowrap'; +function createTable() { + if (typeof document === 'undefined') { + return null; + } + const table = document.createElement('table'); + const tr = document.createElement('tr'); + const th_0 = document.createElement('th'); + const th_1 = document.createElement('th'); + const th_2 = document.createElement('th'); + th_0.innerText = 'dbg;'; + th_1.innerText = 'Hits'; + th_2.innerText = 'Message'; + tr.append(th_0, th_1, th_2); + table.append(tr); + //table.style.maxHeight = '200px'; + //table.style.overflow = 'scroll'; + //table.style.textWrap = 'nowrap'; + return table; +} +const typecheckWarnedTable = createTable(); export {typecheckWarnedTable}; diff --git a/src-runtime/validateType.mjs b/src-runtime/validateType.mjs index e5d9f1c..196b807 100644 --- a/src-runtime/validateType.mjs +++ b/src-runtime/validateType.mjs @@ -76,7 +76,7 @@ function validateType(value, expect, loc, name, critical = true) { return false; } } - if (window.pc) { + if (typeof window !== 'undefined' && window.pc) { const {pc} = window; /** * @param {string|number} prop - Something like 'x', 'y', 'z', 'w', 0, 1, 2, 3, 4 etc.