Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/lints): Revert check for reassignment to classes (#6472)
**Related issue:** - Closes #6471.
- Loading branch information
Showing
11 changed files
with
221 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 |
39 changes: 27 additions & 12 deletions
39
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,28 @@ | ||
//// [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; | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
!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,6 @@ | ||
//// [assignments.ts] | ||
//! | ||
//! x cannot reassign to a class | ||
//! ,-[13:1] | ||
//! 13 | class C { } | ||
//! : | | ||
//! : `-- class name | ||
//! 14 | C = null; // Error | ||
//! : ^ | ||
//! `---- | ||
var E; | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
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; |
15 changes: 5 additions & 10 deletions
15
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,6 @@ | ||
//// [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; | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
!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 |
16 changes: 5 additions & 11 deletions
16
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,6 @@ | ||
//// [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; | ||
import _class_call_check from "@swc/helpers/src/_class_call_check.mjs"; | ||
!function(E) { | ||
E[E.A = 0] = "A"; | ||
}(E || (E = {})), E.A = null, I = null, (M || (M = {})).x = 1, M = null; |
Oops, something went wrong.
ca20d94
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark
es/full/bugs-1
356249
ns/iter (± 20407
)349469
ns/iter (± 26789
)1.02
es/full/minify/libraries/antd
1967249276
ns/iter (± 33762456
)1876656822
ns/iter (± 56033831
)1.05
es/full/minify/libraries/d3
441578998
ns/iter (± 12787212
)404384040
ns/iter (± 21025219
)1.09
es/full/minify/libraries/echarts
1652005840
ns/iter (± 66816973
)1608705814
ns/iter (± 84598762
)1.03
es/full/minify/libraries/jquery
111068792
ns/iter (± 2939161
)106647129
ns/iter (± 4016188
)1.04
es/full/minify/libraries/lodash
126814501
ns/iter (± 4359175
)117891899
ns/iter (± 7177772
)1.08
es/full/minify/libraries/moment
63398303
ns/iter (± 1607889
)59007063
ns/iter (± 2215825
)1.07
es/full/minify/libraries/react
21626929
ns/iter (± 485647
)21631361
ns/iter (± 1280464
)1.00
es/full/minify/libraries/terser
349011734
ns/iter (± 8723158
)315809725
ns/iter (± 20152727
)1.11
es/full/minify/libraries/three
574172952
ns/iter (± 16393970
)560806557
ns/iter (± 39506166
)1.02
es/full/minify/libraries/typescript
3504142555
ns/iter (± 79780212
)3427217507
ns/iter (± 62591104
)1.02
es/full/minify/libraries/victory
859214656
ns/iter (± 17077181
)835004104
ns/iter (± 25292111
)1.03
es/full/minify/libraries/vue
161046298
ns/iter (± 18571293
)156789506
ns/iter (± 33803224
)1.03
es/full/codegen/es3
33727
ns/iter (± 1997
)35363
ns/iter (± 2463
)0.95
es/full/codegen/es5
33643
ns/iter (± 1049
)34630
ns/iter (± 1842
)0.97
es/full/codegen/es2015
33871
ns/iter (± 2679
)34506
ns/iter (± 4392
)0.98
es/full/codegen/es2016
33733
ns/iter (± 1040
)34684
ns/iter (± 1140
)0.97
es/full/codegen/es2017
33797
ns/iter (± 1415
)34941
ns/iter (± 2274
)0.97
es/full/codegen/es2018
33683
ns/iter (± 1273
)34982
ns/iter (± 2754
)0.96
es/full/codegen/es2019
33604
ns/iter (± 1101
)34067
ns/iter (± 1119
)0.99
es/full/codegen/es2020
33677
ns/iter (± 1295
)34735
ns/iter (± 3145
)0.97
es/full/all/es3
192760212
ns/iter (± 8549033
)203149043
ns/iter (± 17675770
)0.95
es/full/all/es5
181547060
ns/iter (± 7814260
)194456614
ns/iter (± 15624268
)0.93
es/full/all/es2015
144928381
ns/iter (± 5724679
)154106465
ns/iter (± 14656696
)0.94
es/full/all/es2016
144712013
ns/iter (± 4750282
)154841236
ns/iter (± 10726170
)0.93
es/full/all/es2017
143166350
ns/iter (± 5142770
)152833698
ns/iter (± 10249986
)0.94
es/full/all/es2018
144221626
ns/iter (± 6971256
)152184171
ns/iter (± 9003410
)0.95
es/full/all/es2019
142035801
ns/iter (± 9576906
)152409785
ns/iter (± 62782543
)0.93
es/full/all/es2020
137723243
ns/iter (± 8606557
)147463031
ns/iter (± 13557910
)0.93
es/full/parser
708888
ns/iter (± 34921
)774906
ns/iter (± 51842
)0.91
es/full/base/fixer
26381
ns/iter (± 2148
)28208
ns/iter (± 1812
)0.94
es/full/base/resolver_and_hygiene
91731
ns/iter (± 5834
)94926
ns/iter (± 10953
)0.97
serialization of ast node
227
ns/iter (± 8
)224
ns/iter (± 10
)1.01
serialization of serde
229
ns/iter (± 14
)228
ns/iter (± 29
)1.00
This comment was automatically generated by workflow using github-action-benchmark.