@jdeighan/coffee-utils 7.0.62 → 7.0.65
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -2
- package/src/coffee_utils.coffee +7 -0
- package/src/coffee_utils.js +6 -0
- package/src/debug_utils.coffee +26 -13
- package/src/debug_utils.js +23 -6
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@jdeighan/coffee-utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "7.0.
|
4
|
+
"version": "7.0.65",
|
5
5
|
"description": "A set of utility functions for CoffeeScript",
|
6
6
|
"main": "coffee_utils.js",
|
7
7
|
"exports": {
|
@@ -52,6 +52,6 @@
|
|
52
52
|
"svelte": "^3.48.0"
|
53
53
|
},
|
54
54
|
"devDependencies": {
|
55
|
-
"@jdeighan/unit-tester": "^2.0.
|
55
|
+
"@jdeighan/unit-tester": "^2.0.7"
|
56
56
|
}
|
57
57
|
}
|
package/src/coffee_utils.coffee
CHANGED
@@ -21,6 +21,13 @@ export isComment = (line) ->
|
|
21
21
|
|
22
22
|
# ---------------------------------------------------------------------------
|
23
23
|
|
24
|
+
export eval_expr = (str) ->
|
25
|
+
|
26
|
+
str = str.replace(/\bundef\b/g, 'undefined')
|
27
|
+
return Function('"use strict";return (' + str + ')')();
|
28
|
+
|
29
|
+
# ---------------------------------------------------------------------------
|
30
|
+
|
24
31
|
export haltOnError = () ->
|
25
32
|
|
26
33
|
doHaltOnError = true
|
package/src/coffee_utils.js
CHANGED
@@ -23,6 +23,12 @@ export var isComment = function(line) {
|
|
23
23
|
return defined(lMatches);
|
24
24
|
};
|
25
25
|
|
26
|
+
// ---------------------------------------------------------------------------
|
27
|
+
export var eval_expr = function(str) {
|
28
|
+
str = str.replace(/\bundef\b/g, 'undefined');
|
29
|
+
return Function('"use strict";return (' + str + ')')();
|
30
|
+
};
|
31
|
+
|
26
32
|
// ---------------------------------------------------------------------------
|
27
33
|
export var haltOnError = function() {
|
28
34
|
return doHaltOnError = true;
|
package/src/debug_utils.coffee
CHANGED
@@ -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
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
|
package/src/debug_utils.js
CHANGED
@@ -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
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
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
|
}
|