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

Source maps: the names attribute is always empty #672

Closed
thorn0 opened this issue Apr 19, 2014 · 1 comment
Closed

Source maps: the names attribute is always empty #672

thorn0 opened this issue Apr 19, 2014 · 1 comment

Comments

@thorn0
Copy link

thorn0 commented Apr 19, 2014

Here is my isolated setup for the issue:

main.js

define(function() {
    var greeting = 'hi';
    console.log(greeting);
});

build.json

{
    "generateSourceMaps": true,
    "name": "main",
    "optimize": "uglify2",
    "out": "main-built.js",
    "preserveLicenseComments": false
}

That's how I run r.js: r.js.cmd -o build.json

And that's the source map I get in the end (formatted by me):

{
    "version": 3,
    "file": "main-built.js",
    "sources": [ "main.js" ],
    "names": [],
    "mappings": "AAAA,OAAA,UAAA,WACA,GAAA,GAAA,IACA,SAAA,IAAA",
    "sourcesContent": [ "define('main',[],function() {\r\n    var greeting = 'hi';\r\n    console.log(greeting);\r\n});\n" ]
}

Note that the names attribute is an empty array. This makes the source maps less usable than they could be as Chrome's debugger doesn't recognize the renamed variables in the mapped code, doesn't show their values on hover, etc.

For comparison, let's process the same main.js with Uglify:
uglifyjs main.js -o main-uglified.js -c -m --source-map main-uglified.js.map

Here is the source map. Note that the names are okay now.

{
    "version": 3,
    "file": "main-uglified.js",
    "sources": [ "main.js" ],
    "names": [ "define", "greeting", "console", "log" ],
    "mappings": "AAAAA,OAAO,WACH,GAAIC,GAAW,IACfC,SAAQC,IAAIF"
}
@thorn0 thorn0 changed the title Source maps: the name attribute is always empty Source maps: the names attribute is always empty Apr 19, 2014
@jrburke
Copy link
Member

jrburke commented Apr 30, 2014

For me, source map support in browsers is really rough, not very consistent. So it is hard for me to justify debugging these issues. I am open to someone else investigating them though and working out a pull request for it if it is possible. However, for this particular issue, it seems better if the browser is just smarter about the translation, as it has the mapping from source to running code in the source map.

Going to close this because I do not plan on working on it, but I am open to working on a merge if someone else does a pull request.

@jrburke jrburke closed this as completed Apr 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants