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

Function name can block access to scope vars where frozen by eval() in another function #539

Open
overlookmotel opened this issue Nov 18, 2023 · 0 comments
Labels
bug Something isn't working eval Issue related to `eval`

Comments

@overlookmotel
Copy link
Owner

overlookmotel commented Nov 18, 2023

Input:

let f = function() { return f; };
export default [
  f,
  function(module, exports) { eval('f'); }
];
f = 123;

Output (with mangle option enabled):

const a = (0, eval)(`
  "use strict";
  f=>[
    function f() { return f; },
    function() { eval("f"); }
  ]
`)(123);
export default [a[0], a[1]];

In input, both functions return 123. In output, first function returns itself, because it's been named explicitly in the output, which introduces another binding for f.

Livepack avoids this problem where the eval() is inside the function which is named, but not where the eval() which freezes the external var name is in another function.

Correct output would be:

const a = (0, eval)(`
  "use strict";
  f=>[
    function() { return f; },
    function() { eval("f"); }
  ]
`)(123);
export default [
  Object.defineProperty(a[0], 'name', {value: 'f'}),
  a[1]
];
@overlookmotel overlookmotel added bug Something isn't working eval Issue related to `eval` labels Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working eval Issue related to `eval`
Projects
None yet
Development

No branches or pull requests

1 participant