compat-table/node-compat-table

Duplicate identifier: why should the first test pass?

Open

#87 建立於 2023年8月4日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)HTML (34 fork)github user discovery
bughelp wanted

倉庫指標

Star
 (874 star)
PR 合併指標
 (PR 指標待抓取)

描述

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 https://github.com/williamkapke/node-compat-table/commit/39a4e84b716a12273ec6c96276b460660345b742, 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:

https://github.com/williamkapke/node-compat-table/commit/39a4e84b716a12273ec6c96276b460660345b742#diff-360bd21e67071c3b8fd48a96bdadbcee20a6ec434aeffb7cd1a0c528ad1644f2L432-R432

貢獻者指南