Skip to content

Commit

Permalink
[[FIX]] Correct error message
Browse files Browse the repository at this point in the history
With the exception of `for..of` and `for..in` heads, constant binding
declarations which lack an initializer are syntactically invalid.
Despite this, the warning emitted for the construction suggests that the
problem lies in runtime behavior. In fact, the constant is not
initialized to any value because the code is never evaluated.

Rephrase the warning to more accurately describe the issue.
  • Loading branch information
jugglinmike authored and rwaldron committed Nov 10, 2022
1 parent fedaf6f commit 03b1a06
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var errors = {

// Constants
E011: "'{a}' has already been declared.",
E012: "const '{a}' is initialized to 'undefined'.",
E012: "Missing initializer for constant '{a}'.",
E013: "Attempting to override '{a}' which is a constant.",

// Regular expressions
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,8 @@ exports.testES6ModulesNamedExportsAffectUnused = function (test) {
];

TestRun(test)
.addError(19, 14, "const 'c1u' is initialized to 'undefined'.")
.addError(19, 19, "const 'c2u' is initialized to 'undefined'.")
.addError(19, 14, "Missing initializer for constant 'c1u'.")
.addError(19, 19, "Missing initializer for constant 'c2u'.")
.test(src1, {
esnext: true,
unused: true
Expand Down Expand Up @@ -2570,15 +2570,15 @@ exports.constWithoutVar = function(test) {

exports.constWithoutInit = function(test) {
TestRun(test, "single binding")
.addError(1, 6, "const 'x' is initialized to 'undefined'.")
.addError(1, 6, "Missing initializer for constant 'x'.")
.test([
"for (const x; ;) {",
" void x;",
"}"
], { esversion: 6 });

TestRun(test, "multiple bindings")
.addError(1, 6, "const 'y' is initialized to 'undefined'.")
.addError(1, 6, "Missing initializer for constant 'y'.")
.test([
"for (const y, z; ;) {",
" void (y, z);",
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2488,11 +2488,11 @@ exports.esnext = function (test) {
];

TestRun(test)
.addError(21, 7, "const 'immutable4' is initialized to 'undefined'.")
.addError(21, 7, "Missing initializer for constant 'immutable4'.")
.test(src, { esnext: true });

TestRun(test)
.addError(21, 7, "const 'immutable4' is initialized to 'undefined'.")
.addError(21, 7, "Missing initializer for constant 'immutable4'.")
.test(src, { moz: true });

TestRun(test)
Expand Down

0 comments on commit 03b1a06

Please sign in to comment.