escodegen icon indicating copy to clipboard operation
escodegen copied to clipboard

Support source maps in browser builds

Open fitzgen opened this issue 10 years ago • 4 comments

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?

fitzgen avatar Sep 24 '13 20:09 fitzgen

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.

michaelficarra avatar Sep 24 '13 21:09 michaelficarra

I tried this locally, unfortunately commonjs-everywhere doesn't like that amdefine require's "path". Not sure how browserify works around that.

fitzgen avatar Sep 24 '13 22:09 fitzgen

Could be fixed by https://github.com/mozilla/source-map/issues/67

fitzgen avatar Sep 24 '13 22:09 fitzgen

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?

GauthamBanasandra avatar Jul 12 '17 03:07 GauthamBanasandra