-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
does not work with babel #12
Comments
@raine I will fix this as soon as I can . Besides if you have good idea about this, a PR is welcomed. |
@raine Can you share steps to reproduce this error? I'm quite curious. This is important anyway |
Here's a repository that reproduces it: https://github.com/thenickdude/better-assert-12 Clone it, run "npm install", then either "npm run-script test-babel-node" to run index.js with
Or run "npm run-script test-precompile" to translate index.js using
I'm using Node v4.4.4. |
I'm running into the same issue, but with using Typescript and |
with this ```better-assert-bug-es6.js```` file: import assert from "better-assert";
assert(false);
|
here is my patch function assert(expr) {
if (expr) return;
var a = new Error();
var errorline = a.stack.split("\n")[2];
var m = errorline.match(/.*(\w)*\((.*):([0-9]*):([0-9]*)\)/);
var func = m[1];
var file = m[2];
var lineno = parseInt(m[3]);
var fullsource = fs.readFileSync(file, 'utf8');
var line = fullsource.split('\n')[lineno-1];
var src = line.match(/assert\((.*)\)/)[1];
var err = new AssertionError({
message: src,
stackStartFunction: func
});
throw err;
} |
@erossignon really glad to see this, could you please open a PR? |
Is there any reason #16 has not been merged? |
…when babel has transpiled all `assert(...)` calls to something else (`(0, _.default)(...)` for example), we look for that transpiled code instead. (assuming Babel 7) - augmented the tests to serve as unit tests which can be executed via `npm test`, including a minimal test to see if a babel-transpiled better-assert library will work.
…file is pulled through `babel` the tests coded in there would fail due the code having been prettyfied by babel. The tests have been adjusted.
…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.
When the PR is going to be merged? |
TypeError: Cannot read property '1' of null
The callsite returns a line number for compiled code but it's trying to read the line from uncompiled one.
The text was updated successfully, but these errors were encountered: