描述
Replacing the a in var with a unicode escape of ASCII a (\u0061) yields v\u0061r in place of this keyword.
## Source
print((function () { v\u0061r a = 1; return a; })())
┌─────────────┬──────────────────────────────────────────────────────────┐
│ d8 │ │
│ node │ SyntaxError: Keyword must not contain escaped characters │
├─────────────┼──────────────────────────────────────────────────────────┤
│ sm │ │
│ │ SyntaxError: var is an invalid identifier: │
├─────────────┼──────────────────────────────────────────────────────────┤
│ node-ch │ │
│ ch-2.0 │ SyntaxError: Syntax error │
│ ch-master │ │
└─────────────┴──────────────────────────────────────────────────────────┘
IMO: SM's error is confusing, and our current error is completely useless. v8 has a good error here.
/cc @curtisman @bterlson
Some info to help investigation (line numbers as of commit 3656c42cd750fcd7883e10159a919309abed0046):
With the above repro, try putting a breakpoint in lib\Parser\kwd-swtch.h line 395 (code follows):
case 'v':
if (identifyKwds)
Step through from here and find out how the error is decided, and then determine how we would emit a better error message without hurting performance.
It appears we ultimately return JsErrorScriptCompile from lib\Jsrt\Jsrt.cpp line 2993:
if (scriptFunction == nullptr)
{
PERFORM_JSRT_TTD_RECORD_ACTION_NOT_IMPLEMENTED(scriptContext);
HandleScriptCompileError(scriptContext, &se);
return JsErrorScriptCompile;
}
Basically we know at that point that the script failed to compile, and that's all the information we have. We would need to return a more specific JsError to improve the error message.