Skip to content

Source maps: the names attribute is always empty #672

Closed

Description

@thorn0

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"
}

Activity

  1. changed the title [-]Source maps: the name attribute is always empty[/-] [+]Source maps: the names attribute is always empty[/+] on Apr 19, 2014
  2. jrburke commented on Apr 30, 2014

    @jrburke
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions