Skip to content

Commit cea499d

Browse files
committed
- fix babel issues reported in tj#12 (and still not fixed in tj#16): when babel has transpiled all assert(...) calls to something else ((0, _.default)(...) for example), we look for that transpiled code instead. (assuming Babel 7)
Defensive coding ensures no crash when these assumptions don't match reality: instead of the function arguments, '???' is reported instead. - Completely removed obsolete callsite references in the code.
1 parent c102b9e commit cea499d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
*/
44

55
var AssertionError = require('assert').AssertionError
6-
, callsite = require('callsite')
76
, fs = require('fs');
87

98
/**
@@ -34,7 +33,14 @@ function assert(expr) {
3433
var lineno = parseInt(m[3]);
3534
var fullsource = fs.readFileSync(file, 'utf8');
3635
var line = fullsource.split('\n')[lineno-1];
37-
var src = line.match(/.*assert\((.*)\)/)[1];
36+
var m = line.match(/assert\((.*)\)/);
37+
if (!m) {
38+
// however, if the entire file doesn't carry any assert() lines any more,
39+
// our next bet is this source file was transpiled by babel:
40+
m = line.match(/\(0, [\w_]+\.default\)\((.*)\)/);
41+
}
42+
43+
var src = m ? m[1] : "???";
3844
var err = new AssertionError({
3945
message: src + "\n ",
4046
stackStartFunction: assert

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
"TonyHe <[email protected]>",
1515
"ForbesLindesay"
1616
],
17-
"dependencies": {
18-
"callsite": "1.0.0"
19-
},
17+
"dependencies": {},
2018
"repository": {
2119
"type": "git",
2220
"url": "https://github.com/visionmedia/better-assert.git"

0 commit comments

Comments
 (0)