v11.6.0linux-4.20.arch1-1-ARCH)When attempting to declare a variable with a reserved word as an identifier name, the SyntaxError message thrown will sometimes highlight the wrong token. For example:
'use strict';
let public = 0;
The above code throws the following error:
let public = 0;
^^^
SyntaxError: Unexpected strict mode reserved word
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
However, changing the let to a const throws this error instead:
const public = 0;
^^^^^^
SyntaxError: Unexpected strict mode reserved word
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
Some additional notes about when this happens, in case it helps:
let declarations, not const or varlet or strict, presumably because they're treated differently according to the ECMA spectrue, false, and null, the bug still occurs with a let declaration, but the error message thrown by const and var declarations becomes SyntaxError: Unexpected token instead of SyntaxError: Unexpected strict mode reserved wordThis is likely a V8 bug. /cc @nodejs/v8
@gsathya
Ping @nodejs/v8
Reported on V8 side: https://crbug.com/v8/10649
We need to fix this on our side.
Most helpful comment
Reported on V8 side: https://crbug.com/v8/10649
We need to fix this on our side.