MatAtBread / fast-async

603 stars 21 forks source link

Issues with source maps #14

Closed Rush closed 8 years ago

Rush commented 8 years ago

To reproduce the second:

git clone https://github.com/Rush/fasy-async-sourcemaps-test
cd fasy-async-sourcemaps-test
npm install
npm test

You will see both first and second run:

> fast-async-sourcemaps@1.0.0 test /code/fasy-async-sourcemaps-test
> rm -f ~/.babel.json && node run-fastasync.js && node run-fastasync.js

Error
    at Foo.$ForStatement_1_loop (/code/fasy-async-sourcemaps-test/test.js:165:31)
    at Function.boundThen [as then] (/code/fasy-async-sourcemaps-test/test.js:132:21)
    at /code/fasy-async-sourcemaps-test/test.js:170:35
    at Foo.<anonymous> (/code/fasy-async-sourcemaps-test/test.js:174:12)
    at boundThen (/code/fasy-async-sourcemaps-test/test.js:132:21)
    at Foo.liveBackup (/code/fasy-async-sourcemaps-test/test.js:149:14)
    at Object.<anonymous> (/code/fasy-async-sourcemaps-test/test.js:216:11)
    at Module._compile (module.js:556:32)
    at loader (/code/fasy-async-sourcemaps-test/node_modules/babel-register/lib/node.js:143:5)
    at Object.require.extensions.(anonymous function) [as .js] (/code/fasy-async-sourcemaps-test/node_modules/babel-register/lib/node.js:153:7)
Error
    at $ForStatement_1_loop (/code/fasy-async-sourcemaps-test/test.js:165:31)
    at Foo.$ForStatement_1_next (/code/fasy-async-sourcemaps-test/test.js:161:26)
    at Foo.<anonymous> (/code/fasy-async-sourcemaps-test/test.js:167:54)
    at then (/code/fasy-async-sourcemaps-test/test.js:125:126)
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:592:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
Error
    at $ForStatement_1_loop (/code/fasy-async-sourcemaps-test/test.js:165:31)
    at $ForStatement_1_next (/code/fasy-async-sourcemaps-test/test.js:161:26)
    at /code/fasy-async-sourcemaps-test/test.js:167:54
    at then (/code/fasy-async-sourcemaps-test/test.js:125:126)
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:592:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
foo
Error
    at Foo.$ForStatement_1_loop (/code/fasy-async-sourcemaps-test/test.js:8:17)
    at Function.boundThen [as then] (/code/fasy-async-sourcemaps-test/test.js:132:21)
    at /code/fasy-async-sourcemaps-test/test.js:5:1
    at Foo.<anonymous> (/code/fasy-async-sourcemaps-test/test.js:5:1)
    at boundThen (/code/fasy-async-sourcemaps-test/test.js:132:21)
    at Foo.liveBackup (/code/fasy-async-sourcemaps-test/test.js:5:1)
    at Object.<anonymous> (/code/fasy-async-sourcemaps-test/test.js:18:11)
    at Module._compile (module.js:556:32)
    at loader (/code/fasy-async-sourcemaps-test/node_modules/babel-register/lib/node.js:143:5)
    at Object.require.extensions.(anonymous function) [as .js] (/code/fasy-async-sourcemaps-test/node_modules/babel-register/lib/node.js:153:7)
Error
    at $ForStatement_1_loop (/code/fasy-async-sourcemaps-test/test.js:8:17)
    at Foo.$ForStatement_1_next (/code/fasy-async-sourcemaps-test/test.js:5:1)
    at Foo.<anonymous> (/code/fasy-async-sourcemaps-test/test.js:9:5)
    at then (/code/fasy-async-sourcemaps-test/test.js:125:126)
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:592:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
Error
    at $ForStatement_1_loop (/code/fasy-async-sourcemaps-test/test.js:8:17)
    at $ForStatement_1_next (/code/fasy-async-sourcemaps-test/test.js:5:1)
    at /code/fasy-async-sourcemaps-test/test.js:9:5
    at then (/code/fasy-async-sourcemaps-test/test.js:125:126)
    at process._tickCallback (internal/process/next_tick.js:103:7)
    at Module.runMain (module.js:592:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3
foo

In contrast the bluebird version works fine:

node run-bluebird.js
matAtWork commented 8 years ago

I'm a little tied up with the day job, but I'll try and look at this at the weekend

Rush commented 8 years ago

Thank you sir, I appreciate it. Have a good day. :)

matAtWork commented 8 years ago

This appears to be a babel thing - when I get nodent to display source maps, it works every time:

node_modules/fast-async/node_modules/nodent/nodent.js --sourcemap test.js

Error
    at Object.<anonymous> (/Users/matthewwoolf/git/fasy-async-sourcemaps-test/test.js:5:17 => …test.js(original):6:12
    at then (eval at <anonymous> (/Users/matthewwoolf/git/fasy-async-sourcemaps-test/node_modules/fast-async/node_modules/nodent/lib/runtime.js:1:80), <anonymous>:3:2066)

(NB: I edited the code to reduce it to the test case, so the line number is different. Also, nodent prints the executed and original line numbers)

When I tell babel not to cache stuff, it fails every time:

BABEL_DISABLE_CACHE=1 node run-fastasync.js

So this seems to be related to Babel's caching mechanism. I'll see what I can find out, but I'm not a Babel expert and the plugin certainly doesn't tell it to do anything with caches or sourcemaps

matAtWork commented 8 years ago

Ok, there seems to be a bun-fight between nodent and Babel over who should do the stack trace mapping. The fix is to supply the dontMapStackTraces flag to nodent. My .babelrc-fastasync now looks like:

{
  "presets": ["es2015"],
  "plugins": [["fast-async", {
    "compiler": {
      "sourcemap": true
    },
    "env":{
      "dontMapStackTraces":true
    }
  }]]
}

...and all looks OK.

Rush commented 8 years ago

Then I guess these should become the default?

matAtWork commented 8 years ago

Probably. I'll update it in the next minor release. Did it fix your issues too?

matAtWork commented 8 years ago

I'm hoping that this fixed your issue, so I'll close this. Please re-open if I'm wrong