@jdeighan/coffee-utils 7.0.47 → 7.0.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/call_stack.coffee +6 -4
- package/src/call_stack.js +6 -4
- package/src/debug_utils.coffee +27 -13
- package/src/debug_utils.js +20 -8
package/package.json
CHANGED
package/src/call_stack.coffee
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# call_stack.coffee
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
undef, defined, croak, assert, isBoolean,
|
|
5
|
+
} from '@jdeighan/coffee-utils'
|
|
4
6
|
import {log, LOG} from '@jdeighan/coffee-utils/log'
|
|
5
7
|
import {getPrefix} from '@jdeighan/coffee-utils/arrow'
|
|
6
8
|
|
|
@@ -64,9 +66,9 @@ export class CallStack
|
|
|
64
66
|
# ........................................................................
|
|
65
67
|
# ........................................................................
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
doCall: (funcName, hInfo, isLogged) ->
|
|
68
70
|
|
|
69
|
-
assert isLogged
|
|
71
|
+
assert isBoolean(isLogged), "CallStack.call(): 3 args required"
|
|
70
72
|
mainPre = getPrefix(@level)
|
|
71
73
|
|
|
72
74
|
if doDebugStack
|
|
@@ -75,7 +77,7 @@ export class CallStack
|
|
|
75
77
|
|
|
76
78
|
@addCall funcName, hInfo, isLogged
|
|
77
79
|
auxPre = getPrefix(@level)
|
|
78
|
-
return [mainPre, auxPre
|
|
80
|
+
return [mainPre, auxPre]
|
|
79
81
|
|
|
80
82
|
# ........................................................................
|
|
81
83
|
|
package/src/call_stack.js
CHANGED
|
@@ -4,8 +4,10 @@ var doDebugStack;
|
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
undef,
|
|
7
|
+
defined,
|
|
7
8
|
croak,
|
|
8
|
-
assert
|
|
9
|
+
assert,
|
|
10
|
+
isBoolean
|
|
9
11
|
} from '@jdeighan/coffee-utils';
|
|
10
12
|
|
|
11
13
|
import {
|
|
@@ -72,9 +74,9 @@ export var CallStack = class CallStack {
|
|
|
72
74
|
|
|
73
75
|
// ........................................................................
|
|
74
76
|
// ........................................................................
|
|
75
|
-
|
|
77
|
+
doCall(funcName, hInfo, isLogged) {
|
|
76
78
|
var auxPre, mainPre, prefix;
|
|
77
|
-
assert(isLogged
|
|
79
|
+
assert(isBoolean(isLogged), "CallStack.call(): 3 args required");
|
|
78
80
|
mainPre = getPrefix(this.level);
|
|
79
81
|
if (doDebugStack) {
|
|
80
82
|
prefix = ' '.repeat(this.lStack.length);
|
|
@@ -82,7 +84,7 @@ export var CallStack = class CallStack {
|
|
|
82
84
|
}
|
|
83
85
|
this.addCall(funcName, hInfo, isLogged);
|
|
84
86
|
auxPre = getPrefix(this.level);
|
|
85
|
-
return [mainPre, auxPre
|
|
87
|
+
return [mainPre, auxPre];
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
// ........................................................................
|
package/src/debug_utils.coffee
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# debug_utils.coffee
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
assert, undef, error, croak, warn,
|
|
4
|
+
assert, undef, error, croak, warn, defined,
|
|
5
|
+
isString, isFunction, isBoolean,
|
|
5
6
|
OL, escapeStr, isNumber, isArray, words, pass,
|
|
6
7
|
} from '@jdeighan/coffee-utils'
|
|
7
8
|
import {blockToArray} from '@jdeighan/coffee-utils/block'
|
|
@@ -14,8 +15,8 @@ import {
|
|
|
14
15
|
|
|
15
16
|
# --- These are saved/restored on the call stack
|
|
16
17
|
export debugging = false
|
|
17
|
-
shouldLogFunc = (func) -> debugging
|
|
18
|
-
shouldLogString = (str)
|
|
18
|
+
shouldLogFunc = (func) -> return debugging
|
|
19
|
+
shouldLogString = (str) -> return debugging
|
|
19
20
|
|
|
20
21
|
stack = new CallStack()
|
|
21
22
|
doDebugDebug = false
|
|
@@ -37,8 +38,8 @@ resetDebugging = () ->
|
|
|
37
38
|
if doDebugDebug
|
|
38
39
|
LOG "resetDebugging() - debugging = false"
|
|
39
40
|
stack.reset()
|
|
40
|
-
shouldLogFunc = (func)
|
|
41
|
-
shouldLogString = (str)
|
|
41
|
+
shouldLogFunc = (func) -> return debugging
|
|
42
|
+
shouldLogString = (str) -> return debugging
|
|
42
43
|
return
|
|
43
44
|
|
|
44
45
|
# ---------------------------------------------------------------------------
|
|
@@ -65,7 +66,7 @@ export setDebugging = (funcDoDebug=undef, funcDoLog=undef) ->
|
|
|
65
66
|
else
|
|
66
67
|
croak "setDebugging(): bad parameter #{OL(funcDoDebug)}"
|
|
67
68
|
|
|
68
|
-
if funcDoLog
|
|
69
|
+
if isFunction(funcDoLog)
|
|
69
70
|
assert isFunction(funcDoLog), "setDebugging: arg 2 not a function"
|
|
70
71
|
shouldLogString = funcDoLog
|
|
71
72
|
return
|
|
@@ -89,8 +90,8 @@ export funcMatch = (curFunc, lFuncNames) ->
|
|
|
89
90
|
# ---------------------------------------------------------------------------
|
|
90
91
|
# 1. adjust call stack on 'enter' or 'return from'
|
|
91
92
|
# 2. adjust debugging flag
|
|
92
|
-
# 3. return [mainPrefix, auxPrefix, hEnv] - hEnv can be undef
|
|
93
|
-
# 4. disable logging by setting
|
|
93
|
+
# 3. return [mainPrefix, auxPrefix, hEnv, type] - hEnv can be undef
|
|
94
|
+
# 4. disable logging by setting type to undef
|
|
94
95
|
|
|
95
96
|
adjustStack = (str) ->
|
|
96
97
|
|
|
@@ -100,17 +101,21 @@ adjustStack = (str) ->
|
|
|
100
101
|
\s+
|
|
101
102
|
([A-Za-z_][A-Za-z0-9_\.]*)
|
|
102
103
|
///))
|
|
104
|
+
|
|
105
|
+
# --- We are entering function curFunc
|
|
103
106
|
curFunc = lMatches[1]
|
|
107
|
+
|
|
104
108
|
hEnv = {
|
|
105
109
|
debugging
|
|
106
110
|
shouldLogFunc
|
|
107
111
|
shouldLogString
|
|
108
112
|
}
|
|
113
|
+
|
|
109
114
|
debugging = shouldLogFunc(curFunc)
|
|
110
115
|
if doDebugDebug
|
|
111
116
|
trans = "#{hEnv.debugging} => #{debugging}"
|
|
112
117
|
LOG " ENTER #{curFunc}, debugging: #{trans}"
|
|
113
|
-
[mainPre, auxPre
|
|
118
|
+
[mainPre, auxPre] = stack.doCall(curFunc, hEnv, debugging)
|
|
114
119
|
return [
|
|
115
120
|
mainPre
|
|
116
121
|
auxPre
|
|
@@ -143,7 +148,6 @@ adjustStack = (str) ->
|
|
|
143
148
|
undef
|
|
144
149
|
if shouldLogString(str) then 'string' else undef
|
|
145
150
|
]
|
|
146
|
-
return
|
|
147
151
|
|
|
148
152
|
# ---------------------------------------------------------------------------
|
|
149
153
|
|
|
@@ -153,21 +157,31 @@ export debug = (lArgs...) ->
|
|
|
153
157
|
# distinguish between 1 arg sent vs. 2 args sent
|
|
154
158
|
nArgs = lArgs.length
|
|
155
159
|
assert (nArgs==1) || (nArgs==2), "debug(): #{nArgs} args"
|
|
160
|
+
|
|
161
|
+
# --- label must always be there, and be a string
|
|
162
|
+
# item is optional
|
|
156
163
|
[label, item] = lArgs
|
|
157
164
|
assert isString(label),
|
|
158
165
|
"debug(): 1st arg #{OL(label)} should be a string"
|
|
159
166
|
|
|
160
167
|
if doDebugDebug
|
|
161
168
|
if nArgs==1
|
|
162
|
-
LOG "debug('#{escapeStr(label)}')"
|
|
169
|
+
LOG "debug('#{escapeStr(label)}') - 1 arg"
|
|
163
170
|
else
|
|
164
|
-
LOG "debug('#{escapeStr(label)}', #{typeof item})"
|
|
171
|
+
LOG "debug('#{escapeStr(label)}', #{typeof item}) - 2 args"
|
|
172
|
+
LOG "debugging flag = #{OL(debugging)}"
|
|
165
173
|
|
|
166
174
|
# --- We always need to manipulate the stack when we encounter
|
|
167
175
|
# either "enter X" or "return from X", so we can't short-circuit
|
|
168
176
|
# when debugging is off
|
|
169
177
|
|
|
170
|
-
|
|
178
|
+
lResult = adjustStack(label)
|
|
179
|
+
if doDebugDebug
|
|
180
|
+
LOG 'lResult', lResult
|
|
181
|
+
[mainPre, auxPre, hEnv, type] = lResult
|
|
182
|
+
if doDebugDebug && (type == undef)
|
|
183
|
+
LOG "type is undef - NOT LOGGING"
|
|
184
|
+
|
|
171
185
|
hOptions = {
|
|
172
186
|
prefix: mainPre
|
|
173
187
|
itemPrefix: auxPre
|
package/src/debug_utils.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
error,
|
|
9
9
|
croak,
|
|
10
10
|
warn,
|
|
11
|
+
defined,
|
|
11
12
|
isString,
|
|
12
13
|
isFunction,
|
|
13
14
|
isBoolean,
|
|
@@ -108,7 +109,7 @@ export var setDebugging = function(funcDoDebug = undef, funcDoLog = undef) {
|
|
|
108
109
|
} else {
|
|
109
110
|
croak(`setDebugging(): bad parameter ${OL(funcDoDebug)}`);
|
|
110
111
|
}
|
|
111
|
-
if (funcDoLog) {
|
|
112
|
+
if (isFunction(funcDoLog)) {
|
|
112
113
|
assert(isFunction(funcDoLog), "setDebugging: arg 2 not a function");
|
|
113
114
|
shouldLogString = funcDoLog;
|
|
114
115
|
}
|
|
@@ -132,11 +133,12 @@ export var funcMatch = function(curFunc, lFuncNames) {
|
|
|
132
133
|
// ---------------------------------------------------------------------------
|
|
133
134
|
// 1. adjust call stack on 'enter' or 'return from'
|
|
134
135
|
// 2. adjust debugging flag
|
|
135
|
-
// 3. return [mainPrefix, auxPrefix, hEnv] - hEnv can be undef
|
|
136
|
-
// 4. disable logging by setting
|
|
136
|
+
// 3. return [mainPrefix, auxPrefix, hEnv, type] - hEnv can be undef
|
|
137
|
+
// 4. disable logging by setting type to undef
|
|
137
138
|
adjustStack = function(str) {
|
|
138
139
|
var _, auxPre, curFunc, hEnv, lMatches, mainPre, trans;
|
|
139
140
|
if ((lMatches = str.match(/^\s*enter\s+([A-Za-z_][A-Za-z0-9_\.]*)/))) {
|
|
141
|
+
// --- We are entering function curFunc
|
|
140
142
|
curFunc = lMatches[1];
|
|
141
143
|
hEnv = {debugging, shouldLogFunc, shouldLogString};
|
|
142
144
|
debugging = shouldLogFunc(curFunc);
|
|
@@ -144,7 +146,7 @@ adjustStack = function(str) {
|
|
|
144
146
|
trans = `${hEnv.debugging} => ${debugging}`;
|
|
145
147
|
LOG(` ENTER ${curFunc}, debugging: ${trans}`);
|
|
146
148
|
}
|
|
147
|
-
[mainPre, auxPre
|
|
149
|
+
[mainPre, auxPre] = stack.doCall(curFunc, hEnv, debugging);
|
|
148
150
|
return [mainPre, auxPre, undef, shouldLogFunc(curFunc) ? 'enter' : undef];
|
|
149
151
|
} else if ((lMatches = str.match(/^\s*return.+from\s+([A-Za-z_][A-Za-z0-9_\.]*)/))) {
|
|
150
152
|
curFunc = lMatches[1];
|
|
@@ -161,24 +163,34 @@ adjustStack = function(str) {
|
|
|
161
163
|
|
|
162
164
|
// ---------------------------------------------------------------------------
|
|
163
165
|
export var debug = function(...lArgs) {
|
|
164
|
-
var auxPre, hEnv, hOptions, item, label, mainPre, nArgs, orgDebugging, trans, type;
|
|
166
|
+
var auxPre, hEnv, hOptions, item, lResult, label, mainPre, nArgs, orgDebugging, trans, type;
|
|
165
167
|
// --- We want to allow item to be undef. Therefore, we need to
|
|
166
168
|
// distinguish between 1 arg sent vs. 2 args sent
|
|
167
169
|
nArgs = lArgs.length;
|
|
168
170
|
assert((nArgs === 1) || (nArgs === 2), `debug(): ${nArgs} args`);
|
|
171
|
+
// --- label must always be there, and be a string
|
|
172
|
+
// item is optional
|
|
169
173
|
[label, item] = lArgs;
|
|
170
174
|
assert(isString(label), `debug(): 1st arg ${OL(label)} should be a string`);
|
|
171
175
|
if (doDebugDebug) {
|
|
172
176
|
if (nArgs === 1) {
|
|
173
|
-
LOG(`debug('${escapeStr(label)}')`);
|
|
177
|
+
LOG(`debug('${escapeStr(label)}') - 1 arg`);
|
|
174
178
|
} else {
|
|
175
|
-
LOG(`debug('${escapeStr(label)}', ${typeof item})`);
|
|
179
|
+
LOG(`debug('${escapeStr(label)}', ${typeof item}) - 2 args`);
|
|
176
180
|
}
|
|
181
|
+
LOG(`debugging flag = ${OL(debugging)}`);
|
|
177
182
|
}
|
|
178
183
|
// --- We always need to manipulate the stack when we encounter
|
|
179
184
|
// either "enter X" or "return from X", so we can't short-circuit
|
|
180
185
|
// when debugging is off
|
|
181
|
-
|
|
186
|
+
lResult = adjustStack(label);
|
|
187
|
+
if (doDebugDebug) {
|
|
188
|
+
LOG('lResult', lResult);
|
|
189
|
+
}
|
|
190
|
+
[mainPre, auxPre, hEnv, type] = lResult;
|
|
191
|
+
if (doDebugDebug && (type === undef)) {
|
|
192
|
+
LOG("type is undef - NOT LOGGING");
|
|
193
|
+
}
|
|
182
194
|
hOptions = {
|
|
183
195
|
prefix: mainPre,
|
|
184
196
|
itemPrefix: auxPre
|