@jdeighan/coffee-utils 7.0.64 → 7.0.65

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.64",
4
+ "version": "7.0.65",
5
5
  "description": "A set of utility functions for CoffeeScript",
6
6
  "main": "coffee_utils.js",
7
7
  "exports": {
@@ -25,12 +25,22 @@ strFuncList = undef # original string
25
25
 
26
26
  # ---------------------------------------------------------------------------
27
27
 
28
+ export interp = (label) ->
29
+
30
+ return label.replace(/// \$ ([A-Za-z_][A-Za-z0-9_]*) ///g,
31
+ (match, varName) -> return "\#{OL(#{varName})\}"
32
+ )
33
+
34
+ # ---------------------------------------------------------------------------
35
+
28
36
  export debug = (orgLabel, lObjects...) ->
29
37
 
30
38
  assert isString(orgLabel), "1st arg #{OL(orgLabel)} should be a string"
31
39
 
32
40
  [type, funcName] = getType(orgLabel, lObjects)
33
41
  label = shouldLog(orgLabel, type, funcName, callStack)
42
+ if defined(label)
43
+ label = interp(label)
34
44
 
35
45
  switch type
36
46
 
@@ -243,22 +253,25 @@ export getType = (str, lObjects) ->
243
253
 
244
254
  if lMatches = str.match(///^
245
255
  \s*
246
- enter
256
+ ( enter | (?: return .+ from ) )
247
257
  \s+
248
- ([A-Za-z_][A-Za-z0-9_\.]*)
258
+ ([A-Za-z_][A-Za-z0-9_]*)
259
+ (?:
260
+ \.
261
+ ([A-Za-z_][A-Za-z0-9_]*)
262
+ )?
249
263
  ///)
264
+ [_, type, ident1, ident2] = lMatches
250
265
 
251
- # --- We are entering function curFunc
252
- return ['enter', lMatches[1]]
253
- else if lMatches = str.match(///^
254
- \s*
255
- return
256
- .+
257
- from
258
- \s+
259
- ([A-Za-z_][A-Za-z0-9_\.]*)
260
- ///)
261
- return ['return', lMatches[1]]
266
+ if ident2
267
+ funcName = ident2
268
+ else
269
+ funcName = ident1
270
+
271
+ if (type == 'enter')
272
+ return ['enter', funcName]
273
+ else
274
+ return ['return', funcName]
262
275
  else
263
276
  return ['string', undef]
264
277
 
@@ -65,12 +65,22 @@ lFuncList = []; // names of functions being debugged
65
65
  strFuncList = undef; // original string
66
66
 
67
67
 
68
+ // ---------------------------------------------------------------------------
69
+ export var interp = function(label) {
70
+ return label.replace(/\$([A-Za-z_][A-Za-z0-9_]*)/g, function(match, varName) {
71
+ return `\#{OL(${varName})\}`;
72
+ });
73
+ };
74
+
68
75
  // ---------------------------------------------------------------------------
69
76
  export var debug = function(orgLabel, ...lObjects) {
70
77
  var funcName, label, type;
71
78
  assert(isString(orgLabel), `1st arg ${OL(orgLabel)} should be a string`);
72
79
  [type, funcName] = getType(orgLabel, lObjects);
73
80
  label = shouldLog(orgLabel, type, funcName, callStack);
81
+ if (defined(label)) {
82
+ label = interp(label);
83
+ }
74
84
  switch (type) {
75
85
  case 'enter':
76
86
  if (defined(label)) {
@@ -292,12 +302,19 @@ export var funcMatch = function(funcName) {
292
302
  // ---------------------------------------------------------------------------
293
303
  // --- type is one of: 'enter', 'return', 'string'
294
304
  export var getType = function(str, lObjects) {
295
- var lMatches;
296
- if (lMatches = str.match(/^\s*enter\s+([A-Za-z_][A-Za-z0-9_\.]*)/)) {
297
- // --- We are entering function curFunc
298
- return ['enter', lMatches[1]];
299
- } else if (lMatches = str.match(/^\s*return.+from\s+([A-Za-z_][A-Za-z0-9_\.]*)/)) {
300
- return ['return', lMatches[1]];
305
+ var _, funcName, ident1, ident2, lMatches, type;
306
+ if (lMatches = str.match(/^\s*(enter|(?:return.+from))\s+([A-Za-z_][A-Za-z0-9_]*)(?:\.([A-Za-z_][A-Za-z0-9_]*))?/)) {
307
+ [_, type, ident1, ident2] = lMatches;
308
+ if (ident2) {
309
+ funcName = ident2;
310
+ } else {
311
+ funcName = ident1;
312
+ }
313
+ if (type === 'enter') {
314
+ return ['enter', funcName];
315
+ } else {
316
+ return ['return', funcName];
317
+ }
301
318
  } else {
302
319
  return ['string', undef];
303
320
  }