Throw a TypeError when reassigning a const (#12252)

This commit is contained in:
Nicolò Ribaudo 2020-10-25 22:30:28 +01:00 committed by GitHub
parent b4ae7b7893
commit a967910b8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 11 additions and 9 deletions

View File

@ -871,7 +871,7 @@ helpers.taggedTemplateLiteralLoose = helper("7.0.0-beta.0")`
helpers.readOnlyError = helper("7.0.0-beta.0")`
export default function _readOnlyError(name) {
throw new Error("\\"" + name + "\\" is read-only");
throw new TypeError("\\"" + name + "\\" is read-only");
}
`;

View File

@ -1,4 +1,4 @@
function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
(function () {
var a = "foo";

View File

@ -1,4 +1,4 @@
function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
var a = 1,
b = 2;

View File

@ -1,4 +1,4 @@
function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
for (var i = 0; i < 3; i = (_readOnlyError("i"), i + 1)) {
console.log(i);

View File

@ -1,4 +1,4 @@
function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
var c = 17;
var a = 0;

View File

@ -1,4 +1,4 @@
function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
var MULTIPLIER = 5;
MULTIPLIER = (_readOnlyError("MULTIPLIER"), "overwrite");

View File

@ -1,4 +1,4 @@
function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
var MULTIPLIER = 5;

View File

@ -1,4 +1,4 @@
function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
var a = "str";
_readOnlyError("a"), --a;

View File

@ -1,4 +1,4 @@
function _readOnlyError(name) { throw new Error("\"" + name + "\" is read-only"); }
function _readOnlyError(name) { throw new TypeError("\"" + name + "\" is read-only"); }
var foo = 1;
_readOnlyError("foo"), foo++;

View File

@ -0,0 +1,2 @@
const a = 1;
expect(() => { a = 2 }).toThrow(TypeError);