Skip to content

Syntax error message sometimes highlights the wrong token for reserved words #25359

@talbenari1

Description

@talbenari1
  • Version: v11.6.0
  • Platform: Linux (linux-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:

  • It only occurs in strict mode; non-strict-mode code gets underlined correctly
  • It only occurs with let declarations, not const or var
  • It does not occur with identifier names of let or strict, presumably because they're treated differently according to the ECMA spec
  • For identifiers true, 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 word

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.v8 engineIssues and PRs related to the V8 dependency.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions