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

Current inlining information looses outer scopes of the inlined function #61

Closed
szuend opened this issue Nov 13, 2023 · 2 comments
Closed

Comments

@szuend
Copy link
Collaborator

szuend commented Nov 13, 2023

Live example here: https://szuend.github.io/scope-proposal-examples/05_inline_across_modules/inline_across_modules.html

Given the following example:

module.js

export const MODULE_CONSTANT = 'module_constant';

export class Logger {
  static CLASS_CONSTANT = 42;

  static log(x) {
    console.log(x);
  }
}

inline_across_modules.js

import {Logger} from './module.js';

function inner(x) {
  Logger.log(x);
}

function outer(x) {
  inner(x);
}

outer(42);
outer(null);

with bundle.js

console.log(42);console.log(null);

produced by Closure JS via

google-closure-compiler --compilation_level ADVANCED inline_across_modules.js module.js --js_output_file bundle.min.js --create_source_map bundle.min.js.map --source_map_include_content --language_in UNSTABLE

Lets say we put a breakpoint on the console.log(x) line in module.js. Once we pause we don't have the surrounding scope information of static log(x). E.g. we don't know that the function was inside the Logger class scope, which in turn was in a module scope. We could make MODULE_CONSTANT and CLASS_CONSTANT available via bindings, but a debuggers scope view would have to make it look like those two were defined inside the static log(x) scope.

The only solution I could come up with is to include the scope trees of each original source file as well (similar to how DWARF does it). But I'm curious what folks think.

From a DevTools/debugger perspective this info would be very much needed. Parsing the original sources and constructing a scope tree is not enough (missing bindings info).

@hbenl
Copy link
Collaborator

hbenl commented Nov 23, 2023

I think there's a misunderstanding here: the proposal calls for including all the original scopes containing the original location. So the function scope for log(), the class scope for Logger and the module scope for module.js would be included.
In this example the sourcemap should include the following scopes for the console.log(42); statement:

  • the module scope for inline_across_modules.js
  • the function scope for outer
  • the function scope for inner
  • the function scope for log
  • the class scope for Logger
  • the module scope for module.js

All of these scopes except the module scope for inline_across_modules.js would have to be repeated for the console.log(null); statement, so explicitly encoding original scopes (like in #62) could be more efficient.

@szuend
Copy link
Collaborator Author

szuend commented Nov 27, 2023

Thanks for the clarification! Just to make sure I understand correctly, the nesting of scopes would look like this:

  • the module scope for inline_across_modules.js
    • the function scope for outer
      • the function scope for inner
        • the module scope for module.js (with the "inherit parent bindings" flag set to false)
          • the class scope for Logger
            • the function scope for log
    • the function scope for outer
      • ...

@szuend szuend closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2023
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

2 participants