@jdeighan/coffee-utils 7.0.54 → 7.0.57

Sign up to get free protection for your applications and to get access to all the features.
package/Debugging.md ADDED
@@ -0,0 +1,6 @@
1
+ Debugging CoffeeScript:
2
+
3
+ 1. install JetBrains IntellijIDE
4
+ 2. create file test/counting.coffee
5
+ 3. compile the file with the sourcemap option:
6
+ coffee -c -m test/counting.coffee
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "7.0.54",
4
+ "version": "7.0.57",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -105,7 +105,7 @@ export class CallStack
105
105
  LOG "[<-- BACK #{fName}]"
106
106
 
107
107
  if @lStack.length == 0
108
- LOG "ERROR: returnFrom('#{funcName}') but stack is empty"
108
+ LOG "ERROR: returnFrom('#{fName}') but stack is empty"
109
109
  return
110
110
 
111
111
  {fullName, isLogged} = @lStack.pop()
@@ -155,10 +155,10 @@ export class CallStack
155
155
 
156
156
  dump: (prefix='', label='CALL STACK') ->
157
157
 
158
- LOG "#{label}:"
158
+ lLines = ["#{label}:"]
159
159
  if @lStack.length == 0
160
- LOG " <EMPTY>"
160
+ lLines.push " <EMPTY>"
161
161
  else
162
162
  for item, i in @lStack
163
- LOG " #{i}: #{item.fullName} #{item.isLogged}"
164
- return
163
+ lLines.push " #{i}: #{item.fullName} #{item.isLogged}"
164
+ return lLines.join("\n") + "\n"
package/src/call_stack.js CHANGED
@@ -107,7 +107,7 @@ export var CallStack = class CallStack {
107
107
  LOG(`[<-- BACK ${fName}]`);
108
108
  }
109
109
  if (this.lStack.length === 0) {
110
- LOG(`ERROR: returnFrom('${funcName}') but stack is empty`);
110
+ LOG(`ERROR: returnFrom('${fName}') but stack is empty`);
111
111
  return;
112
112
  }
113
113
  ({fullName, isLogged} = this.lStack.pop());
@@ -160,17 +160,18 @@ export var CallStack = class CallStack {
160
160
  // ........................................................................
161
161
  // ........................................................................
162
162
  dump(prefix = '', label = 'CALL STACK') {
163
- var i, item, j, len, ref;
164
- LOG(`${label}:`);
163
+ var i, item, j, lLines, len, ref;
164
+ lLines = [`${label}:`];
165
165
  if (this.lStack.length === 0) {
166
- LOG(" <EMPTY>");
166
+ lLines.push(" <EMPTY>");
167
167
  } else {
168
168
  ref = this.lStack;
169
169
  for (i = j = 0, len = ref.length; j < len; i = ++j) {
170
170
  item = ref[i];
171
- LOG(` ${i}: ${item.fullName} ${item.isLogged}`);
171
+ lLines.push(` ${i}: ${item.fullName} ${item.isLogged}`);
172
172
  }
173
173
  }
174
+ return lLines.join("\n") + "\n";
174
175
  }
175
176
 
176
177
  };
@@ -2,7 +2,7 @@
2
2
 
3
3
  import {
4
4
  assert, undef, error, croak, warn, defined,
5
- isString, isFunction, isBoolean, sep_dash,
5
+ isString, isFunction, isBoolean,
6
6
  OL, escapeStr, isNumber, isArray, words, pass,
7
7
  } from '@jdeighan/coffee-utils'
8
8
  import {blockToArray} from '@jdeighan/coffee-utils/block'
@@ -13,19 +13,66 @@ import {
13
13
  getPrefix, addArrow, removeLastVbar,
14
14
  } from '@jdeighan/coffee-utils/arrow'
15
15
  import {
16
- log, logItem, LOG, shortEnough,
16
+ log, logItem, LOG, shortEnough, dashes,
17
17
  } from '@jdeighan/coffee-utils/log'
18
18
 
19
19
  callStack = new CallStack()
20
- doDebugDebug = false
21
20
 
22
- export shouldLog = undef # set in resetDebugging() and setDebugging()
21
+ # --- set in resetDebugging() and setDebugging()
22
+ export shouldLog = () -> undef
23
23
  export lFuncList = []
24
24
 
25
+ # --- internal debugging
26
+ doDebugDebug = false
27
+ lFunctions = undef # --- only used when doDebugDebug is true
28
+
29
+ # ---------------------------------------------------------------------------
30
+
31
+ export setDebugDebugging = (value=true) ->
32
+ # --- value can be a boolean or string of words
33
+
34
+ if isBoolean(value)
35
+ doDebugDebug = value
36
+ else if isString(value)
37
+ doDebugDebug = true
38
+ lFunctions = words(value)
39
+ else
40
+ croak "Bad value: #{OL(value)}"
41
+ return
42
+
43
+ # ---------------------------------------------------------------------------
44
+
45
+ logif = (label, lObjects...) ->
46
+
47
+ if ! doDebugDebug
48
+ return
49
+
50
+ assert isString(label), "1st arg #{OL(label)} should be a string"
51
+ nObjects = lObjects.length
52
+ [type, funcName] = getType(label, nObjects)
53
+ switch type
54
+ when 'enter'
55
+ if defined(lFunctions) && (funcName not in lFunctions)
56
+ return
57
+ callStack.enter funcName
58
+ log label, lObjects...
59
+ when 'return'
60
+ if defined(lFunctions) && (funcName not in lFunctions)
61
+ return
62
+ log label, lObjects...
63
+ callStack.returnFrom funcName
64
+ when 'string'
65
+ log label, lObjects...
66
+ when 'objects'
67
+ log label, lObjects...
68
+ return
69
+
25
70
  # ---------------------------------------------------------------------------
26
71
 
27
72
  export debug = (label, lObjects...) ->
28
73
 
74
+ logif "enter debug(#{OL(label)})", lObjects...
75
+
29
76
  assert isString(label), "1st arg #{OL(label)} should be a string"
30
77
 
31
78
  # --- We want to allow objects to be undef. Therefore, we need to
@@ -34,9 +81,11 @@ export debug = (label, lObjects...) ->
34
81
 
35
82
  # --- funcName is only set for types 'enter' and 'return'
36
83
  [type, funcName] = getType(label, nObjects)
37
- if doDebugDebug
38
- LOG "debug(): type = #{OL(type)}"
39
- LOG "debug(): funcName = #{OL(funcName)}"
84
+ logif "type = #{OL(type)}"
85
+ logif "funcName = #{OL(funcName)}"
86
+
87
+ # --- function shouldLog() returns the (possibly modified) label
88
+ # if we should log this, else it returns undef
40
89
 
41
90
  switch type
42
91
  when 'enter'
@@ -47,42 +96,44 @@ export debug = (label, lObjects...) ->
47
96
  when 'string'
48
97
  label = shouldLog(label, type, undef, callStack)
49
98
  assert (nObjects == 0),
50
- "multiple objects only not allowed for #{OL(type)}"
99
+ "Objects not allowed for #{OL(type)}"
51
100
  when 'objects'
52
101
  label = shouldLog(label, type, undef, callStack)
53
102
  assert (nObjects > 0),
54
- "multiple objects only not allowed for #{OL(type)}"
55
- doLog = defined(label)
103
+ "Objects required for #{OL(type)}"
56
104
 
57
- if doDebugDebug
58
- if nObjects == 0
59
- LOG "debug(#{OL(label)}) - 1 arg"
60
- else
61
- LOG "debug(#{OL(label)}), #{nObjects} args"
62
- LOG "doLog = #{OL(doLog)}"
105
+ assert (label == undef) || isString(label),
106
+ "label not a string: #{OL(label)}"
107
+ doLog = defined(label)
108
+ logif "doLog = #{OL(doLog)}"
109
+ logif "#{nObjects} objects"
63
110
 
64
111
  if doLog
65
112
  level = callStack.getLevel()
66
113
  prefix = getPrefix(level)
114
+ itemPrefix = removeLastVbar(prefix)
115
+ sep = dashes(itemPrefix, 40)
116
+ assert isString(sep), "sep is not a string"
67
117
 
68
- if doDebugDebug
69
- LOG "callStack", callStack
70
- LOG "level = #{OL(level)}"
71
- LOG "prefix = #{OL(prefix)}"
118
+ logif "callStack", callStack
119
+ logif "level = #{OL(level)}"
120
+ logif "prefix = #{OL(prefix)}"
121
+ logif "itemPrefix = #{OL(itemPrefix)}"
122
+ logif "sep = #{OL(sep)}"
72
123
 
73
124
  switch type
74
125
  when 'enter'
75
126
  log label, {prefix}
76
127
  for obj,i in lObjects
77
128
  if (i > 0)
78
- log sep_dash, {prefix: removeLastVbar(prefix)}
79
- logItem undef, obj, {prefix: removeLastVbar(prefix)}
129
+ log sep
130
+ logItem undef, obj, {itemPrefix}
80
131
  when 'return'
81
132
  log label, {prefix: addArrow(prefix)}
82
133
  for obj,i in lObjects
83
134
  if (i > 0)
84
- log sep_dash, {prefix: removeLastVbar(prefix)}
85
- logItem undef, obj, {prefix: removeLastVbar(prefix)}
135
+ log sep
136
+ logItem undef, obj, {itemPrefix}
86
137
  when 'string'
87
138
  log label, {prefix}
88
139
  when 'objects'
@@ -100,6 +151,7 @@ export debug = (label, lObjects...) ->
100
151
  else if (type == 'return')
101
152
  callStack.returnFrom funcName
102
153
 
154
+ logif "return from debug()"
103
155
  return true # allow use in boolean expressions
104
156
 
105
157
  # ---------------------------------------------------------------------------
@@ -120,10 +172,9 @@ export stdShouldLog = (label, type, funcName, stack) ->
120
172
  assert funcName == undef, "func name #{OL(funcName)} not undef"
121
173
  assert stack instanceof CallStack, "not a call stack object"
122
174
 
123
- if doDebugDebug
124
- LOG "stdShouldLog(#{OL(label)}, #{OL(type)}, #{OL(funcName)}, stack)"
125
- LOG "stack", stack
126
- LOG "lFuncList", lFuncList
175
+ logif "stdShouldLog(#{OL(label)}, #{OL(type)}, #{OL(funcName)}, stack)"
176
+ logif "stack", stack
177
+ logif "lFuncList", lFuncList
127
178
 
128
179
  switch type
129
180
  when 'enter'
@@ -145,45 +196,19 @@ export stdShouldLog = (label, type, funcName, stack) ->
145
196
 
146
197
  # ---------------------------------------------------------------------------
147
198
 
148
- export debugDebug = (flag=true) ->
149
-
150
- doDebugDebug = flag
151
- if doDebugDebug
152
- LOG "doDebugDebug = #{flag}"
153
- return
154
-
155
- # ---------------------------------------------------------------------------
156
-
157
- resetDebugging = () ->
158
-
159
- if doDebugDebug
160
- LOG "resetDebugging()"
161
- callStack.reset()
162
- shouldLog = (label, type, funcName, stack) -> undef
163
- return
164
-
165
- # ---------------------------------------------------------------------------
166
-
167
199
  export setDebugging = (option) ->
168
200
 
169
- resetDebugging()
201
+ callStack.reset()
170
202
  if isBoolean(option)
171
203
  if option
172
204
  shouldLog = (label, type, funcName, stack) -> label
173
205
  else
174
206
  shouldLog = (label, type, funcName, stack) -> undef
175
- if doDebugDebug
176
- LOG "setDebugging = #{option}"
177
207
  else if isString(option)
178
208
  lFuncList = getFuncList(option)
179
209
  shouldLog = stdShouldLog
180
- if doDebugDebug
181
- LOG "setDebugging FUNCS: #{option}"
182
- LOG 'lFuncList', lFuncList
183
210
  else if isFunction(option)
184
211
  shouldLog = option
185
- if doDebugDebug
186
- LOG "setDebugging to custom func"
187
212
  else
188
213
  croak "bad parameter #{OL(option)}"
189
214
  return
