Skip to content
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

Defective source maps #240

Closed
durad opened this issue Oct 15, 2014 · 7 comments
Closed

Defective source maps #240

durad opened this issue Oct 15, 2014 · 7 comments

Comments

@durad
Copy link

durad commented Oct 15, 2014

Source maps that compiler produces have some defects. I've tried compiling a simple code snippet:

(function (_) {
    console.log(111);
    setTimeout(_, 10000);
    console.log(222);
})(function () {});

and it compiled to:

/*** Generated by streamline 0.10.15 (callbacks) - DO NOT EDIT ***/
var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb;
(function __1(_) {
  var __frame = {
    name: "__1",
    line: 1
  };
  return __func(_, this, arguments, __1, 0, __frame, function __$__1() {
    console.log(111);
    return setTimeout(__cb(_, __frame, 2, 4, function __$__1() {
      console.log(222);
      _();
    }, true), 10000);
  });
})(function() {

});
//# sourceMappingURL=b.map 

with a sourcemap:

{"version":3,"sources":["b._js"],"names":[],"mappings":";;;;;;;;IACI,QAAQ,GAAR,CAAY,GAAZ,E;WACA,W;MACA,QAAQ,GAAR,CAAY,GAAZ,E;;YADU,EAAI,KAAd,C;;GAED,W","file":"b.js","sourceRoot":""}

The compiled code works as expected, however when I parsed the resulting b.map file using source-map module and looped through all of the mappings and printed original line/column and generated line/column here is what I got:

(2, 4) -> (9, 4)
(2, 12) -> (9, 12)
(2, 4) -> (9, 15)
(2, 16) -> (9, 16)
(2, 4) -> (9, 19)
(undefined, undefined) -> (9, 21)
(3, 4) -> (10, 11)
(undefined, undefined) -> (10, 22)
(4, 4) -> (11, 6)
(4, 12) -> (11, 14)
(4, 4) -> (11, 17)
(4, 16) -> (11, 18)
(4, 4) -> (11, 21)
(undefined, undefined) -> (11, 23)
(3, 14) -> (13, 12)
(3, 18) -> (13, 14)
(3, 4) -> (13, 19)
(undefined, undefined) -> (13, 20)
(5, 3) -> (15, 3)
(undefined, undefined) -> (15, 14)

The first problem is that some of the source line/columns are missing and source-map module is parsing them as undefined.

Second problem is that source line/column pairs are not unique, so in this example you can see that (2, 4) is mapping to (9, 4), (9, 15) and so on.

This is a big problem and makes debugging and the whole build pipeline very difficult. Is there anything that can be done about this?

@bjouhier
Copy link
Member

Looks like a bug. I'll look at it but I won't have time this week.

@durad
Copy link
Author

durad commented Jan 23, 2015

Any luck with this yet?

@bjouhier
Copy link
Member

@77V I have put a fix but I won't be testing it extensively because we are not routinely using sourcemaps in our build chain. If you validate it I'll push a new version to npm.

@durad
Copy link
Author

durad commented Jan 29, 2015

I've cloned the repository and then npm installed it from that folder. However when I try too run the compiler I get the following message:

root@ubuntuserver14:/home/dusan/sltest4# ./node_modules/.bin/_node -m -c s._js TypeError: Object #<MappingList> has no method 'filter' <<< async stack >>> at _compile (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/compile.js:404:19) at __1 (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/compile.js:420:3) at value__1 (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/builtins.js:131:32) at exports_compile__4 (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/compile.js:419:8) <<< raw stack >>> at fixSourceMap (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/compile.js:117:45) at ___ (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/compile.js:198:19) at ___ (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:109:13) at /home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:97:14 at Object.__g.trampoline.flush (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:23:29) at ___ (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:120:61) at fs.js:271:14 at Object.oncomplete (fs.js:107:15) errors found in 1 files Error: errors found in 1 files at __$exports_compile__4 (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/compile.js:422:30) at ___ (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:109:13) at __$value__1 (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/builtins.js:134:129) at __$value__1 (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/builtins.js:131:235) at ___ (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:109:13) at __$value__1 (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/builtins.js:131:194) at ___ (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:109:13) at __$__1 (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/compile.js:422:301) at ___ (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:109:13) at __tryCatch (/home/dusan/sltest4/node_modules/streamline/lib/callbacks/runtime.js:148:4)

@bjouhier
Copy link
Member

It looks like I fixed it with a different version of sourcemap. I'll investigate.

@bjouhier
Copy link
Member

bjouhier commented Feb 1, 2015

@77V should work now with latest sourcemap code.

@durad
Copy link
Author

durad commented Feb 2, 2015

It's working now, I'm closing the issue.

@durad durad closed this as completed Feb 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants