escodegen
escodegen copied to clipboard
Support source maps in browser builds
There is a comment about preventing including the source-map lib when in a browser build.
// And prevent from including source-map by browserify
Two things: a) the source-map lib plays nice with browserify now, and b) my understanding is escodegen uses cjsify for builds now.
Can we either add
global.sourceMap = require('source-map');
to tools/entry-point.js
or change the logic around that comment and try and require the source map lib there?
This should do it.
if (sourceMap) {
- if (!exports.browser) {
- // We assume environment is node.js
- // And prevent from including source-map by browserify
- SourceNode = require('source-map').SourceNode;
- } else {
- SourceNode = global.sourceMap.SourceNode;
- }
+ SourceNode = require('source-map').SourceNode;
} else {
SourceNode = SourceNodeMock;
}
FYI this was left over when switching from browserify to commonjs-everywhere. See #117.
I tried this locally, unfortunately commonjs-everywhere doesn't like that amdefine require's "path". Not sure how browserify works around that.
Could be fixed by https://github.com/mozilla/source-map/issues/67
Whoa! Can't believe this issue has been open for 4 years. Guys, I ran into the same problem - when I built the escodegen.browser.js, source-map didn't work. i.e. The following code -
escodegen.generate(ast, {sourceMap:true});
Gave this error -
VM187:2137 Uncaught TypeError: Cannot read property 'SourceNode' of undefined
I was able to fix this issue by building source-map and appending source-map.js to escodegen.browser.js
I understand that the source-map is not getting imported properly for the browser build of escodegen. Could anyone tell me how this issue could be fixed?