Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "fix(es/lints): Disallow reassignment to a class (#6362)"
This reverts commit 3793e83.
- Loading branch information
Showing
11 changed files
with
217 additions
and
124 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
crates/swc/tests/errors/lints/const-assign/3/output.swc-stderr
This file was deleted.
Oops, something went wrong.
99 changes: 87 additions & 12 deletions
99
crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers.1.normal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,88 @@ | ||
//// [assignmentToParenthesizedIdentifiers.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[65:1] | ||
//! 65 | class C { | ||
//! : | | ||
//! : `-- class name | ||
//! 66 | | ||
//! 67 | } | ||
//! 68 | | ||
//! 69 | C = undefined; // Error | ||
//! : ^ | ||
//! `---- | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
var x; | ||
x = 3; // OK | ||
x = 3; // OK | ||
x = ""; // Error | ||
x = ""; // Error | ||
var M; | ||
(function(M) { | ||
var y; | ||
M.y = y; | ||
})(M || (M = {})); | ||
M.y = 3; // OK | ||
M.y = 3; // OK | ||
M.y = 3; // OK | ||
M.y = ""; // Error | ||
M.y = ""; // Error | ||
M.y = ""; // Error | ||
M = { | ||
y: 3 | ||
}; // Error | ||
M = { | ||
y: 3 | ||
}; // Error | ||
var M2; | ||
(function(M2) { | ||
var M3; | ||
(function(M3) { | ||
var x; | ||
M3.x = x; | ||
})(M3 = M2.M3 || (M2.M3 = {})); | ||
M3 = { | ||
x: 3 | ||
}; // Error | ||
})(M2 || (M2 = {})); | ||
M2.M3 = { | ||
x: 3 | ||
}; // OK | ||
M2.M3 = { | ||
x: 3 | ||
}; // OK | ||
M2.M3 = { | ||
x: 3 | ||
}; // OK | ||
M2.M3 = { | ||
x: "" | ||
}; // Error | ||
M2.M3 = { | ||
x: "" | ||
}; // Error | ||
M2.M3 = { | ||
x: "" | ||
}; // Error | ||
function fn() {} | ||
fn = function() { | ||
return 3; | ||
}; // Bug 823548: Should be error (fn is not a reference) | ||
fn = function() { | ||
return 3; | ||
}; // Should be error | ||
function fn2(x, y) { | ||
x = 3; | ||
x = 3; // OK | ||
x = ""; // Error | ||
x = ""; // Error | ||
y.t = 3; // OK | ||
y.t = 3; // OK | ||
y.t = ""; // Error | ||
y.t = ""; // Error | ||
y["t"] = 3; // OK | ||
y["t"] = 3; // OK | ||
y["t"] = 3; // OK | ||
y["t"] = ""; // Error | ||
y["t"] = ""; // Error | ||
y["t"] = ""; // Error | ||
} | ||
var E; | ||
(function(E) { | ||
E[E["A"] = 0] = "A"; | ||
})(E || (E = {})); | ||
E = undefined; // Error | ||
E = undefined; // Error | ||
var C = function C() { | ||
"use strict"; | ||
_class_call_check(this, C); | ||
}; | ||
C = undefined; // Error | ||
C = undefined; // Error |
38 changes: 26 additions & 12 deletions
38
crates/swc/tests/tsc-references/assignmentToParenthesizedIdentifiers.2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
//// [assignmentToParenthesizedIdentifiers.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[65:1] | ||
//! 65 | class C { | ||
//! : | | ||
//! : `-- class name | ||
//! 66 | | ||
//! 67 | } | ||
//! 68 | | ||
//! 69 | C = undefined; // Error | ||
//! : ^ | ||
//! `---- | ||
var M, M2, E; | ||
!function(M) { | ||
var y; | ||
M.y = y; | ||
}(M || (M = {})), M.y = 3, M.y = 3, M.y = 3, M.y = "", M.y = "", M.y = "", M = { | ||
y: 3 | ||
}, M = { | ||
y: 3 | ||
}, function(M2) { | ||
var x; | ||
(M2.M3 || (M2.M3 = {})).x = x; | ||
}(M2 || (M2 = {})), M2.M3 = { | ||
x: 3 | ||
}, M2.M3 = { | ||
x: 3 | ||
}, M2.M3 = { | ||
x: 3 | ||
}, M2.M3 = { | ||
x: "" | ||
}, M2.M3 = { | ||
x: "" | ||
}, M2.M3 = { | ||
x: "" | ||
}, function(E) { | ||
E[E.A = 0] = "A"; | ||
}(E || (E = {})), E = void 0, E = void 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
//// [assignments.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[13:1] | ||
//! 13 | class C { } | ||
//! : | | ||
//! : `-- class name | ||
//! 14 | C = null; // Error | ||
//! : ^ | ||
//! `---- | ||
// In this file: | ||
// Assign to a module | ||
// Assign to a class | ||
// Assign to an enum | ||
// Assign to a function | ||
// Assign to a variable | ||
// Assign to a parameter | ||
// Assign to an interface | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
M = null; // Error | ||
var C = function C() { | ||
"use strict"; | ||
_class_call_check(this, C); | ||
}; | ||
C = null; // Error | ||
var E; | ||
(function(E) { | ||
E[E["A"] = 0] = "A"; | ||
})(E || (E = {})); | ||
E = null; // Error | ||
E.A = null; // OK per spec, Error per implementation (509581) | ||
function fn() {} | ||
fn = null; // Should be error | ||
var v; | ||
v = null; // OK | ||
function fn2(p) { | ||
p = null; // OK | ||
} | ||
I = null; // Error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
//// [assignments.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[13:1] | ||
//! 13 | class C { } | ||
//! : | | ||
//! : `-- class name | ||
//! 14 | C = null; // Error | ||
//! : ^ | ||
//! `---- | ||
var E; | ||
M = null, function(E) { | ||
E[E.A = 0] = "A"; | ||
}(E || (E = {})), (E = null).A = null, I = null; |
35 changes: 25 additions & 10 deletions
35
crates/swc/tests/tsc-references/invalidUndefinedAssignments.1.normal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
//// [invalidUndefinedAssignments.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[7:1] | ||
//! 7 | class C { foo: string } | ||
//! : | | ||
//! : `-- class name | ||
//! 8 | var f: C; | ||
//! 9 | C = x; | ||
//! : ^ | ||
//! `---- | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
var x; | ||
var E; | ||
(function(E) { | ||
E[E["A"] = 0] = "A"; | ||
})(E || (E = {})); | ||
E = x; | ||
E.A = x; | ||
var C = function C() { | ||
"use strict"; | ||
_class_call_check(this, C); | ||
}; | ||
var f; | ||
C = x; | ||
var g; | ||
g = x; | ||
I = x; | ||
var M; | ||
(function(M) { | ||
var x = M.x = 1; | ||
})(M || (M = {})); | ||
M = x; | ||
function i(a) {} | ||
// BUG 767030 | ||
i = x; |
14 changes: 4 additions & 10 deletions
14
crates/swc/tests/tsc-references/invalidUndefinedAssignments.2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
//// [invalidUndefinedAssignments.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[7:1] | ||
//! 7 | class C { foo: string } | ||
//! : | | ||
//! : `-- class name | ||
//! 8 | var f: C; | ||
//! 9 | C = x; | ||
//! : ^ | ||
//! `---- | ||
var x, E, M; | ||
!function(E) { | ||
E[E.A = 0] = "A"; | ||
}(E || (E = {})), (E = x).A = x, I = x, (M || (M = {})).x = 1, M = x; |
43 changes: 32 additions & 11 deletions
43
crates/swc/tests/tsc-references/validNullAssignments.1.normal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
//// [validNullAssignments.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[12:1] | ||
//! 12 | class C { foo: string } | ||
//! : | | ||
//! : `-- class name | ||
//! 13 | var f: C; | ||
//! 14 | f = null; // ok | ||
//! 15 | C = null; // error | ||
//! : ^ | ||
//! `---- | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
var a = null; | ||
var b = null; | ||
var c = null; | ||
var d = null; | ||
var e = null; | ||
e = null; // ok | ||
var E; | ||
(function(E) { | ||
E[E["A"] = 0] = "A"; | ||
})(E || (E = {})); | ||
E.A = null; // error | ||
var C = function C() { | ||
"use strict"; | ||
_class_call_check(this, C); | ||
}; | ||
var f; | ||
f = null; // ok | ||
C = null; // error | ||
var g; | ||
g = null; // ok | ||
I = null; // error | ||
var M; | ||
(function(M) { | ||
var x = M.x = 1; | ||
})(M || (M = {})); | ||
M = null; // error | ||
var h = null; | ||
function i(a) { | ||
a = null; | ||
} | ||
i = null; // error |
15 changes: 4 additions & 11 deletions
15
crates/swc/tests/tsc-references/validNullAssignments.2.minified.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,5 @@ | ||
//// [validNullAssignments.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[12:1] | ||
//! 12 | class C { foo: string } | ||
//! : | | ||
//! : `-- class name | ||
//! 13 | var f: C; | ||
//! 14 | f = null; // ok | ||
//! 15 | C = null; // error | ||
//! : ^ | ||
//! `---- | ||
var E, M; | ||
!function(E) { | ||
E[E.A = 0] = "A"; | ||
}(E || (E = {})), E.A = null, I = null, (M || (M = {})).x = 1, M = null; |
Oops, something went wrong.