@jdeighan/coffee-utils 7.0.59 → 7.0.60

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/coffee-utils",
3
3
  "type": "module",
4
- "version": "7.0.59",
4
+ "version": "7.0.60",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -1,7 +1,7 @@
1
1
  # call_stack.coffee
2
2
 
3
3
  import {
4
- undef, defined, croak, assert, OL, isBoolean, escapeStr,
4
+ undef, defined, croak, assert, OL, isBoolean, escapeStr, deepCopy,
5
5
  } from '@jdeighan/coffee-utils'
6
6
  import {log, LOG} from '@jdeighan/coffee-utils/log'
7
7
  import {getPrefix} from '@jdeighan/coffee-utils/arrow'
@@ -36,7 +36,7 @@ export class CallStack
36
36
 
37
37
  # ........................................................................
38
38
 
39
- enter: (funcName) ->
39
+ enter: (funcName, lArgs=[]) ->
40
40
  # --- funcName might be <object>.<method>
41
41
 
42
42
  if doDebugStack
@@ -56,12 +56,14 @@ export class CallStack
56
56
  fullName: funcName # "#{ident1}.#{ident2}"
57
57
  funcName: ident2
58
58
  isLogged: false
59
+ lArgs: deepCopy(lArgs)
59
60
  })
60
61
  else
61
62
  @lStack.push({
62
63
  fullName: funcName
63
64
  funcName: ident1
64
65
  isLogged: false
66
+ lArgs: deepCopy(lArgs)
65
67
  })
66
68
  return
67
69
 
@@ -156,15 +158,25 @@ export class CallStack
156
158
 
157
159
  # ........................................................................
158
160
 
159
- dump: (prefix='', label='CALL STACK') ->
161
+ dump: () ->
160
162
 
161
- lLines = ["#{label}:"]
163
+ lLines = ["CALL STACK:"]
162
164
  if @lStack.length == 0
163
165
  lLines.push " <EMPTY>"
164
166
  else
165
167
  for item, i in @lStack
166
- lLines.push " #{i}: #{item.fullName} #{item.isLogged}"
167
- return lLines.join("\n") + "\n"
168
+ lLines.push " " + @callStr(i, item)
169
+ return lLines.join("\n")
170
+
171
+ # ........................................................................
172
+
173
+ callStr: (i, item) ->
174
+
175
+ sym = if item.isLogged then '*' else ''
176
+ str = "#{i}#{sym}: #{item.fullName}"
177
+ for arg in item.lArgs
178
+ str += " #{OL(arg)}"
179
+ return str
168
180
 
169
181
  # ........................................................................
170
182
 
package/src/call_stack.js CHANGED
@@ -9,7 +9,8 @@ import {
9
9
  assert,
10
10
  OL,
11
11
  isBoolean,
12
- escapeStr
12
+ escapeStr,
13
+ deepCopy
13
14
  } from '@jdeighan/coffee-utils';
14
15
 
15
16
  import {
@@ -45,7 +46,7 @@ export var CallStack = class CallStack {
45
46
  }
46
47
 
47
48
  // ........................................................................
48
- enter(funcName) {
49
+ enter(funcName, lArgs = []) {
49
50
  var _, ident1, ident2, lMatches;
50
51
  // --- funcName might be <object>.<method>
51
52
  if (doDebugStack) {
@@ -58,13 +59,15 @@ export var CallStack = class CallStack {
58
59
  this.lStack.push({
59
60
  fullName: funcName, // "#{ident1}.#{ident2}"
60
61
  funcName: ident2,
61
- isLogged: false
62
+ isLogged: false,
63
+ lArgs: deepCopy(lArgs)
62
64
  });
63
65
  } else {
64
66
  this.lStack.push({
65
67
  fullName: funcName,
66
68
  funcName: ident1,
67
- isLogged: false
69
+ isLogged: false,
70
+ lArgs: deepCopy(lArgs)
68
71
  });
69
72
  }
70
73
  }
@@ -162,19 +165,32 @@ export var CallStack = class CallStack {
162
165
  }
163
166
 
164
167
  // ........................................................................
165
- dump(prefix = '', label = 'CALL STACK') {
168
+ dump() {
166
169
  var i, item, j, lLines, len, ref;
167
- lLines = [`${label}:`];
170
+ lLines = ["CALL STACK:"];
168
171
  if (this.lStack.length === 0) {
169
172
  lLines.push(" <EMPTY>");
170
173
  } else {
171
174
  ref = this.lStack;
172
175
  for (i = j = 0, len = ref.length; j < len; i = ++j) {
173
176
  item = ref[i];
174
- lLines.push(` ${i}: ${item.fullName} ${item.isLogged}`);
177
+ lLines.push(" " + this.callStr(i, item));
175
178
  }
176
179
  }
177
- return lLines.join("\n") + "\n";
180
+ return lLines.join("\n");
181
+ }
182
+
183
+ // ........................................................................
184
+ callStr(i, item) {
185
+ var arg, j, len, ref, str, sym;
186
+ sym = item.isLogged ? '*' : '';
187
+ str = `${i}${sym}: ${item.fullName}`;
188
+ ref = item.lArgs;
189
+ for (j = 0, len = ref.length; j < len; j++) {
190
+ arg = ref[j];
191
+ str += ` ${OL(arg)}`;
192
+ }
193
+ return str;
178
194
  }
179
195
 
180
196
  // ........................................................................
@@ -349,7 +349,15 @@ export ltrunc = (str, nChars) ->
349
349
 
350
350
  export deepCopy = (obj) ->
351
351
 
352
- return JSON.parse(JSON.stringify(obj))
352
+ if (obj == undef)
353
+ return undef
354
+ objStr = JSON.stringify(obj)
355
+ try
356
+ newObj = JSON.parse(objStr)
357
+ catch err
358
+ croak "ERROR: err.message", objStr
359
+
360
+ return newObj
353
361
 
354
362
  # ---------------------------------------------------------------------------
355
363
  # escapeStr - escape newlines, TAB chars, etc.
@@ -347,7 +347,18 @@ export var ltrunc = function(str, nChars) {
347
347
  // ---------------------------------------------------------------------------
348
348
  // deepCopy - deep copy an array or object
349
349
  export var deepCopy = function(obj) {
350
- return JSON.parse(JSON.stringify(obj));
350
+ var err, newObj, objStr;
351
+ if (obj === undef) {
352
+ return undef;
353
+ }
354
+ objStr = JSON.stringify(obj);
355
+ try {
356
+ newObj = JSON.parse(objStr);
357
+ } catch (error1) {
358
+ err = error1;
359
+ croak("ERROR: err.message", objStr);
360
+ }
361
+ return newObj;
351
362
  };
352
363
 
353
364
  // ---------------------------------------------------------------------------
@@ -29,9 +29,9 @@ lFunctions = undef # --- only used when doDebugDebug is true
29
29
 
30
30
  # ---------------------------------------------------------------------------
31
31
 
32
- export dumpCallStack = (label) ->
32
+ export dumpCallStack = () ->
33
33
 
34
- LOG callStack.dump('', label)
34
+ LOG callStack.dump()
35
35
  return
36
36
 
37
37
  # ---------------------------------------------------------------------------
@@ -66,7 +66,7 @@ debugDebug = (label, lObjects...) ->
66
66
  switch type
67
67
  when 'enter'
68
68
  assert defined(funcName), "type enter, funcName = undef"
69
- callStack.enter funcName
69
+ callStack.enter funcName, lObjects
70
70
  doLog = (lFunctions == undef) || (funcName in lFunctions)
71
71
 
72
72
  when 'return'
@@ -105,7 +105,7 @@ export debug = (label, lObjects...) ->
105
105
  nObjects = lObjects.length
106
106
  [type, funcName] = getType(label, nObjects)
107
107
  if (type == 'enter')
108
- callStack.enter funcName
108
+ callStack.enter funcName, lObjects
109
109
 
110
110
  debugDebug "enter debug(#{OL(label)})", lObjects...
111
111
  debugDebug "type = #{OL(type)}"
@@ -70,8 +70,8 @@ lFunctions = undef; // --- only used when doDebugDebug is true
70
70
 
71
71
 
72
72
  // ---------------------------------------------------------------------------
73
- export var dumpCallStack = function(label) {
74
- LOG(callStack.dump('', label));
73
+ export var dumpCallStack = function() {
74
+ LOG(callStack.dump());
75
75
  };
76
76
 
77
77
  // ---------------------------------------------------------------------------
@@ -101,7 +101,7 @@ debugDebug = function(label, ...lObjects) {
101
101
  switch (type) {
102
102
  case 'enter':
103
103
  assert(defined(funcName), "type enter, funcName = undef");
104
- callStack.enter(funcName);
104
+ callStack.enter(funcName, lObjects);
105
105
  doLog = (lFunctions === undef) || (indexOf.call(lFunctions, funcName) >= 0);
106
106
  break;
107
107
  case 'return':
@@ -138,7 +138,7 @@ export var debug = function(label, ...lObjects) {
138
138
  nObjects = lObjects.length;
139
139
  [type, funcName] = getType(label, nObjects);
140
140
  if (type === 'enter') {
141
- callStack.enter(funcName);
141
+ callStack.enter(funcName, lObjects);
142
142
  }
143
143
  debugDebug(`enter debug(${OL(label)})`, ...lObjects);
144
144
  debugDebug(`type = ${OL(type)}`);