@@ -227,22 +252,18 @@ export funcMatch = (stack, lFuncList) ->
227
252
  assert isArray(lFuncList), "not an array #{OL(lFuncList)}"
228
253
 
229
254
  curFunc = stack.curFunc()
230
- if doDebugDebug
231
- LOG "funcMatch(): curFunc = #{OL(curFunc)}"
232
- stack.dump(' ')
233
- LOG 'lFuncList', lFuncList
255
+ logif "funcMatch(): curFunc = #{OL(curFunc)}"
256
+ logif stack.dump(' ')
257
+ logif 'lFuncList', lFuncList
234
258
  for h in lFuncList
235
259
  {name, object, plus} = h
236
260
  if (name == curFunc)
237
- if doDebugDebug
238
- LOG " curFunc in lFuncList - match successful"
261
+ logif " curFunc in lFuncList - match successful"
239
262
  return true
240
263
  if plus && stack.isActive(name)
241
- if doDebugDebug
242
- LOG " func #{OL(name)} is active - match successful"
264
+ logif " func #{OL(name)} is active - match successful"
243
265
  return true
244
- if doDebugDebug
245
- LOG " - no match"
266
+ logif " - no match"
246
267
  return false
247
268
 
248
269
  # ---------------------------------------------------------------------------
@@ -285,40 +306,3 @@ reMethod = ///^
285
306
 
286
307
  # ---------------------------------------------------------------------------
287
308
 
288
- export checkTrace = (block) ->
289
- # --- export only to allow unit tests
290
-
291
- lStack = []
292
-
293
- for line in blockToArray(block)
294
- if lMatches = line.match(///
295
- enter
296
- \s+
297
- ([A-Za-z_][A-Za-z0-9_\.]*)
298
- ///)
299
- funcName = lMatches[1]
300
- lStack.push funcName
301
- else if lMatches = line.match(///
302
- return
303
- .*
304
- from
305
- \s+
306
- ([A-Za-z_][A-Za-z0-9_\.]*)
307
- ///)
308
- funcName = lMatches[1]
309
- len = lStack.length
310
- if (len == 0)
311
- log "return from #{funcName} with empty stack"
312
- else if (lStack[len-1] == funcName)
313
- lStack.pop()
314
- else if (lStack[len-2] == funcName)
315
- log "missing return from #{lStack[len-2]}"
316
- lStack.pop()
317
- lStack.pop()
318
- else
319
- log "return from #{funcName} - not found on stack"
320
- return
321
-
322
- # ---------------------------------------------------------------------------
323
-
324
- resetDebugging()
@@ -1,6 +1,7 @@
1
1
  // Generated by CoffeeScript 2.7.0
2
- // debug_utils.coffee
3
- var callStack, doDebugDebug, reMethod, resetDebugging;
2
+ // debug_utils.coffee
3
+ var callStack, doDebugDebug, lFunctions, logif, reMethod,
4
+ indexOf = [].indexOf;
4
5
 
5
6
  import {
6
7
  assert,
@@ -12,7 +13,6 @@ import {
12
13
  isString,
13
14
  isFunction,
14
15
  isBoolean,
15
- sep_dash,
16
16
  OL,
17
17
  escapeStr,
18
18
  isNumber,
@@ -47,30 +47,84 @@ import {
47
47
  log,
48
48
  logItem,
49
49
  LOG,
50
- shortEnough
50
+ shortEnough,
51
+ dashes
51
52
  } from '@jdeighan/coffee-utils/log';
52
53
 
53
54
  callStack = new CallStack();
54
55
 
56
+ // --- set in resetDebugging() and setDebugging()
57
+ export var shouldLog = function() {
58
+ return undef;
59
+ };
60
+
61
+ export var lFuncList = [];
62
+
63
+ // --- internal debugging
55
64
  doDebugDebug = false;
56
65
 
57
- export var shouldLog = undef; // set in resetDebugging() and setDebugging()
66
+ lFunctions = undef; // --- only used when doDebugDebug is true
58
67
 
59
- export var lFuncList = [];
68
+
69
+ // ---------------------------------------------------------------------------
70
+ export var setDebugDebugging = function(value = true) {
71
+ // --- value can be a boolean or string of words
72
+ if (isBoolean(value)) {
73
+ doDebugDebug = value;
74
+ } else if (isString(value)) {
75
+ doDebugDebug = true;
76
+ lFunctions = words(value);
77
+ } else {
78
+ croak(`Bad value: ${OL(value)}`);
79
+ }
80
+ };
81
+
82
+ // ---------------------------------------------------------------------------
83
+ logif = function(label, ...lObjects) {
84
+ var funcName, nObjects, type;
85
+ if (!doDebugDebug) {
86
+ return;
87
+ }
88
+ assert(isString(label), `1st arg ${OL(label)} should be a string`);
89
+ nObjects = lObjects.length;
90
+ [type, funcName] = getType(label, nObjects);
91
+ switch (type) {
92
+ case 'enter':
93
+ if (defined(lFunctions) && (indexOf.call(lFunctions, funcName) < 0)) {
94
+ return;
95
+ }
96
+ callStack.enter(funcName);
97
+ log(label, ...lObjects);
98
+ break;
99
+ case 'return':
100
+ if (defined(lFunctions) && (indexOf.call(lFunctions, funcName) < 0)) {
101
+ return;
102
+ }
103
+ log(label, ...lObjects);
104
+ callStack.returnFrom(funcName);
105
+ break;
106
+ case 'string':
107
+ log(label, ...lObjects);
108
+ break;
109
+ case 'objects':
110
+ log(label, ...lObjects);
111
+ }
112
+ };
60
113
 
61
114
  // ---------------------------------------------------------------------------
62
115
  export var debug = function(label, ...lObjects) {
63
- var doLog, funcName, i, j, k, l, len1, len2, len3, level, nObjects, obj, prefix, type;
116
+ var doLog, funcName, i, itemPrefix, j, k, l, len, len1, len2, level, nObjects, obj, prefix, sep, type;
117
+ logif(`enter debug(${OL(label)})`, ...lObjects);
64
118
  assert(isString(label), `1st arg ${OL(label)} should be a string`);
65
119
  // --- We want to allow objects to be undef. Therefore, we need to
66
120
  // distinguish between 1 arg sent vs. 2 or more args sent
67
121
  nObjects = lObjects.length;
68
122
  // --- funcName is only set for types 'enter' and 'return'
69
123
  [type, funcName] = getType(label, nObjects);
70
- if (doDebugDebug) {
71
- LOG(`debug(): type = ${OL(type)}`);
72
- LOG(`debug(): funcName = ${OL(funcName)}`);
73
- }
124
+ logif(`type = ${OL(type)}`);
125
+ logif(`funcName = ${OL(funcName)}`);
126
+ // --- function shouldLog() returns the (possibly modified) label
127
+ // if we should log this, else it returns undef
74
128
  switch (type) {
75
129
  case 'enter':
76
130
  callStack.enter(funcName);
@@ -81,58 +135,48 @@ export var debug = function(label, ...lObjects) {
81
135
  break;
82
136
  case 'string':
83
137
  label = shouldLog(label, type, undef, callStack);
84
- assert(nObjects === 0, `multiple objects only not allowed for ${OL(type)}`);
138
+ assert(nObjects === 0, `Objects not allowed for ${OL(type)}`);
85
139
  break;
86
140
  case 'objects':
87
141
  label = shouldLog(label, type, undef, callStack);
88
- assert(nObjects > 0, `multiple objects only not allowed for ${OL(type)}`);
142
+ assert(nObjects > 0, `Objects required for ${OL(type)}`);
89
143
  }
144
+ assert((label === undef) || isString(label), `label not a string: ${OL(label)}`);
90
145
  doLog = defined(label);
91
- if (doDebugDebug) {
92
- if (nObjects === 0) {
93
- LOG(`debug(${OL(label)}) - 1 arg`);
94
- } else {
95
- LOG(`debug(${OL(label)}), ${nObjects} args`);
96
- }
97
- LOG(`doLog = ${OL(doLog)}`);
98
- }
146
+ logif(`doLog = ${OL(doLog)}`);
147
+ logif(`${nObjects} objects`);
99
148
  if (doLog) {
100
149
  level = callStack.getLevel();
101
150
  prefix = getPrefix(level);
102
- if (doDebugDebug) {
103
- LOG("callStack", callStack);
104
- LOG(`level = ${OL(level)}`);
105
- LOG(`prefix = ${OL(prefix)}`);
106
- }
151
+ itemPrefix = removeLastVbar(prefix);
152
+ sep = dashes(itemPrefix, 40);
153
+ assert(isString(sep), "sep is not a string");
154
+ logif("callStack", callStack);
155
+ logif(`level = ${OL(level)}`);
156
+ logif(`prefix = ${OL(prefix)}`);
157
+ logif(`itemPrefix = ${OL(itemPrefix)}`);
158
+ logif(`sep = ${OL(sep)}`);
107
159
  switch (type) {
108
160
  case 'enter':
109
161
  log(label, {prefix});
110
- for (i = j = 0, len1 = lObjects.length; j < len1; i = ++j) {
162
+ for (i = j = 0, len = lObjects.length; j < len; i = ++j) {
111
163
  obj = lObjects[i];
112
164
  if (i > 0) {
113
- log(sep_dash, {
114
- prefix: removeLastVbar(prefix)
115
- });
165
+ log(sep);
116
166
  }
117
- logItem(undef, obj, {
118
- prefix: removeLastVbar(prefix)
119
- });
167
+ logItem(undef, obj, {itemPrefix});
120
168
  }
121
169
  break;
122
170
  case 'return':
123
171
  log(label, {
124
172
  prefix: addArrow(prefix)
125
173
  });
126
- for (i = k = 0, len2 = lObjects.length; k < len2; i = ++k) {
174
+ for (i = k = 0, len1 = lObjects.length; k < len1; i = ++k) {
127
175
  obj = lObjects[i];
128
176
  if (i > 0) {
129
- log(sep_dash, {
130
- prefix: removeLastVbar(prefix)
131
- });
177
+ log(sep);
132
178
  }
133
- logItem(undef, obj, {
134
- prefix: removeLastVbar(prefix)
135
- });
179
+ logItem(undef, obj, {itemPrefix});
136
180
  }
137
181
  break;
138
182
  case 'string':
@@ -146,7 +190,7 @@ export var debug = function(label, ...lObjects) {
146
190
  label += ':';
147
191
  }
148
192
  log(label, {prefix});
149
- for (l = 0, len3 = lObjects.length; l < len3; l++) {
193
+ for (l = 0, len2 = lObjects.length; l < len2; l++) {
150
194
  obj = lObjects[l];
151
195
  logItem(undef, obj, {prefix});
152
196
  }
@@ -158,6 +202,7 @@ export var debug = function(label, ...lObjects) {
158
202
  } else if (type === 'return') {
159
203
  callStack.returnFrom(funcName);
160
204
  }
205
+ logif("return from debug()");
161
206
  return true; // allow use in boolean expressions
162
207
  };
163
208
 
@@ -179,11 +224,9 @@ export var stdShouldLog = function(label, type, funcName, stack) {
179
224
  assert(funcName === undef, `func name ${OL(funcName)} not undef`);
180
225
  }
181
226
  assert(stack instanceof CallStack, "not a call stack object");
182
- if (doDebugDebug) {
183
- LOG(`stdShouldLog(${OL(label)}, ${OL(type)}, ${OL(funcName)}, stack)`);
184
- LOG("stack", stack);
185
- LOG("lFuncList", lFuncList);
186
- }
227
+ logif(`stdShouldLog(${OL(label)}, ${OL(type)}, ${OL(funcName)}, stack)`);
228
+ logif("stack", stack);
229
+ logif("lFuncList", lFuncList);
187
230
  switch (type) {
188
231
  case 'enter':
189
232
  if (funcMatch(stack, lFuncList)) {
@@ -206,28 +249,9 @@ export var stdShouldLog = function(label, type, funcName, stack) {
206
249
  return undef;
207
250
  };
208
251
 
209
- // ---------------------------------------------------------------------------
210
- export var debugDebug = function(flag = true) {
211
- doDebugDebug = flag;
212
- if (doDebugDebug) {
213
- LOG(`doDebugDebug = ${flag}`);
214
- }
215
- };
216
-
217
- // ---------------------------------------------------------------------------
218
- resetDebugging = function() {
219
- if (doDebugDebug) {
220
- LOG("resetDebugging()");
221
- }
222
- callStack.reset();
223
- shouldLog = function(label, type, funcName, stack) {
224
- return undef;
225
- };
226
- };
227
-
228
252
  // ---------------------------------------------------------------------------
229
253
  export var setDebugging = function(option) {
230
- resetDebugging();
254
+ callStack.reset();
231
255
  if (isBoolean(option)) {
232
256
  if (option) {
233
257
  shouldLog = function(label, type, funcName, stack) {
@@ -238,21 +262,11 @@ export var setDebugging = function(option) {
238
262
  return undef;
239
263
  };
240
264
  }
241
- if (doDebugDebug) {
242
- LOG(`setDebugging = ${option}`);
243
- }
244
265
  } else if (isString(option)) {
245
266
  lFuncList = getFuncList(option);
246
267
  shouldLog = stdShouldLog;
247
- if (doDebugDebug) {
248
- LOG(`setDebugging FUNCS: ${option}`);
249
- LOG('lFuncList', lFuncList);
250
- }
251
268
  } else if (isFunction(option)) {
252
269
  shouldLog = option;
253
- if (doDebugDebug) {
254
- LOG("setDebugging to custom func");
255
- }
256
270
  } else {
257
271
  croak(`bad parameter ${OL(option)}`);
258
272
  }
@@ -261,10 +275,10 @@ export var setDebugging = function(option) {
261
275
  // ---------------------------------------------------------------------------
262
276
  // --- export only to allow unit tests
263
277
  export var getFuncList = function(str) {
264
- var _, ident1, ident2, j, lMatches, len1, plus, ref, word;
278
+ var _, ident1, ident2, j, lMatches, len, plus, ref, word;
265
279
  lFuncList = [];
266
280
  ref = words(str);
267
- for (j = 0, len1 = ref.length; j < len1; j++) {
281
+ for (j = 0, len = ref.length; j < len; j++) {
268
282
  word = ref[j];
269
283
  if (lMatches = word.match(/^([A-Za-z_][A-Za-z0-9_]*)(?:\.([A-Za-z_][A-Za-z0-9_]*))?(\+)?$/)) {
270
284
  [_, ident1, ident2, plus] = lMatches;
@@ -290,33 +304,25 @@ export var getFuncList = function(str) {
290
304
  // ---------------------------------------------------------------------------
291
305
  // --- export only to allow unit tests
292
306
  export var funcMatch = function(stack, lFuncList) {
293
- var curFunc, h, j, len1, name, object, plus;
307
+ var curFunc, h, j, len, name, object, plus;
294
308
  assert(isArray(lFuncList), `not an array ${OL(lFuncList)}`);
295
309
  curFunc = stack.curFunc();
296
- if (doDebugDebug) {
297
- LOG(`funcMatch(): curFunc = ${OL(curFunc)}`);
298
- stack.dump(' ');
299
- LOG('lFuncList', lFuncList);
300
- }
301
- for (j = 0, len1 = lFuncList.length; j < len1; j++) {
310
+ logif(`funcMatch(): curFunc = ${OL(curFunc)}`);
311
+ logif(stack.dump(' '));
312
+ logif('lFuncList', lFuncList);
313
+ for (j = 0, len = lFuncList.length; j < len; j++) {
302
314
  h = lFuncList[j];
303
315
  ({name, object, plus} = h);
304
316
  if (name === curFunc) {
305
- if (doDebugDebug) {
306
- LOG(" curFunc in lFuncList - match successful");
307
- }
317
+ logif(" curFunc in lFuncList - match successful");
308
318
  return true;
309
319
  }
310
320
  if (plus && stack.isActive(name)) {
311
- if (doDebugDebug) {
312
- LOG(` func ${OL(name)} is active - match successful`);
313
- }
321
+ logif(` func ${OL(name)} is active - match successful`);
314
322
  return true;
315
323
  }
316
324
  }
317
- if (doDebugDebug) {
318
- LOG(" - no match");
319
- }
325
+ logif(" - no match");
320
326
  return false;
321
327
  };
322
328
 
@@ -340,33 +346,3 @@ export var getType = function(str, nObjects) {
340
346
  reMethod = /^([A-Za-z_][A-Za-z0-9_]*)\.([A-Za-z_][A-Za-z0-9_]*)$/;
341
347
 
342
348
  // ---------------------------------------------------------------------------
343
- export var checkTrace = function(block) {
344
- var funcName, j, lMatches, lStack, len, len1, line, ref;
345
- // --- export only to allow unit tests
346
- lStack = [];
347
- ref = blockToArray(block);
348
- for (j = 0, len1 = ref.length; j < len1; j++) {
349
- line = ref[j];
350
- if (lMatches = line.match(/enter\s+([A-Za-z_][A-Za-z0-9_\.]*)/)) {
351
- funcName = lMatches[1];
352
- lStack.push(funcName);
353
- } else if (lMatches = line.match(/return.*from\s+([A-Za-z_][A-Za-z0-9_\.]*)/)) {
354
- funcName = lMatches[1];
355
- len = lStack.length;
356
- if (len === 0) {
357
- log(`return from ${funcName} with empty stack`);
358
- } else if (lStack[len - 1] === funcName) {
359
- lStack.pop();
360
- } else if (lStack[len - 2] === funcName) {
361
- log(`missing return from ${lStack[len - 2]}`);
362
- lStack.pop();
363
- lStack.pop();
364
- } else {
365
- log(`return from ${funcName} - not found on stack`);
366
- }
367
- }
368
- }
369
- };
370
-
371
- // ---------------------------------------------------------------------------
372
- resetDebugging();
@@ -20,6 +20,12 @@ fourSpaces = ' '
20
20
 
21
21
  # ---------------------------------------------------------------------------
22
22
 
23
+ export dashes = (prefix, totalLen=64, ch='-') ->
24
+
25
+ return prefix + ch.repeat(totalLen - prefix.length)
26
+
27
+ # ---------------------------------------------------------------------------
28
+
23
29
  export debugLog = (flag=true) ->
24
30
 
25
31
  doDebugLog = flag
@@ -129,9 +135,9 @@ export log = (str, hOptions={}) ->
129
135
  # --- valid options:
130
136
  # prefix
131
137
 
138
+ assert isString(str), "log(): not a string: #{OL(str)}"
132
139
  assert isFunction(putstr), "putstr not properly set"
133
- assert isString(str), "log(): not a string"
134
- assert isHash(hOptions), "log(): arg 2 not a hash"
140
+ assert isHash(hOptions), "log(): arg 2 not a hash: #{OL(hOptions)}"
135
141
  prefix = fixForTerminal(hOptions.prefix)
136
142
 
137
143
  if doDebugLog
package/src/log_utils.js CHANGED
@@ -39,6 +39,11 @@ export var stringify = undef;
39
39
 
40
40
  fourSpaces = ' ';
41
41
 
42
+ // ---------------------------------------------------------------------------
43
+ export var dashes = function(prefix, totalLen = 64, ch = '-') {
44
+ return prefix + ch.repeat(totalLen - prefix.length);
45
+ };
46
+
42
47
  // ---------------------------------------------------------------------------
43
48
  export var debugLog = function(flag = true) {
44
49
  doDebugLog = flag;
@@ -153,9 +158,9 @@ export var log = function(str, hOptions = {}) {
153
158
  var prefix;
154
159
  // --- valid options:
155
160
  // prefix
161
+ assert(isString(str), `log(): not a string: ${OL(str)}`);
156
162
  assert(isFunction(putstr), "putstr not properly set");
157
- assert(isString(str), "log(): not a string");
158
- assert(isHash(hOptions), "log(): arg 2 not a hash");
163
+ assert(isHash(hOptions), `log(): arg 2 not a hash: ${OL(hOptions)}`);
159
164
  prefix = fixForTerminal(hOptions.prefix);
160
165
  if (doDebugLog) {
161
166
  LOG(`CALL log(${OL(str)}), prefix = ${OL(prefix)}`);