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

Duplicate identifier: why should the first test pass? #87

Open
SheepTester opened this issue Aug 4, 2023 · 1 comment
Open

Duplicate identifier: why should the first test pass? #87

SheepTester opened this issue Aug 4, 2023 · 1 comment

Comments

@SheepTester
Copy link

function(){
try {
  eval('var d = function d([d]) { return d };if (d([true]) !== true) return false;');
} catch (e) {
  return !(e instanceof SyntaxError);
}

try {
  eval('var f = function f([id, id]) { return id }');
  return false;
} catch (e) {
  return e instanceof SyntaxError;
}
}

In the first try/catch block, it evaluates several statements with eval. One of the statements has return false; in it, which is a syntax error because the top level of code evaluated by eval isn't a function. Is this intentional?

The line seems to have changed recently in 39a4e84, which seems to have tried to wrap the code in an eval so that the SyntaxError can be caught and returned as false. However, in doing so, it made versions that formerly pass now fail:

39a4e84#diff-360bd21e67071c3b8fd48a96bdadbcee20a6ec434aeffb7cd1a0c528ad1644f2L432-R432

@ljharb
Copy link
Collaborator

ljharb commented Aug 4, 2023

I agree; the part after the var d = statement should be removed from the eval and moved below it.

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