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

Document the meaning of the "names" array #6

Open
tromey opened this issue Sep 14, 2017 · 7 comments
Open

Document the meaning of the "names" array #6

tromey opened this issue Sep 14, 2017 · 7 comments

Comments

@tromey
Copy link

tromey commented Sep 14, 2017

All that the spec says about "names" is:

Line 7: A list of symbol names used by the “mappings” entry.

It's never explained what one might use these for.

@jkup
Copy link
Collaborator

jkup commented Sep 22, 2023

It's tough to know what all the "names" field is used for. Variable names, function names, fields. Some of this will improve when we add the function and variable names to the official spec this should be able to be deprecated. It would be great if anyone has interesting current uses for this if they would respond in this ticket.

Otherwise it seems like the best way forward might be to leave this vague, work on adding the new features and then deprecate this?

@jkup
Copy link
Collaborator

jkup commented Sep 22, 2023

  1. There can be unreferenced names in the name section, can tools throw them away?
  2. Can we at least list what the restrictions are / what generators are allowed to put in there?

@jkup
Copy link
Collaborator

jkup commented Jan 10, 2024

Ideally we want to say something like "Ideally function names and variables names are put in this array. " and mention that it's deprecated.

@szuend
Copy link
Collaborator

szuend commented Jan 24, 2024

Chrome DevTools utilizes the "names" array for the following features (if available):

  • To show "authored" variable names in the scope view and to allow expression evaluation with "authored" variable names. Expression evaluation is used widely during debugging, e.g.: evaluating from the console, when hovering over variables in the editor or conditional breakpoints.
  • To resolve function names for stack traces. For this, DevTools checks if the mapping for a function scope's opening paren (() has a name attached* and uses that as the function name.

*A previous version of this comment claimed that it's the opening brace ({) of the scope. This is wrong.

@sjrd
Copy link

sjrd commented Jan 24, 2024

To resolve function names for stack traces. For this, DevTools checks if the mapping for a scope's opening brace ({) has a name attached and uses that as the function name.

That's ... unexpected. How is anyone emitting source map supposed to know they have to target the { for the name entry? Why not the name identifier of the function? (either after the function keywordor whatever identifier gives itsnameproperty to the function, such as invar foo = function() { ... }`)?

@szuend
Copy link
Collaborator

szuend commented Jan 24, 2024

Apologies, I read the code comment too fast this moment. We consider the opening paren (() the start of the scope for a function. This is also the case for var foo = function() {.

Implementation-wise DevTools relies on V8 here and we just take V8's word where the scope is starting (in this case). For var foo = function() { V8 also tells us that the function name is foo since it tries to interfere a name for common cases like this. But we don't have a source position for the foo token itself, so we can't map that and try to look for a name there.

nicolo-ribaudo pushed a commit to nicolo-ribaudo/source-map that referenced this issue Mar 13, 2024
@jkup
Copy link
Collaborator

jkup commented Jun 24, 2024

Some generators have declined to use names because they are under-specified. We should better define what is the expected value when they are referenced from a mapping field. Also, under which circumstances there should be such a reference.

These can be used for unminified identifier name, they can also be the full property expression unminified Object.foo and they can also be {}'s or ()'s so you can specified an unminified function name for whatever code is currently being invoked.

Note: When we come up with our Scopes Expression proposal, it should support code like this:

import f from "f";

export function fn() {
  let obj = { x : 1 };
  return f(obj.x, obj.x);
}

Being compiled to

import r from"f";export function fn(){let t=1;return r(t,t)}

And allow you to debug that obj.x is set to t.

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

No branches or pull requests

5 participants